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

@ -1,25 +1,40 @@
const std = @import("std");
pub fn build(b: *std.build.Builder) void {
const mode = b.standardReleaseOptions();
const lib = b.addStaticLibrary("earcut", "src/main.zig");
lib.setBuildMode(mode);
pub fn build(b: *std.Build) void {
const optimize = b.standardOptimizeOption(.{});
const target = b.standardTargetOptions(.{});
const lib = b.addStaticLibrary(.{
.name = "earcut",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
lib.install();
var main_tests = b.addTest("src/main.zig");
main_tests.setBuildMode(mode);
const main_tests = b.addTest(.{
.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");
test_step.dependOn(&main_tests.step);
_ = pkg;
_ = module(b);
}
pub const pkg = std.build.Pkg{
.name = "earcut",
.source = .{ .path = thisDir() ++ "/src/main.zig" },
};
fn thisDir() []const u8 {
return std.fs.path.dirname(@src().file) orelse ".";
pub fn module(b: *std.Build) *std.build.Module {
return b.createModule(.{
.source_file = .{ .path = sdkPath("/src/main.zig") },
});
}
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;
};
}