diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2025-07-19 20:18:15 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2025-07-19 20:18:15 +0200 |
| commit | ae10b7d764d9587ab92a682781f8479107e8dff0 (patch) | |
| tree | 13e060f304ca1cac98ae1e71a2a6e27d9c5fb269 /build.zig | |
| parent | d138a622dcc77302cc452c52946f6202b6a03f5e (diff) | |
add pex
Diffstat (limited to 'build.zig')
| -rw-r--r-- | build.zig | 78 |
1 files changed, 43 insertions, 35 deletions
@@ -1,23 +1,9 @@ const std = @import("std"); -// Although this function looks imperative, note that its job is to -// declaratively construct a build graph that will be executed by an external -// runner. pub fn build(b: *std.Build) void { - // Standard target options allows the person running `zig build` to choose - // what target to build for. Here we do not override the defaults, which - // means any target is allowed, and the default is native. Other options - // for restricting supported target set are available. const target = b.standardTargetOptions(.{}); - - // Standard optimization options allow the person running `zig build` to select - // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not - // set a preferred release mode, allowing the user to decide how to optimize. const optimize = b.standardOptimizeOption(.{}); - // This declares intent for the library to be installed into the standard - // location when the user invokes the "install" step (the default step when - // running `zig build`). const exe = b.addExecutable(.{ .name = "mry", .root_source_file = b.path("src/main.zig"), @@ -25,36 +11,27 @@ pub fn build(b: *std.Build) void { .optimize = optimize, }); - // This declares intent for the executable to be installed into the - // standard location when the user invokes the "install" step (the default - // step when running `zig build`). b.installArtifact(exe); - // This *creates* a Run step in the build graph, to be executed when another - // step is evaluated that depends on it. The next line below will establish - // such a dependency. const run_cmd = b.addRunArtifact(exe); - - // By making the run step depend on the install step, it will be run from the - // installation directory rather than directly from within the cache directory. - // This is not necessary, however, if the application depends on other installed - // files, this ensures they will be present and in the expected location. run_cmd.step.dependOn(b.getInstallStep()); - // This allows the user to pass arguments to the application in the build - // command itself, like this: `zig build run -- arg1 arg2 etc` if (b.args) |args| { run_cmd.addArgs(args); } - // This creates a build step. It will be visible in the `zig build --help` menu, - // and can be selected like this: `zig build run` - // This will evaluate the `run` step rather than the default, which is "install". const run_step = b.step("run", "Run the app"); run_step.dependOn(&run_cmd.step); - // Creates a step for unit testing. This only builds the test executable - // but does not run it. + const install_docs = b.addInstallDirectory(.{ + .source_dir = exe.getEmittedDocs(), + .install_dir = .prefix, + .install_subdir = "docs", + }); + + const docs_step = b.step("docs", "Install docs into zig-out/docs"); + docs_step.dependOn(&install_docs.step); + const exe_unit_tests = b.addTest(.{ .root_source_file = b.path("src/main.zig"), .target = target, @@ -63,9 +40,40 @@ pub fn build(b: *std.Build) void { const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests); - // Similar to creating the run step earlier, this exposes a `test` step to - // the `zig build --help` menu, providing a way for the user to request - // running the unit tests. const test_step = b.step("test", "Run unit tests"); test_step.dependOn(&run_exe_unit_tests.step); + + const plot_step = b.step("plot", "Plot Benchmark"); + const run_plot = b.addSystemCommand(&.{ + "sh", "-c", + \\ [ ! -e "$1" ] && exit 1 + \\ [ ! -e "$2" ] && exit 2 + \\ mkdir -p zig-out/plots/ + \\ + \\ NAME=$(basename "$1") + \\ CSV="zig-out/plots/$NAME.csv" + \\ + \\ if [ "$CSV" -ot "$0" -o "$(($(cat "$CSV" | wc -l) - 1))" -ne "$(cat "$CSV" | wc -l)" ]; then + \\ "$0" benchmark "$1" -i "$2" --csv | tee "$CSV" + \\ fi + \\ + \\ gnuplot -p -e " + \\ set datafile separator ','; + \\ set term x11 size 1000, 300; + \\ set style line 100 lt 1 lc rgb 'grey' lw 0.5; + \\ set grid ls 100; set multiplot layout 1,3; + \\ plot '< sort -t , -g -k 2 $CSV' using 2:3 with lines title 'Duration' lw 3; + \\ plot '< sort -t , -g -k 2 $CSV' using 2:5 with lines title 'Max Heap Size' lw 3; + \\ plot '< sort -t , -g -k 2 $CSV' using 2:6 with lines title 'Number Of Nodes' lw 3; + \\ unset multiplot;" + }); + + run_plot.addArtifactArg(exe); + + if (b.args) |args| { + run_plot.addArgs(args); + } + + plot_step.dependOn(&run_plot.step); + plot_step.dependOn(&exe.step); } |