Skip to content

Commit 3265a6e

Browse files
committed
watch support, broken on windows
1 parent 5290d92 commit 3265a6e

File tree

5 files changed

+153
-19
lines changed

5 files changed

+153
-19
lines changed

Cargo.lock

+130-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
[workspace]
22
members = [
3-
"crates/cargo-gpu",
4-
"crates/xtask",
3+
"crates/cargo-gpu",
4+
"crates/xtask",
55
]
66

77
exclude = [
8-
# This currently needs to be excluded because it depends on a version of `rust-gpu` that
9-
# uses a toolchain whose Cargo version doesn't recognise version 4 of `Cargo.lock`.
10-
"crates/shader-crate-template"
8+
# This currently needs to be excluded because it depends on a version of `rust-gpu` that
9+
# uses a toolchain whose Cargo version doesn't recognise version 4 of `Cargo.lock`.
10+
"crates/shader-crate-template"
1111
]
1212

1313
resolver = "2"
1414

1515
[workspace.dependencies]
16-
spirv-builder = { git = "https://github.com/Rust-GPU/rust-gpu.git", rev = "eca83dfbfc0aae5c72f1e3f53081f5ccb72c27a4", default-features = false }
16+
spirv-builder = { git = "https://github.com/Rust-GPU/rust-gpu.git", rev = "0c7f509f7da93d0bd12d51230d15a07d0152c593", default-features = false }
1717
anyhow = "1.0.94"
1818
clap = { version = "4.5.37", features = ["derive"] }
1919
crossterm = "0.28.1"

crates/cargo-gpu/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ default-run = "cargo-gpu"
1313
[dependencies]
1414
cargo_metadata.workspace = true
1515
anyhow.workspace = true
16-
spirv-builder = { workspace = true, features = ["clap"] }
16+
spirv-builder = { workspace = true, features = ["clap", "watch"] }
1717
clap.workspace = true
1818
directories.workspace = true
1919
env_logger.workspace = true

crates/cargo-gpu/src/build.rs

+15-4
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ use crate::linkage::Linkage;
77
use crate::lockfile::LockfileMismatchHandler;
88
use crate::{install::Install, target_spec_dir};
99
use anyhow::Context as _;
10-
use spirv_builder::ModuleResult;
10+
use spirv_builder::{CompileResult, ModuleResult};
1111
use std::io::Write as _;
1212

1313
/// `cargo build` subcommands
14-
#[derive(clap::Parser, Debug, serde::Deserialize, serde::Serialize)]
14+
#[derive(Clone, clap::Parser, Debug, serde::Deserialize, serde::Serialize)]
1515
pub struct Build {
1616
/// CLI args for install the `rust-gpu` compiler and components
1717
#[clap(flatten)]
@@ -69,10 +69,21 @@ impl Build {
6969
"Compiling shaders at {}...\n",
7070
self.install.spirv_install.shader_crate.display()
7171
);
72+
let result = self.build_args.spirv_builder.build()?;
73+
self.parse_compilation_result(result)?;
74+
Ok(())
75+
} else {
76+
let this = self.clone();
77+
self.build_args.spirv_builder.watch(move |result| {
78+
this.parse_compilation_result(result)
79+
.expect("watch operation failed")
80+
})?;
81+
std::thread::park();
82+
Ok(())
7283
}
84+
}
7385

74-
let result = self.build_args.spirv_builder.build()?;
75-
86+
fn parse_compilation_result(&self, result: CompileResult) -> anyhow::Result<()> {
7687
let shaders = match &result.module {
7788
ModuleResult::MultiModule(modules) => {
7889
anyhow::ensure!(!modules.is_empty(), "No shader modules were compiled");

crates/cargo-gpu/src/install.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::io::Write as _;
1212
use std::path::{Path, PathBuf};
1313

1414
/// `cargo gpu install`
15-
#[derive(clap::Parser, Debug, serde::Deserialize, serde::Serialize)]
15+
#[derive(Clone, clap::Parser, Debug, serde::Deserialize, serde::Serialize)]
1616
pub struct Install {
1717
/// CLI arguments for installing the Rust toolchain and components
1818
#[clap(flatten)]

0 commit comments

Comments
 (0)