Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 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 @@ -15,7 +15,7 @@ exclude = [
resolver = "2"

[workspace.dependencies]
spirv-builder = { git = "https://github.com/Rust-GPU/rust-gpu", rev = "e97524f6b4816056b3edaa70c3e0e0c656392c05", default-features = false }
spirv-builder = { git = "https://github.com/Rust-GPU/rust-gpu", rev = "86d74b65d218bc506f6f68eea42bea56fbc413ec", default-features = false }
anyhow = "1.0.98"
clap = { version = "4.5.41", features = ["derive"] }
crossterm = "0.29.0"
Expand Down
22 changes: 18 additions & 4 deletions crates/cargo-gpu/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@ pub struct BuildArgs {
#[clap(long, short, action)]
pub watch: bool,

/// the flattened [`SpirvBuilder`]
/// The flattened [`SpirvBuilder`]
#[clap(flatten)]
#[serde(flatten)]
pub spirv_builder: SpirvBuilder,

///Renames the manifest.json file to the given name
/// Renames the `manifest.json` file to the given name
#[clap(long, short, default_value = "manifest.json")]
pub manifest_file: String,

/// When building fails with [`SpirvBuilderError::NoArtifactProduced`], count it as a success anyway.
/// Used for e.g. `clippy`, which doesn't produce any artifacts. Defaults to false.
#[clap(skip)]
pub allow_no_artifacts: bool,
}

impl Default for BuildArgs {
Expand All @@ -39,6 +44,7 @@ impl Default for BuildArgs {
watch: false,
spirv_builder: SpirvBuilder::default(),
manifest_file: String::from("manifest.json"),
allow_no_artifacts: false,
}
}
}
Expand Down Expand Up @@ -116,8 +122,16 @@ impl Build {
"Compiling shaders at {}...\n",
self.install.shader_crate.display()
);
let result = self.build.spirv_builder.build()?;
self.parse_compilation_result(&result)?;
let result = self.build.spirv_builder.build();
match result {
Ok(result) => {
self.parse_compilation_result(&result)?;
}
// conditionally ignore NoArtifactProduced
Err(SpirvBuilderError::NoArtifactProduced { .. })
if self.build.allow_no_artifacts => {}
Err(err) => return Err(err.into()),
}
}
Ok(())
}
Expand Down
4 changes: 3 additions & 1 deletion crates/cargo-gpu/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ impl Config {
) -> anyhow::Result<crate::build::Build> {
let mut config = metadata.as_json(shader_crate_path)?;

env_args.retain(|arg| !(arg == "build" || arg == "install"));
env_args.retain(|arg| {
!(arg == "build" || arg == "install" || arg == "check" || arg == "clippy")
});
let cli_args_json = Self::cli_args_to_json(env_args)?;
Self::json_merge(&mut config, cli_args_json, None)?;

Expand Down
20 changes: 19 additions & 1 deletion crates/cargo-gpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ pub enum Command {
/// Compile a shader crate to SPIR-V.
Build(Box<Build>),

/// Run `cargo check` on the shader crate with a SPIR-V target without building the actual shaders
Check(Box<Build>),

/// Run clippy on a shader crate with a SPIR-V target
Clippy(Box<Build>),

/// Show some useful values.
Show(Show),

Expand Down Expand Up @@ -140,13 +146,25 @@ impl Command {
);
command.install.run()?;
}
Self::Build(build) => {
Self::Build(build) | Self::Check(build) | Self::Clippy(build) => {
let shader_crate_path = &build.install.shader_crate;
let mut command = config::Config::clap_command_with_cargo_config(
shader_crate_path,
env_args,
metadata_cache,
)?;
#[expect(clippy::wildcard_enum_match_arm, reason = "unreachable")]
match self {
Self::Check(_) => {
command.build.spirv_builder.cargo_cmd = Some("check".into());
command.build.allow_no_artifacts = true;
}
Self::Clippy(_) => {
command.build.spirv_builder.cargo_cmd = Some("clippy".into());
command.build.allow_no_artifacts = true;
}
_ => {}
}
log::debug!("building with final merged arguments: {command:#?}");

if command.build.watch {
Expand Down
3 changes: 3 additions & 0 deletions crates/shader-crate-template/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ edition = "2021"
[lib]
crate-type = ["rlib", "cdylib"]

[lints.rust]
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(target_arch, values("spirv"))'] }

# Dependencies for CPU and GPU code
[dependencies]
# TODO: use a simple crate version once v0.10.0 is released
Expand Down