zig
zig copied to clipboard
std.Build: changing the default step does silently omit executable installation
Zig Version
0.11.0-dev.1893+2770159606
Steps to Reproduce and Observed Output
mkdir repro && cd repro
zig init-exe
- change build.zig to
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const reduze_exe = b.addExecutable(.{
.name = "reduze",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
// 1 does not change install semantics:
// reduze_exe.install();
// 2 step with "install" does not work, but with install2 it works:
const install_art = b.addInstallArtifact(reduze_exe);
const install_step = b.step("install", "Install reducer executable");
install_step.dependOn(&install_art.step);
// omitted to keep things dense
const reduction_test = b.step("tred", "Run reduction tests");
reduction_test.dependOn(&reduze_exe.step);
}
Expected Output
Comptime or runtime error to ensure zig build
== zig build install
in all standard cases.
Personally, with the arrival of the build system and proper caching of generated artifacts, I would prefer to not have zig build
== zig build install
and rather 1. zig build
ONLY builds the help page + checks consistency and zig build install
does 1. and 2. installs whatever is given as install steps into zig-out/.
I guess the issue is that std.Build
uses an array list, so it doesn't notice when two steps have the same name, so the root of the problem isn't really related to the install step specifically. An easy fix would be to switch to using a HashMap
or ArrayHashMap
and have std.Build.step
error if you try to clobber a step.