wasmerio / wasmer

🚀 The leading Wasm Runtime supporting WASIX and WASI
https://wasmer.io
MIT License
19.08k stars 819 forks source link

wasix: Can't use `sock_bind` on Zig #4217

Closed nikneym closed 1 year ago

nikneym commented 1 year ago

Summary

Hi, I'm trying to use WASIX calls through Zig and currently unable to bind my socket to a local address. You can find the implementation here and my main function here. A call to sock_bind always results with INVAL (sock_connect just works fine by the way). I've compared my declarations with wasix-libc but couldn't spot the issue.

In order to build & run the project I'm running these:

zig build -Dtarget=wasm32-wasi
wasmer run --enable-all -a 127.0.0.1:8080 zig-out/bin/wasix-test.wasm
ptitSeb commented 1 year ago

you need to explicitly enable network. the --enable-all is there to enable WASI features, not network. So try with

wasmer run --enable-all --net -a 127.0.0.1:8080 zig-out/bin/wasix-test.wasm
nikneym commented 1 year ago

you need to explicitly enable network. the --enable-all is there to enable WASI features, not network. So try with

wasmer run --enable-all --net -a 127.0.0.1:8080 zig-out/bin/wasix-test.wasm

Tried as you've claimed, I still get INVAL:

zig build -Dtarget=wasm32-wasi
wasmer run --enable-all --net -a 127.0.0.1:8080 zig-out/bin/wasix-test.wasm
nikneym commented 1 year ago

Turns out in order to create valid TCP/IP socket, address family must be INET4 which is 1. I thought AF_INET (which is 2) is required for creating such socket. All is well now, sorry for the heads up!