10XGenomics / lz4-rs

Rust LZ4 bindings
MIT License
47 stars 27 forks source link

Fail to cross compilation on Linux for Mac #25

Open viirya opened 2 years ago

viirya commented 2 years ago

Hi,

I'm working on cross-compilation of a project on Linux for Mac binaries. Got an error currently:

error: failed to run custom build command for `lz4-sys v1.9.2`

Caused by:
  process didn't exit successfully: `/opt/core/target/release/build/lz4-sys-635d53f76c21d05f/build-script-build` (exit status: 1)
  --- stdout
  TARGET = Some("aarch64-apple-darwin")
  HOST = Some("x86_64-unknown-linux-gnu")
  CC_aarch64-apple-darwin = None
  CC_aarch64_apple_darwin = None
  TARGET_CC = None
  CC = None
  CROSS_COMPILE = None
  CFLAGS_aarch64-apple-darwin = None
  CFLAGS_aarch64_apple_darwin = None
  TARGET_CFLAGS = None
  CFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  CARGO_CFG_TARGET_FEATURE = Some("aes,crc,dit,dotprod,dpb,dpb2,fcma,fhm,flagm,fp16,frintts,jsconv,llvm14-builtins-abi,lor,lse,neon,paca,pacg,pan,pmuv3,ras,rcpc,rcpc2,rdm,sb,sha2,sha3,ssbs,v8.1a,v8.2a,v8.3a,v8.4a,vh")
  running: "cc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-arch" "arm64" "-Wall" "-Wextra" "-o" "/opt/core/target/aarch64-apple-darwin/release/build/lz4-sys-6a23633e37c16f77/out/liblz4/lib/lz4.o" "-c" "liblz4/lib/lz4.c"
  cargo:warning=cc: error: arm64: No such file or directory
  cargo:warning=cc: error: unrecognized command line option ‘-arch’; did you mean ‘-march=’?
  exit status: 1
  running: "cc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-arch" "arm64" "-Wall" "-Wextra" "-o" "/opt/core/target/aarch64-apple-darwin/release/build/lz4-sys-6a23633e37c16f77/out/liblz4/lib/lz4frame.o" "-c" "liblz4/lib/lz4frame.c"
  cargo:warning=cc: error: arm64: No such file or directory
  cargo:warning=cc: error: unrecognized command line option ‘-arch’; did you mean ‘-march=’?
  exit status: 1

  --- stderr

So based on https://stackoverflow.com/questions/4391192/why-do-i-get-cc1plus-error-unrecognized-command-line-option-arch, seems -arch is only for Xcode's gcc. Not sure if lz4-sys's custom build script is able to make some change to fix that?

viirya commented 2 years ago

After installing osxcross toolchain, x86_64-apple-darwin can be cross-built. But aarch64-apple-darwin still fails with an error:

  = note: ld: in /lz4-rs/target/aarch64-apple-darwin/debug/deps/liblz4_sys-8410d92b71c4cdc8.rlib(lz4frame.o), archive member 'lz4frame.o' with length 72128 is not mach-o or llvm bitcode for architecture arm64
          clang-12: error: linker command failed with exit code 1 (use -v to see invocation)