Closed
Description
I have cross-compilation from Linux to macOS set up for a project. cc
1.2.12 omits the --target
argument, which Clang (currently using 18.1.8) doesn't like.
Minimum reproducible example with a dummy project:
$ export CARGO_TARGET_AARCH64_APPLE_DARWIN_RUSTFLAGS="-C linker=clang -C link-arg=--target=aarch64-apple-darwin -C link-arg=-fuse-ld=lld"
$ cargo new hello
$ cd hello
$ cargo add bzip2
$ cargo build --target aarch64-apple-darwin
This fails with:
cargo:warning=clang: error: unsupported option '-arch' for target 'aarch64-unknown-linux-gnu'
cargo:warning=clang: warning: argument unused during compilation: '-mmacosx-version-min=11.0' [-Wunused-command-line-argument]
--- stderr
error occurred in cc-rs: Command LC_ALL="C" "clang" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-gdwarf-2" "-fno-omit-frame-pointer" "-arch" "arm64" "-mmacosx-version-min=11.0" "-I" "bzip2-1.0.8" "-D_FILE_OFFSET_BITS=64" "-DBZ_NO_STDIO" "-o" "/tmp/hello/target/aarch64-apple-darwin/debug/build/bzip2-sys-9c6e283515f24e27/out/lib/a9dc8ba631b1466a-blocksort.o" "-c" "bzip2-1.0.8/blocksort.c" with args clang did not execute successfully (status code exit status: 1).
Click for full output
root@ac6839d585fb:/tmp# curl -L "https://github.com/phracker/MacOSX-SDKs/releases/download/11.0-11.1/MacOSX11.0.sdk.tar.xz" | tar xJ -C /opt
root@ac6839d585fb:/tmp# export SDKROOT=/opt/MacOSX11.0.sdk
root@ac6839d585fb:/tmp# export CARGO_TARGET_AARCH64_APPLE_DARWIN_RUSTFLAGS="-C linker=clang -C link-arg=--target=aarch64-apple-darwin -C link-arg=-fuse-ld=lld"
root@ac6839d585fb:/tmp# rustc --version
rustc 1.84.1 (e71f9a9a9 2025-01-27)
root@ac6839d585fb:/tmp# clang --version
clang version 18.1.8 (http://git.linaro.org/toolchain/jenkins-scripts.git e5def089cd9f5aa71524f82fef301ca66eaa38d2)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/llvm/18.1.8/bin
root@ac6839d585fb:/tmp# cargo new hello
Creating binary (application) `hello` package
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
root@ac6839d585fb:/tmp# cd hello
root@ac6839d585fb:/tmp/hello# cargo add bzip2
Updating crates.io index
Adding bzip2 v0.5.0 to dependencies
Features:
- libbz2-rs-sys
- static
Updating crates.io index
Locking 6 packages to latest compatible versions
root@ac6839d585fb:/tmp/hello# cargo build --target aarch64-apple-darwin
Compiling shlex v1.3.0
Compiling pkg-config v0.3.31
Compiling libc v0.2.169
Compiling cc v1.2.12
Compiling bzip2-sys v0.1.11+1.0.8
warning: bzip2-sys@0.1.11+1.0.8: clang: error: unsupported option '-arch' for target 'aarch64-unknown-linux-gnu'
warning: bzip2-sys@0.1.11+1.0.8: clang: warning: argument unused during compilation: '-mmacosx-version-min=11.0' [-Wunused-command-line-argument]
error: failed to run custom build command for `bzip2-sys v0.1.11+1.0.8`
Caused by:
process didn't exit successfully: `/tmp/hello/target/debug/build/bzip2-sys-a1f70d461238d3ac/build-script-build` (exit status: 1)
--- stdout
cargo:rerun-if-env-changed=BZIP2_NO_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_aarch64-apple-darwin
cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_aarch64_apple_darwin
cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_ALLOW_CROSS
cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS
cargo:rerun-if-env-changed=PKG_CONFIG_aarch64-apple-darwin
cargo:rerun-if-env-changed=PKG_CONFIG_aarch64_apple_darwin
cargo:rerun-if-env-changed=TARGET_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64-apple-darwin
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64_apple_darwin
cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_SYSROOT_DIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
OPT_LEVEL = Some(0)
TARGET = Some(aarch64-apple-darwin)
HOST = Some(aarch64-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(clang)
cargo:rerun-if-env-changed=CC_KNOWN_WRAPPER_CUSTOM
CC_KNOWN_WRAPPER_CUSTOM = None
RUSTC_WRAPPER = None
cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT
cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some(true)
cargo:rerun-if-env-changed=MACOSX_DEPLOYMENT_TARGET
MACOSX_DEPLOYMENT_TARGET = None
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_ENCODED_RUSTFLAGS = Some(-Clinker=clang-Clink-arg=--target=aarch64-apple-darwin-Clink-arg=-fuse-ld=lld)
cargo:warning=clang: error: unsupported option '-arch' for target 'aarch64-unknown-linux-gnu'
cargo:warning=clang: warning: argument unused during compilation: '-mmacosx-version-min=11.0' [-Wunused-command-line-argument]
--- stderr
error occurred in cc-rs: Command LC_ALL="C" "clang" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-gdwarf-2" "-fno-omit-frame-pointer" "-arch" "arm64" "-mmacosx-version-min=11.0" "-I" "bzip2-1.0.8" "-D_FILE_OFFSET_BITS=64" "-DBZ_NO_STDIO" "-o" "/tmp/hello/target/aarch64-apple-darwin/debug/build/bzip2-sys-9c6e283515f24e27/out/lib/a9dc8ba631b1466a-blocksort.o" "-c" "bzip2-1.0.8/blocksort.c" with args clang did not execute successfully (status code exit status: 1).
It works when downgrading cc
to 1.2.11:
root@ac6839d585fb:/tmp/hello# cargo update -p cc --precise 1.2.11
Updating crates.io index
Downgrading cc v1.2.12 -> v1.2.11
root@ac6839d585fb:/tmp/hello# cargo build --target aarch64-apple-darwin
Downloaded cc v1.2.11
Downloaded 1 crate (102.0 KB) in 0.13s
Compiling cc v1.2.11
Compiling bzip2-sys v0.1.11+1.0.8
Compiling bzip2 v0.5.0
Compiling hello v0.1.0 (/tmp/hello)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.80s
I can work around by adding --target=aarch64-apple-darwin
to CFLAGS_aarch64_apple_darwin
.