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

zflecs wasm32-emscripten target #436

Open
dynnamitt opened this issue Oct 31, 2023 · 2 comments
Open

zflecs wasm32-emscripten target #436

dynnamitt opened this issue Oct 31, 2023 · 2 comments
Milestone

Comments

@dynnamitt
Copy link

I tried:

$ cd libs/zflecs
$ zig build test -Dtarget=wasm32-emscripten --sysroot $HOME/code/emsdk/upstream/

zig build-lib zflecs Debug wasm32-emscripten: error: error(compilation): clang failed with stderr: In file included from /home/kdm/code/zig/uber-graphen/zflecs/libs/flecs/flecs.c:19:
/home/kdm/code/zig/uber-graphen/zflecs/libs/flecs/flecs.h:580:10: fatal error: 'assert.h' file not found

zig build-lib zflecs Debug wasm32-emscripten: error: the following command failed with 1 compilation errors:
/snap/zig/8241/zig build-lib -cflags -fno-sanitize=undefined -DFLECS_NO_CPP -DFLECS_USE_OS_ALLOC -DFLECS_SANITIZE -- /home/kdm/code/zig/uber-graphen/zflecs/libs/flecs/flecs.c -lc --cache-dir /home/kdm/code/zig/uber-graphen/zflecs/zig-cache --global-cache-dir /home/kdm/.cache/zig --name zflecs -static -target wasm32-emscripten -mcpu generic -I /home/kdm/code/zig/uber-graphen/zflecs/libs/flecs --sysroot /home/kdm/code/emsdk/upstream/ --listen=- 
Build Summary: 0/4 steps succeeded; 1 failed (disable with --summary none)
test transitive failure
└─ run zflecs-tests transitive failure
   └─ zig test zflecs-tests Debug wasm32-emscripten transitive failure
      └─ zig build-lib zflecs Debug wasm32-emscripten 1 errors
/home/kdm/code/zig/uber-graphen/zflecs/libs/flecs/flecs.c:1:1: error: unable to build C object: clang exited with code 1

Has anyone tried wasm building on this lib alone ?

Others solving this:

  1. https://www.reddit.com/r/Zig/comments/sdcafd/zig_emscripten/
  2. Emscripten support: wasm & webgpu in browser #309 (still open, and far too complex for me)
  3. https://github.com/bluesillybeard/ZigAndRaylibSetup
  4. Building for WebAssembly Not-Nik/raylib-zig#24
@hazeycode
Copy link
Member

hazeycode commented Nov 10, 2023

I think your sysroot path is wrong, it should be something like --sysroot path/to/emsdk/upstream/emscripten/cache/sysroot

Also some changes to zflecs build.zig would be required to build flecs C lib for emscripten using zig cc. You could try the following additions:

zflecs_c_cpp.defineCMacro("__EMSCRIPTEN__", "1");
zflecs_c_cpp.addIncludePath(.{
    .path = try std.fs.path.join(b.allocator, &.{ b.sysroot.?, "include" }),
});

Note: I haven't tried this myself

@hazeycode
Copy link
Member

Relevant info: #309 (comment)

@hazeycode hazeycode modified the milestone: 0.6.0 Feb 5, 2024
@hazeycode hazeycode changed the title zflecs wasm32 target zflecs wasm32-emscripten target Feb 12, 2024
hazeycode added a commit that referenced this issue Feb 12, 2024
Partially addresses #436
hazeycode added a commit that referenced this issue Feb 17, 2024
Partially addresses #436
hazeycode added a commit that referenced this issue Feb 18, 2024
Partially addresses #436
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants