@@ -199,6 +199,62 @@ impl LinkerPluginLto {
199
199
}
200
200
}
201
201
202
+ /// The possible values `-C linker-flavor` can take: either one of the well-known linker flavors, or
203
+ /// an enrichment to one of them, for example representing additional arguments to its principal
204
+ /// linker flavor.
205
+ ///
206
+ /// This a surface enum for the CLI syntax, so that target specs don't have to deal with the
207
+ /// specifics of the CLI: they will always use the well-known principal linker flavor via the
208
+ /// `to_flavor` method, and never the enrichment variants.
209
+ ///
210
+ /// Currently used to represent finer-grained uses of `gcc`, to improve ease-of-use for wrapping a
211
+ /// given linker like `lld`, `gold` or `mold`.
212
+ #[ derive( Clone , Debug , Eq , Ord , PartialEq , PartialOrd ) ]
213
+ pub enum LinkerFlavorCli {
214
+ /// When the CLI option is one of the well-known linker-flavors that don't need special
215
+ /// handling.
216
+ WellKnown ( LinkerFlavor ) ,
217
+
218
+ /// Enrichments to the `LinkerFlavor::Gcc` flavor, to specify the linker via `-fuse-ld`
219
+ Gcc { use_ld : String } ,
220
+ }
221
+
222
+ impl LinkerFlavorCli {
223
+ /// Returns the principal linker flavor that this CLI option represents.
224
+ pub fn to_flavor ( & self ) -> LinkerFlavor {
225
+ match * self {
226
+ LinkerFlavorCli :: WellKnown ( flavor) => flavor,
227
+ LinkerFlavorCli :: Gcc { .. } => LinkerFlavor :: Gcc ,
228
+ }
229
+ }
230
+ }
231
+
232
+ /// Parses a `-C linker-flavor` option
233
+ impl FromStr for LinkerFlavorCli {
234
+ type Err = ( ) ;
235
+
236
+ fn from_str ( s : & str ) -> Result < Self , ( ) > {
237
+ // If the value is one of the existing flavor mappings, return that.
238
+ if let Some ( flavor) = LinkerFlavor :: from_str ( s) {
239
+ return Ok ( LinkerFlavorCli :: WellKnown ( flavor) ) ;
240
+ }
241
+
242
+ // Otherwise, it should be the enrichments to the gcc/cc flavor: wrapping a given linker
243
+ // separated by a colon like `gcc:lld`.
244
+ let parts: Vec < _ > = s. split ( "gcc:" ) . collect ( ) ;
245
+ if parts. len ( ) != 2 {
246
+ return Err ( ( ) ) ;
247
+ }
248
+
249
+ let wrapped_linker = parts[ 1 ] ;
250
+ if !wrapped_linker. is_empty ( ) {
251
+ Ok ( LinkerFlavorCli :: Gcc { use_ld : wrapped_linker. to_string ( ) } )
252
+ } else {
253
+ Err ( ( ) )
254
+ }
255
+ }
256
+ }
257
+
202
258
/// The different settings that can be enabled via the `-Z location-detail` flag.
203
259
#[ derive( Clone , PartialEq , Hash , Debug ) ]
204
260
pub struct LocationDetail {
0 commit comments