Skip to content

Commit 4e65081

Browse files
committed
Introduce LldMode and generalize parsing of use-lld
1 parent 42faef5 commit 4e65081

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed

src/bootstrap/config.rs

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,19 @@ impl Display for DebuginfoLevel {
102102
}
103103
}
104104

105+
#[derive(Default, Clone)]
106+
pub enum LldMode {
107+
/// Do not use LLD
108+
#[default]
109+
Unused,
110+
/// Use `rust-lld` from the compiler's sysroot
111+
SelfContained,
112+
/// Use an externally provided `lld` binary.
113+
/// Note that the linker name cannot be overridden, the binary has to be named `lld` and it has
114+
/// to be in $PATH.
115+
External,
116+
}
117+
105118
/// Global configuration for the entire build and/or bootstrap.
106119
///
107120
/// This structure is parsed from `config.toml`, and some of the fields are inferred from `git` or build-time parameters.
@@ -954,6 +967,44 @@ enum StringOrInt<'a> {
954967
String(&'a str),
955968
Int(i64),
956969
}
970+
971+
impl<'de> Deserialize<'de> for LldMode {
972+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
973+
where
974+
D: Deserializer<'de>,
975+
{
976+
struct LldModeVisitor;
977+
978+
impl<'de> serde::de::Visitor<'de> for LldModeVisitor {
979+
type Value = LldMode;
980+
981+
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
982+
formatter.write_str("one of true, 'self-contained' and 'lld'")
983+
}
984+
985+
fn visit_bool<E>(self, v: bool) -> Result<Self::Value, E>
986+
where
987+
E: serde::de::Error,
988+
{
989+
Ok(if v { LldMode::External } else { LldMode::Unused })
990+
}
991+
992+
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
993+
where
994+
E: serde::de::Error,
995+
{
996+
match v {
997+
"lld" => Ok(LldMode::External),
998+
"self-contained" => Ok(LldMode::SelfContained),
999+
_ => Err(E::custom("unknown mode {v}")),
1000+
}
1001+
}
1002+
}
1003+
1004+
deserializer.deserialize_any(LldModeVisitor)
1005+
}
1006+
}
1007+
9571008
define_config! {
9581009
/// TOML representation of how the Rust build is configured.
9591010
struct Rust {
@@ -989,7 +1040,7 @@ define_config! {
9891040
save_toolstates: Option<String> = "save-toolstates",
9901041
codegen_backends: Option<Vec<String>> = "codegen-backends",
9911042
lld: Option<bool> = "lld",
992-
use_lld: Option<bool> = "use-lld",
1043+
lld_mode: Option<LldMode> = "use-lld",
9931044
llvm_tools: Option<bool> = "llvm-tools",
9941045
deny_warnings: Option<bool> = "deny-warnings",
9951046
backtrace_on_ice: Option<bool> = "backtrace-on-ice",
@@ -1407,7 +1458,13 @@ impl Config {
14071458
if let Some(true) = rust.incremental {
14081459
config.incremental = true;
14091460
}
1410-
set(&mut config.use_lld, rust.use_lld);
1461+
set(
1462+
&mut config.use_lld,
1463+
match rust.lld_mode {
1464+
None | Some(LldMode::Unused) => None,
1465+
_ => Some(true),
1466+
},
1467+
);
14111468
set(&mut config.lld_enabled, rust.lld);
14121469
set(&mut config.llvm_tools_enabled, rust.llvm_tools);
14131470
config.rustc_parallel = rust.parallel_compiler.unwrap_or(false);

src/bootstrap/config/tests.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,11 @@ fn rust_optimize() {
196196
fn invalid_rust_optimize() {
197197
parse("rust.optimize = \"a\"");
198198
}
199+
200+
#[test]
201+
fn rust_lld() {
202+
assert!(!parse("").use_lld);
203+
assert!(parse("rust.use-lld = \"self-contained\"").use_lld);
204+
assert!(parse("rust.use-lld = \"lld\"").use_lld);
205+
assert!(parse("rust.use-lld = true").use_lld);
206+
}

0 commit comments

Comments
 (0)