2
2
3
3
use std:: fs;
4
4
5
- use anyhow:: Context ;
6
-
7
5
use crate :: cache_dir;
8
6
9
7
/// Show the computed source of the spirv-std dependency.
@@ -89,12 +87,12 @@ impl Show {
89
87
( 0 ..=last_capability) . filter_map ( spirv_builder:: Capability :: from_u32)
90
88
}
91
89
92
- // List all available spirv targets, note: the targets from compile time of cargo-gpu and those
93
- // in the cache-directory will be picked up.
90
+ /// List all available spirv targets, note: the targets from compile time of cargo-gpu and those
91
+ /// in the cache-directory will be picked up.
94
92
fn available_spirv_targets_iter ( ) -> anyhow:: Result < impl Iterator < Item = String > > {
95
93
let legacy_targets = legacy_target_specs:: TARGET_SPECS
96
94
. iter ( )
97
- . map ( |( spec, _src) | spec. to_string ( ) ) ; // Convert to String
95
+ . map ( |( spec, _src) | ( * spec) . to_string ( ) ) ;
98
96
99
97
let cache_dir = cache_dir ( ) ?;
100
98
if !cache_dir. exists ( ) {
@@ -103,29 +101,28 @@ impl Show {
103
101
cache_dir. display( )
104
102
) ;
105
103
}
106
-
107
104
let entries = fs:: read_dir ( & cache_dir) ?;
108
-
109
105
let cached_targets: Vec < String > = entries
110
- . filter_map ( |entry| entry . ok ( ) )
106
+ . flatten ( )
111
107
. flat_map ( |entry| {
112
108
let path = entry. path ( ) ;
113
109
if path. is_dir ( ) {
114
110
fs:: read_dir ( path)
115
111
. ok ( )
116
112
. into_iter ( )
117
113
. flatten ( )
118
- . filter_map ( |e| e. ok ( ) )
119
- . filter_map ( |e| {
120
- e. path ( )
114
+ . filter_map ( Result :: ok)
115
+ . filter_map ( |entry| {
116
+ entry
117
+ . path ( )
121
118
. file_stem ( )
122
- . and_then ( |s| s . to_str ( ) )
119
+ . and_then ( std :: ffi :: OsStr :: to_str)
123
120
. map ( str:: to_owned)
124
121
} )
125
122
. collect :: < Vec < _ > > ( )
126
- } else if path. extension ( ) . and_then ( |s| s . to_str ( ) ) == Some ( "json" ) {
123
+ } else if path. extension ( ) . and_then ( std :: ffi :: OsStr :: to_str) == Some ( "json" ) {
127
124
path. file_stem ( )
128
- . and_then ( |s| s . to_str ( ) )
125
+ . and_then ( std :: ffi :: OsStr :: to_str)
129
126
. map ( str:: to_owned)
130
127
. into_iter ( )
131
128
. collect ( )
@@ -134,21 +131,18 @@ impl Show {
134
131
}
135
132
} )
136
133
. collect ( ) ;
137
-
138
134
if cached_targets. is_empty ( ) {
139
135
log:: error!(
140
136
"Cache directory exists but contains no valid SPIR-V target files (*.json): {}" ,
141
137
cache_dir. display( )
142
138
) ;
143
139
}
144
-
145
140
let mut targets: Vec < String > = legacy_targets
146
141
. chain ( cached_targets)
147
- . filter ( |t| t . contains ( "vulkan" ) )
142
+ . filter ( |target| target . contains ( "vulkan" ) )
148
143
. collect :: < std:: collections:: HashSet < _ > > ( )
149
144
. into_iter ( )
150
145
. collect ( ) ;
151
-
152
146
targets. sort ( ) ;
153
147
Ok ( targets. into_iter ( ) )
154
148
}
0 commit comments