Skip to content
This repository was archived by the owner on Apr 15, 2026. It is now read-only.

Commit b0211a3

Browse files
committed
fix: ensure -p package is resolved to shader crate before build and install commands are reconstructed
1 parent bf24eb6 commit b0211a3

3 files changed

Lines changed: 30 additions & 7 deletions

File tree

crates/cargo-gpu/src/build.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ impl Build {
6161
let installed_backend = self.install.run()?;
6262
let mut metadata = crate::metadata::MetadataCache::default();
6363

64-
if let Some(package) = self.install.package.as_ref() {
65-
self.install.shader_crate = metadata.resolve_package_to_shader_crate(package)?;
66-
}
64+
self.install.shader_crate = self.install.get_resolved_shader_crate(&mut metadata)?;
6765

6866
let _lockfile_mismatch_handler = LockfileMismatchHandler::new(
6967
&self.install.shader_crate,

crates/cargo-gpu/src/install.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::spirv_source::{
44
get_channel_from_rustc_codegen_spirv_build_script, query_metadata, FindPackage as _,
55
};
66
use crate::target_specs::update_target_specs_files;
7+
use crate::MetadataCache;
78
use crate::{cache_dir, spirv_source::SpirvSource};
89
use anyhow::Context as _;
910
use spirv_builder::SpirvBuilder;
@@ -150,6 +151,24 @@ impl Install {
150151
}
151152
}
152153

154+
/// Resolves a possible workspace package passed with `-p {package}` to its shader crate path,
155+
/// as if it had been passed with `--shader-crate {package-parent-path}`.
156+
///
157+
/// If no such package was passed, this resolves to the shader crate passed, or the default.
158+
///
159+
/// ## Errors
160+
/// Errs if the metadata cache cannot resolve the shader crate.
161+
/// See [`MetadataCache::resolve_package_to_shader_crate`] for more info.
162+
pub fn get_resolved_shader_crate(
163+
&self,
164+
metadata: &mut MetadataCache,
165+
) -> anyhow::Result<std::path::PathBuf> {
166+
self.package.as_ref().map_or_else(
167+
|| Ok(self.shader_crate.clone()),
168+
|package| metadata.resolve_package_to_shader_crate(package),
169+
)
170+
}
171+
153172
/// Create the `rustc_codegen_spirv_dummy` crate that depends on `rustc_codegen_spirv`
154173
fn write_source_files(source: &SpirvSource, checkout: &Path) -> anyhow::Result<()> {
155174
// skip writing a dummy project if we use a local rust-gpu checkout

crates/cargo-gpu/src/lib.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,12 @@ impl Command {
128128
) -> anyhow::Result<()> {
129129
match &self {
130130
Self::Install(install) => {
131-
let shader_crate_path = &install.shader_crate;
131+
// NOTE: Here `install` is only used for its `shader_crate` field, the rest is
132+
// not used, as config::Config::clap_command_with_cargo_config reconstructs
133+
// the command from the environment.
134+
let shader_crate_path = install.get_resolved_shader_crate(metadata_cache)?;
132135
let command = config::Config::clap_command_with_cargo_config(
133-
shader_crate_path,
136+
&shader_crate_path,
134137
env_args,
135138
metadata_cache,
136139
)?;
@@ -141,9 +144,12 @@ impl Command {
141144
command.install.run()?;
142145
}
143146
Self::Build(build) => {
144-
let shader_crate_path = &build.install.shader_crate;
147+
// NOTE: Here `build` is only used for its `shader_crate` field, the rest is
148+
// not used, as config::Config::clap_command_with_cargo_config reconstructs
149+
// the command from the environment.
150+
let shader_crate_path = build.install.get_resolved_shader_crate(metadata_cache)?;
145151
let mut command = config::Config::clap_command_with_cargo_config(
146-
shader_crate_path,
152+
&shader_crate_path,
147153
env_args,
148154
metadata_cache,
149155
)?;

0 commit comments

Comments
 (0)