Skip to content
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

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

Open
JoeRocky opened this issue May 6, 2024 · 4 comments
Open

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

JoeRocky opened this issue May 6, 2024 · 4 comments
Labels
web Issues regarding web projects and emscripten

Comments

@JoeRocky
Copy link

JoeRocky commented May 6, 2024

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
Copy link
Author

JoeRocky commented May 6, 2024

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
Copy link
Owner

Not-Nik commented May 15, 2024

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
Copy link

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
Copy link

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.

@Not-Nik Not-Nik added the web Issues regarding web projects and emscripten label Sep 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
web Issues regarding web projects and emscripten
Projects
None yet
Development

No branches or pull requests

3 participants