Skip to content

Confusing error when build.zig file does not contain a "build" function #12659

@zxubian

Description

@zxubian

Zig Version

0.9.1 (windows, chocolatey)

Steps to Reproduce

  1. Create a "hello-world" project with the following build.zig file:
const Builder = @import("std").build.Builder;
// note that Build starts with a capital 'B'
pub fn Build(b: *Builder) void {
    const target = b.standardTargetOptions(.{});
    const mode = b.standardReleaseOptions();
    const exe = b.addExecutable("init-exe", "src/main.zig");
    exe.setTarget(target);
    exe.setBuildMode(mode);
    exe.install();
    const run_cmd = exe.run();
    run_cmd.step.dependOn(b.getInstallStep());
    const run_step = b.step("run", "Run the app");
    run_step.dependOn(&run_cmd.step);
}
  1. run zig build from the command line

Expected Behavior

A helpful error is displayed, notifying the user that they should have a function called "build" in their build.zig file, and that such a function could not be found.

Actual Behavior

The following error is displayed:

C:\ProgramData\chocolatey\lib\zig\tools\zig-windows-x86_64-0.9.1\lib\std\special\build_runner.zig:219:45: error: container '.@build' has no member called 'build'
    switch (@typeInfo(@typeInfo(@TypeOf(root.build)).Fn.return_type.?)) {

This error message mentions a ".@build container", which is not helpful for new users, who do not know the internals of the build system.
The message can be improved by guiding the user to check that they have indeed correctly defined the 'build' function.
E.g.:

Could not find a function definition for 'build' in build.zig

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementSolving this issue will likely involve adding new logic or components to the codebase.error messageThis issue points out an error message that is unhelpful and should be improved.frontendTokenization, parsing, AstGen, Sema, and Liveness.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions