Skip to content

Commit 304eb05

Browse files
committed
Fix incorrect watch feature handling in build
1 parent 5840b2b commit 304eb05

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

crates/cargo-gpu/src/build.rs

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,14 @@
22
#![allow(clippy::unwrap_used, reason = "this is basically a test")]
33
//! `cargo gpu build`, analogous to `cargo build`
44
5-
use spirv_builder::SpirvBuilder;
6-
use std::path::PathBuf;
7-
8-
#[cfg(feature = "watch")]
95
use anyhow::Context as _;
10-
#[cfg(feature = "watch")]
11-
use spirv_builder::{CompileResult, ModuleResult};
12-
#[cfg(feature = "watch")]
6+
use spirv_builder::{CompileResult, ModuleResult, SpirvBuilder};
137
use std::io::Write as _;
8+
use std::path::PathBuf;
149

1510
use crate::install::Install;
16-
use crate::lockfile::LockfileMismatchHandler;
17-
18-
#[cfg(feature = "watch")]
1911
use crate::linkage::Linkage;
12+
use crate::lockfile::LockfileMismatchHandler;
2013

2114
/// Args for just a build
2215
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
@@ -101,6 +94,22 @@ impl Build {
10194
std::env::current_dir()?.display()
10295
);
10396

97+
self.build_or_watch()
98+
}
99+
100+
/// Builds shader crate locally or watches it for changes
101+
/// depending on presence of `watch` feature and `BuildArgs::watch` flag.
102+
fn build_or_watch(&self) -> anyhow::Result<()> {
103+
let build = || -> anyhow::Result<()> {
104+
crate::user_output!(
105+
"Compiling shaders at {}...\n",
106+
self.install.shader_crate.display()
107+
);
108+
let result = self.build.spirv_builder.build()?;
109+
self.parse_compilation_result(&result)?;
110+
Ok(())
111+
};
112+
104113
#[cfg(feature = "watch")]
105114
if self.build.watch {
106115
let this = self.clone();
@@ -115,19 +124,16 @@ impl Build {
115124
.context("unreachable")??;
116125
std::thread::park();
117126
} else {
118-
crate::user_output!(
119-
"Compiling shaders at {}...\n",
120-
self.install.shader_crate.display()
121-
);
122-
let result = self.build.spirv_builder.build()?;
123-
self.parse_compilation_result(&result)?;
127+
build()?;
124128
}
125129

130+
#[cfg(not(feature = "watch"))]
131+
build()?;
132+
126133
Ok(())
127134
}
128135

129136
/// Parses compilation result from `SpirvBuilder` and writes it out to a file
130-
#[cfg(feature = "watch")]
131137
fn parse_compilation_result(&self, result: &CompileResult) -> anyhow::Result<()> {
132138
let shaders = match &result.module {
133139
ModuleResult::MultiModule(modules) => {

crates/cargo-gpu/src/linkage.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! Mainly for the Linkage struct, which is written to a json file.
22
3-
#![cfg(feature = "watch")]
4-
53
/// Shader source and entry point that can be used to create shader linkage.
64
#[derive(serde::Serialize, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
75
pub struct Linkage {

0 commit comments

Comments
 (0)