Skip to content

Commit 5d801f4

Browse files
authored
On NixOS find cudatoolkit via which nvcc, fixes Rust-GPU#92. (Rust-GPU#93)
1 parent e9f625c commit 5d801f4

File tree

1 file changed

+20
-0
lines changed
  • crates/find_cuda_helper/src

1 file changed

+20
-0
lines changed

crates/find_cuda_helper/src/lib.rs

+20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Tiny crate for common logic for finding and including CUDA.
22
3+
use std::process::Command;
34
use 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")]
154174
pub fn find_optix_root() -> Option<PathBuf> {
155175
// the optix SDK installer sets OPTIX_ROOT_DIR whenever it installs.

0 commit comments

Comments
 (0)