From 23e443a5faab17059be8b9035bfa6f608cff1530 Mon Sep 17 00:00:00 2001 From: Wang Qilin Date: Fri, 5 May 2023 17:18:42 +0800 Subject: [PATCH 1/2] support enable rpath in each target independently --- config.example.toml | 4 ++++ src/bootstrap/builder.rs | 2 +- src/bootstrap/config.rs | 7 +++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/config.example.toml b/config.example.toml index 6d9c762ceca1e..d0eaa9fd7ffac 100644 --- a/config.example.toml +++ b/config.example.toml @@ -750,6 +750,10 @@ changelog-seen = 2 # This option will override the same option under [build] section. #profiler = build.profiler (bool) +# This option supports enable `rpath` in each target independently, +# and will override the same option under [rust] section. It only works on Unix platforms +#rpath = rust.rpath (bool) + # Force static or dynamic linkage of the standard library for this target. If # this target is a host for rustc, this will also affect the linkage of the # compiler itself. This is useful for building rustc on targets that normally diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 0d2d512b4b2ae..b8e50342f92c2 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -1610,7 +1610,7 @@ impl<'a> Builder<'a> { // argument manually via `-C link-args=-Wl,-rpath,...`. Plus isn't it // fun to pass a flag to a tool to pass a flag to pass a flag to a tool // to change a flag in a binary? - if self.config.rust_rpath && util::use_host_linker(target) { + if self.config.rpath_enabled(target) && util::use_host_linker(target) { let rpath = if target.contains("apple") { // Note that we need to take one extra step on macOS to also pass // `-Wl,-instal_name,@rpath/...` to get things to work right. To diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index ca6dcaf495743..7a1d3e6dc4881 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -455,6 +455,7 @@ pub struct Target { pub ndk: Option, pub sanitizers: Option, pub profiler: Option, + pub rpath: Option, pub crt_static: Option, pub musl_root: Option, pub musl_libdir: Option, @@ -800,6 +801,7 @@ define_config! { android_ndk: Option = "android-ndk", sanitizers: Option = "sanitizers", profiler: Option = "profiler", + rpath: Option = "rpath", crt_static: Option = "crt-static", musl_root: Option = "musl-root", musl_libdir: Option = "musl-libdir", @@ -1301,6 +1303,7 @@ impl Config { target.qemu_rootfs = cfg.qemu_rootfs.map(PathBuf::from); target.sanitizers = cfg.sanitizers; target.profiler = cfg.profiler; + target.rpath = cfg.rpath; config.target_config.insert(TargetSelection::from_user(&triple), target); } @@ -1610,6 +1613,10 @@ impl Config { self.target_config.values().any(|t| t.profiler == Some(true)) || self.profiler } + pub fn rpath_enabled(&self, target: TargetSelection) -> bool { + self.target_config.get(&target).map(|t| t.rpath).flatten().unwrap_or(self.rust_rpath) + } + pub fn llvm_enabled(&self) -> bool { self.rust_codegen_backends.contains(&INTERNER.intern_str("llvm")) } From bb4976ab2daf56b02e3bc94c932927331bd61cb5 Mon Sep 17 00:00:00 2001 From: Wang Qilin Date: Mon, 8 May 2023 09:13:42 +0800 Subject: [PATCH 2/2] supplement CHANGELOG for add rpath in target section --- src/bootstrap/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bootstrap/CHANGELOG.md b/src/bootstrap/CHANGELOG.md index 74dd22df9e062..d6924cf2cfb23 100644 --- a/src/bootstrap/CHANGELOG.md +++ b/src/bootstrap/CHANGELOG.md @@ -27,6 +27,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). from the default rust toolchain. [#78513](https://github.com/rust-lang/rust/pull/78513) - Add options for enabling overflow checks, one for std (`overflow-checks-std`) and one for everything else (`overflow-checks`). Both default to false. - Add llvm option `enable-warnings` to have control on llvm compilation warnings. Default to false. +- Add `rpath` option in `target` section to support set rpath option for each target independently. [#111242](https://github.com/rust-lang/rust/pull/111242) ## [Version 2] - 2020-09-25