-
Notifications
You must be signed in to change notification settings - Fork 483
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
Error when cross-compiling to macOS with cc 1.2.12 #1388
Comments
Argh! |
I'll have a look, thanks for the report. |
Could you share your project setup (if it's GitHub Actions or similar)? I'd like to configure something similar for this repo when fixing the bug. |
It's an internal project, but I'm happy to share a trimmed down Click hereFROM ubuntu:22.04
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get -qq update \
&& apt-get -qq install -y curl \
make cmake ninja-build pkg-config \
libc6-dev libgcc-11-dev libstdc++-11-dev \
&& rm -rf /var/lib/apt/lists/*
ENV LLVM_VERSION=18.1.8
RUN mkdir -p /opt/llvm/$LLVM_VERSION \
&& url=https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/$(test $(arch) = aarch64 && echo "clang+llvm-${LLVM_VERSION}-aarch64-linux-gnu.tar.xz" || echo "clang+llvm-${LLVM_VERSION}-x86_64-linux-gnu-ubuntu-18.04.tar.xz") \
&& curl --fail -L $url | tar xJ --strip-components=1 -C /opt/llvm/$LLVM_VERSION
ENV PATH=/opt/llvm/$LLVM_VERSION/bin:$PATH
ARG RUST_VERSION=1.84.1
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
| bash -s -- -y --default-toolchain=$RUST_VERSION
ENV PATH="/root/.cargo/bin:$PATH"
# Cross-compilation targets
RUN rustup target add \
x86_64-apple-darwin \
aarch64-apple-darwin
# Install macOS SDKs
RUN curl -L "https://github.com/phracker/MacOSX-SDKs/releases/download/11.0-11.1/MacOSX11.0.sdk.tar.xz" | tar xJ -C /opt
ENV SDKROOT=/opt/MacOSX11.0.sdk
# Set default compiler
ENV CC=clang CXX=clang++
# Set flags for cross-compilation
ENV CARGO_TARGET_X86_64_APPLE_DARWIN_RUSTFLAGS="-C linker=clang -C link-arg=--target=x86_64-apple-darwin -C link-arg=-fuse-ld=lld"
ENV CARGO_TARGET_AARCH64_APPLE_DARWIN_RUSTFLAGS="-C linker=clang -C link-arg=--target=aarch64-apple-darwin -C link-arg=-fuse-ld=lld"
# Workaround for cc-rs 1.2.12, see: https://github.com/rust-lang/cc-rs/issues/1388
ENV CFLAGS_x86_64_apple_darwin="--target=x86_64-apple-darwin"
ENV CFLAGS_aarch64_apple_darwin="--target=aarch64-apple-darwin"
# Trial build for supported platforms
RUN cd /tmp \
&& cargo new foo \
&& cd foo \
# add dependency on C library for testing
&& cargo add bzip2 \
# macOS builds through Clang + LLD
&& cargo build --target aarch64-apple-darwin \
&& cargo build --target x86_64-apple-darwin \
&& rm -rf /tmp/foo
|
Thanks! I've filed #1389, and added a CI step loosely based on your work. |
That's fantastic. Thanks for the swift fix! |
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:
This fails with:
Click for full output
It works when downgrading
cc
to 1.2.11:I can work around by adding
--target=aarch64-apple-darwin
toCFLAGS_aarch64_apple_darwin
.The text was updated successfully, but these errors were encountered: