earcut: update to latest Zig build API

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2023-02-08 00:20:49 -07:00 committed by Stephen Gutekanst
parent f56385a76c
commit ca062e08fe
2 changed files with 31 additions and 16 deletions

View file

@ -30,9 +30,9 @@ Then in your `build.zig` add:
... ...
const earcut = @import("libs/mach-earcut/build.zig"); const earcut = @import("libs/mach-earcut/build.zig");
pub fn build(b: *Builder) void { pub fn build(b: *Build) void {
... ...
exe.addPackage(earcut.pkg); exe.addModule("earcut", earcut.module(b));
} }
``` ```

View file

@ -1,25 +1,40 @@
const std = @import("std"); const std = @import("std");
pub fn build(b: *std.build.Builder) void { pub fn build(b: *std.Build) void {
const mode = b.standardReleaseOptions(); const optimize = b.standardOptimizeOption(.{});
const lib = b.addStaticLibrary("earcut", "src/main.zig"); const target = b.standardTargetOptions(.{});
lib.setBuildMode(mode); const lib = b.addStaticLibrary(.{
.name = "earcut",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
lib.install(); lib.install();
var main_tests = b.addTest("src/main.zig"); const main_tests = b.addTest(.{
main_tests.setBuildMode(mode); .name = "earcut-tests",
.kind = .test_exe,
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
const test_step = b.step("test", "Run library tests"); const test_step = b.step("test", "Run library tests");
test_step.dependOn(&main_tests.step); test_step.dependOn(&main_tests.step);
_ = pkg; _ = module(b);
} }
pub const pkg = std.build.Pkg{ pub fn module(b: *std.Build) *std.build.Module {
.name = "earcut", return b.createModule(.{
.source = .{ .path = thisDir() ++ "/src/main.zig" }, .source_file = .{ .path = sdkPath("/src/main.zig") },
}; });
}
fn thisDir() []const u8 {
return std.fs.path.dirname(@src().file) orelse "."; fn sdkPath(comptime suffix: []const u8) []const u8 {
if (suffix[0] != '/') @compileError("suffix must be an absolute path");
return comptime blk: {
const root_dir = std.fs.path.dirname(@src().file) orelse ".";
break :blk root_dir ++ suffix;
};
} }