Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build.zig incorrectly handles --build-file argument / build_root #22956

Open
matklad opened this issue Feb 20, 2025 · 0 comments
Open

Build.zig incorrectly handles --build-file argument / build_root #22956

matklad opened this issue Feb 20, 2025 · 0 comments

Comments

@matklad
Copy link
Contributor

matklad commented Feb 20, 2025

Here's a repro of a simple build script which breaks if used with --build-file argument:

λ pwd
/Users/matklad/tmp/subdir

λ zig build
const std = @import("std");

pub fn build(b: *std.Build) !void {
    const cat = b.addSystemCommand(&.{"cat"});
    cat.addFileArg(b.path("./build.zig"));
    b.default_step = &cat.step;
}

λ cd ..
λ zig build --build-file subdir/build.zig
cat: subdir/build.zig: No such file or directory
run cat failure
error: the following command exited with error code 1:
cat subdir/build.zig
Build Summary: 0/1 steps succeeded; 1 failed (disable with --summary none)
run cat failure
error: the following build command failed with exit code 1:
subdir/.zig-cache/o/cb04b4aa31661e7fda012bf07da1a9ac/build /Users/matklad/p/tb/work/zig/zig subdir subdir/.zig-cache /Users/matklad/.cache/zig --seed 0x8bc81711 -Z62e7f988d57764ec

The problem here is that cat always gets ~/tmp/subdir as its cwd (which looks correct), but it is passed either ./build.zig or ./subdir/build.zig as an argument, and, in the latter case, the file is not found!

This looks like a design bug to me! It feels like b.build_root.path should not exist, the build shouldn't be able to tell where it is running from that easily.

matklad added a commit to tigerbeetle/tigerbeetle that referenced this issue Feb 20, 2025
To have a `cd`! I tried using `--build-root` here, but hit
ziglang/zig#22956
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant