Skip to content

Commit dad58f1

Browse files
committed
Review fixes
1 parent da173ff commit dad58f1

File tree

7 files changed

+44
-63
lines changed

7 files changed

+44
-63
lines changed

src/bootstrap/bin/rustc.rs

+8-14
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ use std::path::PathBuf;
2323
use std::process::{exit, Child, Command};
2424
use std::time::Instant;
2525

26+
use bootstrap::{get_lld_flags, LldMode};
27+
2628
fn main() {
2729
let args = env::args_os().skip(1).collect::<Vec<_>>();
2830
let arg = |name| args.windows(2).find(|args| args[0] == name).and_then(|args| args[1].to_str());
@@ -116,21 +118,13 @@ fn main() {
116118
cmd.arg(format!("-Clinker={host_linker}"));
117119
}
118120
if let Ok(lld) = env::var("RUSTC_HOST_LLD") {
119-
match lld.as_str() {
120-
"external" => {
121-
cmd.arg("-Clink-args=-fuse-ld=lld");
122-
}
123-
"self-contained" => {
124-
let mut arg = std::ffi::OsString::from("-Clink-arg=-B");
125-
arg.push(
126-
env::var_os("RUSTC_HOST_LLD_ROOT")
127-
.expect("RUSTC_HOST_LLD_ROOT env. var missing"),
128-
);
129-
cmd.arg(arg);
130-
131-
cmd.arg("-Clink-args=-fuse-ld=lld");
132-
}
121+
let lld_mode = match lld.as_str() {
122+
"external" => LldMode::External,
123+
"self-contained" => LldMode::SelfContained,
133124
_ => panic!("Unknown host lld value {lld}"),
125+
};
126+
for flag in get_lld_flags(&lld_mode) {
127+
cmd.arg(flag);
134128
}
135129
}
136130

src/bootstrap/bin/rustdoc.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//!
33
//! See comments in `src/bootstrap/rustc.rs` for more information.
44
5+
use bootstrap::{get_lld_flags, LldMode};
56
use std::env;
67
use std::ffi::OsString;
78
use std::path::PathBuf;
@@ -55,25 +56,20 @@ fn main() {
5556
}
5657

5758
if let Ok(lld) = env::var("RUSTDOC_HOST_LLD") {
58-
match lld.as_str() {
59+
let lld_mode = match lld.as_str() {
5960
"external" => {
60-
cmd.arg("-Clink-args=-fuse-ld=lld");
6161
cmd.arg(format!(
6262
"-Clink-arg=-Wl,{}",
6363
env::var("RUSTC_LLD_NO_THREADS")
6464
.expect("RUSTC_LLD_NO_THREADS env. var missing")
6565
));
66+
LldMode::External
6667
}
67-
"self-contained" => {
68-
let mut arg = std::ffi::OsString::from("-Clink-arg=-B");
69-
arg.push(
70-
env::var_os("RUSTDOC_LLD_ROOT").expect("RUSTDOC_LLD_ROOT env. var missing"),
71-
);
72-
cmd.arg(arg);
73-
74-
cmd.arg("-Clink-args=-fuse-ld=lld");
75-
}
68+
"self-contained" => LldMode::SelfContained,
7669
_ => panic!("Unknown host lld value {lld}"),
70+
};
71+
for flag in get_lld_flags(&lld_mode) {
72+
cmd.arg(flag);
7773
}
7874
}
7975

src/bootstrap/builder.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1662,7 +1662,6 @@ impl<'a> Builder<'a> {
16621662
}
16631663
LldMode::SelfContained => {
16641664
cargo.env("RUSTC_HOST_LLD", "self-contained");
1665-
cargo.env("RUSTC_HOST_LLD_ROOT", self.initial_lld_root());
16661665
}
16671666
LldMode::Unused => {}
16681667
}

src/bootstrap/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ impl<'de> Deserialize<'de> for LldMode {
10311031
E: serde::de::Error,
10321032
{
10331033
match v {
1034-
"lld" => Ok(LldMode::External),
1034+
"external" => Ok(LldMode::External),
10351035
"self-contained" => Ok(LldMode::SelfContained),
10361036
_ => Err(E::custom("unknown mode {v}")),
10371037
}

src/bootstrap/lib.rs

+28-21
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use filetime::FileTime;
3434
use once_cell::sync::OnceCell;
3535

3636
use crate::builder::Kind;
37-
use crate::config::{LldMode, LlvmLibunwind, TargetSelection};
37+
use crate::config::{LlvmLibunwind, TargetSelection};
3838
use crate::util::{
3939
dir_is_empty, exe, libdir, mtime, output, run, run_suppressed, symlink_dir, try_run_suppressed,
4040
};
@@ -90,6 +90,7 @@ mod job {
9090
pub use crate::builder::PathSet;
9191
use crate::cache::{Interned, INTERNER};
9292
pub use crate::config::Config;
93+
pub use crate::config::LldMode;
9394
pub use crate::flags::Subcommand;
9495
use termcolor::{ColorChoice, StandardStream, WriteColor};
9596

@@ -1281,29 +1282,11 @@ impl Build {
12811282
target.is_msvc()
12821283
}
12831284

1284-
// Returns the gcc-ld directory of the snapshot compiler's rust-lld.
1285-
fn initial_lld_root(&self) -> PathBuf {
1286-
let mut rust_lld_path = self.initial_lld.clone();
1287-
rust_lld_path.pop();
1288-
rust_lld_path.join("gcc-ld")
1289-
}
1290-
12911285
fn lld_flags(&self, target: TargetSelection, test: bool) -> Vec<String> {
12921286
let mut flags = vec![];
12931287

12941288
if !self.is_lld_direct_linker(target) {
1295-
match self.config.lld_mode {
1296-
LldMode::SelfContained => {
1297-
// FIXME: replace with MCP510 (-Clinker-flavor + -Clink-self-contained)
1298-
// once gcc-ld is available in stage0-sysroot.
1299-
flags.push("-Clink-arg=-fuse-ld=lld".to_string());
1300-
flags.push(format!("-Clink-arg=-B{}", self.initial_lld_root().display()));
1301-
}
1302-
LldMode::External => {
1303-
flags.push("-Clink-arg=-fuse-ld=lld".to_string());
1304-
}
1305-
LldMode::Unused => {}
1306-
};
1289+
flags.extend(get_lld_flags(&self.config.lld_mode));
13071290
}
13081291

13091292
// For tests, we want to disable multi-threading.
@@ -1322,7 +1305,16 @@ impl Build {
13221305
/// and lld version.
13231306
fn lld_single_thread_flag(&self, target: TargetSelection) -> &'static str {
13241307
let new_flags = if let LldMode::External = self.config.lld_mode {
1325-
util::is_lld_newer_than_10()
1308+
// Finds out if the LLD is newer than LLD 10
1309+
static LLD_NO_THREADS: OnceCell<bool> = OnceCell::new();
1310+
*LLD_NO_THREADS.get_or_init(|| {
1311+
let out = output(Command::new("lld").arg("-flavor").arg("ld").arg("--version"));
1312+
let newer = match (out.find(char::is_numeric), out.find('.')) {
1313+
(Some(b), Some(e)) => out.as_str()[b..e].parse::<i32>().ok().unwrap_or(14) > 10,
1314+
_ => true,
1315+
};
1316+
newer
1317+
})
13261318
} else {
13271319
true
13281320
};
@@ -1910,3 +1902,18 @@ pub fn find_recent_config_change_ids(current_id: usize) -> Vec<usize> {
19101902
.cloned()
19111903
.collect()
19121904
}
1905+
1906+
pub fn get_lld_flags(lld_mode: &LldMode) -> Vec<String> {
1907+
let mut flags = vec![];
1908+
match lld_mode {
1909+
LldMode::SelfContained => {
1910+
flags.push("-Clinker-flavor=gnu-lld-cc".to_string());
1911+
flags.push("-Clink-self-contained=+linker".to_string());
1912+
}
1913+
LldMode::External => {
1914+
flags.push("-Clinker-flavor=gnu-lld-cc".to_string());
1915+
}
1916+
LldMode::Unused => {}
1917+
};
1918+
flags
1919+
}

src/bootstrap/test.rs

-1
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,6 @@ impl Step for RustdocTheme {
867867
}
868868
LldMode::SelfContained => {
869869
cmd.env("RUSTDOC_HOST_LLD", "self-contained");
870-
cmd.env("RUSTDOC_HOST_LLD_ROOT", builder.initial_lld_root());
871870
}
872871
LldMode::Unused => {}
873872
}

src/bootstrap/util.rs

-14
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use std::time::{Instant, SystemTime, UNIX_EPOCH};
1414

1515
use crate::builder::Builder;
1616
use crate::config::{Config, TargetSelection};
17-
use crate::OnceCell;
1817

1918
/// A helper macro to `unwrap` a result except also print out details like:
2019
///
@@ -479,19 +478,6 @@ pub fn get_clang_cl_resource_dir(clang_cl_path: &str) -> PathBuf {
479478
clang_rt_dir.to_path_buf()
480479
}
481480

482-
/// Finds out if a global `lld` binary is a newer version than version 10.
483-
pub fn is_lld_newer_than_10() -> bool {
484-
static LLD_NO_THREADS: OnceCell<bool> = OnceCell::new();
485-
*LLD_NO_THREADS.get_or_init(|| {
486-
let out = output(Command::new("lld").arg("-flavor").arg("ld").arg("--version"));
487-
let newer = match (out.find(char::is_numeric), out.find('.')) {
488-
(Some(b), Some(e)) => out.as_str()[b..e].parse::<i32>().ok().unwrap_or(14) > 10,
489-
_ => true,
490-
};
491-
newer
492-
})
493-
}
494-
495481
pub fn dir_is_empty(dir: &Path) -> bool {
496482
t!(std::fs::read_dir(dir)).next().is_none()
497483
}

0 commit comments

Comments
 (0)