File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,11 @@ impl Build {
6060 pub fn run ( & mut self ) -> anyhow:: Result < ( ) > {
6161 let installed_backend = self . install . run ( ) ?;
6262
63+ if let Some ( package) = self . install . package . as_ref ( ) {
64+ self . install . shader_crate =
65+ crate :: metadata:: Metadata :: resolve_package_to_shader_crate ( package) ?;
66+ }
67+
6368 let _lockfile_mismatch_handler = LockfileMismatchHandler :: new (
6469 & self . install . shader_crate ,
6570 & installed_backend. toolchain_channel ,
Original file line number Diff line number Diff line change 11//! Get config from the shader crate's `Cargo.toml` `[*.metadata.rust-gpu.*]`
22
3+ use anyhow:: Context as _;
34use cargo_metadata:: MetadataCommand ;
45use serde_json:: Value ;
56
@@ -9,6 +10,28 @@ use serde_json::Value;
910pub struct Metadata ;
1011
1112impl Metadata {
13+ /// Resolve a package name to a crate directory.
14+ pub fn resolve_package_to_shader_crate ( package : & str ) -> anyhow:: Result < std:: path:: PathBuf > {
15+ log:: debug!( "resolving package '{package}' to shader crate" ) ;
16+ let metadata = MetadataCommand :: new ( ) . exec ( ) ?;
17+ let meta_package = metadata
18+ . packages
19+ . iter ( )
20+ . find ( |pkg| pkg. name . as_str ( ) == package)
21+ . context ( "Package not found in metadata" ) ?;
22+ let shader_crate_path: std:: path:: PathBuf = meta_package
23+ . manifest_path
24+ . parent ( )
25+ . context ( "manifest is missing a parent directory" ) ?
26+ . to_path_buf ( )
27+ . into ( ) ;
28+ log:: debug!(
29+ " determined shader crate path to be '{}'" ,
30+ shader_crate_path. display( )
31+ ) ;
32+ Ok ( shader_crate_path)
33+ }
34+
1235 /// Convert `rust-gpu`-specific sections in `Cargo.toml` to `clap`-compatible arguments.
1336 /// The section in question is: `[package.metadata.rust-gpu.*]`. See the `shader-crate-template`
1437 /// for an example.
You can’t perform that action at this time.
0 commit comments