Skip to content

Commit

Permalink
Ask user if they want to install new toolchains
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tombh committed Dec 21, 2024
1 parent 5c544f8 commit ee1993a
Show file tree
Hide file tree
Showing 13 changed files with 287 additions and 14 deletions.
151 changes: 151 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ resolver = "2"
anyhow = "1.0.94"
clap = { version = "4.4.8", features = ["derive"] }
chrono = { version = "0.4.38", default-features = false, features = ["std"] }
crossterm = "0.28.1"
directories = "5.0.1"
env_home = "0.1.0"
env_logger = "0.10"
Expand Down Expand Up @@ -49,7 +50,6 @@ multiple_crate_versions = { level = "allow", priority = 1 }
pub_with_shorthand = { level = "allow", priority = 1 }
partial_pub_fields = { level = "allow", priority = 1 }
pattern_type_mismatch = { level = "allow", priority = 1 }
print_stdout = { level = "allow", priority = 1 }
std_instead_of_alloc = { level = "allow", priority = 1 }


45 changes: 41 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ Options:
--force-spirv-cli-rebuild
Force `spirv-builder-cli` and `rustc_codegen_spirv` to be rebuilt
--auto-install-rust-toolchain
Assume "yes" to "Install Rust toolchain: [y/n]" prompt
-h, --help
Print help (see a summary with '-h')
Expand Down Expand Up @@ -134,6 +137,9 @@ Options:
--force-spirv-cli-rebuild
Force `spirv-builder-cli` and `rustc_codegen_spirv` to be rebuilt
--auto-install-rust-toolchain
Assume "yes" to "Install Rust toolchain: [y/n]" prompt
--shader-target <SHADER_TARGET>
Shader target
Expand Down Expand Up @@ -197,13 +203,44 @@ Options:
Show some useful values
Usage: cargo-gpu show [OPTIONS]
Usage: cargo-gpu show <COMMAND>
Options:
--cache-directory
Displays the location of the cache directory
Commands:
cache-directory Displays the location of the cache directory
spirv-source The source location of spirv-std
help Print this message or the help of the given subcommand(s)
Options:
-h, --help
Print help
* Cache-directory
Displays the location of the cache directory
Usage: cargo-gpu show cache-directory
Options:
-h, --help
Print help
* Spirv-source
The source location of spirv-std
Usage: cargo-gpu show spirv-source [OPTIONS]
Options:
--shader-crate <SHADER_CRATE>
The location of the shader-crate to inspect to determine its spirv-std dependency
[default: ./]
-h, --help
Print help
````
1 change: 1 addition & 0 deletions crates/cargo-gpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ serde_json.workspace = true
toml.workspace = true
chrono.workspace = true
http.workspace = true
crossterm.workspace = true

[dev-dependencies]
test-log.workspace = true
Expand Down
8 changes: 5 additions & 3 deletions crates/cargo-gpu/src/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! `cargo gpu build`, analogous to `cargo build`
use std::io::Write as _;

use anyhow::Context as _;
use clap::Parser;
use spirv_builder_cli::{Linkage, ShaderModule};
Expand Down Expand Up @@ -64,6 +62,11 @@ impl Build {
let arg = serde_json::to_string_pretty(&spirv_builder_args)?;
log::info!("using spirv-builder-cli arg: {arg}");

crate::user_output!(
"Running `spirv-builder-cli` to compile shader at {}...\n",
self.install.shader_crate.display()
);

// Call spirv-builder-cli to compile the shaders.
let output = std::process::Command::new(spirv_builder_cli_path)
.arg(arg)
Expand Down Expand Up @@ -112,7 +115,6 @@ impl Build {
let manifest_path = self.output_dir.join("manifest.json");
// Sort the contents so the output is deterministic
linkage.sort();
// UNWRAP: safe because we know this always serializes
let json = serde_json::to_string_pretty(&linkage)?;
let mut file = std::fs::File::create(&manifest_path).with_context(|| {
format!(
Expand Down
10 changes: 10 additions & 0 deletions crates/cargo-gpu/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ pub struct Install {
/// Force `spirv-builder-cli` and `rustc_codegen_spirv` to be rebuilt.
#[clap(long)]
force_spirv_cli_rebuild: bool,

/// Assume "yes" to "Install Rust toolchain: [y/n]" prompt.
#[clap(long, action)]
auto_install_rust_toolchain: bool,
}

impl Install {
Expand All @@ -128,6 +132,7 @@ impl Install {
self.spirv_builder_source.clone(),
self.spirv_builder_version.clone(),
self.rust_toolchain.clone(),
self.auto_install_rust_toolchain,
)
}

Expand Down Expand Up @@ -230,6 +235,11 @@ impl Install {
self.write_source_files()?;
self.write_target_spec_files()?;

crate::user_output!(
"Compiling shader-specific `spirv-builder-cli` for {}\n",
self.shader_crate.display()
);

let mut command = std::process::Command::new("cargo");
command
.current_dir(&checkout)
Expand Down
Loading

0 comments on commit ee1993a

Please sign in to comment.