@@ -105,6 +105,39 @@ impl Display for DebuginfoLevel {
105105 }
106106}
107107
108+ /// LLD in bootstrap works like this:
109+ /// - Self-contained lld: use `rust-lld` from the compiler's sysroot
110+ /// - External: use an external `lld` binary
111+ ///
112+ /// It is configured depending on the target:
113+ /// 1) Everything except MSVC
114+ /// - Self-contained: -Clinker-flavor=gnu-lld-cc -Clink-self-contained=+linker
115+ /// - External: -Clinker-flavor=gnu-lld-cc
116+ /// 2) MSVC
117+ /// - Self-contained: -Clinker=<path to rust-lld>
118+ /// - External: -Clinker=lld
119+ #[ derive( Default , Clone ) ]
120+ pub enum LldMode {
121+ /// Do not use LLD
122+ #[ default]
123+ Unused ,
124+ /// Use `rust-lld` from the compiler's sysroot
125+ SelfContained ,
126+ /// Use an externally provided `lld` binary.
127+ /// Note that the linker name cannot be overridden, the binary has to be named `lld` and it has
128+ /// to be in $PATH.
129+ External ,
130+ }
131+
132+ impl LldMode {
133+ pub fn is_used ( & self ) -> bool {
134+ match self {
135+ LldMode :: SelfContained | LldMode :: External => true ,
136+ LldMode :: Unused => false ,
137+ }
138+ }
139+ }
140+
108141/// Global configuration for the entire build and/or bootstrap.
109142///
110143/// This structure is parsed from `config.toml`, and some of the fields are inferred from `git` or build-time parameters.
@@ -199,7 +232,7 @@ pub struct Config {
199232 pub llvm_from_ci : bool ,
200233 pub llvm_build_config : HashMap < String , String > ,
201234
202- pub use_lld : bool ,
235+ pub lld_mode : LldMode ,
203236 pub lld_enabled : bool ,
204237 pub llvm_tools_enabled : bool ,
205238
@@ -981,6 +1014,44 @@ enum StringOrInt<'a> {
9811014 String ( & ' a str ) ,
9821015 Int ( i64 ) ,
9831016}
1017+
1018+ impl < ' de > Deserialize < ' de > for LldMode {
1019+ fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
1020+ where
1021+ D : Deserializer < ' de > ,
1022+ {
1023+ struct LldModeVisitor ;
1024+
1025+ impl < ' de > serde:: de:: Visitor < ' de > for LldModeVisitor {
1026+ type Value = LldMode ;
1027+
1028+ fn expecting ( & self , formatter : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1029+ formatter. write_str ( "one of true, 'self-contained' or 'external'" )
1030+ }
1031+
1032+ fn visit_bool < E > ( self , v : bool ) -> Result < Self :: Value , E >
1033+ where
1034+ E : serde:: de:: Error ,
1035+ {
1036+ Ok ( if v { LldMode :: External } else { LldMode :: Unused } )
1037+ }
1038+
1039+ fn visit_str < E > ( self , v : & str ) -> Result < Self :: Value , E >
1040+ where
1041+ E : serde:: de:: Error ,
1042+ {
1043+ match v {
1044+ "external" => Ok ( LldMode :: External ) ,
1045+ "self-contained" => Ok ( LldMode :: SelfContained ) ,
1046+ _ => Err ( E :: custom ( "unknown mode {v}" ) ) ,
1047+ }
1048+ }
1049+ }
1050+
1051+ deserializer. deserialize_any ( LldModeVisitor )
1052+ }
1053+ }
1054+
9841055define_config ! {
9851056 /// TOML representation of how the Rust build is configured.
9861057 struct Rust {
@@ -1018,7 +1089,7 @@ define_config! {
10181089 save_toolstates: Option <String > = "save-toolstates" ,
10191090 codegen_backends: Option <Vec <String >> = "codegen-backends" ,
10201091 lld: Option <bool > = "lld" ,
1021- use_lld : Option <bool > = "use-lld" ,
1092+ lld_mode : Option <LldMode > = "use-lld" ,
10221093 llvm_tools: Option <bool > = "llvm-tools" ,
10231094 deny_warnings: Option <bool > = "deny-warnings" ,
10241095 backtrace_on_ice: Option <bool > = "backtrace-on-ice" ,
@@ -1446,7 +1517,7 @@ impl Config {
14461517 if let Some ( true ) = rust. incremental {
14471518 config. incremental = true ;
14481519 }
1449- set ( & mut config. use_lld , rust. use_lld ) ;
1520+ set ( & mut config. lld_mode , rust. lld_mode ) ;
14501521 set ( & mut config. lld_enabled , rust. lld ) ;
14511522 set ( & mut config. llvm_tools_enabled , rust. llvm_tools ) ;
14521523 config. rustc_parallel = rust
0 commit comments