Auto merge of #38440 - alexcrichton:fix-osx-nightlies, r=brson
rustbuild: Fix LC_ID_DYLIB directives on OSX Currently libraries installed by rustbuild on OSX have an incorrect `LC_ID_DYLIB` directive located in the dynamic libraries that are installed. The directive we expect looks like: @rpath/libstd.dylib Which means that if you want to find that dynamic library you should look at the dylib's other `@rpath` directives. Typically our `@rpath` directives look like `@loader_path/../lib` for the compiler as that's where the installed libraries will be located. Currently, though, rustbuild produces dylibs with the directive that looks like: /Users/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-mac/build/build/x86_64-apple-darwin/stage1-std/x86_64-apple-darwin/release/deps/libstd-713ad88203512705.dylib In other words, the build directory is encoded erroneously. The compiler already [knows how] to change this directive, but it only passes that argument when `-C rpath` is also passed. The rustbuild system, however, explicitly [does not pass] this option explicitly and instead bakes its own. This logic then also erroneously didn't pass `-Wl,-install_name` like the compiler. [knows how]:4a008cccaa/src/librustc_trans/back/linker.rs (L210-L214)
[does not pass]:4a008cccaa/src/bootstrap/bin/rustc.rs (L133-L158)
To fix this regression this patch introduces a new `-Z` flag, `-Z osx-rpath-install-name` which basically just forces the compiler to take the previous `-install_name` branch when creating a dynamic library. Hopefully we can sort out a better rpath story in the future, but for now this "hack" should suffice in getting our nightly builds back to the same state as before. Closes #38430
This commit is contained in:
commit
d54e723179
@ -158,6 +158,15 @@ fn main() {
|
|||||||
// to change a flag in a binary?
|
// to change a flag in a binary?
|
||||||
if env::var("RUSTC_RPATH") == Ok("true".to_string()) {
|
if env::var("RUSTC_RPATH") == Ok("true".to_string()) {
|
||||||
let rpath = if target.contains("apple") {
|
let rpath = if target.contains("apple") {
|
||||||
|
|
||||||
|
// Note that we need to take one extra step on OSX to also pass
|
||||||
|
// `-Wl,-instal_name,@rpath/...` to get things to work right. To
|
||||||
|
// do that we pass a weird flag to the compiler to get it to do
|
||||||
|
// so. Note that this is definitely a hack, and we should likely
|
||||||
|
// flesh out rpath support more fully in the future.
|
||||||
|
if stage != "0" {
|
||||||
|
cmd.arg("-Z").arg("osx-rpath-install-name");
|
||||||
|
}
|
||||||
Some("-Wl,-rpath,@loader_path/../lib")
|
Some("-Wl,-rpath,@loader_path/../lib")
|
||||||
} else if !target.contains("windows") {
|
} else if !target.contains("windows") {
|
||||||
Some("-Wl,-rpath,$ORIGIN/../lib")
|
Some("-Wl,-rpath,$ORIGIN/../lib")
|
||||||
|
@ -928,6 +928,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
|
|||||||
"print some statistics about MIR"),
|
"print some statistics about MIR"),
|
||||||
always_encode_mir: bool = (false, parse_bool, [TRACKED],
|
always_encode_mir: bool = (false, parse_bool, [TRACKED],
|
||||||
"encode MIR of all functions into the crate metadata"),
|
"encode MIR of all functions into the crate metadata"),
|
||||||
|
osx_rpath_install_name: bool = (false, parse_bool, [TRACKED],
|
||||||
|
"pass `-install_name @rpath/...` to the OSX linker"),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn default_lib_output() -> CrateType {
|
pub fn default_lib_output() -> CrateType {
|
||||||
|
@ -207,7 +207,12 @@ impl<'a> Linker for GnuLinker<'a> {
|
|||||||
if self.sess.target.target.options.is_like_osx {
|
if self.sess.target.target.options.is_like_osx {
|
||||||
self.cmd.args(&["-dynamiclib", "-Wl,-dylib"]);
|
self.cmd.args(&["-dynamiclib", "-Wl,-dylib"]);
|
||||||
|
|
||||||
if self.sess.opts.cg.rpath {
|
// Note that the `osx_rpath_install_name` option here is a hack
|
||||||
|
// purely to support rustbuild right now, we should get a more
|
||||||
|
// principled solution at some point to force the compiler to pass
|
||||||
|
// the right `-Wl,-install_name` with an `@rpath` in it.
|
||||||
|
if self.sess.opts.cg.rpath ||
|
||||||
|
self.sess.opts.debugging_opts.osx_rpath_install_name {
|
||||||
let mut v = OsString::from("-Wl,-install_name,@rpath/");
|
let mut v = OsString::from("-Wl,-install_name,@rpath/");
|
||||||
v.push(out_filename.file_name().unwrap());
|
v.push(out_filename.file_name().unwrap());
|
||||||
self.cmd.arg(&v);
|
self.cmd.arg(&v);
|
||||||
|
Loading…
Reference in New Issue
Block a user