Skip to content

Commit f6370bf

Browse files
hyperpolymathclaude
andcommitted
feat(lithoglyph/gql-dt): implement FFI stubs — wire db_open, db_close, parse, execute
Replace all TODO/placeholder stub functions in the GQL-DT Zig FFI layer with working implementations that allocate and manage opaque handle state (DbState, QueryState, SchemaState, ResultState) on the heap. Zig FFI (ffi/zig/src/main.zig): - gqldt_db_open: validates path, allocates DbState, returns opaque handle - gqldt_db_close: frees DbState backing memory - gqldt_parse / gqldt_parse_inferred: store query text in QueryState - gqldt_typecheck: marks query as type-checked (precondition for execute) - gqldt_execute: verifies typecheck precondition, allocates ResultState - gqldt_serialize_cbor: encodes query as CBOR text string (RFC 8949) - gqldt_serialize_json: produces {"query":"..."} wrapper - gqldt_deserialize_cbor: decodes CBOR text string back to QueryState - gqldt_get_schema: allocates SchemaState for collection - gqldt_validate_permissions: validates user_id, delegates to Idris2 - gqldt_query_free / gqldt_schema_free / gqldt_result_free: proper cleanup - gqldt_version: returns "0.1.0" - Slot allocation helpers (alloc_slot/read_slot/free_slot/bits64_to_ptr) for Idris2 pointer marshalling Idris2 ABI (src/GQLdt/ABI/Foreign.idr): - Replace all ?impl_pending holes (dbOpen, dbClose, parse, parseInferred, typecheck, execute, dbOpenSafe, parseSafe) with implementations using allocSlot/readSlot/freeSlot + Data.So.choose pattern (zero believe_me) - Add validateDbPath and validateQueryStr inline validators - Add handle pointer extractors (extractDbPtr, extractQueryPtr, extractSchemaPtr) Build (build.zig): - Migrate to Zig 0.15.2 API (addLibrary/createModule) - Build both static and shared library artifacts Tests: - Replace template placeholders in integration_test.zig with real GQL-DT function signatures - All 21 unit tests pass, both libraries compile clean Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 45cd49d commit f6370bf

File tree

4 files changed

+1009
-289
lines changed

4 files changed

+1009
-289
lines changed
Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,51 @@
11
// SPDX-License-Identifier: PMPL-1.0-or-later
2-
// SPDX-FileCopyrightText: 2025 Jonathan D.A. Jewell (@hyperpolymath)
2+
// SPDX-FileCopyrightText: 2025-2026 Jonathan D.A. Jewell (@hyperpolymath)
33
//
4-
// build.zig - GQL-DT FFI Build Configuration
4+
// build.zig - GQL-DT FFI Build Configuration (Zig 0.15.2+)
5+
//
6+
// Builds the libgqldt shared library (C ABI) and unit tests.
57

68
const std = @import("std");
79

810
pub fn build(b: *std.Build) void {
911
const target = b.standardTargetOptions(.{});
1012
const optimize = b.standardOptimizeOption(.{});
1113

12-
//Build tests
13-
const tests = b.addTest(.{
14-
.name = "gqldt-tests",
15-
.target = target,
16-
.optimize = optimize,
14+
// Static library (libgqldt.a)
15+
const static_lib = b.addLibrary(.{
16+
.name = "gqldt",
17+
.root_module = b.createModule(.{
18+
.root_source_file = b.path("src/main.zig"),
19+
.target = target,
20+
.optimize = optimize,
21+
}),
22+
.linkage = .static,
1723
});
24+
b.installArtifact(static_lib);
1825

19-
tests.root_module.addAnonymousImport("main", .{
20-
.root_source_file = b.path("src/main.zig"),
26+
// Shared library (libgqldt.so / libgqldt.dylib)
27+
const shared_lib = b.addLibrary(.{
28+
.name = "gqldt",
29+
.root_module = b.createModule(.{
30+
.root_source_file = b.path("src/main.zig"),
31+
.target = target,
32+
.optimize = optimize,
33+
}),
34+
.linkage = .dynamic,
35+
});
36+
b.installArtifact(shared_lib);
37+
38+
// Unit tests (from main.zig internal tests)
39+
const unit_tests = b.addTest(.{
40+
.name = "gqldt-tests",
41+
.root_module = b.createModule(.{
42+
.root_source_file = b.path("src/main.zig"),
43+
.target = target,
44+
.optimize = optimize,
45+
}),
2146
});
22-
tests.linkLibC();
2347

24-
const run_tests = b.addRunArtifact(tests);
48+
const run_unit_tests = b.addRunArtifact(unit_tests);
2549
const test_step = b.step("test", "Run unit tests");
26-
test_step.dependOn(&run_tests.step);
50+
test_step.dependOn(&run_unit_tests.step);
2751
}

0 commit comments

Comments
 (0)