/ build.zig
build.zig
 1  const 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.
 6  pub 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 = "ZDSM",
20          .root_source_file = .{ .path = "src/main.zig" },
21          .target = target,
22          .optimize = optimize,
23      });
24  
25      const zap = b.dependency("zap", .{
26          .target = target,
27          .optimize = optimize,
28          .openssl = false,
29      });
30  
31      const os_stats_module = b.addModule("os-stats", .{ .root_source_file = .{ .path = "src/libs/os-stats.zig" } });
32      const utils = b.addModule("utils", .{ .root_source_file = .{ .path = "src/libs/utils.zig" } });
33  
34      exe.root_module.addAnonymousImport("banner", .{ .root_source_file = .{ .path = "./assets/banner.txt" } });
35      exe.root_module.addImport("os-stats", os_stats_module);
36      exe.root_module.addImport("utils", utils);
37      exe.root_module.addImport("zap", zap.module("zap"));
38      exe.linkLibrary(zap.artifact("facil.io"));
39  
40      os_stats_module.addImport("utils", utils);
41  
42      // This declares intent for the executable to be installed into the
43      // standard location when the user invokes the "install" step (the default
44      // step when running `zig build`).
45      b.installArtifact(exe);
46  
47      // This *creates* a Run step in the build graph, to be executed when another
48      // step is evaluated that depends on it. The next line below will establish
49      // such a dependency.
50      const run_cmd = b.addRunArtifact(exe);
51  
52      // By making the run step depend on the install step, it will be run from the
53      // installation directory rather than directly from within the cache directory.
54      // This is not necessary, however, if the application depends on other installed
55      // files, this ensures they will be present and in the expected location.
56      run_cmd.step.dependOn(b.getInstallStep());
57  
58      // This allows the user to pass arguments to the application in the build
59      // command itself, like this: `zig build run -- arg1 arg2 etc`
60      if (b.args) |args| {
61          run_cmd.addArgs(args);
62      }
63  
64      // This creates a build step. It will be visible in the `zig build --help` menu,
65      // and can be selected like this: `zig build run`
66      // This will evaluate the `run` step rather than the default, which is "install".
67      const run_step = b.step("run", "Run the app");
68      run_step.dependOn(&run_cmd.step);
69  }