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

unable to build for web with zig 0.13.0 #108

Closed
Book-reader opened this issue Jun 20, 2024 · 8 comments
Closed

unable to build for web with zig 0.13.0 #108

Book-reader opened this issue Jun 20, 2024 · 8 comments
Labels
web Issues regarding web projects and emscripten

Comments

@Book-reader
Copy link

Book-reader commented Jun 20, 2024

attempting to build the project created by project_setup.sh with the provided command gives the following output

install
└─ run ../../git/emsdk/upstream/emscripten/emcc
   └─ zig build-lib Project Debug wasm32-emscripten
      └─ zig build-lib raylib Debug wasm32-emscripten 8 errors
/home/user/.cache/zig/p/1220aa75240ee6459499456ef520ab7e8bddffaed8a5055441da457b198fc4e92b26/src/rshapes.c:58:10: error: 'math.h' file not found
#include <math.h>       // Required for: sinf(), asinf(), cosf(), acosf(), sqrtf(), fabsf()
         ^~~~~~~~~
/home/user/.cache/zig/p/1220aa75240ee6459499456ef520ab7e8bddffaed8a5055441da457b198fc4e92b26/src/utils.c:47:10: error: 'stdlib.h' file not found
#include <stdlib.h>                     // Required for: exit()
         ^~~~~~~~~~~
/home/user/.cache/zig/p/122002d98ca255ec706ef8e5497b3723d6c6e163511761d116dac3aee87747d46cf1/src/raygui.h:1032:10: error: 'stdio.h' file not found
#include <stdio.h>              // Required for: FILE, fopen(), fclose(), fprintf(), feof(), fscanf(), vsprintf() [GuiLoadStyle(), GuiLoadIcons()]
         ^~~~~~~~~~
/var/home/user/raylib-zig/Project/.zig-cache/o/ec6be00b9a4f00e4bc20631af1f78af7/raygui.c:2:10: note: in file included from /var/home/user/raylib-zig/Project/.zig-cache/o/ec6be00b9a4f00e4bc20631af1f78af7/raygui.c:2:
#include "raygui.h"
         ^
/home/user/.cache/zig/p/1220aa75240ee6459499456ef520ab7e8bddffaed8a5055441da457b198fc4e92b26/src/rtext.c:68:10: error: 'stdlib.h' file not found
#include <stdlib.h>         // Required for: malloc(), free()
         ^~~~~~~~~~~
/home/user/.cache/zig/p/1220aa75240ee6459499456ef520ab7e8bddffaed8a5055441da457b198fc4e92b26/src/rcore.c:107:10: error: 'stdlib.h' file not found
#include <stdlib.h>                 // Required for: srand(), rand(), atexit()
         ^~~~~~~~~~~
/home/user/.cache/zig/p/1220aa75240ee6459499456ef520ab7e8bddffaed8a5055441da457b198fc4e92b26/src/rtextures.c:76:10: error: 'stdlib.h' file not found
#include <stdlib.h>             // Required for: malloc(), calloc(), free()
         ^~~~~~~~~~~
/home/user/.cache/zig/p/1220aa75240ee6459499456ef520ab7e8bddffaed8a5055441da457b198fc4e92b26/src/raymath.h:169:10: error: 'math.h' file not found
#include <math.h>       // Required for: sinf(), cosf(), tan(), atan2f(), sqrtf(), floor(), fminf(), fmaxf(), fabsf()
         ^~~~~~~~~
/home/user/.cache/zig/p/1220aa75240ee6459499456ef520ab7e8bddffaed8a5055441da457b198fc4e92b26/src/rmodels.c:54:10: note: in file included from /home/user/.cache/zig/p/1220aa75240ee6459499456ef520ab7e8bddffaed8a5055441da457b198fc4e92b26/src/rmodels.c:54:
#include "raymath.h"        // Required for: Vector3, Quaternion and Matrix functionality
         ^
/home/user/.cache/zig/p/1220aa75240ee6459499456ef520ab7e8bddffaed8a5055441da457b198fc4e92b26/src/external/miniaudio.h:3857:18: error: 'pthread.h' file not found
        #include <pthread.h>    /* Unfortunate #include, but needed for pthread_t, pthread_mutex_t and pthread_cond_t types. */
                 ^~~~~~~~~~~~
/home/user/.cache/zig/p/1220aa75240ee6459499456ef520ab7e8bddffaed8a5055441da457b198fc4e92b26/src/raudio.c:180:10: note: in file included from /home/user/.cache/zig/p/1220aa75240ee6459499456ef520ab7e8bddffaed8a5055441da457b198fc4e92b26/src/raudio.c:180:
#include "external/miniaudio.h"         // Audio device initialization and management

it works fine with 0.12.0

another unrelated issue is when using the c_allocator with wasm built with 0.12.0 there is this error:

Uncaught RuntimeError: Aborted(Cannot use convertFrameToPC (needed by __builtin_return_address) without -sUSE_OFFSET_CONVERTER). Build with -sASSERTIONS for more info.

which I was able to fix by adding -sUSE_OFFSET_CONVERTER in emcc.zig after line 109.

@Book-reader Book-reader changed the title unable to build for web with zig 13.0 unable to build for web with zig 0.13.0 Jun 20, 2024
@Not-Nik
Copy link
Owner

Not-Nik commented Jun 25, 2024

I am able to reproduce this, but I am unsure what causes this and I do not think it is an issue on our end

@Teeco123
Copy link

Teeco123 commented Aug 20, 2024

I'm having same error even though I'm not compiling to web, but to linux-x86_64. On linux-x86_64 compiling to Windows works fine.
When using b.host as a target I can compile fine, but when I specify target and arch to linux-x86_64 im getting this error.

@yanfrimmel
Copy link

The original raylib c project use zig.build to build their project so it should be failing for them too, and seems they already closed all wasm zig related issues.

@Not-Nik
Copy link
Owner

Not-Nik commented Aug 31, 2024

I'm having same error even though I'm not compiling to web, but to linux-x86_64.

When I compile for Linux on my MacBook, I only get an error, because it can't find a libGL.so, so the translation step itself works find. This very much smells like a Zig regression.

@Not-Nik Not-Nik added the web Issues regarding web projects and emscripten label Sep 28, 2024
@LunarWarg
Copy link

I was able to build for web with the latest Zig master (0.14.0-dev.1694+3b465ebec). If this was a zig regression it's been resolved.

@Not-Nik
Copy link
Owner

Not-Nik commented Oct 13, 2024

Ok, I can't repro this anymore on 0.13 either. Maybe other fixes had an impact. I'm closing this for now.

@Not-Nik Not-Nik closed this as completed Oct 13, 2024
@sepiatonal
Copy link

I'm getting Uncaught RuntimeError: Aborted(Cannot use convertFrameToPC (needed by __builtin_return_address) without -sUSE_OFFSET_CONVERTER). Build with -sASSERTIONS for more info. in wasm as well (whenever allocating memory).

Simple repro example:

    var foo = std.ArrayList(i32).init(std.heap.c_allocator);
    defer foo.deinit();
    try foo.append(7);

(In a project created by the template. Build for wasm and run in a browser. I can make an example repo if needed.)
Does this repro for others still?

The same fix as above worked for me (adding -sUSE_OFFSET_CONVERTER in emcc.zig after line 109). Perhaps this flag should be added to main? My understanding from digging around is that it's near-necessary, as Zig's std uses @returnAddress a lot, particularly in the Allocator interface.

@Not-Nik
Copy link
Owner

Not-Nik commented Nov 8, 2024

Done!

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

6 participants