Skip to content

Commit 6714ee3

Browse files
committed
Ignore is-like-gpu in target-spec JSON comparison
Normalize target-spec JSON before comparing backend-expected vs provided JSON by dropping the is-like-gpu key, which rustc rejects in external target JSON for non-nvptx/amdgcn targets.
1 parent 6112414 commit 6714ee3

File tree

1 file changed

+14
-3
lines changed
  • crates/rustc_codegen_spirv/src/codegen_cx

1 file changed

+14
-3
lines changed

crates/rustc_codegen_spirv/src/codegen_cx/mod.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@ impl<'tcx> CodegenCx<'tcx> {
116116

117117
// HACK(eddyb) this loads the same `serde_json` used by `rustc_target`.
118118
extern crate serde_json;
119+
fn normalize_target_spec_json(mut json: serde_json::Value) -> serde_json::Value {
120+
// rustc currently rejects this key in external target JSON unless
121+
// the target is `nvptx64` or `amdgcn`, even though the in-memory
122+
// target options for SPIR-V can set it.
123+
if let Some(obj) = json.as_object_mut() {
124+
obj.remove("is-like-gpu");
125+
}
126+
json
127+
}
119128

120129
let expected = &target.rustc_target();
121130
let found = &tcx.sess.target;
@@ -128,11 +137,13 @@ impl<'tcx> CodegenCx<'tcx> {
128137
TargetTuple::TargetTuple(_) => {
129138
// FIXME(eddyb) this case should be impossible as upstream
130139
// `rustc` doesn't support `spirv-*` targets!
131-
(expected != found).then(|| [expected, found].map(|spec| spec.to_json()))
140+
let expected = normalize_target_spec_json(expected.to_json());
141+
let found = normalize_target_spec_json(found.to_json());
142+
(expected != found).then_some([expected, found])
132143
}
133144
TargetTuple::TargetJson { contents, .. } => {
134-
let expected = expected.to_json();
135-
let found = serde_json::from_str(contents).unwrap();
145+
let expected = normalize_target_spec_json(expected.to_json());
146+
let found = normalize_target_spec_json(serde_json::from_str(contents).unwrap());
136147
(expected != found).then_some([expected, found])
137148
}
138149
}

0 commit comments

Comments
 (0)