Conan: [feature] Option to set default profile:build and profile:host in conanfile

Created on 15 Feb 2021  路  4Comments  路  Source: conan-io/conan

Summary
Can we get an option to specify a default profile:build and profile:host in the conanfile?

Nice to haves:

  • Allow for profile:build to use a variable for the current architecture (eg, so it will use a linux_x64 profile if you're on a linux_x64 machine)
  • Allow a 'none' value for profile:host, so that the user is forced to enter a value on the commandline.
  • Allow values specified as command line args to override defaults specified in conanfile

Justification:
On firmware projects that require cross-compilation, profile:build is generally going to be the current architecture of the machine the developer is using, and profile:host will almost always be the embedded device architecture (eg, an ARM toolchain).

Given that omitting profile:build and profile:host from the commandline makes significant changes to the build, I feel like this would end up being a common pitfall when getting new developers up to speed on a conan project. I think it would be less confusing if I could specify default values in the conanfile, but still be able to override them as needed.

triaging question

All 4 comments

Hi @grantfreese

This has been discussed before (wanting to default settings, for example), and while it might seem convenient, it is not the best approach. It is better and more scalable and cleaner to have the configuration (profile) decoupled from the definition (recipe).

The way this will evolve is that the profile:build will also be defaulted, in the same way the host one is defaulted now, using always the build-host context approach. This has not been done yet because it would be breaking for many users, but it will be changed for Conan 2.0 (we have already started working in it). So there will be no need to do it in recipes.

Marking this as Conan 2.0, should be closed when --profile:build is defaulted too.

@memsharded I have a question that might be related to that issue. Older cmake_installer packages used os_build and arch_build settings so one binary package was enough for 4 builds (Windows x86_64/Release, x86_64/Debug, x86/Release, x86/Debug). Newer cmake packages depends on os and arch so I need 4 different packages (and 2 of them I have to build from sources as x86 builds are wiped out from conan-center). --profile:build seems not an option as 1) conan-package-tools do not support it 2) it seems to affect all build requires that in my case are often host-context libraries.

Is it possible to set build context for one specific package (or group of packages) globally? I would like to have in default profile

[build_requires]
*:cmake/3.19.1 

and something that instructs conan to use one cmake x86_64/Release binary for everything.

I'm pretty novice on the cross-build implications. Would it work to add this to the settings of your build_profile?

    [settings]
    cmake:arch=x86_64
    cmake:build_type=Release

@solvingj I never knew that settings could be specified this way for individual packages. That's exactly what I need, thanks a lot!

Was this page helpful?
0 / 5 - 0 ratings