Open MingweiSamuel opened 1 year ago
I've been slowly working through this in down time, current goal is to get a demo on the website
The surface syntax parsing and processing should be good, but I anticipate issues with Tokio on WASM
Oh yes true, I guess there are two issues: get the Hydroflow Language / Dedalus compilers to work on WASM, and get the Hydroflow runtime to work. Found https://github.com/shosti/wraft as a potentially interesting benchmark for the runtime; in principle we should be able to wire up WebRTC as the networking layer with Tokio on WASM.
hydroflow_lang
#331
@tylerhou will look into this soon
I took a brief look at this today. The latest version of Tokio has limited support for WASM including runtime: https://github.com/tokio-rs/tokio/blob/a7945b469d634cf205094d8a1661720358622cc0/tokio/src/lib.rs#L387. Our current version also supports all those features above but it is not documented (tested by compiling for WASM with those features enabled).
For WASM we would need to not specify tokio { ... features = "full" }
in hydroflow/Cargo.toml and instead selectively enable the features based if the target is WASM. hydroflow compiles if we do this and also disable diagnostics for hydroflow_lang. Very rough patch that compiles for WASM: https://gist.github.com/tylerhou/bd3ae3e2bb58c3f0b05fc100a63298b7
There are still two outstanding issues:
time
compiles for non-WASI WASM targets, it panics at runtime. We use timers in only one file -- hydroflow/tests/surface_async.rs -- and its a test, so maybe this is not an issue.cargo test -p hydroflow --target wasm32-unknown-unknown
does not work because the getrandom library (which is included tvia rand and transitively through textnonce -> rand in dev dependencies) requires us to build with the js
feature flag or target wasm32-unknown-emscripten so it knows which random implementation to call. https://docs.rs/getrandom/latest/getrandom/#webassembly-supportThis is very exciting progress! For the second issue, I think we can add a js
feature flag to hydroflow itself that then enables the js
flag on getrandom
. That way we can support both wasm32-unknown-unknown
and wasm32-wasi
(I'm not particularly concerned about -emscripten
).
(Compilation in WASM, i.e. running hydroflow_lang/macro
, has been working for a long time)
Should be possible to do, but do we want to? Would be fun but maybe not high priority. Mentioned in slack briefly @shadaj