Skip to content
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

Fix cross-compiling for Apple platforms #1389

Merged
merged 3 commits into from
Feb 8, 2025

Conversation

madsmtm
Copy link
Collaborator

@madsmtm madsmtm commented Feb 5, 2025

(So, of course we weren't done here...)

Basically, the only difference between this and pre-#1384 is that on visionOS and Mac Catalyst, we pass a versioned --target instead of unversioned --target + -mtargetos=.
This is similar to the alternative I noted in that PR, and while it does run into #1278 (the bug that configuration files + versioned targets are badly supported on older Clang) on those targets, I think that's the better option.

Fixes #1388. To avoid this in the future, I have added a CI step to verify that cross-compilation works (fails in the first commit, succeeds in the second).

Alternatives

I looked through Clang's parsing code, and from that I glean that an alternative would probably be to set --target + *_DEPLOYMENT_TARGET. This has a few problems though:

  • I suspect a lot of users are just inspecting Tool::args/.get_compiler().get_command().get_args(), and forget to also look at Tool::env (I know at least Rust's bootstrap currently forgets to do this).
  • This also doesn't force GCC users to use a compiler configured for Darwin (so we'd still have to pass -mmacosx-version-min= there) (probably acceptable to not do if we did Detect common misconfigurations on error #1391).

@madsmtm madsmtm added bug O-apple Apple targets and toolchains labels Feb 5, 2025
@madsmtm madsmtm force-pushed the apple-cross-compile branch 2 times, most recently from 31e60ea to c12e9cb Compare February 5, 2025 08:58
@madsmtm madsmtm force-pushed the apple-cross-compile branch from 9c4030b to ab6767e Compare February 5, 2025 09:30
@madsmtm madsmtm force-pushed the apple-cross-compile branch 2 times, most recently from 03a896b to c60c0c4 Compare February 5, 2025 10:05
@madsmtm madsmtm force-pushed the apple-cross-compile branch from c60c0c4 to bfdf3d5 Compare February 5, 2025 10:09
# Test with clang/llvm for now, has better cross-compilation support (GCC requires downloading a different toolchain)
echo "CC=clang" >> $GITHUB_ENV
echo "CXX=clang++" >> $GITHUB_ENV
echo "AR=llvm-ar" >> $GITHUB_ENV
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is unclear to me why llvm-ar is required here, it seems to not be on my local Ubuntu 24 VM? But if we don't include it, we fail with:

rust-lld: error: /home/runner/work/cc-rs/cc-rs/target/aarch64-apple-darwin/debug/build/cc-test-5875314a6fda6e38/out/libOptLinkage.a: archive has no index; run ranlib to add one
rust-lld: error: undefined symbol: _answer

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea maybe there's some apple/clang stuff default ar not supporting?

@madsmtm madsmtm marked this pull request as ready for review February 5, 2025 10:40
tests/test.rs Show resolved Hide resolved
@madsmtm madsmtm requested a review from NobodyXu February 8, 2025 04:43
@clubby789
Copy link
Contributor

I'm not sure if this is relevant to the last fix, but trying to bump cc in rust gives us rust-lang/rust#136720 (comment)

clang-15: error: cannot specify '-mtargetos=ios14.2-macabi' along with '--target=arm64-apple-ios14.2-macabi'

@madsmtm madsmtm force-pushed the apple-cross-compile branch from 7e36542 to 7854f2f Compare February 8, 2025 05:07
@madsmtm
Copy link
Collaborator Author

madsmtm commented Feb 8, 2025

Hmm, that's what #1384 fixed.

Seems like it's not failing in bootstrap, but when building compiler-builtins. Maybe library/Cargo.lock was somehow updated to include the broken cc-rs version?

Copy link
Collaborator

@NobodyXu NobodyXu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@NobodyXu NobodyXu merged commit 23c0ee3 into rust-lang:main Feb 8, 2025
73 checks passed
@github-actions github-actions bot mentioned this pull request Feb 8, 2025
@madsmtm madsmtm deleted the apple-cross-compile branch February 8, 2025 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug O-apple Apple targets and toolchains
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error when cross-compiling to macOS with cc 1.2.12
3 participants