|
1 | 1 | // LOL i18n Service — FFI Build Configuration |
2 | 2 | // SPDX-License-Identifier: PMPL-1.0-or-later |
3 | 3 | // Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk> |
| 4 | +// |
| 5 | +// Builds liblol as both shared and static libraries. |
| 6 | +// The library implements the C ABI declared in src/abi/Foreign.idr |
| 7 | +// and specified in generated/abi/lol.h. |
| 8 | +// |
| 9 | +// Modules: |
| 10 | +// src/main.zig — C ABI exports and service state |
| 11 | +// src/locale.zig — BCP 47 locale parsing, validation, normalisation |
| 12 | +// src/store.zig — Thread-safe translation store with fallback |
| 13 | +// src/plural.zig — CLDR plural rule selection per language |
| 14 | +// src/ffi.zig — Module re-exports and FFI surface documentation |
4 | 15 |
|
5 | 16 | const std = @import("std"); |
6 | 17 |
|
7 | 18 | pub fn build(b: *std.Build) void { |
8 | 19 | const target = b.standardTargetOptions(.{}); |
9 | 20 | const optimize = b.standardOptimizeOption(.{}); |
10 | 21 |
|
| 22 | + const root_source = b.path("src/main.zig"); |
| 23 | + |
11 | 24 | // Shared library (liblol.so / liblol.dylib / lol.dll) |
12 | | - const lib = b.addSharedLibrary(.{ |
| 25 | + const lib = b.addLibrary(.{ |
13 | 26 | .name = "lol", |
14 | | - .root_source_file = b.path("src/main.zig"), |
15 | | - .target = target, |
16 | | - .optimize = optimize, |
| 27 | + .root_module = b.createModule(.{ |
| 28 | + .root_source_file = root_source, |
| 29 | + .target = target, |
| 30 | + .optimize = optimize, |
| 31 | + .link_libc = true, |
| 32 | + }), |
| 33 | + .linkage = .dynamic, |
17 | 34 | }); |
18 | | - |
19 | | - lib.version = .{ .major = 0, .minor = 1, .patch = 0 }; |
20 | | - |
21 | 35 | // Static library (liblol.a) |
22 | | - const lib_static = b.addStaticLibrary(.{ |
| 36 | + const lib_static = b.addLibrary(.{ |
23 | 37 | .name = "lol", |
24 | | - .root_source_file = b.path("src/main.zig"), |
25 | | - .target = target, |
26 | | - .optimize = optimize, |
| 38 | + .root_module = b.createModule(.{ |
| 39 | + .root_source_file = root_source, |
| 40 | + .target = target, |
| 41 | + .optimize = optimize, |
| 42 | + .link_libc = true, |
| 43 | + }), |
| 44 | + .linkage = .static, |
27 | 45 | }); |
28 | 46 |
|
29 | 47 | // Install artifacts |
30 | 48 | b.installArtifact(lib); |
31 | 49 | b.installArtifact(lib_static); |
32 | 50 |
|
33 | | - // Install the generated C header |
34 | | - const header = b.addInstallHeader( |
35 | | - b.path("../../generated/abi/lol.h"), |
36 | | - "lol.h", |
37 | | - ); |
38 | | - b.getInstallStep().dependOn(&header.step); |
| 51 | + // Install the generated C header alongside the library. |
| 52 | + b.installFile("../../generated/abi/lol.h", "include/lol.h"); |
39 | 53 |
|
40 | | - // Unit tests |
| 54 | + // Unit tests (main module — needs libc for c_allocator) |
41 | 55 | const lib_tests = b.addTest(.{ |
42 | | - .root_source_file = b.path("src/main.zig"), |
43 | | - .target = target, |
44 | | - .optimize = optimize, |
| 56 | + .root_module = b.createModule(.{ |
| 57 | + .root_source_file = root_source, |
| 58 | + .target = target, |
| 59 | + .optimize = optimize, |
| 60 | + .link_libc = true, |
| 61 | + }), |
45 | 62 | }); |
46 | | - |
47 | 63 | const run_lib_tests = b.addRunArtifact(lib_tests); |
48 | 64 |
|
49 | | - const test_step = b.step("test", "Run library tests"); |
| 65 | + // Sub-module tests: locale |
| 66 | + const locale_tests = b.addTest(.{ |
| 67 | + .root_module = b.createModule(.{ |
| 68 | + .root_source_file = b.path("src/locale.zig"), |
| 69 | + .target = target, |
| 70 | + .optimize = optimize, |
| 71 | + }), |
| 72 | + }); |
| 73 | + const run_locale_tests = b.addRunArtifact(locale_tests); |
| 74 | + |
| 75 | + // Sub-module tests: plural |
| 76 | + const plural_tests = b.addTest(.{ |
| 77 | + .root_module = b.createModule(.{ |
| 78 | + .root_source_file = b.path("src/plural.zig"), |
| 79 | + .target = target, |
| 80 | + .optimize = optimize, |
| 81 | + }), |
| 82 | + }); |
| 83 | + const run_plural_tests = b.addRunArtifact(plural_tests); |
| 84 | + |
| 85 | + // Sub-module tests: store |
| 86 | + const store_tests = b.addTest(.{ |
| 87 | + .root_module = b.createModule(.{ |
| 88 | + .root_source_file = b.path("src/store.zig"), |
| 89 | + .target = target, |
| 90 | + .optimize = optimize, |
| 91 | + }), |
| 92 | + }); |
| 93 | + const run_store_tests = b.addRunArtifact(store_tests); |
| 94 | + |
| 95 | + const test_step = b.step("test", "Run all library tests"); |
50 | 96 | test_step.dependOn(&run_lib_tests.step); |
| 97 | + test_step.dependOn(&run_locale_tests.step); |
| 98 | + test_step.dependOn(&run_plural_tests.step); |
| 99 | + test_step.dependOn(&run_store_tests.step); |
51 | 100 |
|
52 | 101 | // Integration tests |
53 | 102 | const integration_tests = b.addTest(.{ |
54 | | - .root_source_file = b.path("test/integration_test.zig"), |
55 | | - .target = target, |
56 | | - .optimize = optimize, |
| 103 | + .root_module = b.createModule(.{ |
| 104 | + .root_source_file = b.path("test/integration_test.zig"), |
| 105 | + .target = target, |
| 106 | + .optimize = optimize, |
| 107 | + }), |
57 | 108 | }); |
58 | | - |
59 | | - integration_tests.linkLibrary(lib); |
| 109 | + integration_tests.root_module.linkLibrary(lib); |
60 | 110 |
|
61 | 111 | const run_integration_tests = b.addRunArtifact(integration_tests); |
62 | 112 |
|
|
0 commit comments