this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at 3d6965dcb046e3dfd41850c8ccdbe13b2cb2a604 158 lines 4.8 kB view raw
1const std = @import("std"); 2const Build = std.Build; 3 4const sokol = @import("sokol"); 5const cimgui = @import("cimgui"); 6 7const Options = struct { 8 mod_ft: *Build.Module, 9 mod_exe: *Build.Module, 10 dep_sokol: *Build.Dependency, 11 dep_cimgui: *Build.Dependency, 12 cimgui_clib_name: []const u8, 13}; 14 15pub fn build(b: *std.Build) !void { 16 const target = b.standardTargetOptions(.{}); 17 const optimize = b.standardOptimizeOption(.{}); 18 19 const opt_docking = b.option(bool, "docking", "Build with docking support") orelse false; 20 21 const cimgui_conf = cimgui.getConfig(opt_docking); 22 23 const dep_sokol = b.dependency("sokol", .{ 24 .target = target, 25 .optimize = optimize, 26 .with_sokol_imgui = true, 27 }); 28 const dep_cimgui = b.dependency("cimgui", .{ 29 .target = target, 30 .optimize = optimize, 31 }); 32 33 dep_sokol.artifact("sokol_clib").addIncludePath(dep_cimgui.path(cimgui_conf.include_dir)); 34 35 const mod_ft = b.addModule("ft", .{ 36 .root_source_file = b.path("src/root.zig"), 37 .target = target, 38 }); 39 40 const mod_exe = b.createModule(.{ 41 .root_source_file = b.path("src/main.zig"), 42 .target = target, 43 .optimize = optimize, 44 .imports = &.{ 45 .{ .name = "ft", .module = mod_ft }, 46 .{ 47 .name = "sokol", 48 .module = dep_sokol.module("sokol"), 49 }, 50 .{ 51 .name = cimgui_conf.module_name, 52 .module = dep_cimgui.module(cimgui_conf.module_name), 53 }, 54 // .{ .name = "shader", .module = try createShaderModule(b, dep_sokol) }, 55 }, 56 }); 57 58 const options_mod_exe = b.addOptions(); 59 options_mod_exe.addOption(bool, "docking", opt_docking); 60 mod_exe.addOptions("build_options", options_mod_exe); 61 62 const opts = Options{ 63 .mod_ft = mod_ft, 64 .mod_exe = mod_exe, 65 .dep_sokol = dep_sokol, 66 .dep_cimgui = dep_cimgui, 67 .cimgui_clib_name = cimgui_conf.clib_name, 68 }; 69 if (target.result.cpu.arch.isWasm()) { 70 try buildWeb(b, opts); 71 } else { 72 try buildNative(b, opts); 73 } 74} 75 76fn buildNative(b: *Build, opts: Options) !void { 77 const exe = b.addExecutable(.{ 78 .name = "factorio_toolbox", 79 .root_module = opts.mod_exe, 80 }); 81 82 b.installArtifact(exe); 83 84 const run_step = b.step("run", "Run the app"); 85 const run_cmd = b.addRunArtifact(exe); 86 87 run_step.dependOn(&run_cmd.step); 88 run_cmd.step.dependOn(b.getInstallStep()); 89 90 if (b.args) |args| { 91 run_cmd.addArgs(args); 92 } 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 111fn buildWeb(b: *Build, opts: Options) !void { 112 const lib = b.addLibrary(.{ 113 .name = "factorio_toolbox", 114 .root_module = opts.mod_exe, 115 }); 116 117 const emsdk = opts.dep_sokol.builder.dependency("emsdk", .{}); 118 119 const emsdk_incl_path = emsdk.path("upstream/emscripten/cache/sysroot/include"); 120 opts.dep_cimgui.artifact(opts.cimgui_clib_name).addSystemIncludePath(emsdk_incl_path); 121 opts.dep_cimgui.artifact(opts.cimgui_clib_name).step.dependOn(&opts.dep_sokol.artifact("sokol_clib").step); 122 123 const link_step = try sokol.emLinkStep(b, .{ 124 .lib_main = lib, 125 .target = opts.mod_exe.resolved_target.?, 126 .optimize = opts.mod_exe.optimize.?, 127 .emsdk = emsdk, 128 .use_webgl2 = true, 129 .use_emmalloc = true, 130 .use_filesystem = false, 131 .shell_file_path = opts.dep_sokol.path("src/sokol/web/shell.html"), 132 }); 133 b.getInstallStep().dependOn(&link_step.step); 134 135 const run = sokol.emRunStep(b, .{ 136 .name = "factorio_toolbox", 137 .emsdk = emsdk, 138 }); 139 run.step.dependOn(&link_step.step); 140 b.step("run", "Run the web app").dependOn(&run.step); 141} 142 143fn createShaderModule(b: *Build, dep_sokol: *Build.Dependency) !*Build.Module { 144 const mod_sokol = dep_sokol.module("sokol"); 145 const dep_shdc = dep_sokol.builder.dependency("shdc", .{}); 146 return sokol.shdc.createModule(b, "shader", mod_sokol, .{ 147 .shdc_dep = dep_shdc, 148 .input = "src/shader/shader.glsl", 149 .output = "shader.zig", 150 .slang = .{ 151 .glsl410 = true, 152 .glsl300es = true, 153 .hlsl4 = true, 154 .metal_macos = true, 155 .wgsl = true, 156 }, 157 }); 158}