You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
3.7 KiB

4 years ago
const std = @import("std");
const Builder = std.build.Builder;
5 years ago
const builtin = @import("builtin");
pub fn build(b: *Builder) void {
const optimize = b.standardOptimizeOption(.{});
const ecs_module = b.addModule("zig-ecs", .{
.source_file = std.build.FileSource{ .path = "src/ecs.zig" },
});
5 years ago
4 years ago
// use a different cache folder for macos arm builds
b.cache_root = .{
.handle = std.fs.cwd(),
.path = if (builtin.os.tag == .macos and builtin.target.cpu.arch == .aarch64) "zig-arm-cache" else "zig-cache",
};
4 years ago
5 years ago
const examples = [_][2][]const u8{
[_][]const u8{ "view_vs_group", "examples/view_vs_group.zig" },
[_][]const u8{ "group_sort", "examples/group_sort.zig" },
5 years ago
[_][]const u8{ "simple", "examples/simple.zig" },
};
for (examples, 0..) |example, i| {
5 years ago
const name = if (i == 0) "ecs" else example[0];
5 years ago
const source = example[1];
var exe = b.addExecutable(.{
.name = name,
.root_source_file = std.build.FileSource{ .path = source },
.optimize = optimize,
});
// exe.setOutputDir(std.fs.path.join(b.allocator, &[_][]const u8{ b.cache_root, "bin" }) catch unreachable);
1 year ago
// exe.output_dirname_source = .{ .path = std.fs.path.join(b.allocator, &[_][]const u8{ b.cache_root.path.?, "bin" }) catch unreachable, .step = &exe.step };
exe.addModule("ecs", ecs_module);
exe.linkLibC();
3 years ago
const docs = exe;
1 year ago
// docs.emit_docs = .emit;
3 years ago
const doc = b.step(b.fmt("{s}-docs", .{name}), "Generate documentation");
3 years ago
doc.dependOn(&docs.step);
const run_cmd = b.addRunArtifact(exe);
const exe_step = b.step(name, b.fmt("run {s}.zig", .{name}));
5 years ago
exe_step.dependOn(&run_cmd.step);
// first element in the list is added as "run" so "zig build run" works
if (i == 0) {
const run_exe_step = b.step("run", b.fmt("run {s}.zig", .{name}));
5 years ago
run_exe_step.dependOn(&run_cmd.step);
}
}
// internal tests
const internal_test_step = b.addTest(.{
.root_source_file = std.build.FileSource{ .path = "src/tests.zig" },
.optimize = optimize,
});
5 years ago
// public api tests
const test_step = b.addTest(.{
.root_source_file = std.build.FileSource{ .path = "tests/tests.zig" },
.optimize = optimize,
});
test_step.addModule("ecs", ecs_module);
5 years ago
const test_cmd = b.step("test", "Run the tests");
test_cmd.dependOn(&internal_test_step.step);
test_cmd.dependOn(&test_step.step);
}
pub const LibType = enum(i32) {
static,
dynamic, // requires DYLD_LIBRARY_PATH to point to the dylib path
exe_compiled,
};
pub fn getModule(comptime prefix_path: []const u8) std.build.Module {
return .{
.name = "ecs",
.path = .{ .path = prefix_path ++ "src/ecs.zig" },
};
}
/// prefix_path is used to add package paths. It should be the the same path used to include this build file
pub fn linkArtifact(b: *Builder, artifact: *std.build.LibExeObjStep, _: std.build.Target, lib_type: LibType, comptime prefix_path: []const u8) void {
const optimize = b.standardOptimizeOption(.{});
5 years ago
switch (lib_type) {
.static => {
const lib = b.addStaticLibrary(.{ .name = "ecs", .root_source_file = "ecs.zig", .optimize = optimize });
5 years ago
lib.install();
artifact.linkLibrary(lib);
},
.dynamic => {
const lib = b.addSharedLibrary(.{ .name = "ecs", .root_source_file = "ecs.zig", .optimize = optimize });
5 years ago
lib.install();
artifact.linkLibrary(lib);
},
else => {},
}
artifact.addModule(getModule(prefix_path));
5 years ago
}