Skip to content

Commit fe5ed0a

Browse files
committed
G2: panel-clades Zig FFI builds green under Zig 0.15
build.zig migrated to 0.15 API (addSharedLibrary/addStaticLibrary -> addLibrary+linkage, addTest/addExecutable -> root_module via createModule, addInstallHeader -> addInstallFileWithDir, .link_libc on all modules). main.zig: opaque-with-fields -> struct, callconv(.C) -> callconv(.c), removed pointless discard. zig build test now exits 0 (was: didn't compile). Same proven pattern as Axiom.jl PR #17.
1 parent bf4e791 commit fe5ed0a

2 files changed

Lines changed: 46 additions & 29 deletions

File tree

panel-clades/ffi/zig/build.zig

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,49 @@ pub fn build(b: *std.Build) void {
77
const target = b.standardTargetOptions(.{});
88
const optimize = b.standardOptimizeOption(.{});
99

10-
// Shared library (.so, .dylib, .dll)
11-
const lib = b.addSharedLibrary(.{
12-
.name = "panel_clades",
10+
// Root module shared by the library/test artifacts (Zig 0.15 API).
11+
const root_mod = b.createModule(.{
12+
.link_libc = true,
1313
.root_source_file = b.path("src/main.zig"),
1414
.target = target,
1515
.optimize = optimize,
1616
});
1717

18-
// Set version
19-
lib.version = .{ .major = 0, .minor = 1, .patch = 0 };
18+
// Shared library (.so, .dylib, .dll)
19+
const lib = b.addLibrary(.{
20+
.name = "panel_clades",
21+
.linkage = .dynamic,
22+
.root_module = root_mod,
23+
.version = .{ .major = 0, .minor = 1, .patch = 0 },
24+
});
2025

2126
// Static library (.a)
22-
const lib_static = b.addStaticLibrary(.{
27+
const lib_static = b.addLibrary(.{
2328
.name = "panel_clades",
24-
.root_source_file = b.path("src/main.zig"),
25-
.target = target,
26-
.optimize = optimize,
29+
.linkage = .static,
30+
.root_module = root_mod,
2731
});
2832

2933
// Install artifacts
3034
b.installArtifact(lib);
3135
b.installArtifact(lib_static);
3236

33-
// Generate header file for C compatibility
34-
const header = b.addInstallHeader(
37+
// Install the C header (Zig 0.15 API).
38+
const header = b.addInstallFileWithDir(
3539
b.path("include/panel_clades.h"),
40+
.header,
3641
"panel_clades.h",
3742
);
3843
b.getInstallStep().dependOn(&header.step);
3944

4045
// Unit tests
4146
const lib_tests = b.addTest(.{
42-
.root_source_file = b.path("src/main.zig"),
43-
.target = target,
44-
.optimize = optimize,
47+
.root_module = b.createModule(.{
48+
.link_libc = true,
49+
.root_source_file = b.path("src/main.zig"),
50+
.target = target,
51+
.optimize = optimize,
52+
}),
4553
});
4654

4755
const run_lib_tests = b.addRunArtifact(lib_tests);
@@ -51,9 +59,12 @@ pub fn build(b: *std.Build) void {
5159

5260
// Integration tests
5361
const integration_tests = b.addTest(.{
54-
.root_source_file = b.path("test/integration_test.zig"),
55-
.target = target,
56-
.optimize = optimize,
62+
.root_module = b.createModule(.{
63+
.link_libc = true,
64+
.root_source_file = b.path("test/integration_test.zig"),
65+
.target = target,
66+
.optimize = optimize,
67+
}),
5768
});
5869

5970
integration_tests.linkLibrary(lib);
@@ -65,9 +76,12 @@ pub fn build(b: *std.Build) void {
6576

6677
// Documentation
6778
const docs = b.addTest(.{
68-
.root_source_file = b.path("src/main.zig"),
69-
.target = target,
70-
.optimize = .Debug,
79+
.root_module = b.createModule(.{
80+
.link_libc = true,
81+
.root_source_file = b.path("src/main.zig"),
82+
.target = target,
83+
.optimize = .Debug,
84+
}),
7185
});
7286

7387
const docs_step = b.step("docs", "Generate documentation");
@@ -80,9 +94,12 @@ pub fn build(b: *std.Build) void {
8094
// Benchmark (if needed)
8195
const bench = b.addExecutable(.{
8296
.name = "panel_clades-bench",
83-
.root_source_file = b.path("bench/bench.zig"),
84-
.target = target,
85-
.optimize = .ReleaseFast,
97+
.root_module = b.createModule(.{
98+
.link_libc = true,
99+
.root_source_file = b.path("bench/bench.zig"),
100+
.target = target,
101+
.optimize = .ReleaseFast,
102+
}),
86103
});
87104

88105
bench.linkLibrary(lib);

panel-clades/ffi/zig/src/main.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,13 @@ pub const CladeKind = enum(u32) {
5959
terminal = 12,
6060
};
6161

62-
/// Library handle (opaque to prevent direct access)
63-
pub const Handle = opaque {
62+
/// Library handle. A real struct internally; exposed across the C ABI as
63+
/// an opaque pointer (the header forward-declares it). `opaque{}` cannot
64+
/// have fields or be `create`d, so this must be a `struct`.
65+
pub const Handle = struct {
6466
// Internal state hidden from C
6567
allocator: std.mem.Allocator,
6668
initialized: bool,
67-
// Add your fields here
6869
};
6970

7071
//==============================================================================
@@ -154,8 +155,7 @@ export fn panel_clades_load_clade(handle: ?*Handle, clade_id: ?[*:0]const u8) Re
154155
return .invalid_param;
155156
}
156157

157-
// TODO: store clade definition internally
158-
_ = id_str;
158+
// TODO: store clade definition internally (id_str validated above)
159159

160160
clearError();
161161
return .ok;
@@ -318,7 +318,7 @@ export fn panel_clades_build_info() [*:0]const u8 {
318318
//==============================================================================
319319

320320
/// Callback function type (C ABI)
321-
pub const Callback = *const fn (u64, u32) callconv(.C) u32;
321+
pub const Callback = *const fn (u64, u32) callconv(.c) u32;
322322

323323
/// Register a callback
324324
export fn panel_clades_register_callback(

0 commit comments

Comments
 (0)