model3d: update to latest Zig build API
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
ca062e08fe
commit
ae06ca541f
2 changed files with 34 additions and 18 deletions
|
|
@ -1,29 +1,37 @@
|
|||
const std = @import("std");
|
||||
|
||||
pub const pkg = std.build.Pkg{
|
||||
.name = "model3d",
|
||||
.source = .{ .path = sdkPath("/src/main.zig") },
|
||||
};
|
||||
|
||||
pub fn build(b: *std.build.Builder) void {
|
||||
const mode = b.standardReleaseOptions();
|
||||
const target = b.standardTargetOptions(.{});
|
||||
const test_step = b.step("test", "Run library tests");
|
||||
test_step.dependOn(&testStep(b, mode, target).step);
|
||||
pub fn module(b: *std.Build) *std.build.Module {
|
||||
return b.createModule(.{
|
||||
.source_file = .{ .path = sdkPath("/src/main.zig") },
|
||||
});
|
||||
}
|
||||
|
||||
pub fn testStep(b: *std.build.Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget) *std.build.RunStep {
|
||||
const main_tests = b.addTestExe("model3d-tests", "src/main.zig");
|
||||
main_tests.setBuildMode(mode);
|
||||
main_tests.setTarget(target);
|
||||
pub fn build(b: *std.Build) void {
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
const target = b.standardTargetOptions(.{});
|
||||
const test_step = b.step("test", "Run library tests");
|
||||
test_step.dependOn(&testStep(b, optimize, target).step);
|
||||
}
|
||||
|
||||
pub fn testStep(b: *std.Build, optimize: std.builtin.OptimizeMode, target: std.zig.CrossTarget) *std.build.RunStep {
|
||||
const main_tests = b.addTest(.{
|
||||
.name = "model3d-tests",
|
||||
.kind = .test_exe,
|
||||
.root_source_file = .{ .path = sdkPath("/src/main.zig") },
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
link(b, main_tests, target);
|
||||
main_tests.install();
|
||||
return main_tests.run();
|
||||
}
|
||||
|
||||
pub fn link(b: *std.build.Builder, step: *std.build.LibExeObjStep, target: std.zig.CrossTarget) void {
|
||||
const lib = b.addStaticLibrarySource("model3d", null);
|
||||
lib.setTarget(target);
|
||||
pub fn link(b: *std.Build, step: *std.build.CompileStep, target: std.zig.CrossTarget) void {
|
||||
const lib = b.addStaticLibrary(.{
|
||||
.name = "model3d",
|
||||
.target = target,
|
||||
.optimize = step.optimize,
|
||||
});
|
||||
// Note: model3d needs unaligned accesses, which are safe on all modern architectures.
|
||||
// See https://gitlab.com/bztsrc/model3d/-/issues/19
|
||||
lib.addCSourceFile(sdkPath("/src/c/m3d.c"), &.{ "-std=c89", "-fno-sanitize=alignment" });
|
||||
|
|
|
|||
|
|
@ -216,7 +216,7 @@ fn intToError(int: c_int) Error {
|
|||
test {
|
||||
testing.refAllDeclsRecursive(@This());
|
||||
|
||||
var model_file = try std.fs.cwd().openFile("assets/cube.m3d", .{});
|
||||
var model_file = try std.fs.cwd().openFile( thisDir("/../assets/cube.m3d"), .{});
|
||||
defer model_file.close();
|
||||
var model_data = try model_file.readToEndAllocOptions(testing.allocator, 1024, 119, @alignOf(u8), 0);
|
||||
defer testing.allocator.free(model_data);
|
||||
|
|
@ -229,3 +229,11 @@ test {
|
|||
defer std.heap.c_allocator.free(out);
|
||||
try testing.expect(out.len >= 119);
|
||||
}
|
||||
|
||||
fn thisDir(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;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue