raylib-zig icon indicating copy to clipboard operation
raylib-zig copied to clipboard

Building for Wasm "error: unable to spawn mkdir: FileNotFound"

Open JoeRocky opened this issue 1 year ago • 5 comments

Hello, I'm trying to build my raylib-zig project, that is working fine if I build it for my OS (Windows), to wasm. When I run zig build -Dtarget=wasm32-emscripten --sysroot C:\emsdk\upstream\emscripten i get the following error:

install
└─ run C:\emsdk\upstream\emscripten\emcc.bat
   └─ run mkdir failure
error: unable to spawn mkdir: FileNotFound

Build Summary: 4/7 steps succeeded; 1 failed (disable with --summary none)
install transitive failure
└─ run C:\emsdk\upstream\emscripten\emcc.bat transitive failure
   └─ run mkdir failure
error: the following build command failed with exit code 1:

I also ran

emsdk install latest
emsdk activate latest --permanent

just to make sure but it didnt help...

JoeRocky avatar May 06 '24 16:05 JoeRocky

ok i figured out that line 94 in the emcc.zig file is causing the issue: const mkdir_command = b.addSystemCommand(&[_][]const u8{ "mkdir", "-p", emccOutputDir });

JoeRocky avatar May 06 '24 16:05 JoeRocky

mkdir should still be present on Windows systems, also your initial error looks like it originates in C:\emsdk\upstream\emscripten\emcc.bat. Could you check that mkdir works on your system and that emcc works properly?

Not-Nik avatar May 15 '24 19:05 Not-Nik

Hi, I'm encountering the same error. This is my first time using Zig. I'm on the devel branch, using Windows 11 and Zig 0.13.0. When I run the command:

zig build -Dtarget=wasm32-emscripten --sysroot "C:\emsdk\upstream\emscripten"

I get the following error:

install
└─ run C:\emsdk\upstream\emscripten\emcc.bat
   └─ run mkdir failure
error: unable to spawn mkdir: FileNotFound
Build Summary: 5/8 steps succeeded; 1 failed (disable with --summary none)
install transitive failure
└─ run C:\emsdk\upstream\emscripten\emcc.bat transitive failure
   └─ run mkdir failure
error: the following build command failed with exit code 1:
C:\zig-raylib-game\.zig-cache\o\0c522e1745d6b40bc64b3b0e8b6eeb98\build.exe C:\zig\zig-windows-x86_64-0.13.0\zig.exe C:\zig-raylib-game C:\zig-raylib-game\.zig-cache C:\Users\[username]\AppData\Local\zig --seed 0xbb3af7ea -Za21555bea8f8d4b9 -Dtarget=wasm32-emscripten --sysroot C:\emsdk\upstream\emscripten

My workaround is to copy the raylib-zig to a subdirectory and modify it. This is my build.zig.zon:

.{
    .name = "project_name",
    .version = "0.0.1",
    .dependencies = .{
        .@"raylib-zig" = .{ .path = "libs/raylib-zig" },
    },
    .paths = .{""},
}

In emcc.zig, I commented out these lines:

// line 94 // const mkdir_command = b.addSystemCommand(&[_][]const u8{ "mkdir", "-p", emccOutputDir });
// line 104 // emcc_command.step.dependOn(&mkdir_command.step);

Then, I manually call mkdir to create the output directories.

mkdir -p zig-out/htmlout 

I have no idea why mkdir is not accessible to Zig. Manually creating the directory fixed it, and emcc works fine.

I kind of wish I had seen JoeRocky's answer sooner. I spent a week tinkering with raylib-zig to finally get it to work. It was already a reported issue. 😅

eldahine avatar Sep 12 '24 22:09 eldahine

So, I did some research and I think mkdir is only available inside CMD or PowerShell on Windows. I might be wrong about this, so please correct me. In the meantime, I replaced the addSystemCommand call with the code below:

try b.build_root.handle.makePath(emccOutputDir);

I'm not sure if this is the right way of doing things in Zig, but hey, it works.

eldahine avatar Sep 26 '24 08:09 eldahine

I had this same issue when building on windows with powershell, @eldahine's solution has fixed it for me.

I've made are the change on a branch from my fork, I also tested by importing from my branch in my build.zig.zon on my project and it has fixed it, even though the errors it showed were completely off, missing imports, no absolute path etc.


znichola/raylib-zig-fork/tree/emsdk-win-mkdir-fix

I can open a PR for this, but I've not got a linux to test it with. Though I could try through WSL ...

znichola avatar Oct 18 '24 11:10 znichola