-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Improve linker detection for ld64.lld for Apple devices #86064
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @davidtwco (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
☔ The latest upstream changes (presumably #85086) made this pull request unmergeable. Please resolve the merge conflicts. |
@@ -2504,3 +2512,59 @@ fn get_apple_sdk_root(sdk_name: &str) -> Result<String, String> { | |||
Err(e) => Err(format!("failed to get {} SDK path: {}", sdk_name, e)), | |||
} | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The LLVM linker requires the platform_version option. The Apple linker also supports it.
@@ -9,6 +9,10 @@ pub fn target() -> Target { | |||
LinkerFlavor::Gcc, | |||
vec!["-m64".to_string(), "-arch".to_string(), "x86_64".to_string()], | |||
); | |||
base.pre_link_args.insert( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be needed for other Apple devices, but I have no hardware.
@@ -2183,7 +2187,11 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>( | |||
|
|||
// Converts a library file-stem into a cc -l argument | |||
fn unlib<'a>(target: &Target, stem: &'a str) -> &'a str { | |||
if stem.starts_with("lib") && !target.is_like_windows { &stem[3..] } else { stem } | |||
if stem.starts_with("lib") && !target.is_like_windows { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change was by rustfmt.
@@ -231,7 +231,9 @@ impl<'a> GccLinker<'a> { | |||
fn build_dylib(&mut self, out_filename: &Path) { | |||
// On mac we need to tell the linker to let this library be rpathed | |||
if self.sess.target.is_like_osx { | |||
self.cmd.arg("-dynamiclib"); | |||
if self.sess.target.lld_flavor != LldFlavor::Ld64 { | |||
self.cmd.arg("-dynamiclib"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems be only needed for gcc. -dynamiclib is an gcc option.
}; | ||
|
||
let path = format!("{}/usr/lib", &sdk_path); | ||
cmd.args(&["-syslibroot", &sdk_path]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an implementation of -isysroot for ld64.
This PR attempts to add support for linking directly with |
How do I get cargo to use ld64.lld? |
In other words, |
The job Click to see the possible cause of the failure (guessed by this bot)
|
Indeed RUSTFLAGS="-C link-arg=-fuse-ld=/..../ld64.lld" cargo build succeeds. |
Other Apple devices will need a similar solution, but I have no hardware.
see #85938
I can now build a large workspace with 300+ crates.