File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
crates/find_cuda_helper/src Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 11//! Tiny crate for common logic for finding and including CUDA.
22
3+ use std:: process:: Command ;
34use std:: {
45 env,
56 path:: { Path , PathBuf } ,
@@ -131,6 +132,7 @@ pub fn find_cuda_lib_dirs() -> Vec<PathBuf> {
131132 candidates. push ( e)
132133 }
133134 candidates. push ( PathBuf :: from ( "/usr/lib/cuda" ) ) ;
135+ candidates. push ( detect_cuda_root_via_which_nvcc ( ) ) ;
134136
135137 let mut valid_paths = vec ! [ ] ;
136138 for base in & candidates {
@@ -150,6 +152,24 @@ pub fn find_cuda_lib_dirs() -> Vec<PathBuf> {
150152 valid_paths
151153}
152154
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+
153173#[ cfg( target_os = "windows" ) ]
154174pub fn find_optix_root ( ) -> Option < PathBuf > {
155175 // the optix SDK installer sets OPTIX_ROOT_DIR whenever it installs.
You can’t perform that action at this time.
0 commit comments