this repo has no description

rework workflow jobs

altagos.dev 48a7d918 3d6965dc

verified
Changed files
+48 -45
.tangled
workflows
src
+6 -6
.tangled/workflows/build.yml
··· 1 1 when: 2 - - event: ["push", "pull_request"] 3 - branch: ["main"] 2 + - event: ["push", "pull_request"] 3 + branch: ["main", "workflows"] 4 4 5 5 engine: nixery 6 6 7 7 dependencies: 8 8 nixpkgs: 9 - - mise 9 + - mise 10 10 11 11 steps: 12 12 - name: Setup Zig 13 13 command: | 14 14 mise trust 15 - mise exec zig -- zig version 15 + mise exec zig -- zig version 16 16 - name: Run Tests 17 17 command: | 18 - mise exec zig -- zig build test --summary all 18 + mise exec zig -- zig build test -Dbuild-gui=false --summary all 19 19 - name: Build ReleaseSafe 20 20 command: | 21 - mise exec zig -- zig build -Doptimize=ReleaseSafe -Ddocking 21 + mise exec zig -- zig build -Doptimize=ReleaseSafe -Dbuild-gui=false
-18
.tangled/workflows/web.yml
··· 1 - when: 2 - - event: ["push", "pull_request"] 3 - branch: ["main"] 4 - 5 - engine: nixery 6 - 7 - dependencies: 8 - nixpkgs: 9 - - mise 10 - 11 - steps: 12 - - name: Setup Zig 13 - command: | 14 - mise trust 15 - mise exec zig -- zig version 16 - - name: Build ReleaseSafe 17 - command: | 18 - mise exec zig -- zig build -Doptimize=ReleaseSmall -Dtarget=wasm32-emscripten -Ddocking
+41 -20
build.zig
··· 5 5 const cimgui = @import("cimgui"); 6 6 7 7 const Options = struct { 8 + build_gui: bool, 8 9 mod_ft: *Build.Module, 9 10 mod_exe: *Build.Module, 10 11 dep_sokol: *Build.Dependency, ··· 17 18 const optimize = b.standardOptimizeOption(.{}); 18 19 19 20 const opt_docking = b.option(bool, "docking", "Build with docking support") orelse false; 21 + const build_gui_opt = b.option(bool, "build-gui", "When disabled only build FT library and not the gui app") orelse true; 20 22 21 23 const cimgui_conf = cimgui.getConfig(opt_docking); 22 24 ··· 60 62 mod_exe.addOptions("build_options", options_mod_exe); 61 63 62 64 const opts = Options{ 65 + .build_gui = build_gui_opt, 63 66 .mod_ft = mod_ft, 64 67 .mod_exe = mod_exe, 65 68 .dep_sokol = dep_sokol, ··· 67 70 .cimgui_clib_name = cimgui_conf.clib_name, 68 71 }; 69 72 if (target.result.cpu.arch.isWasm()) { 70 - try buildWeb(b, opts); 73 + try buildWebGui(b, opts); 71 74 } else { 72 - try buildNative(b, opts); 75 + if (opts.build_gui) { 76 + try buildNativeGui(b, opts); 77 + } else { 78 + buildFTLib(b, opts); 79 + } 80 + tests(b, opts); 73 81 } 74 82 } 75 83 76 - fn buildNative(b: *Build, opts: Options) !void { 84 + fn buildFTLib(b: *Build, opts: Options) void { 85 + const lib = b.addLibrary(.{ 86 + .name = "factorio-toolbox", 87 + .root_module = opts.mod_ft, 88 + .linkage = if (b.option(bool, "ft-lib-dynamic", "Set linkage option for FT lib to dynamic") orelse false) .dynamic else .static, 89 + }); 90 + b.installArtifact(lib); 91 + } 92 + 93 + fn buildNativeGui(b: *Build, opts: Options) !void { 77 94 const exe = b.addExecutable(.{ 78 95 .name = "factorio_toolbox", 79 96 .root_module = opts.mod_exe, ··· 90 107 if (b.args) |args| { 91 108 run_cmd.addArgs(args); 92 109 } 93 - 94 - const mod_tests = b.addTest(.{ 95 - .name = "mod tests", 96 - .root_module = opts.mod_ft, 97 - }); 98 - const run_mod_tests = b.addRunArtifact(mod_tests); 99 - 100 - const exe_tests = b.addTest(.{ 101 - .name = "exe tests", 102 - .root_module = opts.mod_exe, 103 - }); 104 - const run_exe_tests = b.addRunArtifact(exe_tests); 105 - 106 - const test_step = b.step("test", "Run tests"); 107 - test_step.dependOn(&run_mod_tests.step); 108 - test_step.dependOn(&run_exe_tests.step); 109 110 } 110 111 111 - fn buildWeb(b: *Build, opts: Options) !void { 112 + fn buildWebGui(b: *Build, opts: Options) !void { 112 113 const lib = b.addLibrary(.{ 113 114 .name = "factorio_toolbox", 114 115 .root_module = opts.mod_exe, ··· 138 139 }); 139 140 run.step.dependOn(&link_step.step); 140 141 b.step("run", "Run the web app").dependOn(&run.step); 142 + } 143 + 144 + fn tests(b: *Build, opts: Options) void { 145 + const test_step = b.step("test", "Run tests"); 146 + 147 + const mod_tests = b.addTest(.{ 148 + .name = "mod tests", 149 + .root_module = opts.mod_ft, 150 + }); 151 + const run_mod_tests = b.addRunArtifact(mod_tests); 152 + test_step.dependOn(&run_mod_tests.step); 153 + 154 + if (opts.build_gui) { 155 + const exe_tests = b.addTest(.{ 156 + .name = "exe tests", 157 + .root_module = opts.mod_exe, 158 + }); 159 + const run_exe_tests = b.addRunArtifact(exe_tests); 160 + test_step.dependOn(&run_exe_tests.step); 161 + } 141 162 } 142 163 143 164 fn createShaderModule(b: *Build, dep_sokol: *Build.Dependency) !*Build.Module {
+1 -1
src/root.zig
··· 14 14 try stdout.flush(); // Don't forget to flush! 15 15 } 16 16 17 - pub fn add(a: i32, b: i32) i32 { 17 + pub export fn add(a: i32, b: i32) i32 { 18 18 return a + b; 19 19 } 20 20