Skip to content

Commit 9dc0c03

Browse files
committed
Ask user if they want to install new toolchains
Also add some user output for the major steps of installing toolchains, compiling `spirv-builder-cli` and compiling the actual shader. Surprisingly there's no way in the standard library to get a single keypress from the user! There's ways to get a line, therefore a keypress then a newline, but that's not so conventional for responding to a "y/n" prompt. Fixes #14
1 parent 5c544f8 commit 9dc0c03

File tree

13 files changed

+300
-15
lines changed

13 files changed

+300
-15
lines changed

Cargo.lock

Lines changed: 151 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ resolver = "2"
1717
anyhow = "1.0.94"
1818
clap = { version = "4.4.8", features = ["derive"] }
1919
chrono = { version = "0.4.38", default-features = false, features = ["std"] }
20+
crossterm = "0.28.1"
2021
directories = "5.0.1"
2122
env_home = "0.1.0"
2223
env_logger = "0.10"
@@ -49,7 +50,6 @@ multiple_crate_versions = { level = "allow", priority = 1 }
4950
pub_with_shorthand = { level = "allow", priority = 1 }
5051
partial_pub_fields = { level = "allow", priority = 1 }
5152
pattern_type_mismatch = { level = "allow", priority = 1 }
52-
print_stdout = { level = "allow", priority = 1 }
5353
std_instead_of_alloc = { level = "allow", priority = 1 }
5454

5555

README.md

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ Options:
100100
--force-spirv-cli-rebuild
101101
Force `spirv-builder-cli` and `rustc_codegen_spirv` to be rebuilt
102102
103+
--auto-install-rust-toolchain
104+
Assume "yes" to "Install Rust toolchain: [y/n]" prompt
105+
103106
-h, --help
104107
Print help (see a summary with '-h')
105108
@@ -134,6 +137,9 @@ Options:
134137
--force-spirv-cli-rebuild
135138
Force `spirv-builder-cli` and `rustc_codegen_spirv` to be rebuilt
136139
140+
--auto-install-rust-toolchain
141+
Assume "yes" to "Install Rust toolchain: [y/n]" prompt
142+
137143
--shader-target <SHADER_TARGET>
138144
Shader target
139145
@@ -197,13 +203,44 @@ Options:
197203
198204
Show some useful values
199205
200-
Usage: cargo-gpu show [OPTIONS]
206+
Usage: cargo-gpu show <COMMAND>
201207
202-
Options:
203-
--cache-directory
204-
Displays the location of the cache directory
208+
Commands:
209+
cache-directory Displays the location of the cache directory
210+
spirv-source The source location of spirv-std
211+
help Print this message or the help of the given subcommand(s)
205212
213+
Options:
206214
-h, --help
207215
Print help
208216
217+
218+
* Cache-directory
219+
220+
Displays the location of the cache directory
221+
222+
Usage: cargo-gpu show cache-directory
223+
224+
Options:
225+
-h, --help
226+
Print help
227+
228+
229+
* Spirv-source
230+
231+
The source location of spirv-std
232+
233+
Usage: cargo-gpu show spirv-source [OPTIONS]
234+
235+
Options:
236+
--shader-crate <SHADER_CRATE>
237+
The location of the shader-crate to inspect to determine its spirv-std dependency
238+
239+
[default: ./]
240+
241+
-h, --help
242+
Print help
243+
244+
245+
209246
````

crates/cargo-gpu/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ serde_json.workspace = true
2121
toml.workspace = true
2222
chrono.workspace = true
2323
http.workspace = true
24+
crossterm.workspace = true
2425

2526
[dev-dependencies]
2627
test-log.workspace = true

crates/cargo-gpu/src/build.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! `cargo gpu build`, analogous to `cargo build`
22
3-
use std::io::Write as _;
4-
53
use anyhow::Context as _;
64
use clap::Parser;
75
use spirv_builder_cli::{Linkage, ShaderModule};
@@ -64,6 +62,11 @@ impl Build {
6462
let arg = serde_json::to_string_pretty(&spirv_builder_args)?;
6563
log::info!("using spirv-builder-cli arg: {arg}");
6664

65+
crate::user_output!(
66+
"Running `spirv-builder-cli` to compile shader at {}...\n",
67+
self.install.shader_crate.display()
68+
);
69+
6770
// Call spirv-builder-cli to compile the shaders.
6871
let output = std::process::Command::new(spirv_builder_cli_path)
6972
.arg(arg)
@@ -112,7 +115,6 @@ impl Build {
112115
let manifest_path = self.output_dir.join("manifest.json");
113116
// Sort the contents so the output is deterministic
114117
linkage.sort();
115-
// UNWRAP: safe because we know this always serializes
116118
let json = serde_json::to_string_pretty(&linkage)?;
117119
let mut file = std::fs::File::create(&manifest_path).with_context(|| {
118120
format!(

crates/cargo-gpu/src/install.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ pub struct Install {
118118
/// Force `spirv-builder-cli` and `rustc_codegen_spirv` to be rebuilt.
119119
#[clap(long)]
120120
force_spirv_cli_rebuild: bool,
121+
122+
/// Assume "yes" to "Install Rust toolchain: [y/n]" prompt.
123+
#[clap(long, action)]
124+
auto_install_rust_toolchain: bool,
121125
}
122126

123127
impl Install {
@@ -128,6 +132,7 @@ impl Install {
128132
self.spirv_builder_source.clone(),
129133
self.spirv_builder_version.clone(),
130134
self.rust_toolchain.clone(),
135+
self.auto_install_rust_toolchain,
131136
)
132137
}
133138

@@ -230,6 +235,11 @@ impl Install {
230235
self.write_source_files()?;
231236
self.write_target_spec_files()?;
232237

238+
crate::user_output!(
239+
"Compiling shader-specific `spirv-builder-cli` for {}\n",
240+
self.shader_crate.display()
241+
);
242+
233243
let mut command = std::process::Command::new("cargo");
234244
command
235245
.current_dir(&checkout)

0 commit comments

Comments
 (0)