This reverts commit a1fe671db8.
Lue suggested reverting #661 because ZLS worked around the issue of @src
being relative in that environment: https://github.com/zigtools/zls/pull/898
This is not a perfect solution (what zls did seems to be a workaround), but
is good enough for us until Zig gets an official package manager.
41 lines
1.5 KiB
Zig
41 lines
1.5 KiB
Zig
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 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);
|
|
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);
|
|
// 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" });
|
|
lib.linkLibC();
|
|
step.addIncludePath(sdkPath("/src/c/"));
|
|
step.linkLibrary(lib);
|
|
}
|
|
|
|
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;
|
|
};
|
|
}
|