Skip to content

Commit 34db92e

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 00b0414 commit 34db92e

File tree

1 file changed

+16
-1
lines changed
  • compiler/rustc_target/src/spec

1 file changed

+16
-1
lines changed

compiler/rustc_target/src/spec/mod.rs

+16-1
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 [

0 commit comments

Comments
 (0)