Skip to content

Commit dbb475f

Browse files
hyperpolymathclaude
andcommitted
lol-gateway: retrofit to consume zig-api (uapi_gnosis + path safety)
Replaces the three hand-rolled listeners on 7800/7801/7802 with uapi_gnosis_* pool. Gates file-open paths (main.zig:70/120/290/406/565) through zig-api's proven-backed safePathDefault to close the traversal gap past the alphanumeric sanitizer. lol-specific request handlers (REST / gRPC-JSON / GraphQL) preserved — only listener/transport/threading and path-safety layers change. Per UNIFIED-ZIG-API-STACK.adoc. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 3e0d73b commit dbb475f

2 files changed

Lines changed: 810 additions & 59 deletions

File tree

lol/api/zig-gateway/build.zig

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,112 @@
44
// Build configuration for LOL (1000Langs) Zig API gateway.
55
// Replaces the V vweb gateway in api/v-gateway/.
66
// Requires Zig 0.15.2+.
7+
//
8+
// Modules compiled:
9+
// src/main.zig — HTTP gateway, REST / gRPC-compat / GraphQL handlers
10+
// src/types.zig — Public domain types (replaces v-lol/src/types.v)
11+
// src/lol_ffi.zig — Zig wrapper around liblol (replaces v-lol/src/lol.v + ffi.v)
12+
//
13+
// External dependencies:
14+
//
15+
// liblol — LOL i18n Zig FFI from ffi/zig/ (in-repo).
16+
// Build with `zig build` from standards/lol/ffi/zig/ if absent.
17+
// Linked from: ../../ffi/zig/zig-out/lib
18+
// Headers from: ../../generated/abi
19+
//
20+
// libzig_api — Unified Zig API stack from developer-ecosystem/zig-api.
21+
// Provides:
22+
// uapi_init / uapi_teardown — library lifecycle
23+
// uapi_gnosis_create / _start / _stop — HTTP server pool
24+
// uapi_gnosis_destroy / _state — pool management
25+
// uapi_safe_path_default — proven-backed path gate
26+
// Build with `zig build` in developer-ecosystem/zig-api/ffi/zig/.
27+
// Default paths override-able via -Dzig-api-lib-path and
28+
// -Dzig-api-include-path for CI environments.
29+
//
30+
// libproven_ffi — formally-verified safety primitives from
31+
// verification-ecosystem/proven.
32+
// Needed at link time because libzig_api.a references
33+
// proven_path_has_traversal.
34+
// Default path override-able via -Dproven-lib-path.
735

836
const std = @import("std");
937

38+
// -----------------------------------------------------------------------------
39+
// Default paths — canonical Eclipse-drive locations
40+
// -----------------------------------------------------------------------------
41+
42+
/// Pre-built libzig_api (developer-ecosystem/zig-api/ffi/zig/zig-out/lib).
43+
const DEFAULT_ZIG_API_LIB_PATH =
44+
"/var/mnt/eclipse/repos/developer-ecosystem/zig-api/ffi/zig/zig-out/lib";
45+
46+
/// C header for libzig_api (developer-ecosystem/zig-api/generated/abi).
47+
const DEFAULT_ZIG_API_INCLUDE_PATH =
48+
"/var/mnt/eclipse/repos/developer-ecosystem/zig-api/generated/abi";
49+
50+
/// Pre-built libproven_ffi (verification-ecosystem/proven/ffi/zig/zig-out-standalone/lib).
51+
const DEFAULT_PROVEN_LIB_PATH =
52+
"/var/mnt/eclipse/repos/verification-ecosystem/proven/ffi/zig/zig-out-standalone/lib";
53+
1054
pub fn build(b: *std.Build) void {
1155
const target = b.standardTargetOptions(.{});
1256
const optimize = b.standardOptimizeOption(.{});
1357

58+
// -------------------------------------------------------------------------
59+
// Build options — allow CI to override library paths
60+
// -------------------------------------------------------------------------
61+
const zig_api_lib_path = b.option(
62+
[]const u8,
63+
"zig-api-lib-path",
64+
"Directory containing libzig_api.a (default: " ++ DEFAULT_ZIG_API_LIB_PATH ++ ")",
65+
) orelse DEFAULT_ZIG_API_LIB_PATH;
66+
67+
const zig_api_include_path = b.option(
68+
[]const u8,
69+
"zig-api-include-path",
70+
"Directory containing zig_api.h (default: " ++ DEFAULT_ZIG_API_INCLUDE_PATH ++ ")",
71+
) orelse DEFAULT_ZIG_API_INCLUDE_PATH;
72+
73+
const proven_lib_path = b.option(
74+
[]const u8,
75+
"proven-lib-path",
76+
"Directory containing libproven_ffi.a (default: " ++ DEFAULT_PROVEN_LIB_PATH ++ ")",
77+
) orelse DEFAULT_PROVEN_LIB_PATH;
78+
79+
// -------------------------------------------------------------------------
80+
// Main module
81+
// -------------------------------------------------------------------------
82+
1483
const main_mod = b.createModule(.{
1584
.root_source_file = b.path("src/main.zig"),
1685
.target = target,
1786
.optimize = optimize,
87+
// liblol and libzig_api both use the C standard library.
88+
.link_libc = true,
1889
});
1990

91+
// ── In-repo liblol (LOL i18n FFI) ────────────────────────────────────────
92+
// `zig build` in ffi/zig/ produces zig-out/lib/liblol.a and liblol.so.
93+
// We prefer the static library to keep the gateway binary self-contained.
94+
main_mod.addLibraryPath(b.path("../../ffi/zig/zig-out/lib"));
95+
main_mod.addIncludePath(b.path("../../generated/abi"));
96+
main_mod.linkSystemLibrary("lol", .{});
97+
98+
// ── libzig_api (unified-zig-api HTTP server pool + path safety) ───────────
99+
main_mod.addLibraryPath(.{ .cwd_relative = zig_api_lib_path });
100+
main_mod.addIncludePath(.{ .cwd_relative = zig_api_include_path });
101+
main_mod.linkSystemLibrary("zig_api", .{});
102+
103+
// ── libproven_ffi (transitive dep of libzig_api) ──────────────────────────
104+
// libzig_api.a references proven_path_has_traversal from libproven_ffi.
105+
// Link it here so the final executable resolves all symbols.
106+
main_mod.addLibraryPath(.{ .cwd_relative = proven_lib_path });
107+
main_mod.linkSystemLibrary("proven_ffi", .{});
108+
109+
// -------------------------------------------------------------------------
110+
// Gateway executable
111+
// -------------------------------------------------------------------------
112+
20113
const exe = b.addExecutable(.{
21114
.name = "lol_gateway",
22115
.root_module = main_mod,
@@ -29,8 +122,26 @@ pub fn build(b: *std.Build) void {
29122
const run_step = b.step("run", "Run the LOL API gateway");
30123
run_step.dependOn(&run_cmd.step);
31124

125+
// -------------------------------------------------------------------------
126+
// Unit tests (covers main.zig, types.zig, lol_ffi.zig)
127+
// -------------------------------------------------------------------------
128+
32129
const unit_tests = b.addTest(.{ .root_module = main_mod });
33130
const run_tests = b.addRunArtifact(unit_tests);
34131
const test_step = b.step("test", "Run unit tests");
35132
test_step.dependOn(&run_tests.step);
133+
134+
// -------------------------------------------------------------------------
135+
// Separate type / FFI module smoke tests (can run without liblol present)
136+
// -------------------------------------------------------------------------
137+
138+
const types_mod = b.createModule(.{
139+
.root_source_file = b.path("src/types.zig"),
140+
.target = target,
141+
.optimize = optimize,
142+
});
143+
const types_tests = b.addTest(.{ .root_module = types_mod });
144+
const run_types_tests = b.addRunArtifact(types_tests);
145+
const types_test_step = b.step("test-types", "Run types.zig tests");
146+
types_test_step.dependOn(&run_types_tests.step);
36147
}

0 commit comments

Comments
 (0)