usearch icon indicating copy to clipboard operation
usearch copied to clipboard

WIP: WASM builds

Open sroussey opened this issue 2 years ago โ€ข 5 comments

WASM is arch independant, so no need to make for each arch. Will just build on linux.

Get mmap emulation working.

We need stdlib

To use like a library requires some __attribute__ stuff in cpp and -mexec-model=reactor in the build command.

Still fails:

wasm-ld: error: /var/folders/74/djsf8lv965l2tkgr29ybpz4h0000gn/T/lib-a51bfe.o: undefined symbol: __cxa_allocate_exception
wasm-ld: error: /var/folders/74/djsf8lv965l2tkgr29ybpz4h0000gn/T/lib-a51bfe.o: undefined symbol: __cxa_throw
wasm-ld: error: /var/folders/74/djsf8lv965l2tkgr29ybpz4h0000gn/T/lib-a51bfe.o: undefined symbol: __cxa_free_exception

sroussey avatar Jan 06 '24 00:01 sroussey

Related: https://github.com/unum-cloud/usearch/issues/328

sroussey avatar Jan 06 '24 00:01 sroussey

I start thinking that for WASM support, we must change at least JS and Rust bindings to use the intermediate C layer, introducing ABI stability, and then simply shipping precompiled shared libraries for WASM. What do you think, @sroussey?

ashvardanian avatar Feb 27 '24 16:02 ashvardanian

Can't ship anything that uses exceptions at the moment, at least with wasi. Quickly changing area, but still not there yet.

sroussey avatar Feb 27 '24 17:02 sroussey

I am not sure about JavaScript WASM support yet, but CloudFlare recently posted an article about their Pyodide workers:


LLVM provides three target triples for WebAssembly:

  • wasm32-unknown-unknown โ€“ this backend provides no C standard library or system call interface; to support this backend, we would need to manually rewrite every system or library call to make use of imports we would define ourselves in the runtime.
  • wasm32-wasi โ€“ WASI is a standardized system interface, and defines a standard set of imports that are implemented in WASI runtimes such as wasmtime.
  • wasm32-unknown-emscripten โ€“ Like WASI, Emscripten defines the imports that a WebAssembly program needs to execute, but also outputs an accompanying JavaScript library that implements these imported functions.

Pyodide uses Emscripten, and provides three things:

  • A distribution of the CPython interpreter, compiled using Emscripten
  • A foreign function interface (FFI) between Python and JavaScript
  • A set of third-party Python packages, compiled using Emscriptenโ€™s compiler to WebAssembly.

I am thinking to update the setup.py to support Emscripten and other compilers, and later upload the wheel to release notes.

ashvardanian avatar Apr 03 '24 18:04 ashvardanian