Not-Nik / raylib-zig

Manually tweaked, auto-generated raylib bindings for zig. https://github.com/raysan5/raylib
MIT License
619 stars 115 forks source link

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

Open JoeRocky opened 4 months ago

JoeRocky commented 4 months ago

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 commented 4 months ago

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 });

Not-Nik commented 4 months ago

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?

eldahine commented 2 weeks ago

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 commented 1 week ago

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.