Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross compile from x86_64-unknown-linux-gnu to aarch64-apple-darwin fails #679

Open
kcalvinalvin opened this issue Feb 3, 2024 · 3 comments

Comments

@kcalvinalvin
Copy link

I came across this error and wanted to document it here in case it's of help. I was compiling bdk which also compiles secp256k1-sys and when trying to cross-compile to aarch64-apple-darwin from x86_64-unknown-linxu-gnu, compilation fails with gcc: error: unrecognized command-line option ‘-arch’.

This stackoverflow answer suggests that -arch is only for gcc with xcode, which means I wouldn't be able to cross-compile.

Below is the full error log I got:

[I] calvin@bitcoin ~/b/r/r/utreexod (main)> cargo build --release --target=aarch64-apple-darwin                                                                                                                                                                                                              
   Compiling secp256k1-sys v0.8.1                                                                                                                                                                                                                                                                            
   Compiling bip39 v2.0.0                                                                                                                                                                                                                                                                                    
   Compiling weedle2 v4.0.0                                                                                                                                                                                                                                                                                  
   Compiling uniffi v0.25.0                                                                                                                                                                                                                                                                                  
The following warnings were emitted during compilation:                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                                                                             
warning: gcc: error: unrecognized command-line option ‘-arch’                                                                                                                                                                                                                                                
warning: gcc: error: unrecognized command-line option ‘-arch’                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                                             
error: failed to run custom build command for `secp256k1-sys v0.8.1`                                                                                                                                                                                                                                         
                                                                                                                                                                                                                                                                                                             
Caused by:                                                                                                                                                                                                                                                                                                   
  process didn't exit successfully: `/home/calvin/bitcoin-projects/rust/rustup/utreexod/target/release/build/secp256k1-sys-678d711ae927d0b8/build-script-build` (exit status: 1)                                                                                                                             
  --- stdout                                                                                                                                                                                                                                                                                                 
  TARGET = Some("aarch64-apple-darwin")                                                                                                                                                                                                                                                                      
  OPT_LEVEL = Some("3")                                                                                                                                                                                                                                                                                      
  HOST = Some("x86_64-unknown-linux-gnu")                                                                                                                                                                                                                                                                    
  cargo:rerun-if-env-changed=CC_aarch64-apple-darwin                                                                                                                                                                                                                                                         
  CC_aarch64-apple-darwin = None                                                                                                                                                                                                                                                                             
  cargo:rerun-if-env-changed=CC_aarch64_apple_darwin                                                                                                                                                                                                                                                         
  CC_aarch64_apple_darwin = None                                                                                                                                                                                                                                                                             
  cargo:rerun-if-env-changed=TARGET_CC                                                                                                                                                                                                                                                                       
  TARGET_CC = None                                                                                                                                                                                                                                                                                           
  cargo:rerun-if-env-changed=CC                                                                                                                                                                                                                                                                              
  CC = Some("gcc")                                                                                                                                                                                                                                                                                           
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS                                                                                                                                                                                                                                                            
  CRATE_CC_NO_DEFAULTS = None                                                                                                                                                                                                                                                                                
  DEBUG = Some("false")                                                                                                                                                                                                                                                                                      
  CARGO_CFG_TARGET_FEATURE = Some("aes,crc,dit,dotprod,dpb,dpb2,fcma,fhm,flagm,fp16,frintts,jsconv,lor,lse,neon,paca,pacg,pan,pmuv3,ras,rcpc,rcpc2,rdm,sb,sha2,sha3,ssbs,vh")                                                                                                                                
  cargo:rerun-if-env-changed=CFLAGS_aarch64-apple-darwin                                                                                                                                                                                                                                                     
  CFLAGS_aarch64-apple-darwin = None                                                                                                                                                                                                                                                                         
  cargo:rerun-if-env-changed=CFLAGS_aarch64_apple_darwin                                                                                                                                                                                                                                                     
  CFLAGS_aarch64_apple_darwin = None                                                                                                                                                                                                                                                                         
  cargo:rerun-if-env-changed=TARGET_CFLAGS                                                                                                                                                                                                                                                                   
  TARGET_CFLAGS = None                                                                                                                                                                                                                                                                                       
  cargo:rerun-if-env-changed=CFLAGS                                                                                                                                                                                                                                                                          
  CFLAGS = None                                                                                                                                                                                                                                                                                              
  cargo:rerun-if-env-changed=CC_aarch64-apple-darwin                                                                                                                                                                                                                                                         
  CC_aarch64-apple-darwin = None                                                                                                                                                                                                                                                                             
  cargo:rerun-if-env-changed=CC_aarch64_apple_darwin                                                                                                                                                                                                                                                         
  CC_aarch64_apple_darwin = None                                                                                                                                                                                                                                                                             
  cargo:rerun-if-env-changed=TARGET_CC                                                                                                                                                                                                                                                                       
  TARGET_CC = None                                                                                                                                                                                                                                                                                           
  cargo:rerun-if-env-changed=CC                                                                                                                                                                                                                                                                              
  CC = Some("gcc")                                                                                                                                                                                                                                                                                           
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS                                                                                                                                                                                                                                                            
  CRATE_CC_NO_DEFAULTS = None                                                                                                                                                                                                                                                                                
  CARGO_CFG_TARGET_FEATURE = Some("aes,crc,dit,dotprod,dpb,dpb2,fcma,fhm,flagm,fp16,frintts,jsconv,lor,lse,neon,paca,pacg,pan,pmuv3,ras,rcpc,rcpc2,rdm,sb,sha2,sha3,ssbs,vh")                                                                                                                                
  cargo:rerun-if-env-changed=CFLAGS_aarch64-apple-darwin                                                                                                                                                                                                                                                     
  CFLAGS_aarch64-apple-darwin = None                                                                                                                                                                                                                                                                         
  cargo:rerun-if-env-changed=CFLAGS_aarch64_apple_darwin                                                                                                                                                                                                                                                     
  CFLAGS_aarch64_apple_darwin = None                                                                                                                                                                                                                                                                         
  cargo:rerun-if-env-changed=TARGET_CFLAGS                                                                                                                                                                                                                                                                   
  TARGET_CFLAGS = None                                                                                                                                                                                                                                                                                       
  cargo:rerun-if-env-changed=CFLAGS                                                                                                                                                                                                                                                                          
  CFLAGS = None                                                                                                                                                                                                                                                                                              
  running: "gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-arch" "arm64" "-I" "depend/secp256k1/" "-I" "depend/secp256k1/include" "-I" "depend/secp256k1/src" "-Wall" "-Wextra" "-DSECP256K1_API=" "-DENABLE_MODULE_ECDH=1" "-DENABLE_MODULE_SCHNORRSIG=1" "-DENABLE_MODULE_EXTRAKEYS=1" "-DECM
ULT_GEN_PREC_BITS=4" "-DECMULT_WINDOW_SIZE=15" "-DUSE_EXTERNAL_DEFAULT_CALLBACKS=1" "-DENABLE_MODULE_RECOVERY=1" "-o" "/home/calvin/bitcoin-projects/rust/rustup/utreexod/target/aarch64-apple-darwin/release/build/secp256k1-sys-0f08fdb2410250b6/out/depend/secp256k1/contrib/lax_der_parsing.o" "-c" "depe
nd/secp256k1/contrib/lax_der_parsing.c"                                                                                                                                                                                                                                                                      
  cargo:warning=gcc: error: unrecognized command-line option ‘-arch’                                                                                                                                                                                                                                         
                                                                                                                                                                                                                                                                                                             
  exit status: 1                                                                                                                                                                                                                                                                                             
  running: "gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-arch" "arm64" "-I" "depend/secp256k1/" "-I" "depend/secp256k1/include" "-I" "depend/secp256k1/src" "-I" "wasm/wasm-sysroot" "-Wall" "-Wextra" "-DSECP256K1_API=" "-DENABLE_MODULE_ECDH=1" "-DENABLE_MODULE_SCHNORRSIG=1" "-DENABLE_M
ODULE_EXTRAKEYS=1" "-DECMULT_GEN_PREC_BITS=4" "-DECMULT_WINDOW_SIZE=15" "-DUSE_EXTERNAL_DEFAULT_CALLBACKS=1" "-DENABLE_MODULE_RECOVERY=1" "-o" "/home/calvin/bitcoin-projects/rust/rustup/utreexod/target/aarch64-apple-darwin/release/build/secp256k1-sys-0f08fdb2410250b6/out/depend/secp256k1/contrib/lax_
der_parsing.o" "-c" "depend/secp256k1/contrib/lax_der_parsing.c"                                                                                                                                                                                                                                             
  cargo:warning=gcc: error: unrecognized command-line option ‘-arch’                                                                                                                                                                                                                                         
                                                                                                                                                                                                                                                                                                             
  exit status: 1                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                             
  --- stderr                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                               
                                                                                                                                                                                                                                                                               
  error occurred: Command "gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-arch" "arm64" "-I" "depend/secp256k1/" "-I" "depend/secp256k1/include" "-I" "depend/secp256k1/src" "-I" "wasm/wasm-sysroot" "-Wall" "-Wextra" "-DSECP256K1_API=" "-DENABLE_MODULE_ECDH=1" "-DENABLE_MODULE_SCHNORRSIG
=1" "-DENABLE_MODULE_EXTRAKEYS=1" "-DECMULT_GEN_PREC_BITS=4" "-DECMULT_WINDOW_SIZE=15" "-DUSE_EXTERNAL_DEFAULT_CALLBACKS=1" "-DENABLE_MODULE_RECOVERY=1" "-o" "/home/calvin/bitcoin-projects/rust/rustup/utreexod/target/aarch64-apple-darwin/release/build/secp256k1-sys-0f08fdb2410250b6/out/depend/secp256
k1/contrib/lax_der_parsing.o" "-c" "depend/secp256k1/contrib/lax_der_parsing.c" with args "gcc" did not execute successfully (status code exit status: 1).                       
@Kixunil
Copy link
Collaborator

Kixunil commented Feb 3, 2024

Sounds like this is a problem with the cc crate, would you mind reporting to them?

@elichai
Copy link
Member

elichai commented Feb 4, 2024

I don't think you can easily cross-compile from linux to OSX, their linker tools are proprietery, so even if you plug clang instead of gcc and make it produce the right code you won't be able to produce an executable without their xcode stuff AFAIR

@elichai
Copy link
Member

elichai commented Feb 4, 2024

Maybe you can make this work: https://github.com/tpoechtrager/osxcross

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants