Skip to content

Commit 025af1f

Browse files
committed
feature flags
1 parent f50708b commit 025af1f

File tree

6 files changed

+41
-12
lines changed

6 files changed

+41
-12
lines changed

crates/cuda_builder/Cargo.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@ description = "Builder for easily building rustc_codegen_nvvm crates"
88
repository = "https://github.com/Rust-GPU/Rust-CUDA"
99
readme = "../../README.md"
1010

11+
[features]
12+
default = ["nvvm-v19"]
13+
nvvm-v7 = ["dep:rustc_codegen_nvvm_v7"]
14+
nvvm-v19 = ["dep:rustc_codegen_nvvm_v19"]
15+
1116
[dependencies]
12-
rustc_codegen_nvvm_v7 = { version = "0.3", path = "../rustc_codegen_nvvm_v7" }
13-
rustc_codegen_nvvm_v19 = { version = "0.3", path = "../rustc_codegen_nvvm_v19" }
17+
rustc_codegen_nvvm_v7 = { version = "0.3", path = "../rustc_codegen_nvvm_v7", optional = true }
18+
rustc_codegen_nvvm_v19 = { version = "0.3", path = "../rustc_codegen_nvvm_v19", optional = true }
1419
nvvm = { path = "../nvvm", version = "0.1" }
1520
serde = { version = "1.0.217", features = ["derive"] }
16-
serde_json = "1.0.138"
21+
serde_json = "1.0.138"

crates/cuda_builder/src/lib.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,13 @@ impl CudaBuilder {
162162
ptx_file_copy_path: None,
163163
generate_line_info: true,
164164
nvvm_opts: true,
165-
arch: NvvmArch::Compute61,
165+
arch: if cfg!(feature = "nvvm-v19") {
166+
NvvmArch::Compute100
167+
} else if cfg!(feature = "nvvm-v7") {
168+
NvvmArch::default()
169+
} else {
170+
panic!("No NVVM version feature enabled. Enable either 'nvvm-v7' or 'nvvm-v19'");
171+
},
166172
ftz: false,
167173
fast_sqrt: false,
168174
fast_div: false,
@@ -358,17 +364,29 @@ fn dylib_path() -> Vec<PathBuf> {
358364
}
359365

360366
fn find_rustc_codegen_nvvm() -> PathBuf {
367+
// Determine which version to look for based on enabled features
368+
let version_suffix = if cfg!(feature = "nvvm-v19") {
369+
"_v19"
370+
} else if cfg!(feature = "nvvm-v7") {
371+
"_v7"
372+
} else {
373+
panic!("No NVVM version feature enabled. Enable either 'nvvm-v7' or 'nvvm-v19'");
374+
};
375+
361376
let filename = format!(
362-
"{}rustc_codegen_nvvm{}",
377+
"{}rustc_codegen_nvvm{}{}",
363378
env::consts::DLL_PREFIX,
379+
version_suffix,
364380
env::consts::DLL_SUFFIX
365381
);
382+
366383
for mut path in dylib_path() {
367384
path.push(&filename);
368385
if path.is_file() {
369386
return path;
370387
}
371388
}
389+
372390
panic!("Could not find {} in library path", filename);
373391
}
374392

crates/rustc_codegen_nvvm_v19/build.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ fn target_to_llvm_prebuilt(target: &str) -> String {
6565

6666
fn find_llvm_config(target: &str) -> PathBuf {
6767
// first, if LLVM_CONFIG is set then see if its llvm version if 7.x, if so, use that.
68-
let config_env = tracked_env_var_os("LLVM_CONFIG");
68+
let config_env = tracked_env_var_os("LLVM_CONFIG_19");
6969
// if LLVM_CONFIG is not set, try using llvm-config as a normal app in PATH.
70-
let path_to_try = config_env.unwrap_or_else(|| "llvm-config".into());
70+
let path_to_try = config_env.unwrap_or_else(|| "llvm-config-19".into());
7171

7272
// if USE_PREBUILT_LLVM is set to 1 then download prebuilt llvm without trying llvm-config
73-
if tracked_env_var_os("USE_PREBUILT_LLVM") != Some("1".into()) {
73+
if tracked_env_var_os("USE_PREBUILT_LLVM_19") != Some("1".into()) {
7474
let cmd = Command::new(&path_to_try).arg("--version").output();
7575

7676
if let Ok(out) = cmd {
@@ -125,7 +125,7 @@ fn find_llvm_config(target: &str) -> PathBuf {
125125

126126
out_path
127127
.join("bin")
128-
.join(format!("llvm-config{}", std::env::consts::EXE_SUFFIX))
128+
.join(format!("llvm-config-19{}", std::env::consts::EXE_SUFFIX))
129129
}
130130

131131
fn detect_llvm_link() -> (&'static str, &'static str) {
@@ -152,7 +152,7 @@ fn run_llvm_as() {
152152

153153
println!("cargo:rerun-if-changed=libintrinsics.ll");
154154

155-
let mut cmd = Command::new("llvm-as");
155+
let mut cmd = Command::new("llvm-as-19");
156156
cmd.arg("libintrinsics.ll");
157157

158158
let output = match cmd.stderr(Stdio::inherit()).output() {
-44 Bytes
Binary file not shown.

crates/rustc_codegen_nvvm_v19/src/debug_info/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ pub(crate) fn build_compile_unit_di_node<'ll, 'tcx>(
804804

805805
debug!("build_compile_unit_di_node: {:?}", name_in_debuginfo);
806806

807-
let rustc_producer = "rustc_codegen_nvvm".to_string();
807+
let rustc_producer = "rustc_codegen_nvvm_v19".to_string();
808808

809809
// leave the clang LLVM in there just in case, although it shouldnt be needed because
810810
// gpu stuff is different

xtask/Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@ version = "0.0.0"
44
edition = "2021"
55
license = "MIT"
66

7+
[features]
8+
default = ["nvvm-v19"]
9+
nvvm-v7 = ["dep:rustc_codegen_nvvm_v7"]
10+
nvvm-v19 = ["dep:rustc_codegen_nvvm_v19"]
11+
712
[dependencies]
813
pico-args = "0.4.2"
914
rayon = "1.10"
1015
regex = "1.11.1"
11-
rustc_codegen_nvvm = { path = "../crates/rustc_codegen_nvvm" }
16+
rustc_codegen_nvvm_v7 = { path = "../crates/rustc_codegen_nvvm_v7", optional = true }
17+
rustc_codegen_nvvm_v19 = { path = "../crates/rustc_codegen_nvvm_v19", optional = true }

0 commit comments

Comments
 (0)