DOOM's fire algo, in zig, for 256 color terminals w/no dependencies
at main 3.5 kB view raw
1const std = @import("std"); 2 3// Although this function looks imperative, note that its job is to 4// declaratively construct a build graph that will be executed by an external 5// runner. 6pub fn build(b: *std.Build) void { 7 // Standard target options allows the person running `zig build` to choose 8 // what target to build for. Here we do not override the defaults, which 9 // means any target is allowed, and the default is native. Other options 10 // for restricting supported target set are available. 11 const target = b.standardTargetOptions(.{}); 12 13 // Standard optimization options allow the person running `zig build` to select 14 // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not 15 // set a preferred release mode, allowing the user to decide how to optimize. 16 const optimize = b.standardOptimizeOption(.{}); 17 18 const exe = b.addExecutable(.{ 19 .name = "DOOM-fire", 20 .root_module = b.createModule(.{ 21 .root_source_file = b.path("src/main.zig"), 22 .target = target, 23 .optimize = optimize, 24 }), 25 }); 26 27 //libc linking 28 exe.linkLibC(); 29 30 // This declares intent for the executable to be installed into the 31 // standard location when the user invokes the "install" step (the default 32 // step when running `zig build`). 33 b.installArtifact(exe); 34 35 // This *creates* a Run step in the build graph, to be executed when another 36 // step is evaluated that depends on it. The next line below will establish 37 // such a dependency. 38 const run_cmd = b.addRunArtifact(exe); 39 40 // By making the run step depend on the install step, it will be run from the 41 // installation directory rather than directly from within the cache directory. 42 // This is not necessary, however, if the application depends on other installed 43 // files, this ensures they will be present and in the expected location. 44 run_cmd.step.dependOn(b.getInstallStep()); 45 46 // This allows the user to pass arguments to the application in the build 47 // command itself, like this: `zig build run -- arg1 arg2 etc` 48 if (b.args) |args| { 49 run_cmd.addArgs(args); 50 } 51 52 // This creates a build step. It will be visible in the `zig build --help` menu, 53 // and can be selected like this: `zig build run` 54 // This will evaluate the `run` step rather than the default, which is "install". 55 const run_step = b.step("run", "Run the app"); 56 run_step.dependOn(&run_cmd.step); 57 58 // ----------------------------------- 59 // commented out test to avoid permission issues when building .exe 60 61 // Creates a step for unit testing. This only builds the test executable 62 // but does not run it. 63 //const lib_unit_tests = b.addTest(.{ 64 // .root_source_file = b.path("src/root.zig"), 65 // .target = target, 66 // .optimize = optimize, 67 //}); 68 69 // const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests); 70 71 //const exe_unit_tests = b.addTest(.{ 72 // .root_source_file = b.path("src/main.zig"), 73 // .target = target, 74 // .optimize = optimize, 75 //}); 76 77 // const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests); 78 79 // Similar to creating the run step earlier, this exposes a `test` step to 80 // the `zig build --help` menu, providing a way for the user to request 81 // running the unit tests. 82 //const test_step = b.step("test", "Run unit tests"); 83 //test_step.dependOn(&run_lib_unit_tests.step); 84 //test_step.dependOn(&run_exe_unit_tests.step); 85}