Zig Version
0.16.0
Steps to Reproduce and Observed Behavior
In the ziglang/zig compiler source tree change directory to lib/std (or any directory below that) and run zig build. You will get an error:
/opt/zig/zig-aarch64-macos-0.16.0/lib/std/Build.zig:2263:50: error: root source file struct 'build' has no member named 'build'
switch (@typeInfo(@typeInfo(@TypeOf(build_zig.build)).@"fn".return_type.?)) {
~~~~~~~~~^~~~~~
build.zig:1:1: note: struct declared here
const Build = @This();
^~~~~
referenced by:
main: /opt/zig/zig-aarch64-macos-0.16.0/lib/compiler/build_runner.zig:463:29
callMain [inlined]: /opt/zig/zig-aarch64-macos-0.16.0/lib/std/start.zig:699:88
callMainWithArgs [inlined]: /opt/zig/zig-aarch64-macos-0.16.0/lib/std/start.zig:638:20
main: /opt/zig/zig-aarch64-macos-0.16.0/lib/std/start.zig:663:28
1 reference(s) hidden; use '-freference-trace=5' to see all references
This also happens in the kristoff-it/zine source tree when you change directory to src and run zig build.
Expected Behavior
Expect to compile in the same way as when started in the root of the project or any other directory under the root directory.
The reason why this fails is that the directories (ziglang/zig/lib/src and kristoff-it/zine/src) both contain a file Build.zig, combined with the fact that macOS' apfs filesystem is not case sensitive by default. Because of this the zig compiler tries to use the wrong files as the project's build.zig and fails to find the build() function.
My suggestion is to, after searching up the directory tree and finding build.zig, also check if there is a build.zig.zonin the directory and directly use the build.zig if that build.zig.zon file is found. If the the build.zig.zon is not available, the build.zig should be scanned for e.g. something like pub fn build( at the beginning of a line to increase the chance that you have the compiler has the right file).
( Once #32097 is implemented this should not recompile at all, if zig build was already run from the root of the project)
### Zig Version
0.16.0
### Steps to Reproduce and Observed Behavior
In the `ziglang/zig` compiler source tree change directory to `lib/std` (or any directory below that) and run `zig build`. You will get an error:
```
/opt/zig/zig-aarch64-macos-0.16.0/lib/std/Build.zig:2263:50: error: root source file struct 'build' has no member named 'build'
switch (@typeInfo(@typeInfo(@TypeOf(build_zig.build)).@"fn".return_type.?)) {
~~~~~~~~~^~~~~~
build.zig:1:1: note: struct declared here
const Build = @This();
^~~~~
referenced by:
main: /opt/zig/zig-aarch64-macos-0.16.0/lib/compiler/build_runner.zig:463:29
callMain [inlined]: /opt/zig/zig-aarch64-macos-0.16.0/lib/std/start.zig:699:88
callMainWithArgs [inlined]: /opt/zig/zig-aarch64-macos-0.16.0/lib/std/start.zig:638:20
main: /opt/zig/zig-aarch64-macos-0.16.0/lib/std/start.zig:663:28
1 reference(s) hidden; use '-freference-trace=5' to see all references
```
This also happens in the `kristoff-it/zine` source tree when you change directory to `src` and run `zig build`.
### Expected Behavior
Expect to compile in the same way as when started in the root of the project or any other directory under the root directory.
The reason why this fails is that the directories (`ziglang/zig/lib/src` and `kristoff-it/zine/src`) both contain a file `Build.zig`, combined with the fact that macOS' `apfs` filesystem is not case sensitive by default. Because of this the zig compiler tries to use the wrong files as the project's `build.zig` and fails to find the `build()` function.
My suggestion is to, after searching up the directory tree and finding `build.zig`, also check if there is a `build.zig.zon`in the directory and directly use the `build.zig` if that `build.zig.zon` file is found. If the the `build.zig.zon` is not available, the `build.zig` should be scanned for e.g. something like `pub fn build(` at the beginning of a line to increase the chance that you have the compiler has the right file).
( Once https://codeberg.org/ziglang/zig/issues/32097 is implemented this should not recompile at all, if `zig build` was already run from the root of the project)