While working through some ziglings using zig-windows-x86_64-0.14.0-dev.2851+b074fb7dd.zip, I discovered an issue with std.debug.print. If I use a variable as an arg, I get the following error:
Compiling: 003_assignment.zig
Checking: 003_assignment.zig
error: unable to spawn C:\Users\jmbaughman\source\repos\ziglings\.zig-cache\o\337199d0ff8989da63cae01f3d767d2d\003_assignment: FileNotFound
I tried this outside of ziglings with a newly generated project, and found this to be consistent there too.
This works fine when the value is passed in as a raw string.
pub fn main() void {
//const codebase = "codebase";
// Prints to stderr (it's a shortcut based on `std.io.getStdErr()`)
//std.debug.print("All your {s} are belong to us.\n", .{codebase});
std.debug.print("All your {s} are belong to us.\n", .{"codebase"});
}
> .\zig-out\bin\zig.exe
All your codebase are belong to us.
However, when I switch to using a variable, similar to examples found in ziglings, build throws no exceptions and I cannot execute the resulting exe. And the exe is deleted after the execution attempt?
pub fn main() void {
const codebase = "codebase";
// Prints to stderr (it's a shortcut based on `std.io.getStdErr()`)
std.debug.print("All your {s} are belong to us.\n", .{codebase});
//std.debug.print("All your {s} are belong to us.\n", .{"codebase"});
}
> .\zig-out\bin\zig.exe
ResourceUnavailable: Program 'zig.exe' failed to run: An error occurred trying to start process 'C:\Users\jmbaughman\source\zig-debug\zig-out\bin\zig.exe' with working directory 'C:\Users\jmbaughman\source\zig-debug'. Access is denied.At line:1 char:1
+ .\zig-out\bin\zig.exe
+ ~~~~~~~~~~~~~~~~~~~~~.
In some cases, not all, changing void to !void works.
Is there something I’m missing with this? Is this a possible bug?
zig is in my path and I’m running on Windows 10 22H2.
The clue is at the end of the error message: Access is denied.
I think this can happen if the file is already opened by another process or if you accidentally compiled it as administrator.
The simple solution would be to just try deleting the C:\Users\jmbaughman\source\zig-debug\zig-out folder, and maybe also the .zig-cache folder too for good measure. And then you can just try again.
Try deleting the .zig-cache folder then. Build artifacts of past builds are stored in the cache and then just copied over to the zig-out folder instead of recompiling. So it might copy a file with broken permissions.
I’ve done all of that too, and this example is out of a new zig init project.
Also before I execute the file, I see the file in zig-out. After executing, the file is gone. It’s almost as if the file space is allocated in the file system, but as soon as it’s attempted to be executed, Windows deletes the allocation space.
It seems as if the exception during the build is not properly caught and the space is allocated but not actually used and will cause the access denied/file not found issue.
I chatted with @chrboesch about this and it’s definitely seems to be a zig issue in the latest build. Ziglings’ minimum release is 0.14.0-dev.1573 which he stated that everything works fine at least in the Linux build. However, in at least the Windows build 0.14.0-dev.2851, I am seeing this issue.
You could try using an older version of Zig.
I do happen to have a copy of 0.14.0-dev.1550 hosted for my own project which should be close enough to the 0.14.0-dev.1573 that zigling wants.