bitcoin/build_msvc
fanquake f0e829022a
Merge bitcoin/bitcoin#28967: build: disable external-signer for Windows
308aec3e56 build: disable external-signer for Windows (fanquake)
35537318a1 ci: remove --enable-external-signer from win64 job (fanquake)

Pull request description:

  It's come to light that Boost ASIO (a Boost Process sub dep) has in some
  instances, been quietly  initialising our network stack on Windows (see
  PR https://github.com/bitcoin/bitcoin/pull/28486 and discussion in https://github.com/bitcoin/bitcoin/issues/28940).

  This has been shielding a bug in our own code, but the larger issue
  is that Boost Process/ASIO is running code before main, and doing things
  like setting up networking. This undermines our own assumptions about
  how our binary works, happens before we run any sanity checks,
  and before we call our own code to setup networking. Note that ASIO also
  calls WSAStartup with version `2.0`, whereas we call with `2.2`.

  It's also not clear why a feature like external signer would have a
  dependency that would be doing anything network/socket related,
  given it only exists to spawn a local process.

  See also the discussion in https://github.com/bitcoin/bitcoin/issues/24907. Note that the maintaince of Boost Process in general,
  has not really improved. For example, rather than fixing bugs like https://github.com/boostorg/process/issues/111,
  i.e, https://github.com/boostorg/process/pull/317, the maintainer chooses to just wrap exception causing overflows
  in try-catch blocks: 0c42a58eac. These changes get merged in large,
  unreviewed PRs, i.e https://github.com/boostorg/process/pull/319.

  This PR disables external-signer on Windows for now. If, in future, someone
  changes how Boost Process works, or replaces it entirely with some
  properly reviewed and maintained code, we could reenable this feature on
  Windows.

ACKs for top commit:
  hebasto:
    re-ACK 308aec3e56.
  TheCharlatan:
    ACK 308aec3e56

Tree-SHA512: 7405f7fc9833eeaacd6836c4e5b1c1a7845a40c1fdd55c1060152f8d8189e4777464fde650e11eb1539556a75dddf49667105987078b1457493ee772945da66e
2023-12-13 11:55:21 +00:00
..
bench_bitcoin scripted-diff: Rename libbitcoinconsensus to libbitcoin_consensus 2023-05-10 11:26:35 +01:00
bitcoin-cli refactor: move url.h/cpp from lib util to lib common 2022-10-31 10:17:04 +00:00
bitcoin-qt build: Drop no longer needed MSVC warning suppressions 2023-11-05 17:34:30 +00:00
bitcoin-tx scripted-diff: Rename libbitcoinconsensus to libbitcoin_consensus 2023-05-10 11:26:35 +01:00
bitcoin-util scripted-diff: Rename libbitcoinconsensus to libbitcoin_consensus 2023-05-10 11:26:35 +01:00
bitcoin-wallet scripted-diff: Rename libbitcoinconsensus to libbitcoin_consensus 2023-05-10 11:26:35 +01:00
bitcoind scripted-diff: Rename libbitcoinconsensus to libbitcoin_consensus 2023-05-10 11:26:35 +01:00
libbitcoin_cli [MSVC] Copy build output to src/ automatically after build 2019-07-01 19:16:19 +09:00
libbitcoin_common refactor: move url.h/cpp from lib util to lib common 2022-10-31 10:17:04 +00:00
libbitcoin_consensus msvc: Clean up libbitcoin_consensus source files 2023-05-10 11:26:44 +01:00
libbitcoin_crypto [MSVC] Copy build output to src/ automatically after build 2019-07-01 19:16:19 +09:00
libbitcoin_node scripted-diff: Rename libbitcoin_server.a to libbitcoin_node.a 2021-12-20 10:53:01 -05:00
libbitcoin_qt qt, refactor: Add transactionoverviewwidget.cpp source file 2022-06-14 16:55:22 +02:00
libbitcoin_util refactor: move url.h/cpp from lib util to lib common 2022-10-31 10:17:04 +00:00
libbitcoin_wallet Do not compile BDB things when USE_BDB is defined 2020-11-18 11:56:08 -05:00
libbitcoin_wallet_tool [MSVC] Copy build output to src/ automatically after build 2019-07-01 19:16:19 +09:00
libbitcoin_zmq [MSVC] Copy build output to src/ automatically after build 2019-07-01 19:16:19 +09:00
libleveldb msvc: Optimize "Release" builds 2023-12-09 13:15:30 +00:00
libminisketch build: Drop no longer needed MSVC warning suppressions 2023-11-05 17:34:30 +00:00
libsecp256k1 build: Drop no longer needed MSVC warning suppressions 2023-11-05 17:34:30 +00:00
libtest_util Introduce MockableDatabase for wallet unit tests 2023-05-03 10:45:10 -04:00
libunivalue [MSVC] Copy build output to src/ automatically after build 2019-07-01 19:16:19 +09:00
msbuild/tasks [MSVC]: Create the config.ini as part of bitcoind build 2019-06-21 16:23:35 +09:00
test_bitcoin msvc: Optimize "Release" builds 2023-12-09 13:15:30 +00:00
test_bitcoin-qt build: Drop no longer needed MSVC warning suppressions 2023-11-05 17:34:30 +00:00
.gitignore build: Do not modify common.init.vcxproj directly 2022-04-05 19:06:03 +02:00
bitcoin.sln scripted-diff: Rename libbitcoinconsensus to libbitcoin_consensus 2023-05-10 11:26:35 +01:00
bitcoin_config.h.in build: disable external-signer for Windows 2023-12-01 10:46:19 +00:00
common.init.vcxproj.in msvc: Optimize "Release" builds 2023-12-09 13:15:30 +00:00
common.qt.init.vcxproj msvc: Define the same QT_... macros as in Autotools builds 2023-12-09 16:15:33 +00:00
common.vcxproj Adjusted msvc compiler and linker settings to remove optimisations that are causing sporadic ABI issues on Visual Studio updates. 2020-12-02 11:39:01 +00:00
msvc-autogen.py msvc: Cleanup after upgrading libsecp256k1 up to 0.3.0 2023-05-05 10:58:15 +01:00
README.md Add a note to msvc readme re building Qt for Bitcoin Core. 2023-12-10 15:46:36 +00:00
vcpkg.json build: disable external-signer for Windows 2023-12-01 10:46:19 +00:00

Building Bitcoin Core with Visual Studio

Introduction

Visual Studio 2022 is minimum required to build Bitcoin Core.

Solution and project files to build with msbuild or Visual Studio can be found in the build_msvc directory.

To build Bitcoin Core from the command-line, it is sufficient to only install the Visual Studio Build Tools component.

The "Desktop development with C++" workload must be installed as well.

Building with Visual Studio is an alternative to the Linux based cross-compiler build.

Prerequisites

To build dependencies (except for Qt), the default approach is to use the vcpkg package manager from Microsoft:

  1. Install vcpkg.

  2. By default, vcpkg makes both release and debug builds for each package. To save build time and disk space, one could skip debug builds (example uses PowerShell):


Add-Content -Path "vcpkg\triplets\x64-windows-static.cmake" -Value "set(VCPKG_BUILD_TYPE release)"

Qt

To build Bitcoin Core with the GUI, a static build of Qt is required.

  1. Download a single ZIP archive of Qt source code from https://download.qt.io/official_releases/qt/ (e.g., qt-everywhere-opensource-src-5.15.11.zip), and expand it into a dedicated folder. The following instructions assume that this folder is C:\dev\qt-source.

💡 Tip: If you use the default path with "Extract All" for the Qt source code zip file, and end up with something like C:\dev\qt-everywhere-opensource-src-5.15.11\qt-everywhere-src-5.15.11, you are likely to encounter a "path too long" error when building. To fix the problem move the source files to a shorter path such as the recommended C:\dev\qt-source.

  1. Open "x64 Native Tools Command Prompt for VS 2022", and input the following commands:
cd C:\dev\qt-source
mkdir build
cd build
..\configure -release -silent -opensource -confirm-license -opengl desktop -static -static-runtime -mp -qt-zlib -qt-pcre -qt-libpng -nomake examples -nomake tests -nomake tools -no-angle -no-dbus -no-gif -no-gtk -no-ico -no-icu -no-libjpeg -no-libudev -no-sql-sqlite -no-sql-odbc -no-sqlite -no-vulkan -skip qt3d -skip qtactiveqt -skip qtandroidextras -skip qtcharts -skip qtconnectivity -skip qtdatavis3d -skip qtdeclarative -skip doc -skip qtdoc -skip qtgamepad -skip qtgraphicaleffects -skip qtimageformats -skip qtlocation -skip qtlottie -skip qtmacextras -skip qtmultimedia -skip qtnetworkauth -skip qtpurchasing -skip qtquick3d -skip qtquickcontrols -skip qtquickcontrols2 -skip qtquicktimeline -skip qtremoteobjects -skip qtscript -skip qtscxml -skip qtsensors -skip qtserialbus -skip qtserialport -skip qtspeech -skip qtsvg -skip qtvirtualkeyboard -skip qtwayland -skip qtwebchannel -skip qtwebengine -skip qtwebglplugin -skip qtwebsockets -skip qtwebview -skip qtx11extras -skip qtxmlpatterns -no-openssl -no-feature-bearermanagement -no-feature-printdialog -no-feature-printer -no-feature-printpreviewdialog -no-feature-printpreviewwidget -no-feature-sql -no-feature-sqlmodel -no-feature-textbrowser -no-feature-textmarkdownwriter -no-feature-textodfwriter -no-feature-xml -prefix C:\Qt_static
nmake
nmake install

One could speed up building with jom, a replacement for nmake which makes use of all CPU cores.

To build Bitcoin Core without Qt, unload or disable the bitcoin-qt, libbitcoin_qt and test_bitcoin-qt projects.

Building

  1. Use Python to generate *.vcxproj for the Visual Studio 2022 toolchain from Makefile:
python build_msvc\msvc-autogen.py
  1. An optional step is to adjust the settings in the build_msvc directory and the common.init.vcxproj file. This project file contains settings that are common to all projects such as the runtime library version and target Windows SDK version. The Qt directories can also be set. To specify a non-default path to a static Qt package directory, use the QTBASEDIR environment variable.

  2. To build from the command-line with the Visual Studio toolchain use:

msbuild build_msvc\bitcoin.sln -property:Configuration=Release -maxCpuCount -verbosity:minimal

Alternatively, open the build_msvc/bitcoin.sln file in Visual Studio.

Security

Base address randomization is used to make Bitcoin Core more secure. When building Bitcoin using the build_msvc process base address randomization can be disabled by editing common.init.vcproj to change RandomizedBaseAddress from true to false and then rebuilding the project.

To check if bitcoind has RandomizedBaseAddress enabled or disabled run

.\dumpbin.exe /headers src/bitcoind.exe

If is it enabled then in the output Dynamic base will be listed in the DLL characteristics under OPTIONAL HEADER VALUES as shown below

            8160 DLL characteristics
                   High Entropy Virtual Addresses
                   Dynamic base
                   NX compatible
                   Terminal Server Aware

This may not disable all stack randomization as versions of windows employ additional stack randomization protections. These protections must be turned off in the OS configuration.