Figure out what's wrong with zig wasm support
dfellis opened this issue · comments
While working the gridDisk
binding, I ran into this:
damocles@elack:~/oss/h3-wasm(main)$ make hello
zig build-lib h3.zig -target wasm32-freestanding-musl -dynamic -O ReleaseSmall -rdynamic -I./h3/src/h3lib/include ./h3/src/h3lib/lib/*.c -lc -lm --verbose-cc --verbose-link --verbose-cimport
info(compilation): C import output: /home/damocles/.cache/zig/o/ae400350c14cbeae789d9496bf645d38/cimport.zig
LLD Link... wasm-ld --error-limit=0 --export-memory -s --stack-first --export-dynamic -z stack-size=1048576 --no-entry -o h3.wasm /home/damocles/.cache/zig/o/ccdb873a6ef6dedadb6128c0c746ba41/algos.o /home/damocles/.cache/zig/o/9cf0961aa59f1de0dd4fb1038b518cb8/baseCells.o /home/damocles/.cache/zig/o/49830cac4d5558b21eadb42243d67da8/bbox.o /home/damocles/.cache/zig/o/2cf9763888e90c5e823adc75823d85f8/coordijk.o /home/damocles/.cache/zig/o/31063997a610e0bf1359458476eb41b7/directedEdge.o /home/damocles/.cache/zig/o/06c1ea23bb6f952ddd37fc3ac505d3e9/faceijk.o /home/damocles/.cache/zig/o/aa3c4a2384d9e54ed701c3db7f003438/h3Assert.o /home/damocles/.cache/zig/o/cab7c849b9b1c08ca72c4b2aced60746/h3Index.o /home/damocles/.cache/zig/o/ed3f715619b62691949d749a8f6474ea/iterators.o /home/damocles/.cache/zig/o/ffde34296abf9485c027cd60adc4b186/latLng.o /home/damocles/.cache/zig/o/d1312944654dffe1756c463553c97826/linkedGeo.o /home/damocles/.cache/zig/o/249f2f1aceb1e82f52faa80abbdc490a/localij.o /home/damocles/.cache/zig/o/9a29e9b677678c0c27f8788f868cfd6a/mathExtensions.o /home/damocles/.cache/zig/o/1e6a1b89e4145f5e1d6b942a1bcffe06/polygon.o /home/damocles/.cache/zig/o/6622da7e91a6752e1b6d1893867d9b4e/vec2d.o /home/damocles/.cache/zig/o/eebfbab5ff3def3dae5acd7ef5cfe054/vec3d.o /home/damocles/.cache/zig/o/6ced0447fba225b67c87b0413b177649/vertex.o /home/damocles/.cache/zig/o/cbcc39266a178f52c3770637e92d8dfa/vertexGraph.o h3.wasm.o /home/damocles/.cache/zig/o/a7dbba7cde05d04e413ba524da106553/libcompiler_rt.a
error: wasm-ld: /home/damocles/.cache/zig/o/ccdb873a6ef6dedadb6128c0c746ba41/algos.o: undefined symbol: calloc
error: wasm-ld: /home/damocles/.cache/zig/o/ccdb873a6ef6dedadb6128c0c746ba41/algos.o: undefined symbol: free
make: *** [Makefile:6: h3.wasm] Error 1
While I think I could write something that implements calloc
and free
now that I'm getting a bit more familiar with Zig, this seems like an unreasonable requirement for anyone trying to compile a Zig + C/C++ project to WASM, so I feel like I must have something misconfigured with the build system, though I can't figure out what. There's little official documentation for Zig's WASM support and most of the tutorials only focus on pure Zig projects being compiled to WASM. (Such that some of them recommend compiling without a libc at all.)
If I have to rewrite my own libc implementation in Zig itself to get this port working, that's a tall order. (Or I should make a separate Zig project this one depends on to do exactly that?)