#What does Zig Build do here?

1 messages · Page 1 of 1 (latest)

median dagger
#

I was following this here https://zigtools.org/zls/guides/build-on-save/ and the zig build code included defining two different executable objects, one for the installed executable and one for a check executable. I thought that was a bit verbose, so I tried to create a version of the code which just uses the one executable, however it for some reason still installs the executable when running the check step. The code is as follows:

const std = @import("std");

pub fn build(b: *std.Build) void {
    const optimize = b.standardOptimizeOption(.{});
    const exe = b.addExecutable(.{
        .name = "PLACEHOLDER",
        .root_source_file = b.path("src/main.zig"),
        .optimize = optimize,
        .target = target,
    });

    const checkStep = b.step("check", "Check if the executable compiles");
    checkStep.dependOn(&exe.step);

    const installExe = b.addInstallArtifact(exe, .{});
    b.getInstallStep().dependOn(&installExe.step);

    const runExe = b.addRunArtifact(exe);
    const runStep = b.step("run", "Run the executable");
    runStep.dependOn(&runExe.step);
}

Can someone explain to me what exactly the build script is doing and if there's a way to do it without defining two executables?

jade yew
#

as for what exactly is happening: when you (or, addInstallArtifact in this case) request the output file from the build step, it registers at configure time that that file is required

#

so it always builds it, because there's a build step that requires it

#

even if that build step is never actually run

tight geyser
jade yew
#

okay, yeah fair

#

but zls looks for a check step, not a -Dno-bin option

tight geyser
#

well you can change the args it uses, check is just a default