ziglang / www.ziglang.org

https://ziglang.org/
MIT License
252 stars 149 forks source link

Discrepancy between @src when invoked via `zig build` or in project code #344

Closed swan-www closed 3 months ago

swan-www commented 3 months ago

Tested on Windows, I've not tested on other platforms.

When the @src builtin is called from build.zig (or any code that runs during zig build), in the returned SourceLocation the .file field appears to be always an absolute path, e.g.: D:\devspace\myproject\build.zig

But when called in project code, it only returns the name of the file and not a full path: projectcode.zig

The case where I hit this was writing a test for some of my build utils, inside build.zig. The functionality works when calling zig build but if I call zig test build.zig then the different value returned by @src() causes my tests to fail.

swan-www commented 3 months ago

Oops, somehow clicked through to the wrong repo, closing this now.