From 4fce466d1a3e345836434f8fb375980f626981f1 Mon Sep 17 00:00:00 2001 From: TheCharlatan Date: Tue, 8 Apr 2025 16:51:37 +0200 Subject: [PATCH] kernel: Fix bitcoin-chainstate for windows And turn it on in the CI. --- .github/workflows/ci.yml | 3 ++- src/bitcoin-chainstate.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7e4dea822f2..5a772b11ae9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -202,7 +202,7 @@ jobs: job-type: [standard, fuzz] include: - job-type: standard - generate-options: '-DBUILD_GUI=ON -DWITH_ZMQ=ON -DBUILD_BENCH=ON -DBUILD_KERNEL_LIB=ON -DWERROR=ON' + generate-options: '-DBUILD_GUI=ON -DWITH_ZMQ=ON -DBUILD_BENCH=ON -DBUILD_KERNEL_LIB=ON -DBUILD_UTIL_CHAINSTATE=ON -DBUILD_KERNEL_TEST=OFF -DWERROR=ON' job-name: 'Windows native, VS 2022' - job-type: fuzz generate-options: '-DVCPKG_MANIFEST_NO_DEFAULT_FEATURES=ON -DVCPKG_MANIFEST_FEATURES="wallet" -DBUILD_GUI=OFF -DBUILD_FOR_FUZZING=ON -DWERROR=ON' @@ -307,6 +307,7 @@ jobs: BITCOINTX: '${{ github.workspace }}\build\bin\Release\bitcoin-tx.exe' BITCOINUTIL: '${{ github.workspace }}\build\bin\Release\bitcoin-util.exe' BITCOINWALLET: '${{ github.workspace }}\build\bin\Release\bitcoin-wallet.exe' + BITCOINCHAINSTATE: '${{ github.workspace }}\build\bin\Release\bitcoin-chainstate.exe' TEST_RUNNER_EXTRA: ${{ github.event_name != 'pull_request' && '--extended' || '' }} run: py -3 test/functional/test_runner.py --jobs $NUMBER_OF_PROCESSORS --ci --quiet --tmpdirprefix="${RUNNER_TEMP}" --combinedlogslen=99999999 --timeout-factor=${TEST_RUNNER_TIMEOUT_FACTOR} ${TEST_RUNNER_EXTRA} diff --git a/src/bitcoin-chainstate.cpp b/src/bitcoin-chainstate.cpp index 6c3bd9cfe01..24127d0764f 100644 --- a/src/bitcoin-chainstate.cpp +++ b/src/bitcoin-chainstate.cpp @@ -9,6 +9,15 @@ #include #include +#ifdef WIN32 +// clang-format off +#include +// clang-format on +#include +#include +#include +#endif + using namespace btck; std::vector hex_string_to_byte_vec(std::string_view hex) @@ -140,6 +149,22 @@ int main(int argc, char* argv[]) << " BREAK IN FUTURE VERSIONS. DO NOT USE ON YOUR ACTUAL DATADIR." << std::endl; return 1; } + +#ifdef WIN32 + int win_argc; + wchar_t** wargv = CommandLineToArgvW(GetCommandLineW(), &win_argc); + std::vector utf8_args(win_argc); + std::vector win_argv(win_argc); + std::wstring_convert, wchar_t> utf8_cvt; + for (int i = 0; i < win_argc; i++) { + utf8_args[i] = utf8_cvt.to_bytes(wargv[i]); + win_argv[i] = &utf8_args[i][0]; + } + LocalFree(wargv); + argc = win_argc; + argv = win_argv.data(); +#endif + std::filesystem::path abs_datadir{std::filesystem::absolute(argv[1])}; std::filesystem::create_directories(abs_datadir);