second-state / wasmedge-quickjs

A high-performance, secure, extensible, and OCI-complaint JavaScript runtime for WasmEdge.
Apache License 2.0
477 stars 59 forks source link

Using the WASM file from Rust code instead of the WasmEdge CLI Tool #96

Open skirodev opened 1 year ago

skirodev commented 1 year ago

I want to embed this Javascript WASM runtime by using a Rust WASM runtime in a Rust program, for example wasmer or wasmtime and so on. However, When I use wasmer and wasmer_wasi crates to write code, I realize that I encountered a problem about WASI.

Error: Error while importing "wasi_snapshot_preview1"."sock_open": unknown import. Expected Function(FunctionType { params: [I32, I32, I32], results: [I32] })

Is there any way to help me solve it here? I will be very grateful for your help.

juntao commented 1 year ago

The wasmedge_quickjs runtime depends on the async networking API provided by WasmEdge. It would not work on other Wasm implementations.

Can you use the WasmEdge Rust SDK to embed it? It is quite similar to Rust SDKs provided by the other two runtimes. Thanks.

skirodev commented 1 year ago

The problem is that the working of the WasmEdge Rust SDK depends on the installation of WasmEdge, and it's not practical to install the WasmEdge on every user's computer because its install script keeps failing due to some weird network issues.

Is it feasible that I want to migrate the the async networking API implementation of WasmEdge to wasmer?

juntao commented 1 year ago

Hmm, what are the networking issues you are encountering? I think our installer files are hosted on GitHub. But we can also mirror it somewhere else.

You are welcome to port the wasmedge socket impl to wasmer or wasmtime, but it is likely to be a big task since those are written in different languages.

skirodev commented 1 year ago

Running command with VPN:

skiro@MacBook-Pro ~ % sudo curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- -p /usr/local
Password: ********
Using Python: /usr/local/bin/python3
curl: (56) LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 60

Running command without VPN:

skiro@MacBook-Pro ~ % sudo curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- -p /usr/local
Using Python: /usr/local/bin/python3
Compatible with current configuration
Running Uninstaller
CRITICAL- Error opening file: /usr/local/env error: Permission denied
ERROR   - Not able to write to env file
WARNING - SHELL variable not found. Using zsh as SHELL
shell configuration updated
Downloading WasmEdge
|===============================                             | 53.05 %Traceback (most recent call last):
  File "<stdin>", line 1524, in <module>
  File "<stdin>", line 1309, in main
  File "/usr/local/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 278, in urlretrieve
    raise ContentTooShortError(
urllib.error.ContentTooShortError: <urlopen error retrieval incomplete: got only 13205504 out of 24892048 bytes>

I have run the above command on MacOS Big Sur 11.7 in China.

Might be useful info is that when I ran the installation scripts of Wasmer and Wasmtime, it was very smooth and completed within 5 seconds. Also worth noting that not every user is willing to install Python for WasmEdge.

alabulei1 commented 1 year ago

Hi @skirodev

Sorry for the inconvenience. Because the installation of WasmEdge depends on rawgithubcontents.com, which doesn't work well in China. I think https://ghproxy.com/ can help solve this problem. Let me know if this works. Thanks.

BTW, we're also looking for more advanced solutions. Do you have any suggestions?

guest271314 commented 1 year ago

You are welcome to port the wasmedge socket impl to wasmer or wasmtime, but it is likely to be a big task since those are written in different languages.

What are the source files?