Skip to content
Open
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: 1 addition & 3 deletions crates/cargo-gpu/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ impl Build {
let installed_backend = self.install.run()?;
let mut metadata = crate::metadata::MetadataCache::default();

if let Some(package) = self.install.package.as_ref() {
self.install.shader_crate = metadata.resolve_package_to_shader_crate(package)?;
}
self.install.shader_crate = self.install.get_resolved_shader_crate(&mut metadata)?;

let _lockfile_mismatch_handler = LockfileMismatchHandler::new(
&self.install.shader_crate,
Expand Down
19 changes: 19 additions & 0 deletions crates/cargo-gpu/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::spirv_source::{
get_channel_from_rustc_codegen_spirv_build_script, query_metadata, FindPackage as _,
};
use crate::target_specs::update_target_specs_files;
use crate::MetadataCache;
use crate::{cache_dir, spirv_source::SpirvSource};
use anyhow::Context as _;
use spirv_builder::SpirvBuilder;
Expand Down Expand Up @@ -150,6 +151,24 @@ impl Install {
}
}

/// Resolves a possible workspace package passed with `-p {package}` to its shader crate path,
/// as if it had been passed with `--shader-crate {package-parent-path}`.
///
/// If no such package was passed, this resolves to the shader crate passed, or the default.
///
/// ## Errors
/// Errs if the metadata cache cannot resolve the shader crate.
/// See [`MetadataCache::resolve_package_to_shader_crate`] for more info.
pub fn get_resolved_shader_crate(
&self,
metadata: &mut MetadataCache,
) -> anyhow::Result<std::path::PathBuf> {
self.package.as_ref().map_or_else(
|| Ok(self.shader_crate.clone()),
|package| metadata.resolve_package_to_shader_crate(package),
)
}

/// Create the `rustc_codegen_spirv_dummy` crate that depends on `rustc_codegen_spirv`
fn write_source_files(source: &SpirvSource, checkout: &Path) -> anyhow::Result<()> {
// skip writing a dummy project if we use a local rust-gpu checkout
Expand Down
14 changes: 10 additions & 4 deletions crates/cargo-gpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,12 @@ impl Command {
) -> anyhow::Result<()> {
match &self {
Self::Install(install) => {
let shader_crate_path = &install.shader_crate;
// NOTE: Here `install` is only used for its `shader_crate` field, the rest is
// not used, as config::Config::clap_command_with_cargo_config reconstructs
// the command from the environment.
let shader_crate_path = install.get_resolved_shader_crate(metadata_cache)?;
let command = config::Config::clap_command_with_cargo_config(
shader_crate_path,
&shader_crate_path,
env_args,
metadata_cache,
)?;
Expand All @@ -141,9 +144,12 @@ impl Command {
command.install.run()?;
}
Self::Build(build) => {
let shader_crate_path = &build.install.shader_crate;
// NOTE: Here `build` is only used for its `shader_crate` field, the rest is
// not used, as config::Config::clap_command_with_cargo_config reconstructs
// the command from the environment.
let shader_crate_path = build.install.get_resolved_shader_crate(metadata_cache)?;
let mut command = config::Config::clap_command_with_cargo_config(
shader_crate_path,
&shader_crate_path,
env_args,
metadata_cache,
)?;
Expand Down
Loading