88 lines
2.8 KiB
Zig
88 lines
2.8 KiB
Zig
const std = @import("std");
|
|
|
|
pub fn build(b: *std.Build) !void {
|
|
const target = b.standardTargetOptions(.{});
|
|
const optimize = b.standardOptimizeOption(.{});
|
|
|
|
const plugin_dynamic_enabled = b.option(bool, "plugin-dynamic", "Enable loading plugin through a dynamic library") orelse true;
|
|
const plugin_static_enabled = b.option(bool, "plugin-static", "Enable loading plugin through a dynamic library") orelse true;
|
|
|
|
const build_options = b.addOptions();
|
|
build_options.addOption(bool, "plugin_dynamic", plugin_dynamic_enabled);
|
|
build_options.addOption(bool, "plugin_static", plugin_static_enabled);
|
|
|
|
const plugin_api_mod = b.createModule(.{
|
|
.root_source_file = b.path("src/plugin_api.zig"),
|
|
});
|
|
|
|
const exe_mod = b.createModule(.{
|
|
.root_source_file = b.path("src/main.zig"),
|
|
.target = target,
|
|
.optimize = optimize
|
|
});
|
|
exe_mod.addOptions("build_options", build_options);
|
|
exe_mod.addImport("plugin_api", plugin_api_mod);
|
|
|
|
const plugin_mod = b.createModule(.{
|
|
.root_source_file = b.path("src/plugin.zig"),
|
|
.target = target,
|
|
.optimize = optimize
|
|
});
|
|
plugin_mod.addImport("plugin_api", plugin_api_mod);
|
|
if (plugin_static_enabled) {
|
|
exe_mod.addImport("plugin", plugin_mod);
|
|
}
|
|
|
|
const exe = b.addExecutable(.{
|
|
.name = "sokol_template_v2",
|
|
.root_module = exe_mod,
|
|
});
|
|
|
|
const plugin_dynamic = b.addLibrary(.{
|
|
.name = "plugin",
|
|
.linkage = .dynamic,
|
|
.root_module = b.createModule(.{
|
|
.root_source_file = b.path("src/plugin_dynamic.zig"),
|
|
.target = target,
|
|
.optimize = optimize
|
|
})
|
|
});
|
|
plugin_dynamic.root_module.addImport("plugin_api", plugin_api_mod);
|
|
plugin_dynamic.root_module.addImport("plugin", plugin_mod);
|
|
|
|
const plugin_install_artifact = b.addInstallArtifact(plugin_dynamic, .{ });
|
|
if (plugin_dynamic_enabled) {
|
|
exe.step.dependOn(&plugin_install_artifact.step);
|
|
}
|
|
|
|
b.installArtifact(exe);
|
|
|
|
{
|
|
const run_cmd = b.addRunArtifact(exe);
|
|
run_cmd.step.dependOn(b.getInstallStep());
|
|
if (plugin_dynamic_enabled) {
|
|
run_cmd.addArg("--plugin-path");
|
|
run_cmd.addArg(b.getInstallPath(.lib, plugin_dynamic.out_lib_filename));
|
|
}
|
|
if (b.args) |args| {
|
|
run_cmd.addArgs(args);
|
|
}
|
|
|
|
const run_step = b.step("run", "Run the app");
|
|
run_step.dependOn(&run_cmd.step);
|
|
}
|
|
|
|
{
|
|
const run_step = b.step("build-plugin", "Build plugin");
|
|
run_step.dependOn(&plugin_install_artifact.step);
|
|
}
|
|
|
|
{
|
|
const exe_tests = b.addTest(.{ .root_module = exe_mod, });
|
|
const run_exe_tests = b.addRunArtifact(exe_tests);
|
|
|
|
const test_step = b.step("test", "Run tests");
|
|
test_step.dependOn(&run_exe_tests.step);
|
|
}
|
|
}
|