conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.26k stars 981 forks source link

[question] profile tool-requires not applied as direct requirement #17138

Closed dannera closed 3 weeks ago

dannera commented 1 month ago

Describe the bug

Environment details Operating System+version: n/a Compiler+version: n/a Conan version: 2.8.0 Python version: 3.11

General information We are trying to cross compile a package. Therefore we created two profiles that differ in 'os' and 'arch'. For building we want to use a compiler which is not available on the host system, but required as a tool_requires. Therefore the build profile has the compiler package added in the tool-requires section of the profile.

How to reproduce it

(build) profile-with-tool-requires:

[settings]
os = Windows
arch = x86_64
compiler = tasking-vx
compiler.version = 6.3r1p8
compiler.compiler_variant = carm
build_type = Release
[tool_requires]
tasking-tricore/6.3r1p8

(host) profile-without-tool-requires:

[settings]
os = baremetal
arch = armv6
compiler = tasking-vx
compiler.version = 6.3r1p8
compiler.compiler_variant = carm
build_type = Release

Build command: conan create . -pr:b=<profile-with-tool-requires> -pr:h=<profile-without-tool-requires>

The tool-requires package will be shown as skipped binary. The package cannot be build, because the compiler cannot be found.

Expected behaviour We were expecting the tool-require from the profile to be added to the complete dependency graph as stated here (https://github.com/conan-io/conan/issues/14300#issuecomment-1663476092).

Actual behaviour

The tool-require is added as a dependency to the build_requirements of the root package, but not as a direct dependency of the root package itself

memsharded commented 1 month ago

Hi @dannera

Thanks for your report.

I think there might be some misunderstanding. The tool_requires should go to the "host" profile, not to the "build" profile. The meaning is:

I hope this clarify the issue, please try that and let me know.

dannera commented 1 month ago

Thanks for the fast feedback. We tried to add the tool requires to the host profile:

[settings]
os = baremetal
arch = armv6
compiler = tasking-vx
compiler.version = 6.3r1p8
compiler.compiler_variant = carm
build_type = Release
[tool_requires]
tasking-tricore/6.3r1p8

Building now works as expected, however we get an issue when using the same profile for installing on the host machine. Obviously the compiler package isn't available for the respective settings. This is how we install the package:

conan install --requires=my_package -pr:b=<host-profile-with-tool-requires> -pr:h=<host-profile-with-tool-requires>

Does that mean we need effectively 3 profiles?

  1. Build profile for the build environment (e.g. windows)
  2. Host profile including the tool requires (Used when building the package)
  3. Host profile without the tool requires (Used when consuming the package)

Alternatively: Is there some command that allows the installation to only consider the host environment and thus ignores any tool_requires?

memsharded commented 1 month ago

Building now works as expected,

Great

Does that mean we need effectively 3 profiles?

No, this shouldn't be necessary, you can use the same host profile both for building the package and consuming the package.

In both cases it should be:

conan create . -pr:b=<build-profile-without-tool-requires> -pr:h=<host-profile-with-tool-requires>
conan install --requires=mypkg/version -pr:b=<build-profile-without-tool-requires> -pr:h=<host-profile-with-tool-requires>

You shouldn't really use the host-profile as -pr:b for the build context.

Note the tool_requires in the "host" profile might not download the package binary (the heavy part) if it is not really needed to build, only the recipe will be downloaded while computing the graph, but that is very fast, and the binary will be marked as "skip" and not downloaded.

dannera commented 1 month ago

Ok, thanks for your answers. The proposed code works now.

One remark regarding the build profile on the host machine: It's a bit unconvenient to provide the original build profile if one only wants to install the binaries without building. The original build profile of a package might not be known to the consumer of a package. Additionally I assume the only information used is for installing the tool requires - which are skipped in this case. So basically none of the build profile information is actually used, is this correct?

memsharded commented 1 month ago

One remark regarding the build profile on the host machine: It's a bit unconvenient to provide the original build profile if one only wants to install the binaries without building. The original build profile of a package might not be known to the consumer of a package.

Sometimes it is true, sometimes it might not be the case. In general, the "build" profile is irrelevant when packages are already built, so in fact using a very simple "build" profile, maybe with the os/arch settings only might be enough for many cases.

But Conan also allows to have "tool_requires" affect the package_id of the consumers. While this is not a common case, when it happens it means that the packages in the "build" context must be known to compute the right package_id for the packages in the "host" context. Even if the "build" context packages are not necessary and are not actually downloaded, their "identity" must be known in order to compute which "host" packages are to be downloaded, and in that case, the "build" profile might be relevant too.

Additionally I assume the only information used is for installing the tool requires - which are skipped in this case. So basically none of the build profile information is actually used, is this correct?

Yes, in most cases this is true (except the case commented above), you can use a very simple "build" profile, or typically the Conan auto detected one (default), which is already the default when not being explicitly specified.

memsharded commented 3 weeks ago

Hi @dannera

Did you check my last comment? Any further question? Thanks for your feedback.

dannera commented 3 weeks ago

Hi @memsharded, everythings clear now. I have no further questions. Thanks for your answers and your support!

memsharded commented 3 weeks ago

Happy to help!