Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On NixOS find cudatoolkit via which nvcc, fixes #92. #93

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions crates/find_cuda_helper/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Tiny crate for common logic for finding and including CUDA.

use std::process::Command;
use std::{
env,
path::{Path, PathBuf},
Expand Down Expand Up @@ -131,6 +132,7 @@ pub fn find_cuda_lib_dirs() -> Vec<PathBuf> {
candidates.push(e)
}
candidates.push(PathBuf::from("/usr/lib/cuda"));
candidates.push(detect_cuda_root_via_which_nvcc());

let mut valid_paths = vec![];
for base in &candidates {
Expand All @@ -150,6 +152,24 @@ pub fn find_cuda_lib_dirs() -> Vec<PathBuf> {
valid_paths
}

#[cfg(not(target_os = "windows"))]
fn detect_cuda_root_via_which_nvcc() -> PathBuf {
let output = Command::new("which")
.arg("nvcc")
.output()
.expect("Command `which` must be available on *nix like systems.")
.stdout;

let path: PathBuf = String::from_utf8(output)
.expect("Result must be valid UTF-8")
.trim()
.to_string()
.into();

// The above finds `CUDASDK/bin/nvcc`, so we have to go 2 up for the SDK root.
path.parent().unwrap().parent().unwrap().to_path_buf()
}

#[cfg(target_os = "windows")]
pub fn find_optix_root() -> Option<PathBuf> {
// the optix SDK installer sets OPTIX_ROOT_DIR whenever it installs.
Expand Down