Skip to content

Commit f41d7ff

Browse files
authored
Merge pull request #7 from stringintech/static-link
2 parents 7d2bf14 + 1513470 commit f41d7ff

28 files changed

+60
-70
lines changed

.github/workflows/ci.yml

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66

77
jobs:
88
ubuntu:
9-
name: Build and Test on Ubuntu
9+
name: Build, Test, and Lint on Ubuntu
1010
runs-on: ubuntu-latest
1111

1212
steps:
@@ -31,6 +31,11 @@ jobs:
3131
- name: Run tests
3232
run: make test
3333

34+
- name: Run linter
35+
uses: golangci/golangci-lint-action@v9
36+
with:
37+
version: v2.6.1
38+
3439
macos:
3540
name: Build and Test on macOS
3641
runs-on: macos-latest
@@ -59,31 +64,30 @@ jobs:
5964
windows:
6065
name: Build and Test on Windows
6166
runs-on: windows-latest
67+
defaults:
68+
run:
69+
shell: msys2 {0}
6270

6371
steps:
6472
- uses: actions/checkout@v4
6573

74+
- name: Set up MSYS2 with MinGW
75+
uses: msys2/setup-msys2@v2
76+
with:
77+
msystem: MINGW64
78+
update: true
79+
path-type: inherit
80+
install: >-
81+
mingw-w64-x86_64-gcc
82+
mingw-w64-x86_64-cmake
83+
mingw-w64-x86_64-boost
84+
make
85+
6686
- name: Set up Go
6787
uses: actions/setup-go@v5
6888
with:
6989
go-version: '1.23.3'
7090

71-
- name: Install Boost library
72-
run: |
73-
git clone https://github.com/microsoft/vcpkg.git
74-
cd vcpkg
75-
.\bootstrap-vcpkg.bat
76-
.\vcpkg install boost-multi-index:x64-windows boost-headers:x64-windows
77-
78-
- name: Set environment variables
79-
run: |
80-
echo "BOOST_ROOT=$env:GITHUB_WORKSPACE\vcpkg\installed\x64-windows" | Out-File -FilePath $env:GITHUB_ENV -Append
81-
echo "BOOST_INCLUDEDIR=$env:GITHUB_WORKSPACE\vcpkg\installed\x64-windows\include" | Out-File -FilePath $env:GITHUB_ENV -Append
82-
echo "$env:GITHUB_WORKSPACE\depend\bitcoin\build\bin\RelWithDebInfo" | Out-File -FilePath $env:GITHUB_PATH -Append
83-
84-
- name: Install make
85-
run: choco install make
86-
8791
- name: Build Kernel
8892
run: make build-kernel
8993

@@ -92,20 +96,3 @@ jobs:
9296

9397
- name: Run tests
9498
run: make test
95-
96-
lint:
97-
name: Lint
98-
runs-on: ubuntu-latest
99-
100-
steps:
101-
- uses: actions/checkout@v4
102-
103-
- name: Set up Go
104-
uses: actions/setup-go@v5
105-
with:
106-
go-version: '1.23.3'
107-
108-
- name: Run linter
109-
uses: golangci/golangci-lint-action@v9
110-
with:
111-
version: v2.6.1

Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ build-kernel:
88
cd depend/bitcoin && \
99
cmake -B build \
1010
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
11-
-DBUILD_SHARED_LIBS=ON \
11+
-DBUILD_SHARED_LIBS=OFF \
1212
-DBUILD_KERNEL_LIB=ON \
1313
-DBUILD_KERNEL_TEST=OFF \
1414
-DBUILD_TESTS=OFF \
@@ -21,8 +21,11 @@ build-kernel:
2121
-DBUILD_DAEMON=OFF \
2222
-DBUILD_UTIL_CHAINSTATE=OFF \
2323
-DBUILD_CLI=OFF \
24-
-DENABLE_IPC=OFF && \
25-
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
24+
-DENABLE_IPC=OFF \
25+
-DCMAKE_INSTALL_LIBDIR=lib \
26+
-DCMAKE_INSTALL_PREFIX=$$PWD/install && \
27+
cmake --build build --config RelWithDebInfo --parallel$(if $(NUM_JOBS),=$(NUM_JOBS)) && \
28+
cmake --install build --config RelWithDebInfo
2629

2730
build:
2831
go build ./...
@@ -32,6 +35,7 @@ test:
3235

3336
clean:
3437
rm -rf depend/bitcoin/build
38+
rm -rf depend/bitcoin/install
3539
go clean ./...
3640
go clean -testcache
3741

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ cd go-bitcoinkernel
3939
make build-kernel
4040
```
4141

42-
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:
42+
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:
4343
([Unix](./depend/bitcoin/doc/build-unix.md),
4444
[macOS](./depend/bitcoin/doc/build-osx.md),
4545
[Windows](./depend/bitcoin/doc/build-windows.md))
4646

47+
**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.
48+
4749
### Step 3: Run Tests
4850

4951
```bash
@@ -92,8 +94,4 @@ call `Destroy()` methods when you're done with owned objects to free resources i
9294

9395
### Error Handling
9496

95-
The library uses structured error types for better error handling (see [errors.go](./kernel/errors.go)).
96-
97-
### Runtime Dependencies
98-
99-
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.
97+
The library uses structured error types for better error handling (see [errors.go](./kernel/errors.go)).

kernel/block.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package kernel
22

33
/*
4-
#include "kernel/bitcoinkernel.h"
4+
#include "bitcoinkernel.h"
55
*/
66
import "C"
77
import (

kernel/block_hash.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package kernel
22

33
/*
4-
#include "kernel/bitcoinkernel.h"
4+
#include "bitcoinkernel.h"
55
*/
66
import "C"
77
import (

kernel/block_spent_outputs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package kernel
22

33
/*
4-
#include "kernel/bitcoinkernel.h"
4+
#include "bitcoinkernel.h"
55
*/
66
import "C"
77
import (

kernel/block_tree_entry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package kernel
22

33
/*
4-
#include "kernel/bitcoinkernel.h"
4+
#include "bitcoinkernel.h"
55
*/
66
import "C"
77

kernel/block_validation_state.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package kernel
22

33
/*
4-
#include "kernel/bitcoinkernel.h"
4+
#include "bitcoinkernel.h"
55
*/
66
import "C"
77

kernel/cgo_unix.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
package kernel
44

55
/*
6-
#cgo CFLAGS: -I../depend/bitcoin/src
7-
#cgo LDFLAGS: -L../depend/bitcoin/build/lib -lbitcoinkernel -Wl,-rpath,${SRCDIR}/../depend/bitcoin/build/lib
6+
#cgo CFLAGS: -I../depend/bitcoin/install/include -DBITCOINKERNEL_STATIC
7+
#cgo darwin LDFLAGS: -L../depend/bitcoin/install/lib -lbitcoinkernel -lc++
8+
#cgo !darwin LDFLAGS: -L../depend/bitcoin/install/lib -lbitcoinkernel -lstdc++ -lm
89
*/
910
import "C"

kernel/cgo_windows.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
package kernel
44

55
/*
6-
#cgo CFLAGS: -I../depend/bitcoin/src
7-
#cgo LDFLAGS: -L../depend/bitcoin/build/bin/RelWithDebInfo -lbitcoinkernel -lbcrypt -lshell32
6+
#cgo CFLAGS: -I../depend/bitcoin/install/include -DBITCOINKERNEL_STATIC
7+
#cgo LDFLAGS: -L../depend/bitcoin/install/lib -lbitcoinkernel -lstdc++ -lbcrypt -lshell32
88
*/
99
import "C"

0 commit comments

Comments
 (0)