Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
lqd committed Oct 18, 2023
commit 5f24e314ef9a87a796dd8a06b2e0ecff4ac2e8da
23 changes: 20 additions & 3 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ impl LinkerFlavor {
}
}

/// Returns the corresponding backwards-compatible CLI flavor.
fn to_cli(self) -> LinkerFlavorCli {
match self {
LinkerFlavor::Gnu(Cc::Yes, _)
Expand All @@ -298,6 +299,20 @@ impl LinkerFlavor {
}
}

/// Returns the modern CLI flavor that is the counterpart of this flavor.
fn to_cli_counterpart(self) -> LinkerFlavorCli {
match self {
LinkerFlavor::Gnu(cc, lld) => LinkerFlavorCli::Gnu(cc, lld),
LinkerFlavor::Darwin(cc, lld) => LinkerFlavorCli::Darwin(cc, lld),
LinkerFlavor::WasmLld(cc) => LinkerFlavorCli::WasmLld(cc),
LinkerFlavor::Unix(cc) => LinkerFlavorCli::Unix(cc),
LinkerFlavor::Msvc(lld) => LinkerFlavorCli::Msvc(lld),
LinkerFlavor::EmCc => LinkerFlavorCli::EmCc,
LinkerFlavor::Bpf => LinkerFlavorCli::Bpf,
LinkerFlavor::Ptx => LinkerFlavorCli::Ptx,
}
}

fn infer_cli_hints(cli: LinkerFlavorCli) -> (Option<Cc>, Option<Lld>) {
match cli {
LinkerFlavorCli::Gnu(cc, lld) | LinkerFlavorCli::Darwin(cc, lld) => {
Expand Down Expand Up @@ -2273,7 +2288,7 @@ impl TargetOptions {
}

fn update_to_cli(&mut self) {
self.linker_flavor_json = self.linker_flavor.to_cli();
self.linker_flavor_json = self.linker_flavor.to_cli_counterpart();
self.lld_flavor_json = self.linker_flavor.lld_flavor();
self.linker_is_gnu_json = self.linker_flavor.is_gnu();
for (args, args_json) in [
Expand All @@ -2283,8 +2298,10 @@ impl TargetOptions {
(&self.late_link_args_static, &mut self.late_link_args_static_json),
(&self.post_link_args, &mut self.post_link_args_json),
] {
*args_json =
args.iter().map(|(flavor, args)| (flavor.to_cli(), args.clone())).collect();
*args_json = args
.iter()
.map(|(flavor, args)| (flavor.to_cli_counterpart(), args.clone()))
.collect();
}
}
}
Expand Down