Skip to content

Commit 0ad5521

Browse files
committed
use TARGET_SPECS_PATH and the LEGACY_TARGET_SPECS if not there...
1 parent 5570a22 commit 0ad5521

File tree

1 file changed

+21
-39
lines changed

1 file changed

+21
-39
lines changed

crates/cargo-gpu/src/show.rs

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! Display various information about `cargo gpu`, eg its cache directory.
22
3-
use std::process::{Command, Stdio};
4-
53
use crate::cache_dir;
64

75
/// Show the computed source of the spirv-std dependency.
@@ -69,8 +67,9 @@ impl Show {
6967
}
7068
}
7169
Info::Targets => {
72-
let target_info = get_spirv_targets()?.join("\n");
73-
println!("{}", target_info);
70+
for t in Self::available_spirv_targets_iter() {
71+
println!("{}", t);
72+
}
7473
}
7574
}
7675

@@ -85,43 +84,26 @@ impl Show {
8584
let last_capability = spirv_builder::Capability::CacheControlsINTEL as u32;
8685
(0..=last_capability).filter_map(spirv_builder::Capability::from_u32)
8786
}
88-
}
8987

90-
/// Gets available SPIR-V targets by calling the `spirv-tools`' validator:
91-
/// ```sh
92-
/// $ spirv-val --version
93-
/// SPIRV-Tools v2022.2-dev unknown hash, 2022-02-16T16:37:15
94-
/// Targets:
95-
/// SPIR-V 1.0
96-
/// SPIR-V 1.1
97-
/// SPIR-V 1.2
98-
/// ... snip for brevity
99-
/// SPIR-V 1.6 (under Vulkan 1.3 semantics)
100-
/// ```
101-
fn get_spirv_targets() -> anyhow::Result<Vec<String>> {
102-
// Defaults that have been tested, 1.2 is the existing default in the shader-crate-template.toml
103-
let mut targets = vec![
104-
"spirv-unknown-vulkan1.0",
105-
"spirv-unknown-vulkan1.1",
106-
"spirv-unknown-vulkan1.2",
107-
];
88+
fn available_spirv_targets_iter() -> impl Iterator<Item = String> {
89+
const TARGET_SPECS_PATH: &str = "~/.cache/rust-gpu/codegen/<version_string>/target-specs/";
10890

109-
let output = Command::new("spirv-val")
110-
.arg("--version")
111-
.stdout(Stdio::piped())
112-
.stderr(Stdio::piped())
113-
.output();
91+
let cache_iter = std::fs::read_dir(TARGET_SPECS_PATH)
92+
.ok()
93+
.into_iter()
94+
.flatten()
95+
.filter_map(|entry| entry.ok())
96+
.map(|de| de.path())
97+
.filter(|p| p.extension().is_some_and(|v| v == "json"))
98+
.filter_map(|mut p| {
99+
p.set_extension("");
100+
p.file_name().map(|f| f.to_string_lossy().into_owned())
101+
});
114102

115-
if let Ok(output) = output {
116-
let version_info = String::from_utf8_lossy(&output.stdout);
117-
if version_info.contains("SPIR-V 1.3") {
118-
targets.push("spirv-unknown-vulkan1.3");
119-
}
120-
if version_info.contains("SPIR-V 1.4") {
121-
targets.push("spirv-unknown-vulkan1.4");
122-
}
123-
// Exhaustively, manually put in all possible versions? or regex them out?
124-
}
103+
let legacy_iter = legacy_target_specs::TARGET_SPECS
104+
.iter()
105+
.map(|(spec, _src)| spec.replace(".json", ""));
125106

126-
Ok(targets.into_iter().map(String::from).collect())
107+
cache_iter.chain(legacy_iter)
108+
}
127109
}

0 commit comments

Comments
 (0)