Merge bitcoin/bitcoin#31507: build: Use clang-cl to build on Windows natively
What changed, and why it matters
This commit changes Bitcoin Core's Windows build system to use the Clang compiler (clang-cl) instead of Microsoft's own C++ compiler (MSVC/cl.exe). It is a build-toolchain change, not a fix for a security vulnerability in running code. The pull request mentions that MSVC had bugs and missing features, but those are described as development/maintenance problems, not as remotely exploitable flaws. There is no indication this patch fixes an active security issue.
No security response required. Treat as a normal build-system update. Reviewers may want to verify that the new clang-cl CI job and release builds produce bit-identical or otherwise expected binaries, and that the clang_rt.builtins linking does not introduce unexpected runtime dependencies.
Security signals we found
Build toolchain migration from MSVC to clang-cl
Removal of MSVC-specific non-constexpr byteswap paths
Re-enabling of a previously disabled static_assert test
No direct runtime vulnerability described in commit or PR
Evidence from the diff
The merge drops MSVC cl.exe support and switches native Windows builds to clang-cl. It updates CMake presets, compiler flags, intrinsics detection, warning flags, and documentation. Code changes include making byteswap helpers unconditionally constexpr (previously non-constexpr on MSVC), enabling ARM64/x64 inline-assembly paths, and adding a link dependency on clang_rt.builtins. The change also re-enables a static_assert in util_not_null_tests.cpp that MSVC failed to compile. These are correctness/portability improvements for the build and test infrastructure, not runtime security patches.
Changed components
Windows native build configuration (CMake, presets, CI)src/compat/byteswap.hsrc/compat/endian.hsrc/qt/CMakeLists.txtsrc/test/util_not_null_tests.cppDocumentation build guidesInspect captured patch +206 / −231
### .github/ci-windows.py
@@ -65,11 +65,15 @@ def github_import_vs_env(_ci_type):
def generate(ci_type):
command = [
+ "cmake",
+ "-E",
+ "env",
+ "CXXFLAGS=-Wno-error=return-type -Wno-error=conditional-uninitialized -Wno-error=unused-macros",
"cmake",
"-B",
"build",
"-Werror=dev",
- "--preset=vs2026",
+ "--preset=windows",
# Using x64-windows-release for both host and target triplets
# to ensure vcpkg builds only release packages, thereby optimizing
# build time.
### .github/workflows/ci.yml
@@ -207,9 +207,9 @@ jobs:
job-type: [standard, fuzz]
include:
- job-type: standard
- job-name: 'Windows native, VS'
+ job-name: 'Windows native, clang-cl'
- job-type: fuzz
- job-name: 'Windows native, fuzz, VS'
+ job-name: 'Windows native, fuzz, clang-cl'
steps:
- *ANNOTATION_PR_NUMBER
### CMakeLists.txt
@@ -290,19 +290,20 @@ target_compile_definitions(core_interface_debug INTERFACE
if(WIN32)
#[=[
- This build system supports two ways to build binaries for Windows.
+ This build system supports two ways to build binaries for Windows:
- 1. Building on Windows using MSVC.
- Implementation notes:
- - /DWIN32 and /D_WINDOWS definitions are included into the CMAKE_CXX_FLAGS_INIT
- and CMAKE_CXX_FLAGS_INIT variables by default.
- - A run-time library is selected using the CMAKE_MSVC_RUNTIME_LIBRARY variable.
- - MSVC-specific options, for example, /Zc:__cplusplus, are additionally required.
+ 1. Building on Windows using clang-cl.exe, which is compatible with MSVC’s cl.exe.
+ This case is handled when the MSVC variable is true.
+ Implementation notes:
+ - /DWIN32 and /D_WINDOWS definitions are included in the CMAKE_C_FLAGS_INIT
+ and CMAKE_CXX_FLAGS_INIT variables by default.
+ - The run-time library is selected using the CMAKE_MSVC_RUNTIME_LIBRARY variable.
2. Cross-compiling using MinGW.
- Implementation notes:
- - WIN32 and _WINDOWS definitions must be provided explicitly.
- - A run-time library must be specified explicitly using _MT definition.
+ This case is handled when the MINGW variable is true.
+ Implementation notes:
+ - WIN32 and _WINDOWS definitions must be provided explicitly.
+ - The run-time library must be configured explicitly via the _MT definition.
]=]
target_compile_definitions(core_interface INTERFACE
@@ -324,12 +325,21 @@ if(WIN32)
target_compile_definitions(core_interface INTERFACE
_UNICODE;UNICODE
)
- target_compile_options(core_interface INTERFACE
- /utf-8
- /Zc:preprocessor
- /Zc:__cplusplus
- /sdl
+
+ if(CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64")
+ set(system_arch_suffix x86_64)
+ elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "ARM64")
+ set(system_arch_suffix aarch64)
+ else()
+ message(FATAL_ERROR "Unsupported architecture: ${CMAKE_SYSTEM_PROCESSOR}")
+ endif()
+ # __int128 division when using clang-cl requires the builtins library.
+ # See https://clang.llvm.org/docs/UsersManual.html#finding-clang-runtime-libraries.
+ target_link_libraries(core_interface INTERFACE
+ clang_rt.builtins-${system_arch_suffix}
)
+ unset(system_arch_suffix)
+
# Improve parallelism in MSBuild.
# See: https://devblogs.microsoft.com/cppblog/improved-parallelism-in-msbuild/.
list(APPEND CMAKE_VS_GLOBALS "UseMultiToolTask=true")
@@ -350,14 +360,10 @@ if(WIN32)
# As a best effort, target Windows 8.
try_append_linker_flag("-Wl,--major-subsystem-version,6" TARGET core_interface)
try_append_linker_flag("-Wl,--minor-subsystem-version,2" TARGET core_interface)
- endif()
- # Workaround producing large object files, which cannot be handled by the assembler.
- # More likely to happen with no, or lower levels of optimisation.
- # See discussion in https://github.com/bitcoin/bitcoin/issues/28109.
- if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
- try_append_cxx_flags("/bigobj" TARGET core_interface_debug SKIP_LINK)
- else()
+ # Workaround for large object files, which cannot be handled by the assembler.
+ # More likely to happen with no, or lower levels of optimisation.
+ # See discussion in https://github.com/bitcoin/bitcoin/issues/28109.
try_append_cxx_flags("-Wa,-mbig-obj" TARGET core_interface_debug SKIP_LINK)
endif()
endif()
@@ -459,57 +465,56 @@ include(cmake/ccache.cmake)
add_library(warn_interface INTERFACE)
target_link_libraries(core_interface INTERFACE warn_interface)
if(MSVC)
- try_append_cxx_flags("/W3" TARGET warn_interface SKIP_LINK)
- try_append_cxx_flags("/wd4018" TARGET warn_interface SKIP_LINK)
- try_append_cxx_flags("/wd4146" TARGET warn_interface SKIP_LINK)
- try_append_cxx_flags("/wd4244" TARGET warn_interface SKIP_LINK)
- try_append_cxx_flags("/wd4267" TARGET warn_interface SKIP_LINK)
- try_append_cxx_flags("/wd4715" TARGET warn_interface SKIP_LINK)
- try_append_cxx_flags("/wd4805" TARGET warn_interface SKIP_LINK)
+ # clang-cl maps some options to Clang's internal options as follows:
+ # /W1 or /W2 or /W3 --> -Wall
+ # /W4 --> -Wall and -Wextra
+ # /Wall --> -Weverything
+ # See https://clang.llvm.org/docs/UsersManual.html.
+ try_append_cxx_flags("/W3" TARGET warn_interface SKIP_LINK) # Enables Clang's internal -Wall option.
target_compile_definitions(warn_interface INTERFACE
_CRT_SECURE_NO_WARNINGS
)
else()
try_append_cxx_flags("-Wall" TARGET warn_interface SKIP_LINK)
- try_append_cxx_flags("-Wextra" TARGET warn_interface SKIP_LINK)
- try_append_cxx_flags("-Wgnu" TARGET warn_interface SKIP_LINK)
- try_append_cxx_flags("-Wcovered-switch-default" TARGET warn_interface SKIP_LINK)
- # Some compilers will ignore -Wformat-security without -Wformat, so just combine the two here.
- try_append_cxx_flags("-Wformat -Wformat-security" TARGET warn_interface SKIP_LINK)
- try_append_cxx_flags("-Wvla" TARGET warn_interface SKIP_LINK)
- try_append_cxx_flags("-Wshadow-field" TARGET warn_interface SKIP_LINK)
- try_append_cxx_flags("-Wthread-safety" TARGET warn_interface SKIP_LINK)
- try_append_cxx_flags("-Wthread-safety-pointer" TARGET warn_interface SKIP_LINK)
- try_append_cxx_flags("-Wloop-analysis" TARGET warn_interface SKIP_LINK)
- try_append_cxx_flags("-Wredundant-decls" TARGET warn_interface SKIP_LINK)
- try_append_cxx_flags("-Wunused-const-variable" TARGET warn_interface SKIP_LINK)
- try_append_cxx_flags("-Wunused-exception-parameter" TARGET warn_interface SKIP_LINK)
- try_append_cxx_flags("-Wunused-macros" TARGET warn_interface SKIP_LINK)
- try_append_cxx_flags("-Wunused-member-function" TARGET warn_interface SKIP_LINK)
- try_append_cxx_flags("-Wunused-template" TARGET warn_interface SKIP_LINK)
- try_append_cxx_flags("-Wdate-time" TARGET warn_interface SKIP_LINK)
- try_append_cxx_flags("-Wconditional-uninitialized" TARGET warn_interface SKIP_LINK)
- try_append_cxx_flags("-Wduplicated-branches" TARGET warn_interface SKIP_LINK)
- try_append_cxx_flags("-Wduplicated-cond" TARGET warn_interface SKIP_LINK)
- try_append_cxx_flags("-Wlogical-op" TARGET warn_interface SKIP_LINK)
- try_append_cxx_flags("-Woverloaded-virtual" TARGET warn_interface SKIP_LINK)
- try_append_cxx_flags("-Wsuggest-override" TARGET warn_interface SKIP_LINK)
- try_append_cxx_flags("-Wimplicit-fallthrough" TARGET warn_interface SKIP_LINK)
- try_append_cxx_flags("-Wunreachable-code" TARGET warn_interface SKIP_LINK)
- try_append_cxx_flags("-Wdocumentation" TARGET warn_interface SKIP_LINK)
- try_append_cxx_flags("-Wself-assign" TARGET warn_interface SKIP_LINK)
- try_append_cxx_flags("-Wbidi-chars=any" TARGET warn_interface SKIP_LINK)
- try_append_cxx_flags("-Wundef" TARGET warn_interface SKIP_LINK)
- try_append_cxx_flags("-Wleading-whitespace=spaces" TARGET warn_interface SKIP_LINK)
- try_append_cxx_flags("-Wtrailing-whitespace=any" TARGET warn_interface SKIP_LINK)
-
- # Some compilers (gcc) ignore unknown -Wno-* options, but warn about all
- # unknown options if any other warning is produced. Test the -Wfoo case, and
- # set the -Wno-foo case if it works.
- try_append_cxx_flags("-Wunused-parameter" TARGET warn_interface SKIP_LINK
- IF_CHECK_PASSED "-Wno-unused-parameter"
- )
endif()
+try_append_cxx_flags("-Wextra" TARGET warn_interface SKIP_LINK)
+try_append_cxx_flags("-Wgnu" TARGET warn_interface SKIP_LINK)
+try_append_cxx_flags("-Wcovered-switch-default" TARGET warn_interface SKIP_LINK)
+# Some compilers will ignore -Wformat-security without -Wformat, so just combine the two here.
+try_append_cxx_flags("-Wformat -Wformat-security" TARGET warn_interface SKIP_LINK)
+try_append_cxx_flags("-Wvla" TARGET warn_interface SKIP_LINK)
+try_append_cxx_flags("-Wshadow-field" TARGET warn_interface SKIP_LINK)
+try_append_cxx_flags("-Wthread-safety" TARGET warn_interface SKIP_LINK)
+try_append_cxx_flags("-Wthread-safety-pointer" TARGET warn_interface SKIP_LINK)
+try_append_cxx_flags("-Wloop-analysis" TARGET warn_interface SKIP_LINK)
+try_append_cxx_flags("-Wredundant-decls" TARGET warn_interface SKIP_LINK)
+try_append_cxx_flags("-Wunused-const-variable" TARGET warn_interface SKIP_LINK)
+try_append_cxx_flags("-Wunused-exception-parameter" TARGET warn_interface SKIP_LINK)
+try_append_cxx_flags("-Wunused-macros" TARGET warn_interface SKIP_LINK)
+try_append_cxx_flags("-Wunused-member-function" TARGET warn_interface SKIP_LINK)
+try_append_cxx_flags("-Wunused-template" TARGET warn_interface SKIP_LINK)
+try_append_cxx_flags("-Wdate-time" TARGET warn_interface SKIP_LINK)
+try_append_cxx_flags("-Wconditional-uninitialized" TARGET warn_interface SKIP_LINK)
+try_append_cxx_flags("-Wduplicated-branches" TARGET warn_interface SKIP_LINK)
+try_append_cxx_flags("-Wduplicated-cond" TARGET warn_interface SKIP_LINK)
+try_append_cxx_flags("-Wlogical-op" TARGET warn_interface SKIP_LINK)
+try_append_cxx_flags("-Woverloaded-virtual" TARGET warn_interface SKIP_LINK)
+try_append_cxx_flags("-Wsuggest-override" TARGET warn_interface SKIP_LINK)
+try_append_cxx_flags("-Wimplicit-fallthrough" TARGET warn_interface SKIP_LINK)
+try_append_cxx_flags("-Wunreachable-code" TARGET warn_interface SKIP_LINK)
+try_append_cxx_flags("-Wdocumentation" TARGET warn_interface SKIP_LINK)
+try_append_cxx_flags("-Wself-assign" TARGET warn_interface SKIP_LINK)
+try_append_cxx_flags("-Wbidi-chars=any" TARGET warn_interface SKIP_LINK)
+try_append_cxx_flags("-Wundef" TARGET warn_interface SKIP_LINK)
+try_append_cxx_flags("-Wleading-whitespace=spaces" TARGET warn_interface SKIP_LINK)
+try_append_cxx_flags("-Wtrailing-whitespace=any" TARGET warn_interface SKIP_LINK)
+
+# Some compilers (gcc) ignore unknown -Wno-* options, but warn about all
+# unknown options if any other warning is produced. Test the -Wfoo case, and
+# set the -Wno-foo case if it works.
+try_append_cxx_flags("-Wunused-parameter" TARGET warn_interface SKIP_LINK
+ IF_CHECK_PASSED "-Wno-unused-parameter"
+)
configure_file(cmake/script/Coverage.cmake Coverage.cmake USE_SOURCE_PERMISSIONS COPYONLY)
configure_file(cmake/script/CoverageFuzz.cmake CoverageFuzz.cmake USE_SOURCE_PERMISSIONS COPYONLY)
### CMakePresets.json
@@ -2,15 +2,14 @@
"version": 3,
"configurePresets": [
{
- "name": "vs2026",
- "displayName": "Build using 'Visual Studio 18 2026' generator and 'x64-windows' triplet",
+ "name": "windows",
+ "displayName": "Build using clang-cl and 'x64-windows' triplet",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
},
- "generator": "Visual Studio 18 2026",
- "architecture": "x64",
+ "toolset": "ClangCL",
"toolchainFile": "$env{VCPKG_ROOT}\\scripts\\buildsystems\\vcpkg.cmake",
"cacheVariables": {
"VCPKG_TARGET_TRIPLET": "x64-windows",
@@ -19,15 +18,14 @@
}
},
{
- "name": "vs2026-static",
- "displayName": "Build using 'Visual Studio 18 2026' generator and 'x64-windows-static' triplet",
+ "name": "windows-static",
+ "displayName": "Build using clang-cl and 'x64-windows-static' triplet",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
},
- "generator": "Visual Studio 18 2026",
- "architecture": "x64",
+ "toolset": "ClangCL",
"toolchainFile": "$env{VCPKG_ROOT}\\scripts\\buildsystems\\vcpkg.cmake",
"cacheVariables": {
"VCPKG_TARGET_TRIPLET": "x64-windows-static",
### cmake/crc32c.cmake
@@ -38,11 +38,7 @@ check_cxx_source_compiles("
)
# Check for SSE4.2 support in the compiler.
-if(MSVC)
- set(SSE42_CXXFLAGS /arch:AVX)
-else()
- set(SSE42_CXXFLAGS -msse4.2)
-endif()
+set(SSE42_CXXFLAGS -msse4.2)
check_cxx_source_compiles_with_flags("
#include <cstdint>
#if defined(_MSC_VER)
### cmake/introspection.cmake
@@ -4,6 +4,7 @@
include(CheckCXXSourceCompiles)
include(CheckCXXSymbolExists)
+include(CheckSourceCompilesWithFlags)
check_cxx_symbol_exists(O_CLOEXEC "fcntl.h" HAVE_O_CLOEXEC)
check_cxx_symbol_exists(fdatasync "unistd.h" HAVE_FDATASYNC)
@@ -114,7 +115,6 @@ check_cxx_source_compiles("
" HAVE_GETENTROPY_RAND
)
-
# - BSD sysctl()
check_cxx_source_compiles("
#include <sys/types.h>
@@ -148,71 +148,67 @@ check_cxx_source_compiles("
" HAVE_SYSCTL_ARND
)
-if(NOT MSVC)
- include(CheckSourceCompilesWithFlags)
-
- # Check for SSE4.1 intrinsics.
- set(SSE41_CXXFLAGS -msse4.1)
- check_cxx_source_compiles_with_flags("
- #include <immintrin.h>
-
- int main()
- {
- __m128i a = _mm_set1_epi32(0);
- __m128i b = _mm_set1_epi32(1);
- __m128i r = _mm_blend_epi16(a, b, 0xFF);
- return _mm_extract_epi32(r, 3);
- }
- " HAVE_SSE41
- CXXFLAGS ${SSE41_CXXFLAGS}
- )
-
- # Check for AVX2 intrinsics.
- set(AVX2_CXXFLAGS -mavx -mavx2)
- check_cxx_source_compiles_with_flags("
- #include <immintrin.h>
-
- int main()
- {
- __m256i l = _mm256_set1_epi32(0);
- return _mm256_extract_epi32(l, 7);
- }
- " HAVE_AVX2
- CXXFLAGS ${AVX2_CXXFLAGS}
- )
-
- # Check for x86 SHA-NI intrinsics.
- set(X86_SHANI_CXXFLAGS -msse4.1 -msha)
- check_cxx_source_compiles_with_flags("
- #include <immintrin.h>
-
- int main()
- {
- __m128i i = _mm_set1_epi32(0);
- __m128i j = _mm_set1_epi32(1);
- __m128i k = _mm_set1_epi32(2);
- return _mm_extract_epi32(_mm_sha256rnds2_epu32(i, j, k), 0);
- }
- " HAVE_X86_SHANI
- CXXFLAGS ${X86_SHANI_CXXFLAGS}
- )
-
- # Check for ARMv8 SHA-NI intrinsics.
- set(ARM_SHANI_CXXFLAGS -march=armv8-a+crypto)
- check_cxx_source_compiles_with_flags("
- #include <arm_neon.h>
-
- int main()
- {
- uint32x4_t a = vdupq_n_u32(0);
- uint32x4_t b = vdupq_n_u32(1);
- uint32x4_t c = vdupq_n_u32(2);
- vsha256h2q_u32(a, b, c);
- vsha256hq_u32(a, b, c);
- vsha256su0q_u32(a, b);
- vsha256su1q_u32(a, b, c);
- }
- " HAVE_ARM_SHANI
- CXXFLAGS ${ARM_SHANI_CXXFLAGS}
- )
-endif()
+# Check for SSE4.1 intrinsics.
+set(SSE41_CXXFLAGS -msse4.1)
+check_cxx_source_compiles_with_flags("
+ #include <immintrin.h>
+
+ int main()
+ {
+ __m128i a = _mm_set1_epi32(0);
+ __m128i b = _mm_set1_epi32(1);
+ __m128i r = _mm_blend_epi16(a, b, 0xFF);
+ return _mm_extract_epi32(r, 3);
+ }
+ " HAVE_SSE41
+ CXXFLAGS ${SSE41_CXXFLAGS}
+)
+
+# Check for AVX2 intrinsics.
+set(AVX2_CXXFLAGS -mavx -mavx2)
+check_cxx_source_compiles_with_flags("
+ #include <immintrin.h>
+
+ int main()
+ {
+ __m256i l = _mm256_set1_epi32(0);
+ return _mm256_extract_epi32(l, 7);
+ }
+ " HAVE_AVX2
+ CXXFLAGS ${AVX2_CXXFLAGS}
+)
+
+# Check for x86 SHA-NI intrinsics.
+set(X86_SHANI_CXXFLAGS -msse4.1 -msha)
+check_cxx_source_compiles_with_flags("
+ #include <immintrin.h>
+
+ int main()
+ {
+ __m128i i = _mm_set1_epi32(0);
+ __m128i j = _mm_set1_epi32(1);
+ __m128i k = _mm_set1_epi32(2);
+ return _mm_extract_epi32(_mm_sha256rnds2_epu32(i, j, k), 0);
+ }
+ " HAVE_X86_SHANI
+ CXXFLAGS ${X86_SHANI_CXXFLAGS}
+)
+
+# Check for ARMv8 SHA-NI intrinsics.
+set(ARM_SHANI_CXXFLAGS -march=armv8-a+crypto)
+check_cxx_source_compiles_with_flags("
+ #include <arm_neon.h>
+
+ int main()
+ {
+ uint32x4_t a = vdupq_n_u32(0);
+ uint32x4_t b = vdupq_n_u32(1);
+ uint32x4_t c = vdupq_n_u32(2);
+ vsha256h2q_u32(a, b, c);
+ vsha256hq_u32(a, b, c);
+ vsha256su0q_u32(a, b);
+ vsha256su1q_u32(a, b, c);
+ }
+ " HAVE_ARM_SHANI
+ CXXFLAGS ${ARM_SHANI_CXXFLAGS}
+)
### cmake/leveldb.cmake
@@ -76,17 +76,13 @@ target_include_directories(leveldb
add_library(nowarn_leveldb_interface INTERFACE)
if(MSVC)
- target_compile_options(nowarn_leveldb_interface INTERFACE
- /wd4722
- )
target_compile_definitions(nowarn_leveldb_interface INTERFACE
_CRT_NONSTDC_NO_WARNINGS
)
-else()
- try_append_cxx_flags("-Wcovered-switch-default" TARGET nowarn_leveldb_interface SKIP_LINK
- IF_CHECK_PASSED "-Wno-covered-switch-default"
- )
endif()
+try_append_cxx_flags("-Wcovered-switch-default" TARGET nowarn_leveldb_interface SKIP_LINK
+ IF_CHECK_PASSED "-Wno-covered-switch-default"
+)
target_link_libraries(leveldb PRIVATE
core_interface
### cmake/minisketch.cmake
@@ -5,11 +5,7 @@
include(CheckSourceCompilesWithFlags)
# Check for clmul instructions support.
-if(MSVC)
- set(CLMUL_CXXFLAGS "")
-else()
- set(CLMUL_CXXFLAGS -mpclmul)
-endif()
+set(CLMUL_CXXFLAGS -mpclmul)
check_cxx_source_compiles_with_flags("
#include <immintrin.h>
#include <cstdint>
@@ -27,17 +23,6 @@ check_cxx_source_compiles_with_flags("
CXXFLAGS ${CLMUL_CXXFLAGS}
)
-add_library(minisketch_common INTERFACE)
-if(MSVC)
- target_compile_options(minisketch_common INTERFACE
- /wd4060
- /wd4065
- /wd4146
- /wd4244
- /wd4267
- )
-endif()
-
add_library(minisketch STATIC EXCLUDE_FROM_ALL
${PROJECT_SOURCE_DIR}/src/minisketch/src/minisketch.cpp
${PROJECT_SOURCE_DIR}/src/minisketch/src/fields/generic_1byte.cpp
@@ -64,7 +49,6 @@ target_include_directories(minisketch
target_link_libraries(minisketch
PRIVATE
core_interface
- minisketch_common
)
set_target_properties(minisketch PROPERTIES
### cmake/module/TryAppendCXXFlags.cmake
@@ -119,8 +119,4 @@ function(try_append_cxx_flags flags)
endif()
endfunction()
-if(MSVC)
- try_append_cxx_flags("/WX /options:strict" VAR working_compiler_werror_flag SKIP_LINK)
-else()
- try_append_cxx_flags("-Werror" VAR working_compiler_werror_flag SKIP_LINK)
-endif()
+try_append_cxx_flags("-Werror" VAR working_compiler_werror_flag SKIP_LINK)
### doc/README.md
@@ -44,7 +44,7 @@ The following are developer notes on how to build Bitcoin Core on your native pl
- [Dependencies](dependencies.md)
- [macOS Build Notes](build-osx.md)
- [Unix Build Notes](build-unix.md)
-- [Windows Build Notes](build-windows-msvc.md)
+- [Windows Build Notes](build-windows-native.md)
- [FreeBSD Build Notes](build-freebsd.md)
- [OpenBSD Build Notes](build-openbsd.md)
- [NetBSD Build Notes](build-netbsd.md)
### doc/build-windows-native.md
@@ -1,4 +1,4 @@
-# Windows / MSVC Build Guide
+# Windows / VS Build Guide
This guide describes how to build bitcoind, command-line utilities, and GUI on Windows using Microsoft Visual Studio.
@@ -16,19 +16,22 @@ WinGet is available on all supported Windows versions. The applications mentione
This guide relies on using CMake and vcpkg package manager provided with the Visual Studio installation.
-Minimum required version: Visual Studio 2026 version 18.3 with the "Desktop development with C++" workload.
-
To install Visual Studio Community Edition with the necessary components, run:
```powershell
-winget install --id Microsoft.VisualStudio.Community --override "--wait --quiet --add Microsoft.VisualStudio.Workload.NativeDesktop --add Microsoft.VisualStudio.Component.Git --includeRecommended"
+winget install --id Microsoft.VisualStudio.Community --override "--wait --add Microsoft.VisualStudio.Workload.NativeDesktop --add Microsoft.VisualStudio.Component.VC.Llvm.ClangToolset --add Microsoft.VisualStudio.Component.VC.Llvm.Clang --add Microsoft.VisualStudio.Component.Git --includeRecommended"
```
This installs:
- Visual Studio
- The "Desktop development with C++" workload (NativeDesktop)
+- The "MSBuild support for LLVM (clang-cl) toolset" component
+- The "C++ Clang Compiler for Windows" component
- Git component
+Make sure the "C++ Clang Compiler for Windows" component meets the minimum
+required Clang version specified in [dependencies.md](dependencies.md).
+
After installation, the commands in this guide should be executed in "Developer PowerShell for VS" or "Developer Command Prompt for VS".
The former is assumed hereinafter.
@@ -73,7 +76,7 @@ Run `cmake -B build -LH` to see the full list of available options.
### Building with Static Linking with GUI
```powershell
-cmake -B build --preset vs2026-static # It might take a while if the vcpkg binary cache is unpopulated or invalidated.
+cmake -B build --preset windows-static # It might take a while if the vcpkg binary cache is unpopulated or invalidated.
cmake --build build --config Release # Append "-j N" for N parallel jobs.
ctest --test-dir build --build-config Release # Append "-j N" for N parallel tests.
cmake --install build --config Release # Optional.
@@ -82,9 +85,9 @@ cmake --install build --config Release # Optional.
### Building with Dynamic Linking without GUI
```powershell
-cmake -B build --preset vs2026 -DBUILD_GUI=OFF # It might take a while if the vcpkg binary cache is unpopulated or invalidated.
-cmake --build build --config Release # Append "-j N" for N parallel jobs.
-ctest --test-dir build --build-config Release # Append "-j N" for N parallel tests.
+cmake -B build --preset windows -DBUILD_GUI=OFF # It might take a while if the vcpkg binary cache is unpopulated or invalidated.
+cmake --build build --config Release # Append "-j N" for N parallel jobs.
+ctest --test-dir build --build-config Release # Append "-j N" for N parallel tests.
```
### vcpkg-specific Issues and Workarounds
@@ -97,15 +100,15 @@ specify a shorter path to store intermediate build files by using
the [`--x-buildtrees-root`](https://learn.microsoft.com/en-us/vcpkg/commands/common-options#buildtrees-root) option:
```powershell
-cmake -B build --preset vs2026-static -DVCPKG_INSTALL_OPTIONS="--x-buildtrees-root=C:\vcpkg"
+cmake -B build --preset windows-static -DVCPKG_INSTALL_OPTIONS="--x-buildtrees-root=C:\vcpkg"
```
If vcpkg installation fails with the message "Paths with embedded space may be handled incorrectly", which
can occur if your local Bitcoin Core repository path contains spaces, you can override the vcpkg install directory
by setting the [`VCPKG_INSTALLED_DIR`](https://github.com/microsoft/vcpkg-docs/blob/main/vcpkg/users/buildsystems/cmake-integration.md#vcpkg_installed_dir) variable:
```powershell
-cmake -B build --preset vs2026-static -DVCPKG_INSTALLED_DIR="C:\path_without_spaces"
+cmake -B build --preset windows-static -DVCPKG_INSTALLED_DIR="C:\path_without_spaces"
```
## Performance Notes
@@ -115,7 +118,7 @@ cmake -B build --preset vs2026-static -DVCPKG_INSTALLED_DIR="C:\path_without_spa
One can skip vcpkg manifest default features to speed up the configuration step.
For example, the following invocation will skip all features except for "wallet" and "tests" and their dependencies:
```powershell
-cmake -B build --preset vs2026 -DVCPKG_MANIFEST_NO_DEFAULT_FEATURES=ON -DVCPKG_MANIFEST_FEATURES="wallet;tests" -DBUILD_GUI=OFF -DWITH_ZMQ=OFF
+cmake -B build --preset windows -DVCPKG_MANIFEST_NO_DEFAULT_FEATURES=ON -DVCPKG_MANIFEST_FEATURES="wallet;tests" -DBUILD_GUI=OFF -DWITH_ZMQ=OFF
```
Available features are listed in the [`vcpkg.json`](/vcpkg.json) file.
### doc/build-windows.md
@@ -7,7 +7,7 @@ The options known to work for building Bitcoin Core on Windows are:
* On Linux, using the [Mingw-w64](https://www.mingw-w64.org/) cross compiler tool chain.
* On Windows, using [Windows Subsystem for Linux (WSL)](https://learn.microsoft.com/en-us/windows/wsl/about) and Mingw-w64.
-* On Windows, using [Microsoft Visual Studio](https://visualstudio.microsoft.com). See [`build-windows-msvc.md`](./build-windows-msvc.md).
+* On Windows, using [Microsoft Visual Studio](https://visualstudio.microsoft.com). See [`build-windows-native.md`](./build-windows-native.md).
Other options may work, but are not officially tested:
### doc/dependencies.md
@@ -13,7 +13,7 @@ Bitcoin Core requires one of the following compilers.
| [Clang](https://clang.llvm.org) | [17.0](https://github.com/bitcoin/bitcoin/pull/33555) |
| [GCC](https://gcc.gnu.org) | [12.1](https://github.com/bitcoin/bitcoin/pull/33842) |
| [Xcode CLT](/doc/build-osx.md) | [26.3](https://github.com/bitcoin/bitcoin/pull/36287) |
-| [MSVC](/doc/build-windows-msvc.md) | [18.3](https://github.com/bitcoin/bitcoin/pull/33861) |
+| [Visual Studio (with clang-cl)](/doc/build-windows-native.md) | [18.7](https://github.com/bitcoin/bitcoin/pull/31507) |
## Required
### doc/release-notes-31507.md
@@ -0,0 +1,15 @@
+Build System
+------------
+
+- Support for building with MSVC (`cl.exe`) on Windows has been dropped.
+ Building natively on Windows is now supported only with Clang
+ (`clang-cl.exe`), which remains compatible with the MSVC toolchain,
+ including the Visual Studio build environment, the MSVC standard
+ library and runtime, and vcpkg-provided dependencies. (#31507)
+
+ Clang is preferred over MSVC for the following reasons:
+ - MSVC does not support inline assembly on x64 and ARM64, which
+ precludes some hardware-accelerated implementations.
+ - MSVC has repeatedly caused maintenance overhead due to internal
+ compiler errors that required workarounds not needed for any
+ other supported compiler.
### src/compat/byteswap.h
@@ -26,22 +26,10 @@
# if __has_builtin(__builtin_bswap64)
# define bitcoin_builtin_bswap64(x) __builtin_bswap64(x)
# endif
-# elif defined(_MSC_VER)
-# define bitcoin_builtin_bswap16(x) _byteswap_ushort(x)
-# define bitcoin_builtin_bswap32(x) _byteswap_ulong(x)
-# define bitcoin_builtin_bswap64(x) _byteswap_uint64(x)
# endif
#endif
-// MSVC's _byteswap_* functions are not constexpr
-
-#ifndef _MSC_VER
-#define BSWAP_CONSTEXPR constexpr
-#else
-#define BSWAP_CONSTEXPR
-#endif
-
-inline BSWAP_CONSTEXPR uint16_t internal_bswap_16(uint16_t x)
+inline constexpr uint16_t internal_bswap_16(uint16_t x)
{
#ifdef bitcoin_builtin_bswap16
return bitcoin_builtin_bswap16(x);
@@ -50,7 +38,7 @@ inline BSWAP_CONSTEXPR uint16_t internal_bswap_16(uint16_t x)
#endif
}
-inline BSWAP_CONSTEXPR uint32_t internal_bswap_32(uint32_t x)
+inline constexpr uint32_t internal_bswap_32(uint32_t x)
{
#ifdef bitcoin_builtin_bswap32
return bitcoin_builtin_bswap32(x);
@@ -60,7 +48,7 @@ inline BSWAP_CONSTEXPR uint32_t internal_bswap_32(uint32_t x)
#endif
}
-inline BSWAP_CONSTEXPR uint64_t internal_bswap_64(uint64_t x)
+inline constexpr uint64_t internal_bswap_64(uint64_t x)
{
#ifdef bitcoin_builtin_bswap64
return bitcoin_builtin_bswap64(x);
### src/compat/endian.h
@@ -10,62 +10,62 @@
#include <bit>
#include <cstdint>
-inline BSWAP_CONSTEXPR uint16_t htobe16_internal(uint16_t host_16bits)
+inline constexpr uint16_t htobe16_internal(uint16_t host_16bits)
{
if constexpr (std::endian::native == std::endian::little) return internal_bswap_16(host_16bits);
else return host_16bits;
}
-inline BSWAP_CONSTEXPR uint16_t htole16_internal(uint16_t host_16bits)
+inline constexpr uint16_t htole16_internal(uint16_t host_16bits)
{
if constexpr (std::endian::native == std::endian::big) return internal_bswap_16(host_16bits);
else return host_16bits;
}
-inline BSWAP_CONSTEXPR uint16_t be16toh_internal(uint16_t big_endian_16bits)
+inline constexpr uint16_t be16toh_internal(uint16_t big_endian_16bits)
{
if constexpr (std::endian::native == std::endian::little) return internal_bswap_16(big_endian_16bits);
else return big_endian_16bits;
}
-inline BSWAP_CONSTEXPR uint16_t le16toh_internal(uint16_t little_endian_16bits)
+inline constexpr uint16_t le16toh_internal(uint16_t little_endian_16bits)
{
if constexpr (std::endian::native == std::endian::big) return internal_bswap_16(little_endian_16bits);
else return little_endian_16bits;
}
-inline BSWAP_CONSTEXPR uint32_t htobe32_internal(uint32_t host_32bits)
+inline constexpr uint32_t htobe32_internal(uint32_t host_32bits)
{
if constexpr (std::endian::native == std::endian::little) return internal_bswap_32(host_32bits);
else return host_32bits;
}
-inline BSWAP_CONSTEXPR uint32_t htole32_internal(uint32_t host_32bits)
+inline constexpr uint32_t htole32_internal(uint32_t host_32bits)
{
if constexpr (std::endian::native == std::endian::big) return internal_bswap_32(host_32bits);
else return host_32bits;
}
-inline BSWAP_CONSTEXPR uint32_t be32toh_internal(uint32_t big_endian_32bits)
+inline constexpr uint32_t be32toh_internal(uint32_t big_endian_32bits)
{
if constexpr (std::endian::native == std::endian::little) return internal_bswap_32(big_endian_32bits);
else return big_endian_32bits;
}
-inline BSWAP_CONSTEXPR uint32_t le32toh_internal(uint32_t little_endian_32bits)
+inline constexpr uint32_t le32toh_internal(uint32_t little_endian_32bits)
{
if constexpr (std::endian::native == std::endian::big) return internal_bswap_32(little_endian_32bits);
else return little_endian_32bits;
}
-inline BSWAP_CONSTEXPR uint64_t htobe64_internal(uint64_t host_64bits)
+inline constexpr uint64_t htobe64_internal(uint64_t host_64bits)
{
if constexpr (std::endian::native == std::endian::little) return internal_bswap_64(host_64bits);
else return host_64bits;
}
-inline BSWAP_CONSTEXPR uint64_t htole64_internal(uint64_t host_64bits)
+inline constexpr uint64_t htole64_internal(uint64_t host_64bits)
{
if constexpr (std::endian::native == std::endian::big) return internal_bswap_64(host_64bits);
else return host_64bits;
}
-inline BSWAP_CONSTEXPR uint64_t be64toh_internal(uint64_t big_endian_64bits)
+inline constexpr uint64_t be64toh_internal(uint64_t big_endian_64bits)
{
if constexpr (std::endian::native == std::endian::little) return internal_bswap_64(big_endian_64bits);
else return big_endian_64bits;
}
-inline BSWAP_CONSTEXPR uint64_t le64toh_internal(uint64_t little_endian_64bits)
+inline constexpr uint64_t le64toh_internal(uint64_t little_endian_64bits)
{
if constexpr (std::endian::native == std::endian::big) return internal_bswap_64(little_endian_64bits);
else return little_endian_64bits;
### src/kernel/CMakeLists.txt
@@ -87,9 +87,7 @@ add_library(bitcoinkernel
# These can be more strict and/or warnings that only apply to shared
# libs.
add_library(kernel_warn_interface INTERFACE)
-if(NOT MSVC)
- try_append_cxx_flags("-Wunique-object-duplication" TARGET kernel_warn_interface SKIP_LINK)
-endif()
+try_append_cxx_flags("-Wunique-object-duplication" TARGET kernel_warn_interface SKIP_LINK)
# Also manually apply the warnings to the kernel's internal dependencies
target_link_libraries(bitcoin_clientversion PRIVATE kernel_warn_interface)
### src/qt/CMakeLists.txt
@@ -153,7 +153,7 @@ target_link_libraries(bitcoinqt
Boost::headers
$<TARGET_NAME_IF_EXISTS:QRencode::QRencode>
$<$<PLATFORM_ID:Darwin>:-framework\ AppKit>
- $<$<CXX_COMPILER_ID:MSVC>:shlwapi>
+ $<$<BOOL:${MSVC}>:shlwapi>
)
if(ENABLE_WALLET)
### src/qt/README.md
@@ -4,7 +4,7 @@ The current precise version for Qt is specified in [qt_details.mk](/depends/pack
## Compile and run
-See build instructions: [Unix](/doc/build-unix.md), [macOS](/doc/build-osx.md), [Windows](/doc/build-windows-msvc.md), [FreeBSD](/doc/build-freebsd.md), [NetBSD](/doc/build-netbsd.md), [OpenBSD](/doc/build-openbsd.md)
+See build instructions: [Unix](/doc/build-unix.md), [macOS](/doc/build-osx.md), [Windows](/doc/build-windows-native.md), [FreeBSD](/doc/build-freebsd.md), [NetBSD](/doc/build-netbsd.md), [OpenBSD](/doc/build-openbsd.md)
When following your systems build instructions, make sure to install the `Qt` dependencies.
### src/test/util_not_null_tests.cpp
@@ -109,12 +109,8 @@ BOOST_AUTO_TEST_CASE(check_cross_type_conversion)
};
// Assume checks failed conversions during constant evaluation.
-#if !defined(_MSC_VER)
- // MSVC does not reject this failed constant evaluation in a requires-expression.
- // See https://github.com/bitcoin/bitcoin/issues/36153.
static_assert(!NotNullCopyConvertible<NullPtr, SomePtr>);
static_assert(!NotNullMoveConvertible<NullPtr, SomePtr>);
-#endif
}
BOOST_AUTO_TEST_CASE(check_null_smart_pointer)Why this scored 18/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.