building emscripten: "No emscripten cache. Generate it!"
This is going to be a bit of a rambling issue; sorry about that. I'm confused about what exactly the problem is here, there's too many things going on that I'm unfamiliar with.
tl;dr
I don't have emsdk but I do have the manjaro emscripten package; I think raylib is hard-coded to assume I have emsdk, and it's causing problems when try to build for web. But I'm not really certain about anything and don't know the best way to fix it.
emsdk
I'm running Manjaro Linux, and I have the emscripten package installed:
> pacman -Qi emscripten | head -n2
Name : emscripten
Version : 3.1.61-1
This installed emcc etc for me:
> emcc -v
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.61-git (67fa4c16496b157a7fc3377afd69ee0445e8a6e3)
clang version 19.0.0git (/startdir/llvm-project 7cfffe74eeb68fbb3fb9706ac7071f8caeeb6520)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /opt/emscripten-llvm/bin
When I run > ls $(dirname $(which emcc)) I see various other executables, like em++, emrun, emstrip. But I don't have emsdk (> which emsdk says "emsdk not found")
My best guess about what's going on here is that emsdk is "a small package manager for controlling which tools are installed" , and Manjaro doesn't want another package manager around, so the manjaro emscripten package is meant to replace any need for having emsdk.
zig build ... emscripten
My project uses zig 0.13.0 and a recent version of this library (raylib-zig). My build file is minimally modified from the example project, and includes these lines:
if (target.query.os_tag == .emscripten) {
const exe_lib = rlz.emcc.compileForEmscripten(b, name, "src/main.zig", target, optimize);
// ...
I tried to build it with > zig build run -Dtarget=wasm32-emscripten but got panic: Pass '--sysroot "$EMSDK/upstream/emscripten"'. But, I don't have EMSDK! > echo $EMSDK prints nothing.
I figured out where my emscripten cache is by running > emcc main.c on a simple Hello World program:
> emcc main.c
shared:INFO: old sanity: 3.1.55-git|/opt/emscripten-llvm/bin
shared:INFO: new sanity: 3.1.61-git|/opt/emscripten-llvm/bin
shared:INFO: (Emscripten: config changed, clearing cache)
shared:INFO: (Emscripten: Running sanity checks)
cache:INFO: generating system headers: sysroot_install.stamp... (this will be cached in "/home/pancelor/.emscripten_cache/sysroot_install.stamp" for subsequent builds)
cache:INFO: - ok
cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/libGL-getprocaddr.a... (this will be cached in "/home/pancelor/.emscripten_cache/sysroot/lib/wasm32-emscripten/libGL-getprocaddr.a" for subsequent builds)
system_libs:INFO: compiled 4 inputs in 0.42s
cache:INFO: - ok
...
Alright, so then I tried > zig build run -Dtarget=wasm32-emscripten --sysroot ~/.emscripten_cache/sysroot but this fails with "panic: No emscripten cache. Generate it!"
This is coming from raylib/src/build.zig, which seems to be assuming that my cache is managed by emsdk? This line: const cache_include = std.fs.path.join(b.allocator, &.{ b.sysroot.?, "cache", "sysroot", "include" }) catch @panic("Out of memory").
I think this means it's looking for ~/.emscripten_cache/sysroot/cache/sysroot/include on my machine and not finding it, because it doesn't exist. I think it should be looking for ~/.emscripten_cache/sysroot/include instead, but it's hard-coded to assume I have emsdk, which I don't.
editing raylib/src/build.zig
I tried hacking at raylib/src/build.zig and using this:
var dir = std.fs.openDirAbsolute(b.sysroot.?, std.fs.Dir.OpenDirOptions{ .access_sub_paths = true, .no_follow = true }) catch @panic("No emscripten cache. Generate it!");
dir.close();
raylib.addIncludePath(std.Build.LazyPath{ .cwd_relative = b.sysroot.? });
which worked(?) but is now giving me error: 'stdlib.h' file not found, error: 'math.h' file not found, etc. pretty similar to #108. Maybe I didn't "fully" generate the emscripten cache somehow, and I need to flesh it out somehow? But, > ls ~/.emscripten_cache/sysroot/include/stdlib.h finds the file -- it exists.
edit: ah! my bad, I needed b.sysroot.? ++ "/include". well, not that exact syntax; see my comment below
questions
- Have I misunderstood anything here?
- Do I need emsdk?
- Do I just need to edit
raylib/src/build.zig? I did that above but I feel like I'm probably making this way harder somehow- ~~why do I get
error: 'stdlib.h' file not found, when then file exists?~~ (edit: resolved, see below)
- ~~why do I get