Stream: general

Topic: Trying to compile a rust program into wasm32-wasi


view this post on Zulip celine santosh (Mar 13 2025 at 21:43):

Can anyone please help me to convert a rust program (Noise protocol) which has tcp connect functions and cryptographic handshakes into wasm32-wasi target.

I get error
wasmtime run -S tcp=y -S inherit-network=y -S allow-ip-name-lookup=y noise_demo/target/wasm32-wasi/debug/noise_wasi_demo.wasm 

Error: Error { kind: Unsupported, message: "operation not supported on this platform" }

view this post on Zulip Joel Dice (Mar 13 2025 at 21:47):

wasm32-wasi (also know by its newer name wasm32-wasip1) has only very rudimentary TCP networking support. You'll want to use the wasm32-wasip2 target if you're using TCP.

view this post on Zulip Victor Adossi (Mar 14 2025 at 09:06):

In addition to what Joel already covered, with the recent addition of a wasi-tls implementation, you should likely check out the example programs that are now in the codebase:

https://github.com/bytecodealliance/wasmtime/blob/a3381e48775912a3e1a68c05180932f3ce74c5b4/crates/test-programs/src/bin/tls_sample_application.rs

https://github.com/bytecodealliance/wasmtime/blob/a3381e48775912a3e1a68c05180932f3ce74c5b4/crates/test-programs/src/tls.rs

wasmtime run on main has -S tls, so you should be able to try it out that way.

On the lib side, you'll have to fork the relevant program and fill out the conditional compilation bits that do the TCP.

TCP might be the easier bit there -- as far as crypto goes, this actually recently came up on Zulip, so I made an issue in the component-docs repo to get it added to the component model docs -- there are a bunch of ways to get crypto working, at various levels of completeness/testing.

fixes: #10089 This adds a crate that provides the Wasmtime host implementation for the wasi-tls API. The wasi-tls world allows WebAssembly modules to perform SSL/TLS operations, such as establishin...
A lightweight WebAssembly runtime that is fast, secure, and standards-compliant - bytecodealliance/wasmtime
A lightweight WebAssembly runtime that is fast, secure, and standards-compliant - bytecodealliance/wasmtime
A great answer popped on up Zulip that might be worth sharing more widely: #general > Stable crypto library which can be converted to wasm @ 💬 It would be great if there was a page (likely in "Adva...

view this post on Zulip celine santosh (Mar 14 2025 at 11:13):

Thanks a lot for the insights!


Last updated: Apr 08 2025 at 11:03 UTC