Backlog/engine/core/build.zig

62 lines
2.0 KiB
Zig

const std = @import("std");
const dependencyList = [_][]const u8{
"p2",
"tracy", // usually doesnt have C deps... unless we're compiled with it on, in which case we only support static builds
"zmath",
"packer", // packer no longer has C deps.
};
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false;
const mod = b.addModule("core", .{
.target = target,
.optimize = optimize,
.root_source_file = b.path("src/core.zig"),
});
for (dependencyList) |depName| {
const dep = b.dependency(depName, .{ .target = target, .optimize = optimize, .static_build = static_build });
mod.addImport(depName, dep.module(depName));
}
const test_step = b.step("test", "run unit tests for core");
const tests = b.addTest(.{
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
.root_source_file = b.path("tests/tests.zig"),
}),
.use_llvm = true,
});
const sampleGameExtern = b.addLibrary(.{
.root_module = b.createModule(.{
.root_source_file = b.path("tests/externalModule.zig"),
.link_libc = true,
.optimize = optimize,
.target = target,
}),
.linkage = .dynamic,
.use_llvm = true,
.name = "external",
});
sampleGameExtern.root_module.addImport("core", mod);
const installExtern = b.addInstallArtifact(sampleGameExtern, .{
.dest_dir = .{ .override = .{ .custom = "modules" } },
});
b.getInstallStep().dependOn(&installExtern.step);
tests.root_module.addImport("core", mod);
const runArtifact = b.addRunArtifact(tests);
test_step.dependOn(&runArtifact.step);
runArtifact.step.dependOn(b.getInstallStep());
b.installArtifact(tests);
}