Skip to content

Commit 5e26615

Browse files
committed
watch support, broken on windows
1 parent 5290d92 commit 5e26615

File tree

5 files changed

+161
-20
lines changed

5 files changed

+161
-20
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 6 additions & 6 deletions
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 = "74d1c66ceb855f60a995621652c5158a474cb2ee", 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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 21 additions & 5 deletions
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)]
@@ -64,15 +64,31 @@ impl Build {
6464
std::env::current_dir()?.display()
6565
);
6666

67-
if !self.build_args.watch {
67+
if self.build_args.watch {
68+
let this = self.clone();
69+
self.build_args
70+
.spirv_builder
71+
.watch(move |result, accept| {
72+
let result1 = this.parse_compilation_result(&result);
73+
if let Some(accept) = accept {
74+
accept.submit(result1);
75+
}
76+
})?
77+
.context("unreachable")??;
78+
std::thread::park();
79+
} else {
6880
crate::user_output!(
6981
"Compiling shaders at {}...\n",
7082
self.install.spirv_install.shader_crate.display()
7183
);
84+
let result = self.build_args.spirv_builder.build()?;
85+
self.parse_compilation_result(&result)?;
7286
}
87+
Ok(())
88+
}
7389

74-
let result = self.build_args.spirv_builder.build()?;
75-
90+
/// Parses compilation result from `SpirvBuilder` and writes it out to a file
91+
fn parse_compilation_result(&self, result: &CompileResult) -> anyhow::Result<()> {
7692
let shaders = match &result.module {
7793
ModuleResult::MultiModule(modules) => {
7894
anyhow::ensure!(!modules.is_empty(), "No shader modules were compiled");

crates/cargo-gpu/src/install.rs

Lines changed: 1 addition & 1 deletion
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)