From ca7129adf172eaf4d17a5927c0f66608f1409cf7 Mon Sep 17 00:00:00 2001 From: stringintech Date: Tue, 11 Nov 2025 14:10:29 +0330 Subject: [PATCH 1/3] Switch to static linking and migrate Windows CI to MinGW Simplify the build process by statically linking `libbitcoinkernel` to produces more self-contained binaries with fewer moving parts. --- .github/workflows/ci.yml | 31 ++++++++++++------------ Makefile | 10 +++++--- kernel/block.go | 2 +- kernel/block_hash.go | 2 +- kernel/block_spent_outputs.go | 2 +- kernel/block_tree_entry.go | 2 +- kernel/block_validation_state.go | 2 +- kernel/cgo_unix.go | 5 ++-- kernel/cgo_windows.go | 4 +-- kernel/chain.go | 2 +- kernel/chain_parameters.go | 2 +- kernel/chainstate_manager.go | 2 +- kernel/chainstate_manager_options.go | 2 +- kernel/coin.go | 2 +- kernel/context.go | 2 +- kernel/context_options.go | 2 +- kernel/logging_connection.go | 2 +- kernel/notification_callbacks.go | 2 +- kernel/script_pubkey.go | 2 +- kernel/transaction.go | 2 +- kernel/transaction_input.go | 2 +- kernel/transaction_out_point.go | 2 +- kernel/transaction_output.go | 2 +- kernel/transaction_spent_outputs.go | 2 +- kernel/txid.go | 2 +- kernel/validation_interface_callbacks.go | 2 +- kernel/writer_helper.go | 2 +- 27 files changed, 50 insertions(+), 46 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 004fca8..0d23455 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,31 +59,30 @@ jobs: windows: name: Build and Test on Windows runs-on: windows-latest + defaults: + run: + shell: msys2 {0} steps: - uses: actions/checkout@v4 + - name: Set up MSYS2 with MinGW + uses: msys2/setup-msys2@v2 + with: + msystem: MINGW64 + update: true + path-type: inherit + install: >- + mingw-w64-x86_64-gcc + mingw-w64-x86_64-cmake + mingw-w64-x86_64-boost + make + - name: Set up Go uses: actions/setup-go@v5 with: go-version: '1.23.3' - - name: Install Boost library - run: | - git clone https://github.com/microsoft/vcpkg.git - cd vcpkg - .\bootstrap-vcpkg.bat - .\vcpkg install boost-multi-index:x64-windows boost-headers:x64-windows - - - name: Set environment variables - run: | - echo "BOOST_ROOT=$env:GITHUB_WORKSPACE\vcpkg\installed\x64-windows" | Out-File -FilePath $env:GITHUB_ENV -Append - echo "BOOST_INCLUDEDIR=$env:GITHUB_WORKSPACE\vcpkg\installed\x64-windows\include" | Out-File -FilePath $env:GITHUB_ENV -Append - echo "$env:GITHUB_WORKSPACE\depend\bitcoin\build\bin\RelWithDebInfo" | Out-File -FilePath $env:GITHUB_PATH -Append - - - name: Install make - run: choco install make - - name: Build Kernel run: make build-kernel diff --git a/Makefile b/Makefile index 90307b4..5fc28bd 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ build-kernel: cd depend/bitcoin && \ cmake -B build \ -DCMAKE_BUILD_TYPE=RelWithDebInfo \ - -DBUILD_SHARED_LIBS=ON \ + -DBUILD_SHARED_LIBS=OFF \ -DBUILD_KERNEL_LIB=ON \ -DBUILD_KERNEL_TEST=OFF \ -DBUILD_TESTS=OFF \ @@ -21,8 +21,11 @@ build-kernel: -DBUILD_DAEMON=OFF \ -DBUILD_UTIL_CHAINSTATE=OFF \ -DBUILD_CLI=OFF \ - -DENABLE_IPC=OFF && \ - cmake --build build --config RelWithDebInfo --parallel$(if $(NUM_JOBS),=$(NUM_JOBS)) # Use NUM_JOBS variable if set (e.g., make build-kernel NUM_JOBS=8), otherwise auto-detect CPU cores + -DENABLE_IPC=OFF \ + -DCMAKE_INSTALL_LIBDIR=lib \ + -DCMAKE_INSTALL_PREFIX=$$PWD/install && \ + cmake --build build --config RelWithDebInfo --parallel$(if $(NUM_JOBS),=$(NUM_JOBS)) && \ + cmake --install build --config RelWithDebInfo build: go build ./... @@ -32,6 +35,7 @@ test: clean: rm -rf depend/bitcoin/build + rm -rf depend/bitcoin/install go clean ./... go clean -testcache diff --git a/kernel/block.go b/kernel/block.go index 738cb91..3c2e13c 100644 --- a/kernel/block.go +++ b/kernel/block.go @@ -1,7 +1,7 @@ package kernel /* -#include "kernel/bitcoinkernel.h" +#include "bitcoinkernel.h" */ import "C" import ( diff --git a/kernel/block_hash.go b/kernel/block_hash.go index b1339bd..3dfa5c1 100644 --- a/kernel/block_hash.go +++ b/kernel/block_hash.go @@ -1,7 +1,7 @@ package kernel /* -#include "kernel/bitcoinkernel.h" +#include "bitcoinkernel.h" */ import "C" import ( diff --git a/kernel/block_spent_outputs.go b/kernel/block_spent_outputs.go index 3f726dc..ca1a467 100644 --- a/kernel/block_spent_outputs.go +++ b/kernel/block_spent_outputs.go @@ -1,7 +1,7 @@ package kernel /* -#include "kernel/bitcoinkernel.h" +#include "bitcoinkernel.h" */ import "C" import ( diff --git a/kernel/block_tree_entry.go b/kernel/block_tree_entry.go index 1de4390..308260c 100644 --- a/kernel/block_tree_entry.go +++ b/kernel/block_tree_entry.go @@ -1,7 +1,7 @@ package kernel /* -#include "kernel/bitcoinkernel.h" +#include "bitcoinkernel.h" */ import "C" diff --git a/kernel/block_validation_state.go b/kernel/block_validation_state.go index 8f8d40f..dc249d6 100644 --- a/kernel/block_validation_state.go +++ b/kernel/block_validation_state.go @@ -1,7 +1,7 @@ package kernel /* -#include "kernel/bitcoinkernel.h" +#include "bitcoinkernel.h" */ import "C" diff --git a/kernel/cgo_unix.go b/kernel/cgo_unix.go index 54a1399..678b5b7 100644 --- a/kernel/cgo_unix.go +++ b/kernel/cgo_unix.go @@ -3,7 +3,8 @@ package kernel /* -#cgo CFLAGS: -I../depend/bitcoin/src -#cgo LDFLAGS: -L../depend/bitcoin/build/lib -lbitcoinkernel -Wl,-rpath,${SRCDIR}/../depend/bitcoin/build/lib +#cgo CFLAGS: -I../depend/bitcoin/install/include -DBITCOINKERNEL_STATIC +#cgo darwin LDFLAGS: -L../depend/bitcoin/install/lib -lbitcoinkernel -lc++ +#cgo !darwin LDFLAGS: -L../depend/bitcoin/install/lib -lbitcoinkernel -lstdc++ -lm */ import "C" diff --git a/kernel/cgo_windows.go b/kernel/cgo_windows.go index 83556c6..cc3306a 100644 --- a/kernel/cgo_windows.go +++ b/kernel/cgo_windows.go @@ -3,7 +3,7 @@ package kernel /* -#cgo CFLAGS: -I../depend/bitcoin/src -#cgo LDFLAGS: -L../depend/bitcoin/build/bin/RelWithDebInfo -lbitcoinkernel -lbcrypt -lshell32 +#cgo CFLAGS: -I../depend/bitcoin/install/include -DBITCOINKERNEL_STATIC +#cgo LDFLAGS: -L../depend/bitcoin/install/lib -lbitcoinkernel -lstdc++ -lbcrypt -lshell32 */ import "C" diff --git a/kernel/chain.go b/kernel/chain.go index c692c4e..28de25a 100644 --- a/kernel/chain.go +++ b/kernel/chain.go @@ -1,7 +1,7 @@ package kernel /* -#include "kernel/bitcoinkernel.h" +#include "bitcoinkernel.h" */ import "C" diff --git a/kernel/chain_parameters.go b/kernel/chain_parameters.go index 0ac942e..3e78ee8 100644 --- a/kernel/chain_parameters.go +++ b/kernel/chain_parameters.go @@ -1,7 +1,7 @@ package kernel /* -#include "kernel/bitcoinkernel.h" +#include "bitcoinkernel.h" */ import "C" import ( diff --git a/kernel/chainstate_manager.go b/kernel/chainstate_manager.go index 270b16c..99be3a0 100644 --- a/kernel/chainstate_manager.go +++ b/kernel/chainstate_manager.go @@ -1,7 +1,7 @@ package kernel /* -#include "kernel/bitcoinkernel.h" +#include "bitcoinkernel.h" #include */ import "C" diff --git a/kernel/chainstate_manager_options.go b/kernel/chainstate_manager_options.go index a25cc1a..cc451b8 100644 --- a/kernel/chainstate_manager_options.go +++ b/kernel/chainstate_manager_options.go @@ -1,7 +1,7 @@ package kernel /* -#include "kernel/bitcoinkernel.h" +#include "bitcoinkernel.h" #include */ import "C" diff --git a/kernel/coin.go b/kernel/coin.go index 77bbd69..7be70eb 100644 --- a/kernel/coin.go +++ b/kernel/coin.go @@ -1,7 +1,7 @@ package kernel /* -#include "kernel/bitcoinkernel.h" +#include "bitcoinkernel.h" */ import "C" import ( diff --git a/kernel/context.go b/kernel/context.go index 167da9c..58e888d 100644 --- a/kernel/context.go +++ b/kernel/context.go @@ -1,7 +1,7 @@ package kernel /* -#include "kernel/bitcoinkernel.h" +#include "bitcoinkernel.h" */ import "C" import ( diff --git a/kernel/context_options.go b/kernel/context_options.go index 8bd75bb..60b76fb 100644 --- a/kernel/context_options.go +++ b/kernel/context_options.go @@ -1,7 +1,7 @@ package kernel /* -#include "kernel/bitcoinkernel.h" +#include "bitcoinkernel.h" #include #include diff --git a/kernel/logging_connection.go b/kernel/logging_connection.go index 85ee7a9..2a56e43 100644 --- a/kernel/logging_connection.go +++ b/kernel/logging_connection.go @@ -1,7 +1,7 @@ package kernel /* -#include "kernel/bitcoinkernel.h" +#include "bitcoinkernel.h" #include #include diff --git a/kernel/notification_callbacks.go b/kernel/notification_callbacks.go index 7d0e8f2..8030d18 100644 --- a/kernel/notification_callbacks.go +++ b/kernel/notification_callbacks.go @@ -1,7 +1,7 @@ package kernel /* -#include "kernel/bitcoinkernel.h" +#include "bitcoinkernel.h" */ import "C" import ( diff --git a/kernel/script_pubkey.go b/kernel/script_pubkey.go index 1acb08c..4bb1de7 100644 --- a/kernel/script_pubkey.go +++ b/kernel/script_pubkey.go @@ -1,7 +1,7 @@ package kernel /* -#include "kernel/bitcoinkernel.h" +#include "bitcoinkernel.h" */ import "C" import ( diff --git a/kernel/transaction.go b/kernel/transaction.go index 5304e67..d3e77fa 100644 --- a/kernel/transaction.go +++ b/kernel/transaction.go @@ -1,7 +1,7 @@ package kernel /* -#include "kernel/bitcoinkernel.h" +#include "bitcoinkernel.h" */ import "C" import ( diff --git a/kernel/transaction_input.go b/kernel/transaction_input.go index 38b2ea4..2f12ae9 100644 --- a/kernel/transaction_input.go +++ b/kernel/transaction_input.go @@ -1,7 +1,7 @@ package kernel /* -#include "kernel/bitcoinkernel.h" +#include "bitcoinkernel.h" */ import "C" import ( diff --git a/kernel/transaction_out_point.go b/kernel/transaction_out_point.go index 10ea559..9728f4f 100644 --- a/kernel/transaction_out_point.go +++ b/kernel/transaction_out_point.go @@ -1,7 +1,7 @@ package kernel /* -#include "kernel/bitcoinkernel.h" +#include "bitcoinkernel.h" */ import "C" import ( diff --git a/kernel/transaction_output.go b/kernel/transaction_output.go index d82261f..6ddbc22 100644 --- a/kernel/transaction_output.go +++ b/kernel/transaction_output.go @@ -1,7 +1,7 @@ package kernel /* -#include "kernel/bitcoinkernel.h" +#include "bitcoinkernel.h" */ import "C" import ( diff --git a/kernel/transaction_spent_outputs.go b/kernel/transaction_spent_outputs.go index ea9c513..455ef34 100644 --- a/kernel/transaction_spent_outputs.go +++ b/kernel/transaction_spent_outputs.go @@ -1,7 +1,7 @@ package kernel /* -#include "kernel/bitcoinkernel.h" +#include "bitcoinkernel.h" */ import "C" import ( diff --git a/kernel/txid.go b/kernel/txid.go index 1f81213..e372697 100644 --- a/kernel/txid.go +++ b/kernel/txid.go @@ -1,7 +1,7 @@ package kernel /* -#include "kernel/bitcoinkernel.h" +#include "bitcoinkernel.h" */ import "C" import ( diff --git a/kernel/validation_interface_callbacks.go b/kernel/validation_interface_callbacks.go index 6ac66e5..41369df 100644 --- a/kernel/validation_interface_callbacks.go +++ b/kernel/validation_interface_callbacks.go @@ -1,7 +1,7 @@ package kernel /* -#include "kernel/bitcoinkernel.h" +#include "bitcoinkernel.h" */ import "C" import ( diff --git a/kernel/writer_helper.go b/kernel/writer_helper.go index 8670861..c45c116 100644 --- a/kernel/writer_helper.go +++ b/kernel/writer_helper.go @@ -1,7 +1,7 @@ package kernel /* -#include "kernel/bitcoinkernel.h" +#include "bitcoinkernel.h" #include #include From 912ba6665aa2fa9289f6ec401b8a328e6e866c6d Mon Sep 17 00:00:00 2001 From: stringintech Date: Wed, 12 Nov 2025 16:58:30 +0330 Subject: [PATCH 2/3] Update README to reflect static linking changes --- README.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 838232c..22dc83d 100644 --- a/README.md +++ b/README.md @@ -39,11 +39,13 @@ cd go-bitcoinkernel make build-kernel ``` -This command will configure Bitcoin Core's CMake build system and build only the `libbitcoinkernel` shared library. Refer to Bitcoin Core's build documentation to for the minimum requirements to compile `libbitcoinkernel` from source: +This command will configure Bitcoin Core's CMake build system and statically compile the `libbitcoinkernel` library. Building requires CMake, a C++ compiler, Boost library, and Make. For platform-specific setup instructions, consult Bitcoin Core's build documentation: ([Unix](./depend/bitcoin/doc/build-unix.md), [macOS](./depend/bitcoin/doc/build-osx.md), [Windows](./depend/bitcoin/doc/build-windows.md)) +**Addtional note for Windows:** MinGW toolchain is required. CGo uses GCC on Windows, so static linking requires the library to be compiled with GCC/MinGW rather than MSVC for ABI compatibility. + ### Step 3: Run Tests ```bash @@ -92,8 +94,4 @@ call `Destroy()` methods when you're done with owned objects to free resources i ### Error Handling -The library uses structured error types for better error handling (see [errors.go](./kernel/errors.go)). - -### Runtime Dependencies - -Your Go application will have a runtime dependency on the shared `libbitcoinkernel` library produced by `make build-kernel` in `/path/to/go-bitcoinkernel/depend/bitcoin/build`. Do not delete or move these built library files as your application needs them to run. \ No newline at end of file +The library uses structured error types for better error handling (see [errors.go](./kernel/errors.go)). \ No newline at end of file From 1513470b8955ce7e31f74b6a45e06e51109b7552 Mon Sep 17 00:00:00 2001 From: stringintech Date: Wed, 12 Nov 2025 17:31:32 +0330 Subject: [PATCH 3/3] Fix lint job by running after build in ubuntu job --- .github/workflows/ci.yml | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0d23455..6057dd6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,7 +6,7 @@ on: jobs: ubuntu: - name: Build and Test on Ubuntu + name: Build, Test, and Lint on Ubuntu runs-on: ubuntu-latest steps: @@ -31,6 +31,11 @@ jobs: - name: Run tests run: make test + - name: Run linter + uses: golangci/golangci-lint-action@v9 + with: + version: v2.6.1 + macos: name: Build and Test on macOS runs-on: macos-latest @@ -91,20 +96,3 @@ jobs: - name: Run tests run: make test - - lint: - name: Lint - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: '1.23.3' - - - name: Run linter - uses: golangci/golangci-lint-action@v9 - with: - version: v2.6.1