rust-lang / rust-lang/libz-sys
Build fails with `unrecognized command-line option '-arch'` when cross-compiling
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 138
- Forks
- 88
- PR merge metrics
- No merged PRs in 30d
Description
Hi :-)
Has anyone seen anything like this before when cross-compiling on an M1 Mac?
This cross-compile configuration works successfully for a variety of other crates, however this is the first crate I'm using that uses CMake, so I'm not sure if it's a libz-sys specific problem, or with cross-compiling with CMake and this toolchain in general.
Steps to reproduce
brew install messense/macos-cross-toolchains/x86_64-unknown-linux-musl(to install this cross-compile toolchain)brew install cmake(sincelibz-sysrequires it)rustup target add x86_64-unknown-linux-musl- Ensure the new toolchain can be found:
export CC_x86_64_unknown_linux_musl=x86_64-unknown-linux-musl-gcc export CXX_x86_64_unknown_linux_musl=x86_64-unknown-linux-musl-g++ export AR_x86_64_unknown_linux_musl=x86_64-unknown-linux-musl-ar export CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER=x86_64-unknown-linux-musl-gcc cargo new testcase-libz-sys-cross-compile && cd_cargo build --target x86_64-unknown-linux-musl
Expected
The build completes successfully (like it does on this machine, when not cross-compiling).
Actual
The build fails with:
Compiling cc v1.0.73
Compiling pkg-config v0.3.24
Compiling libc v0.2.121
Compiling cmake v0.1.48
Compiling libz-sys v1.1.5
error: failed to run custom build command for `libz-sys v1.1.5`
Caused by:
process didn't exit successfully: `/Users/emorley/src/testcase-libz-sys-cross-compile/target/debug/build/libz-sys-720c0d8a10ea6099/build-script-build` (exit status: 101)
--- stdout
cargo:rerun-if-env-changed=LIBZ_SYS_STATIC
cargo:rerun-if-changed=build.rs
CMAKE_TOOLCHAIN_FILE_x86_64-unknown-linux-musl = None
CMAKE_TOOLCHAIN_FILE_x86_64_unknown_linux_musl = None
TARGET_CMAKE_TOOLCHAIN_FILE = None
CMAKE_TOOLCHAIN_FILE = None
CMAKE_GENERATOR_x86_64-unknown-linux-musl = None
CMAKE_GENERATOR_x86_64_unknown_linux_musl = None
TARGET_CMAKE_GENERATOR = None
CMAKE_GENERATOR = None
CMAKE_PREFIX_PATH_x86_64-unknown-linux-musl = None
CMAKE_PREFIX_PATH_x86_64_unknown_linux_musl = None
TARGET_CMAKE_PREFIX_PATH = None
CMAKE_PREFIX_PATH = None
CMAKE_x86_64-unknown-linux-musl = None
CMAKE_x86_64_unknown_linux_musl = None
TARGET_CMAKE = None
CMAKE = None
running: "cmake" "/Users/emorley/.cargo/registry/src/github.com-1ecc6299db9ec823/libz-sys-1.1.5/src/zlib-ng" "-DBUILD_SHARED_LIBS=OFF" "-DZLIB_COMPAT=ON" "-DWITH_GZFILEOP=ON" "-DCMAKE_INSTALL_PREFIX=/Users/emorley/src/testcase-libz-sys-cross-compile/target/x86_64-unknown-linux-musl/debug/build/libz-sys-2b3ea8f924a72b91/out" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_C_COMPILER=/opt/homebrew/bin/x86_64-unknown-linux-musl-gcc" "-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_CXX_COMPILER=/opt/homebrew/bin/x86_64-unknown-linux-musl-g++" "-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_ASM_COMPILER=/opt/homebrew/bin/x86_64-unknown-linux-musl-gcc" "-DCMAKE_BUILD_TYPE=Debug"
-- Using CMake version 3.22.3
-- ZLIB_HEADER_VERSION: 1.2.11
-- ZLIBNG_HEADER_VERSION: 2.1.0.devel
-- The C compiler identification is GNU 11.2.0
-- Checking whether C compiler has -isysroot
-- Checking whether C compiler has -isysroot - yes
-- Checking whether C compiler supports OSX deployment target flag
-- Checking whether C compiler supports OSX deployment target flag - no
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /opt/homebrew/bin/x86_64-unknown-linux-musl-gcc
-- Check for working C compiler: /opt/homebrew/bin/x86_64-unknown-linux-musl-gcc - broken
-- Configuring incomplete, errors occurred!
See also "/Users/emorley/src/testcase-libz-sys-cross-compile/target/x86_64-unknown-linux-musl/debug/build/libz-sys-2b3ea8f924a72b91/out/build/CMakeFiles/CMakeOutput.log".
See also "/Users/emorley/src/testcase-libz-sys-cross-compile/target/x86_64-unknown-linux-musl/debug/build/libz-sys-2b3ea8f924a72b91/out/build/CMakeFiles/CMakeError.log".
--- stderr
CMake Error at /opt/homebrew/Cellar/cmake/3.22.3/share/cmake/Modules/CMakeTestCCompiler.cmake:69 (message):
The C compiler
"/opt/homebrew/bin/x86_64-unknown-linux-musl-gcc"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /Users/emorley/src/testcase-libz-sys-cross-compile/target/x86_64-unknown-linux-musl/debug/build/libz-sys-2b3ea8f924a72b91/out/build/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make -f Makefile cmTC_710b5/fast && /Library/Developer/CommandLineTools/usr/bin/make -f CMakeFiles/cmTC_710b5.dir/build.make CMakeFiles/cmTC_710b5.dir/build
Building C object CMakeFiles/cmTC_710b5.dir/testCCompiler.c.o
/opt/homebrew/bin/x86_64-unknown-linux-musl-gcc -ffunction-sections -fdata-sections -fPIC -m64 -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk -std=c11 -o CMakeFiles/cmTC_710b5.dir/testCCompiler.c.o -c /Users/emorley/src/testcase-libz-sys-cross-compile/target/x86_64-unknown-linux-musl/debug/build/libz-sys-2b3ea8f924a72b91/out/build/CMakeFiles/CMakeTmp/testCCompiler.c
x86_64-unknown-linux-musl-gcc: error: unrecognized command-line option '-arch'
make[1]: *** [CMakeFiles/cmTC_710b5.dir/testCCompiler.c.o] Error 1
make: *** [cmTC_710b5/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:37 (project)
thread 'main' panicked at '
command did not execute successfully, got: exit status: 1
build script failed, must exit now', /Users/emorley/.cargo/registry/src/github.com-1ecc6299db9ec823/cmake-0.1.48/src/lib.rs:975:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Environment
- macOS 12.3 on Apple Silicon (M1 Max)
- rustc 1.60.0-beta.6 (7bccde197 2022-03-22)
- Crate versions at time of testing:
libz-sys: 1.1.5cmake: 0.1.48pkg-config: 0.3.24
- The cross-compile toolchain currently uses GCC 11.2.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with build.rs and the CMake configuration referenced at CMakeLists.txt:37, then reproduce the command shown in the issue with the x86_64-unknown-linux-musl toolchain. Check the CMake compiler-detection output and determine what causes the cross-compiler to receive -arch; done means the cargo build completes successfully for that target.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cmake, rust
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100