Not-Nik / raylib-zig

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

unable to build for web with zig 0.13.0 #108

Open Book-reader opened 2 weeks ago

Book-reader commented 2 weeks ago

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.

Not-Nik commented 1 week ago

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