11//! Display various information about `cargo gpu`, eg its cache directory.
22
33use crate :: cache_dir;
4- use crate :: spirv_source:: { query_metadata, SpirvSource } ;
5- use crate :: target_specs:: update_target_specs_files;
6- use anyhow:: bail;
7- use std:: fs;
8- use std:: path:: Path ;
4+ use crate :: spirv_source:: SpirvSource ;
95
106/// Show the computed source of the spirv-std dependency.
117#[ derive( Clone , Debug , clap:: Parser ) ]
@@ -26,9 +22,6 @@ pub enum Info {
2622 Commitsh ,
2723 /// All the available SPIR-V capabilities that can be set with `--capabilities`
2824 Capabilities ,
29-
30- /// All available SPIR-V targets
31- Targets ( SpirvSourceDep ) ,
3225}
3326
3427/// `cargo gpu show`
@@ -70,13 +63,6 @@ impl Show {
7063 println ! ( " {capability:?}" ) ;
7164 }
7265 }
73- Info :: Targets ( SpirvSourceDep { shader_crate } ) => {
74- let ( source, targets) = Self :: available_spirv_targets_iter ( shader_crate) ?;
75- println ! ( "All available targets for rust-gpu version '{source}':" ) ;
76- for target in targets {
77- println ! ( "{target}" ) ;
78- }
79- }
8066 }
8167
8268 Ok ( ( ) )
@@ -90,32 +76,4 @@ impl Show {
9076 let last_capability = spirv_builder:: Capability :: CacheControlsINTEL as u32 ;
9177 ( 0 ..=last_capability) . filter_map ( spirv_builder:: Capability :: from_u32)
9278 }
93-
94- /// List all available spirv targets, note: the targets from compile time of cargo-gpu and those
95- /// in the cache-directory will be picked up.
96- fn available_spirv_targets_iter (
97- shader_crate : & Path ,
98- ) -> anyhow:: Result < ( SpirvSource , impl Iterator < Item = String > ) > {
99- let source = SpirvSource :: new ( shader_crate, None , None ) ?;
100- let install_dir = source. install_dir ( ) ?;
101- if !install_dir. is_dir ( ) {
102- bail ! ( "rust-gpu version {} is not installed" , source) ;
103- }
104- let dummy_metadata = query_metadata ( & install_dir) ?;
105- let target_specs_dir = update_target_specs_files ( & source, & dummy_metadata, false ) ?;
106-
107- let mut targets = fs:: read_dir ( target_specs_dir) ?
108- . filter_map ( |entry| {
109- let file = entry. ok ( ) ?;
110- if file. path ( ) . is_file ( ) {
111- if let Some ( target) = file. file_name ( ) . to_string_lossy ( ) . strip_suffix ( ".json" ) {
112- return Some ( target. to_owned ( ) ) ;
113- }
114- }
115- None
116- } )
117- . collect :: < Vec < _ > > ( ) ;
118- targets. sort ( ) ;
119- Ok ( ( source, targets. into_iter ( ) ) )
120- }
12179}
0 commit comments