conan-io / conan

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

[bug] Cross compilation detection when build/host arch/os matches but not other parameters #14134

Open vithalsm opened 1 year ago

vithalsm commented 1 year ago

Environment details

Steps to reproduce

Setup: Build machine os/arch - Linux/ x86_64 Host machine os/arch - Linux/ x86_64 Let other config settings in conan profile like libc, compiler version be different.

Now, when the project conan receipe adds libs, say libev for example as dependency and exepects it to be built with host tool chains and also detect it as 'cross compilation', build for libev (in this example) fails. Reason, '--host' is not passed to configure script (conanbuild.sh).

There are quite a few tickets raised here and have varying solutions. Mostly requires, forking 'libev' source code and making changes to its recipe to manually update with options like '--host'. But, problem here is not with libev alone, but many.

Further investigating, found that, AutotoolsToolChain() which generates the 'configure command with options', doesn't detect it to be 'cross-compiling' as it compares arch/os of build and hosts. Ignores 'vendor' option.

Yes, 'vendor' option can be optional, but needs to be internally calculated as like config.guess does and compared. Even, API to generate triplet misses the 'vendor' field.

However, setting tools.gnu:host_triplet under [conf] section in conan profile solves the problem, as it properly generates the triplet.

Instead of setting complete triplet at profile, can consider setting 'os.vendor' in conan profile and gen_triplet API of auto tool chain can use same and also in comparison to check whether being cross compiled (just generating triplet n comparing may suffice).

This should globally solve the problems that are being hit in multiple cases.

Logs

No response

memsharded commented 1 year ago

Hi @vithalsm

Thanks for your comments.

It would be necessary to narrow the scope, and have something reproducible, with real code, that we can all reproduce and agree on the behavior. I suggest starting with the conan new autotools_lib -d name=pkg -d version=0.1 template, as I understand that we are talking mostly about autotools, and then we want to check the AutotoolsToolchain behavior.

Then, it would be necessary to clearly define the profiles. If both build and host have the same os and arch why would it be considered cross-building? It is not fully clear what are the configurations of compilers and build. You comment about a os.vendor new setting, can you please elaborate a bit further about this new setting? What would be the values for it to define in the settings.yml file for all Conan users? If you can also detail the exact triplet that you are providing in the profile, that is also useful information.

vithalsm commented 1 year ago

Hi @memsharded thanks for the response. Here are the details on build/host (target) profiles, highlighting the differences.

======== Input profiles ======== Profile host: [settings] arch=x86_64 build_type=Release compiler=gcc compiler.libc=glibc compiler.libc.version=2.34 compiler.libcxx=libstdc++ compiler.version=10.3 os=Linux os.version=4.14.188 [conf] tools.build:sysroot=/usr/bandol-sysroot tools.build:skip_test=True tools.cmake.cmake_layout:build_folder_vars=['settings.os.platform'] tools.gnu:host_triplet=x86_64-aruba-linux-gnu [buildenv] ...


Profile build: [settings] arch=x86_64 build_type=Release compiler=gcc compiler.cppstd=gnu14 compiler.libc=glibc compiler.libc.version=2.31 compiler.libcxx=libstdc++11 compiler.version=9 os=Linux os.platform=native os.version=5.15 [conf] tools.cmake.cmake_layout:build_folder_vars=['settings.os.platform']


conanfile.py: requirements() requires("libev/4.33") >>>>>> Fails w/ mismatch in libc ver, as it doesn't detect cross-comp and tries to test compile

How I solved it?? By setting the triplet in the profile: [conf] tools.gnu:host_triplet=x86_64-xxxx-linux-gnu

In the above triplet, 'xxxx' is the vendor field which is being ignored when conan generates the triplets. config.guess auto generates this based on arch/os like.. 'pc', 'unknown' etc.

So, instead of setting the complete triplet, if optional profile variable 'os.vendor' can be introduced and used to construct the triplet, existing conan code to detect the cross compilation would work fine.

os.vendor can have default of 'unknown' unless overridden by the profile.