File tree 1 file changed +20
-0
lines changed
crates/find_cuda_helper/src
1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 1
1
//! Tiny crate for common logic for finding and including CUDA.
2
2
3
+ use std:: process:: Command ;
3
4
use std:: {
4
5
env,
5
6
path:: { Path , PathBuf } ,
@@ -131,6 +132,7 @@ pub fn find_cuda_lib_dirs() -> Vec<PathBuf> {
131
132
candidates. push ( e)
132
133
}
133
134
candidates. push ( PathBuf :: from ( "/usr/lib/cuda" ) ) ;
135
+ candidates. push ( detect_cuda_root_via_which_nvcc ( ) ) ;
134
136
135
137
let mut valid_paths = vec ! [ ] ;
136
138
for base in & candidates {
@@ -150,6 +152,24 @@ pub fn find_cuda_lib_dirs() -> Vec<PathBuf> {
150
152
valid_paths
151
153
}
152
154
155
+ #[ cfg( not( target_os = "windows" ) ) ]
156
+ fn detect_cuda_root_via_which_nvcc ( ) -> PathBuf {
157
+ let output = Command :: new ( "which" )
158
+ . arg ( "nvcc" )
159
+ . output ( )
160
+ . expect ( "Command `which` must be available on *nix like systems." )
161
+ . stdout ;
162
+
163
+ let path: PathBuf = String :: from_utf8 ( output)
164
+ . expect ( "Result must be valid UTF-8" )
165
+ . trim ( )
166
+ . to_string ( )
167
+ . into ( ) ;
168
+
169
+ // The above finds `CUDASDK/bin/nvcc`, so we have to go 2 up for the SDK root.
170
+ path. parent ( ) . unwrap ( ) . parent ( ) . unwrap ( ) . to_path_buf ( )
171
+ }
172
+
153
173
#[ cfg( target_os = "windows" ) ]
154
174
pub fn find_optix_root ( ) -> Option < PathBuf > {
155
175
// the optix SDK installer sets OPTIX_ROOT_DIR whenever it installs.
You can’t perform that action at this time.
0 commit comments