Std.debug.print exception when passing variables in as args (latest dev version)

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.

-John

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.

Deleting the file and building again still produces this error.

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.

Same issue… :frowning:

Hmm, that’s a difficult one. Maybe, just to be absolutely sure, you could try and make a new clone the ziglings repo in another folder.

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.

If I could get the build version he used, I would test it there. And unfortunately, I don’t have a Linux instance availlable… :frowning:

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.

2 Likes

Thanks! I’ll give it a try and adjust the build file.

Well, that build worked! It’s definitely something with the latest build.

I’ll use this one while I work through things. Hopefully, this issue is resolved at some point.

Thank you for the help!

Cross linking the conversation in ziglings…

5 Likes

If your dev folder is somewhere under OneDrive, either exclude it from OneDrive, or move it somewhere else (e.g. c:\projects or another drive).

Also make sure your dev folder is excluded from Defender or any other antivirus you have installed.

Current Windows offers “Development mode”, which is very helpful for setting up a reliable dev environment.

None of that applies for me and already in dev mode with Visual Studio and normal dev work, but thanks.

It works for the 1550 build but not the latest 2851 build.

Another thought… I’ve been working through the Exercism exercises and the latest works with those.

There’s got to be something I’m missing here…