conan-io / conan

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

Cross compiling macos x86_64 library on macos arm64 - what is best practice #16585

Open bldrvnlw opened 3 days ago

bldrvnlw commented 3 days ago

What is your question?

Hi! I'm using the latest macos arm64 images on github actions and we are still supporting x86_64. Therefore cross-compiling from arm to the x86_64 target.

Am I correct in thinking that the recommended way to cross-compiler to x86_64 on an arm macos is as follows:

  1. Install python universal
  2. Install conan using arch -x86_64 python -m pip
  3. Create the correct x86_64 profiles
  4. arch -x86_64 conan build with the x86_64 profiles.

This approach is implied in #15892 and in #15973. Should it be considered/documented as the best practice for cross-compiling?

An additional question: will using the Brew (from _SystemPackageManagerTool) in this x86_64 python context also result in brew installing x86_64 binaries? For example for libomp?

bldrvnlw commented 3 days ago

Testing locally :

arm test

arch -arm64 conan profile detect                   
detect_api: Found apple-clang 15.0
detect_api: apple-clang>=13, using the major as version

Detected profile:
[settings]
arch=armv8
build_type=Release
compiler=apple-clang
compiler.cppstd=gnu17
compiler.libcxx=libc++
compiler.version=15
os=Macos

x86_64 test

arch -x86_64 conan profile detect -f
detect_api: Found apple-clang 15.0
detect_api: apple-clang>=13, using the major as version

Detected profile:
[settings]
arch=x86_64
build_type=Release
compiler=apple-clang
compiler.cppstd=gnu17
compiler.libcxx=libc++
compiler.version=15
os=Macos
AbrilRBS commented 2 days ago

Hi @bldrvnlw thanks a lot for taking the time to sumbit your question, we appreciate it. I'm moving this to the main Conan repo as a more general "cross-compilation" question not necessarily limited to CCI :)

memsharded commented 2 days ago

Thanks for your question @bldrvnlw

This approach is implied in https://github.com/conan-io/conan/issues/15892 and in https://github.com/conan-io/conan/issues/15973. Should it be considered/documented as the best practice for cross-compiling?

I am not 100% sure it is really necessary to use the arch -<value> prefix always. Once the profiles are defined, I think you might be able to just use conan build . -pr=myx86_64_profile (assuming the default profile is armv8 with the auto-detection), as Conan does not do any auto-detection while running, and assumes the one from the profile. But I don't know enough about the Apple ecosystem, I'll ping some colleagues to check.

franramirez688 commented 2 days ago

Hi @bldrvnlw

Cross-compiling from ARM to Intel, you don't need to execute it every time. It's enough to know both profiles and save them locally or wherever you want:

arm-profile

[settings]
arch=armv8
build_type=Release
compiler=apple-clang
compiler.cppstd=gnu17
compiler.libcxx=libc++
compiler.version=15
os=Macos

x86-64-profile

[settings]
arch=x86_64
build_type=Release
compiler=apple-clang
compiler.cppstd=gnu17
compiler.libcxx=libc++
compiler.version=15
os=Macos

Building from ARM to Intel: conan build . -pr:h x86-64-profile -pr:b arm-profile