diff --git a/.tangled/workflows/build.yml b/.tangled/workflows/build.yml index 27ad1f6..c091af1 100644 --- a/.tangled/workflows/build.yml +++ b/.tangled/workflows/build.yml @@ -1,21 +1,21 @@ when: - - event: ["push", "pull_request"] - branch: ["main"] + - event: ["push", "pull_request"] + branch: ["main", "workflows"] engine: nixery dependencies: nixpkgs: - - mise + - mise steps: - name: Setup Zig command: | mise trust - mise exec zig -- zig version + mise exec zig -- zig version - name: Run Tests command: | - mise exec zig -- zig build test --summary all + mise exec zig -- zig build test -Dbuild-gui=false --summary all - name: Build ReleaseSafe command: | - mise exec zig -- zig build -Doptimize=ReleaseSafe -Ddocking \ No newline at end of file + mise exec zig -- zig build -Doptimize=ReleaseSafe -Dbuild-gui=false \ No newline at end of file diff --git a/.tangled/workflows/web.yml b/.tangled/workflows/web.yml deleted file mode 100644 index 053bb78..0000000 --- a/.tangled/workflows/web.yml +++ /dev/null @@ -1,18 +0,0 @@ -when: - - event: ["push", "pull_request"] - branch: ["main"] - -engine: nixery - -dependencies: - nixpkgs: - - mise - -steps: - - name: Setup Zig - command: | - mise trust - mise exec zig -- zig version - - name: Build ReleaseSafe - command: | - mise exec zig -- zig build -Doptimize=ReleaseSmall -Dtarget=wasm32-emscripten -Ddocking \ No newline at end of file diff --git a/build.zig b/build.zig index 6d059c1..c3d4e45 100644 --- a/build.zig +++ b/build.zig @@ -5,6 +5,7 @@ const sokol = @import("sokol"); const cimgui = @import("cimgui"); const Options = struct { + build_gui: bool, mod_ft: *Build.Module, mod_exe: *Build.Module, dep_sokol: *Build.Dependency, @@ -17,6 +18,7 @@ pub fn build(b: *std.Build) !void { const optimize = b.standardOptimizeOption(.{}); const opt_docking = b.option(bool, "docking", "Build with docking support") orelse false; + const build_gui_opt = b.option(bool, "build-gui", "When disabled only build FT library and not the gui app") orelse true; const cimgui_conf = cimgui.getConfig(opt_docking); @@ -60,6 +62,7 @@ pub fn build(b: *std.Build) !void { mod_exe.addOptions("build_options", options_mod_exe); const opts = Options{ + .build_gui = build_gui_opt, .mod_ft = mod_ft, .mod_exe = mod_exe, .dep_sokol = dep_sokol, @@ -67,13 +70,27 @@ pub fn build(b: *std.Build) !void { .cimgui_clib_name = cimgui_conf.clib_name, }; if (target.result.cpu.arch.isWasm()) { - try buildWeb(b, opts); + try buildWebGui(b, opts); } else { - try buildNative(b, opts); + if (opts.build_gui) { + try buildNativeGui(b, opts); + } else { + buildFTLib(b, opts); + } + tests(b, opts); } } -fn buildNative(b: *Build, opts: Options) !void { +fn buildFTLib(b: *Build, opts: Options) void { + const lib = b.addLibrary(.{ + .name = "factorio-toolbox", + .root_module = opts.mod_ft, + .linkage = if (b.option(bool, "ft-lib-dynamic", "Set linkage option for FT lib to dynamic") orelse false) .dynamic else .static, + }); + b.installArtifact(lib); +} + +fn buildNativeGui(b: *Build, opts: Options) !void { const exe = b.addExecutable(.{ .name = "factorio_toolbox", .root_module = opts.mod_exe, @@ -90,25 +107,9 @@ fn buildNative(b: *Build, opts: Options) !void { if (b.args) |args| { run_cmd.addArgs(args); } - - const mod_tests = b.addTest(.{ - .name = "mod tests", - .root_module = opts.mod_ft, - }); - const run_mod_tests = b.addRunArtifact(mod_tests); - - const exe_tests = b.addTest(.{ - .name = "exe tests", - .root_module = opts.mod_exe, - }); - const run_exe_tests = b.addRunArtifact(exe_tests); - - const test_step = b.step("test", "Run tests"); - test_step.dependOn(&run_mod_tests.step); - test_step.dependOn(&run_exe_tests.step); } -fn buildWeb(b: *Build, opts: Options) !void { +fn buildWebGui(b: *Build, opts: Options) !void { const lib = b.addLibrary(.{ .name = "factorio_toolbox", .root_module = opts.mod_exe, @@ -140,6 +141,26 @@ fn buildWeb(b: *Build, opts: Options) !void { b.step("run", "Run the web app").dependOn(&run.step); } +fn tests(b: *Build, opts: Options) void { + const test_step = b.step("test", "Run tests"); + + const mod_tests = b.addTest(.{ + .name = "mod tests", + .root_module = opts.mod_ft, + }); + const run_mod_tests = b.addRunArtifact(mod_tests); + test_step.dependOn(&run_mod_tests.step); + + if (opts.build_gui) { + const exe_tests = b.addTest(.{ + .name = "exe tests", + .root_module = opts.mod_exe, + }); + const run_exe_tests = b.addRunArtifact(exe_tests); + test_step.dependOn(&run_exe_tests.step); + } +} + fn createShaderModule(b: *Build, dep_sokol: *Build.Dependency) !*Build.Module { const mod_sokol = dep_sokol.module("sokol"); const dep_shdc = dep_sokol.builder.dependency("shdc", .{}); diff --git a/src/root.zig b/src/root.zig index 94c7cd0..4a13102 100644 --- a/src/root.zig +++ b/src/root.zig @@ -14,7 +14,7 @@ pub fn bufferedPrint() !void { try stdout.flush(); // Don't forget to flush! } -pub fn add(a: i32, b: i32) i32 { +pub export fn add(a: i32, b: i32) i32 { return a + b; }