Skip to content

" failed to rename compilation results " Zig build fails to compile while zig build run is active. #21168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MassKlaus opened this issue Aug 22, 2024 · 14 comments
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@MassKlaus
Copy link

Zig Version

0.13.0

Steps to Reproduce and Observed Behavior

I have a hot reload plugin system added to my project on windows. While the main project is running attempting to recompile the shared library results in the zig.build compilation to fail and throw this error.

error: failed to rename compilation results ('C:\...\.zig-cache\tmp\59219da4de8d4725') into local cache ('C:\...\.zig-cache\o\dbf31f96302da5d52610317112474912'): AccessDenied

Modifying the zig.build by adding a comment line results in the library compiling with 0 issues.

Here is the repo used for this test: Repo

Expected Behavior

zig build -Dplug_only=true To compile normally.

@MassKlaus MassKlaus added the bug Observed behavior contradicts documented or intended behavior label Aug 22, 2024
@rohlem
Copy link
Contributor

rohlem commented Aug 22, 2024

I'd assume that a .dll file currently loaded into and used by a process cannot be overwritten. That would explain the AccessDenied error.
Do you know / have you checked whether the .dll file is unloaded by your running program at the point you trigger the next compilation?

If I'm not wrong about this being the issue, then I'm not sure whether the build system integration can/should do much to work around such a system-level limitation.
Maybe a userland workaround could be that the program always copies/moves the dll file to load it under a different name/path, then monitors the original dll file for changes/rebuilds and redoes this process every time to reload the file for every new change?

@MassKlaus
Copy link
Author

MassKlaus commented Aug 22, 2024

I unload the .dll manually before starting the compilation but even for that case. I build the library as syalizer.plug.next.dll when the -Dplug_only=true flag is set.

I believe the access denied is related to the hash generated by the compiler in .zig-cache when compiling the build.zig file it self as just adding a new line in the middle makes the .dll compile with no problems and hot swaps with no issues.

This also only happens when using zig build run. If I launch the program through the .exe directly and then attempt a compilation it goes through with no issues which I believe removes the .dll being loaded doubt.

@rohlem
Copy link
Contributor

rohlem commented Aug 22, 2024

just adding a new line in the middle makes the .dll compile with no problems and hot swaps with no issues.

I'm not sure where you're adding this newline. Do you see effects of the hot swapping within the running program? Your original post says

Modifying the zig.build by adding a comment line results in the library compiling with 0 issues.

however the build system caches every step based on the inputs.
If the build.zig is modified but the compilation would be the same (same input files, flags etc.), the compilation is skipped.
From what I understand this would also skip the file copy, so wouldn't trigger an AccessDenied either - it would just do nothing.

This also only happens when using zig build run. If I launch the program through the .exe directly and then attempt a compilation it goes through with no issues which I believe removes the .dll being loaded doubt.

I'm not sure whether the run step runs the .exe from the location it is installed.
I think the build system is perfectly capable of compiling a .exe file and running it even if it never installs it (copies it outside of the zig cache directory), therefore the run step might also launch it from within the cache directory.
Technically the installation step (zig build or zig build install) should fail though while the program is running, from what I understand.

@MassKlaus
Copy link
Author

MassKlaus commented Aug 22, 2024

I am not knowledgeable on the inner workings of the compiler so I am not 100% but whenever I run zig build -Dplug_only=true

I always see this output which I just noticed:
Code_6fXXdWEhi1

This will show every time I run the command

In the case I run the .exe manually and I make sure the .dll to be replaced is already busy I get this message

unable to update file from 'C:\...\syalizer\.zig-cache\o\8dec672f861e4b9a5a05785b20289173\syalizer.plug.next.dll' to 'C:\...\syalizer\zig-out\bin\syalizer.plug.next.dll': AccessDenied

I think the build system is perfectly capable of compiling a .exe file and running it even if it never installs it

I think that is what could be happening, the compile script is held in the cache with a handle, so attempting to copy the file to the cache with the same hash ends up with an open file that is being process/used therefore resulting in an AccessDenied.

@MassKlaus
Copy link
Author

Figured out that due to some odd caching, the build script was recompiling itself. Deleting the cache and rebuilding fixed it

@FMurray
Copy link

FMurray commented Sep 18, 2024

I know this is closed, but I had a similar error message on MacOS and it turns out that iCloud sync running on the directory also causes a similar error message.

@rohlem
Copy link
Contributor

rohlem commented Sep 18, 2024

@FMurray Just FYI, #17342 seems to be the more iCloud-centric/-relevant issue .

@MassKlaus
Copy link
Author

MassKlaus commented Sep 18, 2024

I've seen that issue but I am fully on Windows so I think with no iTunes or any cloud tooling actually

@KarryCharon
Copy link

@rohlem So this issuse is not fixed on mac. right?
This is my log:

➜  Zig mkdir L    
➜  Zig cd L           
➜  L zig init                  
info: created build.zig
info: created build.zig.zon
info: created src/main.zig
info: created src/root.zig
info: see `zig build --help` for a menu of options
➜  L zig build -Dplug_only=True
error: failed to rename compilation results ('/Volumes/Code/Zig/L/.zig-cache/tmp/034576442839a131') into local cache ('/Volumes/Code/Zig/L/.zig-cache/o/e3d9f058575d2a681706b7facbb05072'): AccessDenied
➜  L zig build                 
error: failed to rename compilation results ('/Volumes/Code/Zig/L/.zig-cache/tmp/49a39d08c090f394') into local cache ('/Volumes/Code/Zig/L/.zig-cache/o/e3d9f058575d2a681706b7facbb05072'): AccessDenied

@KarryCharon
Copy link

@rohlem So this issuse is not fixed on mac. right? This is my log:

➜  Zig mkdir L    
➜  Zig cd L           
➜  L zig init                  
info: created build.zig
info: created build.zig.zon
info: created src/main.zig
info: created src/root.zig
info: see `zig build --help` for a menu of options
➜  L zig build -Dplug_only=True
error: failed to rename compilation results ('/Volumes/Code/Zig/L/.zig-cache/tmp/034576442839a131') into local cache ('/Volumes/Code/Zig/L/.zig-cache/o/e3d9f058575d2a681706b7facbb05072'): AccessDenied
➜  L zig build                 
error: failed to rename compilation results ('/Volumes/Code/Zig/L/.zig-cache/tmp/49a39d08c090f394') into local cache ('/Volumes/Code/Zig/L/.zig-cache/o/e3d9f058575d2a681706b7facbb05072'): AccessDenied

Additional info, this project dir is on my truenas smb volume

@rohlem
Copy link
Contributor

rohlem commented Feb 10, 2025

@KarryCharon This issue's original post is someone experiencing AccessDenied on Windows, and I'm not sure what they did to fix it.
I don't know if your issue is related in any way. If it's unrelated, you should create a new issue if you don't find an existing one.
I also suggest asking for help in one of the community spaces; you usually get quicker responses there.

Also I don't think you ever stating what version of zig you're using (the output of zig version).
On a more recent build (master from https://ziglang.org/download/) the error might already be fixed, or you might encounter a different error.

@KarryCharon
Copy link

@KarryCharon This issue's original post is someone experiencing AccessDenied on Windows, and I'm not sure what they did to fix it. I don't know if your issue is related in any way. If it's unrelated, you should create a new issue if you don't find an existing one. I also suggest asking for help in one of the community spaces; you usually get quicker responses there.

Also I don't think you ever stating what version of zig you're using (the output of zig version). On a more recent build (master from https://ziglang.org/download/) the error might already be fixed, or you might encounter a different error.

Ok thanks, and my zig version is 0.13.0. And I'll create a issuse then.

➜  Learn zig version
0.13.0

@MassKlaus
Copy link
Author

Regarding my issue, it was the build.zig Recompiling at every run. Deleting the cash folder fixed the issue but I am unsure what caused the behaviour in the first place.

@KarryCharon
Copy link

Regarding my issue, it was the build.zig Recompiling at every run. Deleting the cash folder fixed the issue but I am unsure what caused the behaviour in the first place.

Not the same with me...Caz even create a new project bug also

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

4 participants