@@ -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