bitcoin/build_msvc
fanquake a68de12c0e
Merge bitcoin/bitcoin#22890: doc: Replace a link to Qt precompiled binaries with compile instructions
6bc4398937 doc: Suggest using jom instead of nmake (Hennadii Stepanov)
c4139f06a9 doc: Replace a link to Qt precompiled binaries with compile instructions (Hennadii Stepanov)
5e42f2ad26 build: Make <QtBaseDir> default name Qt and VS versions agnostic (Hennadii Stepanov)

Pull request description:

  This PR replaces a [link to Qt precompiled binaries](https://github.com/sipsorcery/qt_win_binary/releases) with compile instructions that allow users to self-compile static Qt package which is required for building Bitcoin Core with Visual Studio.

ACKs for top commit:
  sipsorcery:
    ACK 6bc4398937.

Tree-SHA512: 0c91536e51177ec2ed437614cb37b3fd1dccce856548c22307359da68200433971fd97cd8a537b0856cfccc521ac50d61801a78cb5275b818829ee7b43bc7d6a
2021-10-07 08:39:52 +08:00
..
bench_bitcoin Added libtest_util library to msvc build configuration. 2019-11-23 15:49:16 +00:00
bitcoin-cli [MSVC] Copy build output to src/ automatically after build 2019-07-01 19:16:19 +09:00
bitcoin-qt Start using init makeNode, makeChain, etc methods 2021-08-17 03:05:15 -05:00
bitcoin-tx [MSVC] Copy build output to src/ automatically after build 2019-07-01 19:16:19 +09:00
bitcoin-util build_msvc: Make bitcoin-util ProjectGuid unique 2021-09-08 11:58:03 +03:00
bitcoin-wallet [MSVC] Copy build output to src/ automatically after build 2019-07-01 19:16:19 +09:00
bitcoind test: Fix tests on Windows 2021-09-08 18:58:31 +02:00
libbitcoin_cli [MSVC] Copy build output to src/ automatically after build 2019-07-01 19:16:19 +09:00
libbitcoin_common [MSVC] Copy build output to src/ automatically after build 2019-07-01 19:16:19 +09:00
libbitcoin_crypto [MSVC] Copy build output to src/ automatically after build 2019-07-01 19:16:19 +09:00
libbitcoin_qt build_msvc: Drop 32-bit build configurations 2021-09-08 11:58:12 +03:00
libbitcoin_server [MSVC] Copy build output to src/ automatically after build 2019-07-01 19:16:19 +09:00
libbitcoin_util Drop unintended bitcoin-tx dependency on libevent 2020-04-02 08:28:11 -04: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
libbitcoinconsensus [MSVC] Copy build output to src/ automatically after build 2019-07-01 19:16:19 +09:00
libleveldb build: Enable safe warnings for msvc builds 2021-03-29 11:01:19 +03:00
libsecp256k1 Disable certain false positive warnings for libsecp256k1 msvc build 2021-04-02 13:17:49 -07:00
libtest_util Added libtest_util library to msvc build configuration. 2019-11-23 15:49:16 +00: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 wallet test refactor: add CreateSyncedWallet function 2021-06-12 11:22:41 -04:00
test_bitcoin-qt Start using init makeNode, makeChain, etc methods 2021-08-17 03:05:15 -05:00
testconsensus refactor: Replace &foo[0] with foo.data() 2021-05-04 06:55:31 +02:00
.gitignore Update msvc build to use new vcpkg manifest 2020-09-29 13:48:28 +01:00
bitcoin_config.h msvc: update bitcoin_config.h defines 2021-09-02 11:14:18 +08:00
bitcoin.sln build_msvc: Drop 32-bit build configurations 2021-09-08 11:58:12 +03:00
common.init.vcxproj build_msvc: Drop 32-bit build configurations 2021-09-08 11:58:12 +03:00
common.qt.init.vcxproj build: Make <QtBaseDir> default name Qt and VS versions agnostic 2021-09-07 22:25:38 +03: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
libsecp256k1_config.h Update MSVC build config for libsecp256k1 2020-06-09 13:41:38 -07:00
msvc-autogen.py build: Update default platform toolset in msvc-autogen.py 2021-09-04 15:34:58 +03:00
README.md doc: Suggest using jom instead of nmake 2021-09-30 11:07:43 +03:00
vcpkg.json ci: remove boost thread installation 2021-02-02 12:38:22 +08:00

Building Bitcoin Core with Visual Studio

Introduction

Solution and project files to build Bitcoin Core with msbuild or Visual Studio can be found in the build_msvc directory. The build has been tested with Visual Studio 2019 (building with earlier versions of Visual Studio should not be expected to work).

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

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-src-5.12.11.zip), and expand it into a dedicated folder. The following instructions assume that this folder is C:\dev\qt-source.

  2. Open "x64 Native Tools Command Prompt for VS 2019", and input the following commands:

cd C:\dev\qt-source
mkdir build
cd build
..\configure -release -silent -opensource -confirm-license -opengl desktop -no-shared -static -static-runtime -mp -qt-zlib -qt-pcre -qt-libpng -no-libjpeg -nomake examples -nomake tests -nomake tools -no-dbus -no-libudev -no-icu -no-gtk -no-opengles3 -no-angle -no-sql-sqlite -no-sql-odbc -no-sqlite -no-libudev -no-vulkan -skip qt3d -skip qtactiveqt -skip qtandroidextras -skip qtcanvas3d -skip qtcharts -skip qtconnectivity -skip qtdatavis3d -skip qtdeclarative -skip qtdoc -skip qtgamepad -skip qtgraphicaleffects -skip qtimageformats -skip qtlocation -skip qtmacextras -skip qtmultimedia -skip qtnetworkauth -skip qtpurchasing -skip qtquickcontrols -skip qtquickcontrols2 -skip qtscript -skip qtscxml -skip qtsensors -skip qtserialbus -skip qtserialport -skip qtspeech -skip qtvirtualkeyboard -skip qtwayland -skip qtwebchannel -skip qtwebengine -skip qtwebsockets -skip qtwebview -skip qtx11extras -skip qtxmlpatterns -no-openssl -no-feature-sql -no-feature-sqlmodel -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 from Makefile:
PS >py -3 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 2019 toolchain use:

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

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

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.