Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ jobs:

- name: zig build (Release Safe)
run: zig build --release=safe

- name: zig build test (Release Safe)
run: zig build test --release=safe
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,14 @@ const blst_dep = b.dependency("blst", .{
.optimize = optimize,
});

your_exe.linkLibrary(blst_dep.artifact("blst"));
your_exe.root_module.addImport("blst", blst_dep.module("blst"));
```

The module contains the translated declarations from `blst.h` and
`blst_aux.h`, and links the native library automatically:

```zig
const blst = @import("blst");

const generator = blst.blst_p1_generator();
```
24 changes: 24 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,29 @@ pub fn build(b: *std.Build) !void {
.flags = c_flags.items,
});

const translated_headers = b.addTranslateC(.{
.root_source_file = upstream.path("bindings/blst.h"),
.target = target,
.optimize = optimize,
});
translated_headers.addIncludePath(upstream.path("bindings"));

const module = translated_headers.addModule("blst");
module.linkLibrary(lib);

b.installArtifact(lib);

const module_tests = b.addTest(.{
.name = "blst-module-tests",
.root_module = b.createModule(.{
.root_source_file = b.path("src/test.zig"),
.target = target,
.optimize = optimize,
}),
});
module_tests.root_module.addImport("blst", module);

const run_module_tests = b.addRunArtifact(module_tests);
const test_step = b.step("test", "Test the public blst module");
test_step.dependOn(&run_module_tests.step);
}
7 changes: 7 additions & 0 deletions src/test.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const std = @import("std");
const blst = @import("blst");

test "translated core and auxiliary APIs are linked" {
try std.testing.expect(blst.blst_p1_generator() != null);
try std.testing.expectEqual(@sizeOf(blst.blst_p1), blst.blst_p1_sizeof());
}
Loading