Skip to content

Commit b007891

Browse files
committed
make naga-wgsl target's file extensions .wgsl instead of .spv
1 parent c4c5e15 commit b007891

3 files changed

Lines changed: 25 additions & 5 deletions

File tree

‎crates/rustc_codegen_spirv/src/link.rs‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,12 @@ fn link_exe(
174174

175175
let cg_args = CodegenArgs::from_session(sess);
176176

177-
// HACK(eddyb) this removes the `.json` in `.spv.json`, from `out_filename`.
177+
let target = SpirvTarget::parse_target(sess.opts.target_triple.tuple())
178+
.expect("parsing should fail earlier");
179+
// this removes the `.json` in `.spv.json`, from `out_filename`.
178180
let out_path_spv = out_filename.with_extension("");
181+
// this replaces the `.spv` with a target-specific file extension, like `.wgsl` for `naga-wgsl`
182+
let out_path_spv = out_path_spv.with_extension(target.file_extension());
179183

180184
let link_result = do_link(
181185
sess,
@@ -188,7 +192,7 @@ fn link_exe(
188192
let compile_result = match link_result {
189193
linker::LinkResult::SingleModule(module) => {
190194
let entry_points = entry_points(&module);
191-
post_link_single_module(sess, &cg_args, *module, &out_path_spv, None);
195+
post_link_single_module(sess, &cg_args, target, *module, &out_path_spv, None);
192196
CompileResult {
193197
entry_points,
194198
module: ModuleResult::SingleModule(out_path_spv),
@@ -211,6 +215,7 @@ fn link_exe(
211215
post_link_single_module(
212216
sess,
213217
&cg_args,
218+
target,
214219
module,
215220
&out_file_path,
216221
Some(disambiguated_crate_name_for_dumps),
@@ -243,6 +248,7 @@ fn entry_points(module: &rspirv::dr::Module) -> Vec<String> {
243248
fn post_link_single_module(
244249
sess: &Session,
245250
cg_args: &CodegenArgs,
251+
target: SpirvTarget,
246252
module: Module,
247253
out_filename: &Path,
248254
dump_prefix: Option<&OsStr>,
@@ -304,7 +310,7 @@ fn post_link_single_module(
304310

305311
let binary = {
306312
let _transpile_timer = sess.timer("link_transpile");
307-
match transpile(sess, cg_args, &spv_binary) {
313+
match transpile(sess, target, cg_args, &spv_binary) {
308314
Ok(e) => e,
309315
Err(_) => return,
310316
}

‎crates/rustc_codegen_spirv/src/naga_transpile.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ use rustc_span::ErrorGuaranteed;
55

66
pub fn transpile(
77
sess: &Session,
8+
target: SpirvTarget,
89
cg_args: &CodegenArgs,
910
spv_binary: &[u32],
1011
) -> Result<Vec<u8>, ErrorGuaranteed> {
11-
let target = SpirvTarget::parse_target(sess.opts.target_triple.tuple())
12-
.expect("parsing should fail earlier");
1312
match target {
1413
#[cfg(feature = "naga")]
1514
SpirvTarget::Naga(NagaTarget::NAGA_WGSL) => {

‎crates/rustc_codegen_spirv/src/target.rs‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,12 @@ impl NagaTarget {
469469
pub const fn new(out: NagaOut) -> Self {
470470
Self { out }
471471
}
472+
473+
pub fn file_extension(&self) -> String {
474+
match self.out {
475+
NagaOut::WGSL => "wgsl".to_string(),
476+
}
477+
}
472478
}
473479

474480
impl SpirvTargetVariant for NagaTarget {
@@ -617,6 +623,15 @@ impl SpirvTarget {
617623
format!("{}{}", SPIRV_TARGET_PREFIX, self.env())
618624
}
619625

626+
pub fn file_extension(&self) -> String {
627+
match self {
628+
SpirvTarget::Universal(_) | SpirvTarget::Vulkan(_) | SpirvTarget::OpenGL(_) => {
629+
"spv".to_string()
630+
}
631+
SpirvTarget::Naga(t) => t.file_extension(),
632+
}
633+
}
634+
620635
pub fn all_targets() -> impl Iterator<Item = Self> {
621636
UniversalTarget::ALL_UNIVERSAL_TARGETS
622637
.iter()

0 commit comments

Comments
 (0)