Skip to content

Commit 5f24e31

Browse files
committed
use asymmetric json roundtripping
this ensures roundtripping of stable and unstable values: - backwards-compatible values can be deserialized, as well as the new unstable values - unstable values are serialized.
1 parent 0bca45f commit 5f24e31

File tree

1 file changed

+20
-3
lines changed
  • compiler/rustc_target/src/spec

1 file changed

+20
-3
lines changed

compiler/rustc_target/src/spec/mod.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ impl LinkerFlavor {
278278
}
279279
}
280280

281+
/// Returns the corresponding backwards-compatible CLI flavor.
281282
fn to_cli(self) -> LinkerFlavorCli {
282283
match self {
283284
LinkerFlavor::Gnu(Cc::Yes, _)
@@ -298,6 +299,20 @@ impl LinkerFlavor {
298299
}
299300
}
300301

302+
/// Returns the modern CLI flavor that is the counterpart of this flavor.
303+
fn to_cli_counterpart(self) -> LinkerFlavorCli {
304+
match self {
305+
LinkerFlavor::Gnu(cc, lld) => LinkerFlavorCli::Gnu(cc, lld),
306+
LinkerFlavor::Darwin(cc, lld) => LinkerFlavorCli::Darwin(cc, lld),
307+
LinkerFlavor::WasmLld(cc) => LinkerFlavorCli::WasmLld(cc),
308+
LinkerFlavor::Unix(cc) => LinkerFlavorCli::Unix(cc),
309+
LinkerFlavor::Msvc(lld) => LinkerFlavorCli::Msvc(lld),
310+
LinkerFlavor::EmCc => LinkerFlavorCli::EmCc,
311+
LinkerFlavor::Bpf => LinkerFlavorCli::Bpf,
312+
LinkerFlavor::Ptx => LinkerFlavorCli::Ptx,
313+
}
314+
}
315+
301316
fn infer_cli_hints(cli: LinkerFlavorCli) -> (Option<Cc>, Option<Lld>) {
302317
match cli {
303318
LinkerFlavorCli::Gnu(cc, lld) | LinkerFlavorCli::Darwin(cc, lld) => {
@@ -2273,7 +2288,7 @@ impl TargetOptions {
22732288
}
22742289

22752290
fn update_to_cli(&mut self) {
2276-
self.linker_flavor_json = self.linker_flavor.to_cli();
2291+
self.linker_flavor_json = self.linker_flavor.to_cli_counterpart();
22772292
self.lld_flavor_json = self.linker_flavor.lld_flavor();
22782293
self.linker_is_gnu_json = self.linker_flavor.is_gnu();
22792294
for (args, args_json) in [
@@ -2283,8 +2298,10 @@ impl TargetOptions {
22832298
(&self.late_link_args_static, &mut self.late_link_args_static_json),
22842299
(&self.post_link_args, &mut self.post_link_args_json),
22852300
] {
2286-
*args_json =
2287-
args.iter().map(|(flavor, args)| (flavor.to_cli(), args.clone())).collect();
2301+
*args_json = args
2302+
.iter()
2303+
.map(|(flavor, args)| (flavor.to_cli_counterpart(), args.clone()))
2304+
.collect();
22882305
}
22892306
}
22902307
}

0 commit comments

Comments
 (0)