rust-lang / cc-rs

Rust library for build scripts to compile C/C++ code into a Rust library
https://docs.rs/cc
Apache License 2.0
1.77k stars 425 forks source link

x86_64-apple-darwin: unrecognized command line option ‘-arch’ #710

Open wafflespeanut opened 1 year ago

wafflespeanut commented 1 year ago

When I attempted to cross-compile cxx from linux, I got the following emitted from link-cplus-plus dependency, which uses cc-rs:

   Compiling link-cplusplus v1.0.6 (/work/depends/link-cplusplus)
The following warnings were emitted during compilation:

warning: c++: error: x86_64: No such file or directory
warning: c++: error: unrecognized command line option '-arch'; did you mean '-march='?

error: failed to run custom build command for `link-cplusplus v1.0.6 (/work/depends/link-cplusplus)`

Caused by:
  process didn't exit successfully: `/work/depends/link-cplusplus/target/debug/build/link-cplusplus-8998b4e36463b047/build-script-build` (exit status: 1)
  --- stdout
  TARGET = Some("x86_64-apple-darwin")
  OPT_LEVEL = Some("0")
  HOST = Some("x86_64-unknown-linux-gnu")
  CXX_x86_64-apple-darwin = None
  CXX_x86_64_apple_darwin = None
  TARGET_CXX = None
  CXX = None
  CROSS_COMPILE = None
  CXXFLAGS_x86_64-apple-darwin = None
  CXXFLAGS_x86_64_apple_darwin = None
  TARGET_CXXFLAGS = None
  CXXFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2,sse3,ssse3")
  running: "c++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-arch" "x86_64" "-Wall" "-Wextra" "-o" "/work/depends/link-cplusplus/target/x86_64-apple-darwin/debug/build/link-cplusplus-a777ebbad1615f40/out/dummy.o" "-c" "/work/depends/link-cplusplus/target/x86_64-apple-darwin/debug/build/link-cplusplus-a777ebbad1615f40/out/dummy.cc"
  cargo:warning=c++: error: x86_64: No such file or directory
  cargo:warning=c++: error: unrecognized command line option '-arch'; did you mean '-march='?
  exit status: 1

  --- stderr

  error occurred: Command "c++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-arch" "x86_64" "-Wall" "-Wextra" "-o" "/work/depends/link-cplusplus/target/x86_64-apple-darwin/debug/build/link-cplusplus-a777ebbad1615f40/out/dummy.o" "-c" "/work/depends/link-cplusplus/target/x86_64-apple-darwin/debug/build/link-cplusplus-a777ebbad1615f40/out/dummy.cc" with args "c++" did not execute successfully (status code exit status: 1).

Instead of -arch x86-64, the argument should be -march=x86-64 for darwin target (-march instead of -arch as key-value parameter and Apple target is dashed x86-64 instead of x86_64).

If there's some way to override or work around this, then I'd happily go for that until this issue can be fixed.

dot-asm commented 1 year ago

Can you confirm that you can cross-compile the simplest hello-world Rust snippet on Linux for MacOS? Not that I know it can't ever work, but if I simply add x86_64-apple-darwin target and try to compile "hello, world", I get error messages similar to yours. This suggests that you might have also attempted simply adding the target. And from what I do know, those error message are not unexpected. And even if I tweak my environment to bypass the -arch error, I'll face even more serious problems later on.

As a general rule of thumb. In most common, all non-bare-metal really, cases it's user's responsibility to provide working cross-compiling environment that actually meets specific expectations. Even for compiling pure Rust code, let alone mixed one. This is because even pure Rust relies on C toolchain to link the final application.