Skip to content

Commit 3f6b4b3

Browse files
committed
fix(ci): install shared lib, add cgo include, fix Python/C++ paths
- build.zig: use addInstallArtifact in shared step (was only compiling, not installing) - go/goldenfloat/gf16.go: add #include "gf16.h" to cgo preamble - python/_binding.py: honor GOLDENFLOAT_LIB_DIR env, add restype for phi/trinity/version - cpp/CMakeLists.txt: search $GOLDENFLOAT_LIB_DIR in find_library - CI: remove conflicting CGO env vars, let cgo relative paths work
1 parent 2f6d2dc commit 3f6b4b3

5 files changed

Lines changed: 19 additions & 6 deletions

File tree

.github/workflows/test-bindings.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,6 @@ jobs:
9999
if: matrix.language == 'go'
100100
run: |
101101
cd go/goldenfloat
102-
CGO_CFLAGS="-I$GITHUB_WORKSPACE/src/c" CGO_LDFLAGS="-L$GITHUB_WORKSPACE/zig-out/lib -lgoldenfloat" go test -v ./...
102+
go test -v ./...
103103
env:
104104
LD_LIBRARY_PATH: ${{ github.workspace }}/zig-out/lib

build.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ pub fn build(b: *std.Build) void {
5656
.version = .{ .major = 2, .minor = 1, .patch = 0 },
5757
});
5858

59-
b.installArtifact(c_abi_lib);
59+
const install_lib = b.addInstallArtifact(c_abi_lib);
6060

6161
// Install C header alongside library
6262
const header_install = b.addInstallHeaderFile(b.path("src/c/gf16.h"), "gf16.h");
6363

6464
const shared_step = b.step("shared", "Build C-ABI shared library (libgoldenfloat)");
65-
shared_step.dependOn(&c_abi_lib.step);
65+
shared_step.dependOn(&install_lib.step);
6666
shared_step.dependOn(&header_install.step);
6767

6868
// ─────────────────────────────────────────────────────────────────

cpp/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ project(goldenfloat VERSION 1.0.0 LANGUAGES CXX)
88

99
# Find GoldenFloat shared library
1010
find_library(GOLDENFLOAT NAMES goldenfloat PATHS
11+
"$ENV{GOLDENFLOAT_LIB_DIR}"
1112
"${CMAKE_SOURCE_DIR}/../../zig-out/lib"
1213
"${CMAKE_SOURCE_DIR}/../zig-out/lib"
1314
"${CMAKE_SOURCE_DIR}/../../zig-out/bin"
1415
"${CMAKE_SOURCE_DIR}/../../build"
1516
"${CMAKE_SOURCE_DIR}/../../zig-out/lib"
16-
NO_DEFAULT_PATH
1717
)
1818

1919
if(NOT GOLDENFLOAT)

go/goldenfloat/gf16.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package goldenfloat
88
/*
99
#cgo LDFLAGS: -L../../zig-out/lib -lgoldenfloat
1010
#cgo CFLAGS: -I../../src/c
11+
#include "gf16.h"
1112
*/
1213
import "C"
1314

python/goldenfloat/_binding.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@
1616

1717
def _find_library():
1818
"""Find libgoldenfloat.{so,dylib,dll}"""
19-
# Check zig-out/lib first
2019
search_paths = [
2120
os.path.join(os.path.dirname(__file__), "..", "..", "zig-out", "lib"),
2221
os.path.join(os.path.dirname(__file__), "..", "..", "..", "..", "zig-out", "lib"),
22+
os.path.join(os.getcwd(), "zig-out", "lib"),
2323
]
2424

25-
# Add current directory for development
25+
env_dir = os.environ.get("GOLDENFLOAT_LIB_DIR")
26+
if env_dir:
27+
search_paths.insert(0, env_dir)
28+
2629
search_paths.append(os.getcwd())
2730

2831
lib_name = None
@@ -126,6 +129,15 @@ def _get_lib():
126129
_lib.gf16_fma.restype = _gf16_t
127130
_lib.gf16_fma.argtypes = [_gf16_t, _gf16_t, _gf16_t]
128131

132+
_lib.goldenfloat_phi.restype = ctypes.c_double
133+
_lib.goldenfloat_phi.argtypes = []
134+
135+
_lib.goldenfloat_trinity.restype = ctypes.c_double
136+
_lib.goldenfloat_trinity.argtypes = []
137+
138+
_lib.goldenfloat_version.restype = ctypes.c_char_p
139+
_lib.goldenfloat_version.argtypes = []
140+
129141
return _lib
130142

131143

0 commit comments

Comments
 (0)