Skip to content

Commit 54cce37

Browse files
committed
Fix: try a different strategy for adding libnvvm to path
1 parent 6b3fc44 commit 54cce37

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

crates/cuda_builder/src/lib.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ pub use nvvm::*;
44
use serde::Deserialize;
55
use std::{
66
borrow::Borrow,
7-
env, fmt,
7+
env,
8+
ffi::OsString,
9+
fmt,
810
path::{Path, PathBuf},
911
process::{Command, Stdio},
1012
};
@@ -278,16 +280,15 @@ fn find_rustc_codegen_nvvm() -> PathBuf {
278280
panic!("Could not find {} in library path", filename);
279281
}
280282

281-
fn add_libnvvm_to_path() {
283+
fn get_new_path_var() -> OsString {
282284
let split_paths = env::var_os(dylib_path_envvar()).unwrap_or_default();
283285
let mut paths = env::split_paths(&split_paths).collect::<Vec<_>>();
284286
let libnvvm_path = find_cuda_helper::find_cuda_root()
285287
.unwrap()
286288
.join("nvvm")
287289
.join("bin");
288290
paths.push(libnvvm_path);
289-
let joined = env::join_paths(&paths).expect("Failed to join paths for PATH");
290-
env::set_var(dylib_path_envvar(), joined);
291+
env::join_paths(&paths).expect("Failed to join paths for PATH")
291292
}
292293

293294
/// Joins strings together while ensuring none of the strings contain the separator.
@@ -309,7 +310,7 @@ fn invoke_rustc(builder: &CudaBuilder) -> Result<PathBuf, CudaBuilderError> {
309310
// on what this does
310311
let rustc_codegen_nvvm = find_rustc_codegen_nvvm();
311312

312-
add_libnvvm_to_path();
313+
let new_path = get_new_path_var();
313314

314315
let mut rustflags = vec![format!(
315316
"-Zcodegen-backend={}",
@@ -367,6 +368,8 @@ fn invoke_rustc(builder: &CudaBuilder) -> Result<PathBuf, CudaBuilderError> {
367368
target,
368369
]);
369370

371+
cargo.env(dylib_path_envvar(), new_path);
372+
370373
if builder.release {
371374
cargo.arg("--release");
372375
}

0 commit comments

Comments
 (0)