Skip to content

Commit 6477e78

Browse files
committed
bender-slang: Fix windows build
bender-slang: Fix windows build 2
1 parent 9553d41 commit 6477e78

3 files changed

Lines changed: 27 additions & 17 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ jobs:
4747
with:
4848
toolchain: stable
4949
- name: Build
50-
run: cargo build --all-features --release
50+
run: cargo build --all-features
5151
- name: Cargo Test
52-
run: cargo test --workspace --all-features --release
52+
run: cargo test --workspace --all-features
5353
- name: Run unit-tests
5454
run: tests/run_all.sh
5555
shell: bash

.github/workflows/cli_regression.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
with:
3030
toolchain: stable
3131
- name: Run CLI Regression
32-
run: cargo test --all-features --test cli_regression --release -- --ignored
32+
run: cargo test --all-features --test cli_regression -- --ignored
3333
env:
3434
BENDER_TEST_GOLDEN_BRANCH: ${{ github.base_ref }}
3535

crates/bender-slang/build.rs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ fn main() {
55
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
66
let target_env = std::env::var("CARGO_CFG_TARGET_ENV").unwrap();
77
let build_profile = std::env::var("PROFILE").unwrap();
8+
let cmake_profile = match (target_env.as_str(), build_profile.as_str()) {
9+
// Rust MSVC links against the release CRT;
10+
// using C++ Debug CRT (/MDd) causes LNK2038 mismatches.
11+
("msvc", _) => "RelWithDebInfo",
12+
(_, "debug") => "Debug",
13+
_ => "Release",
14+
};
815

916
// Create the configuration builder
1017
let mut slang_lib = cmake::Config::new("vendor/slang");
@@ -20,7 +27,7 @@ fn main() {
2027
];
2128

2229
// Add debug define if in debug build
23-
if build_profile == "debug" {
30+
if build_profile == "debug" && !(target_env == "msvc") {
2431
common_cxx_defines.push(("SLANG_DEBUG", "1"));
2532
common_cxx_defines.push(("SLANG_ASSERT_ENABLED", "1"));
2633
};
@@ -41,7 +48,8 @@ fn main() {
4148
// Disable finding system-installed packages, we want to fetch and build them from source.
4249
.define("CMAKE_DISABLE_FIND_PACKAGE_fmt", "ON")
4350
.define("CMAKE_DISABLE_FIND_PACKAGE_mimalloc", "ON")
44-
.define("CMAKE_DISABLE_FIND_PACKAGE_Boost", "ON");
51+
.define("CMAKE_DISABLE_FIND_PACKAGE_Boost", "ON")
52+
.profile(cmake_profile);
4553

4654
// Apply common defines and flags
4755
for (def, value) in common_cxx_defines.iter() {
@@ -54,22 +62,24 @@ fn main() {
5462

5563
// Build the slang library
5664
let dst = slang_lib.build();
65+
let lib_dir = dst.join("lib");
5766

5867
// Configure Linker to find Slang static library
59-
println!("cargo:rustc-link-search=native={}/lib", dst.display());
68+
println!("cargo:rustc-link-search=native={}", lib_dir.display());
6069
println!("cargo:rustc-link-lib=static=svlang");
6170

62-
// Link the additional libraries based on build profile and OS
63-
match (build_profile.as_str(), target_env.as_str()) {
64-
("release", _) | (_, "msvc") => {
65-
println!("cargo:rustc-link-lib=static=fmt");
66-
println!("cargo:rustc-link-lib=static=mimalloc");
67-
}
68-
("debug", _) => {
69-
println!("cargo:rustc-link-lib=static=fmtd");
70-
println!("cargo:rustc-link-lib=static=mimalloc-debug");
71-
}
72-
_ => unreachable!(),
71+
// Link the additional libraries based on build profile.
72+
let (fmt_lib, mimalloc_lib) = match (target_env.as_str(), build_profile.as_str()) {
73+
("msvc", _) => ("fmt", "mimalloc"),
74+
(_, "debug") => ("fmtd", "mimalloc-debug"),
75+
_ => ("fmt", "mimalloc"),
76+
};
77+
78+
println!("cargo:rustc-link-lib=static={fmt_lib}");
79+
println!("cargo:rustc-link-lib=static={mimalloc_lib}");
80+
81+
if target_os == "windows" {
82+
println!("cargo:rustc-link-lib=advapi32");
7383
}
7484

7585
// Compile the C++ Bridge

0 commit comments

Comments
 (0)