@@ -11,8 +11,30 @@ fn main() {
1111
1212 let build_config = "RelWithDebInfo" ;
1313
14+ let target_os = std:: env:: var ( "CARGO_CFG_TARGET_OS" ) . unwrap ( ) ;
15+
16+ // Prevent the cmake crate from injecting cc-derived compiler flags
17+ // (e.g. /MD on MSVC) that conflict with Bitcoin Core's own CMakeLists.txt
18+ // flag management. Bitcoin Core's build system manages all necessary
19+ // compiler flags itself via target_compile_options.
20+ //
21+ // On Windows/MSVC, CMake normally adds /DWIN32 and /D_WINDOWS via
22+ // CMAKE_CXX_FLAGS_INIT, but setting CMAKE_CXX_FLAGS to empty overrides
23+ // that. We must restore these definitions so that code guarded by
24+ // #if defined(WIN32) (e.g. cleanse.cpp's SecureZeroMemory path) compiles
25+ // correctly instead of falling through to GCC-style inline assembly.
26+ let ( c_flags, cxx_flags) = if target_os == "windows" {
27+ ( "/DWIN32 /D_WINDOWS" , "/DWIN32 /D_WINDOWS" )
28+ } else {
29+ ( "" , "" )
30+ } ;
31+
1432 let output_dir = cmake:: Config :: new ( "bitcoin" )
1533 . profile ( build_config)
34+ . no_default_flags ( true )
35+ . define ( "CMAKE_C_FLAGS" , c_flags)
36+ . define ( "CMAKE_CXX_FLAGS" , cxx_flags)
37+ . define ( "CMAKE_ASM_FLAGS" , "" )
1638 . define ( "BUILD_KERNEL_LIB" , "ON" )
1739 . define ( "BUILD_TESTS" , "OFF" )
1840 . define ( "BUILD_BENCH" , "OFF" )
@@ -64,7 +86,6 @@ fn main() {
6486 . expect ( "Couldn't write bindings!" ) ;
6587
6688 let compiler = cc:: Build :: new ( ) . get_compiler ( ) ;
67- let target_os = std:: env:: var ( "CARGO_CFG_TARGET_OS" ) . unwrap ( ) ;
6889
6990 if target_os == "windows" {
7091 println ! ( "cargo:rustc-link-lib=bcrypt" ) ;
0 commit comments