ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
35.27k stars 2.57k forks source link

FileNotFound when compiling Zig with relative `--zig-lib-dir` #22119

Open MatthiasPortzel opened 3 days ago

MatthiasPortzel commented 3 days ago

Zig Version

0.14.0-dev.2370+5c6b25d9b

Steps to Reproduce and Observed Behavior

Compile Zig with a relative path for --zig-lib-dir, for example after bootstrapping Zig with zig-bootstrap [1].

Or at any time after with a command like

./zig-out/bin/zig build --zig-lib-dir lib

1: https://github.com/ziglang/zig/wiki/Building-Zig-From-Source#option-b-use-a-pre-built-zig-binary Option B: Use a Pre-Built Zig Binary

Output:

install
└─ install generated to doc/langref.html
   └─ run docgen (langref.html)
      └─ WriteFile Assembly Syntax Explained.out
         └─ run doctest (error_return_trace.out) failure
error: unable to open zig lib directory 'lib': FileNotFound

The following command exited with code 1:
/home/matthias/zig-dev/zig-bootstrap/out/zig-native-linux-gnu-native/zig build-exe --name error_return_trace --color on /home/matthias/zig-dev/zig/doc/langref/error_return_trace.zig --zig-lib-dir lib/
error: example failed to compile
error: the following command exited with error code 1:
/home/matthias/zig-dev/zig/.zig-cache/o/960da317854210c3c0761d0d96a694fb/doctest --zig /home/matthias/zig-dev/zig-bootstrap/out/zig-native-linux-gnu-native/zig --cache-root /home/matthias/zig-dev/zig/.zig-cache --zig-lib-dir lib/ -i /home/matthias/zig-dev/zig/doc/langref/error_return_trace.zig -o /home/matthias/zig-dev/zig/.zig-cache/o/c6011bcebd0182a9e7e9e6d3fb2dac00/error_return_trace.out

Expected Behavior

Compilation succeeds with an absolute path, for example, --zig-lib-dir $(realpath lib).

MatthiasPortzel commented 3 days ago

This looks to be because doctest invokes zig as a subprocess to compile doctests without passing through the current working directory. Edit: or intentionally invokes Zig in a tmp directory.

https://github.com/ziglang/zig/blob/master/tools/doctest.zig