Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
[Docs] Update tutorials for renaming SSVM to WasmEdge
Browse files Browse the repository at this point in the history
  • Loading branch information
hydai authored and dm4 committed Oct 8, 2021
1 parent 7c79281 commit 24b9219
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 28 deletions.
30 changes: 14 additions & 16 deletions Tutorial_Wasm32_Wasi.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# How to run wasm applications with ssvm-napi (General Wasm32-wasi with interpreter mode)
# How to run wasm applications with wasmedge-core (General Wasm32-wasi with interpreter mode)

## Environment Setup for Rust, Nodejs, and ssvmup
## Environment Setup for Rust, Nodejs, and rustwasmc

```bash
$ sudo apt-get update
Expand All @@ -19,7 +19,7 @@ $ [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
$ nvm install v14.2.0
$ nvm use v14.2.0

$ npm i -g ssvmup
$ npm i -g rustwasmc
```

## Example 1. Print environment variables, arguments, and test filesystem
Expand All @@ -42,7 +42,7 @@ use std::fs::File;
use std::io::{Write, Read};

fn main() {
println!("This is a demo application to show how to run a standalone wasi program with ssvm-napi!");
println!("This is a demo application to show how to run a standalone wasi program with wasmedge-core!");
println!("============================================");
println!("Print environment variables");
println!("--------------------------------------------");
Expand All @@ -61,7 +61,7 @@ fn main() {
println!("Test filesystem, create a /hello.txt, read and write to it, and then delete it");
println!("--------------------------------------------");
let path = "/hello.txt".to_string();
let content = "Hello from SSVM\nThis file is located at wasm binary folder".to_string();
let content = "Hello from WasmEdge\nThis file is located at wasm binary folder".to_string();
let mut output = File::create(&path).unwrap();
output.write_all(&content.as_bytes()).unwrap();
let mut f = File::open(&path).unwrap();
Expand All @@ -84,21 +84,21 @@ cargo build --release --target wasm32-wasi

After building, our target wasm file is located at `target/wasm32-wasi/release/file-example.wasm`.

### Install SSVM addon for your application
### Install WasmEdge-core addon for your application

```bash
npm install ssvm
npm install wasmedge-core
```

or if you want to build from source:

```bash
export CXX=g++-9
npm install --build-from-source https://github.com/second-state/ssvm-napi
npm install --build-from-source https://github.com/second-state/wasmedge-core
```

### Use SSVM addon
After installing the SSVM addon, we could now interact with `file_example.wasm` generated by wasm32-wasi backend in Node.js.
### Use WasmEdge addon
After installing the WasmEdge addon, we could now interact with `file_example.wasm` generated by wasm32-wasi backend in Node.js.

- Create js file `app.js` and `lib.js` in the root folder.

Expand All @@ -110,8 +110,6 @@ After installing the SSVM addon, we could now interact with `file_example.wasm`
├── README.md
├── app.js
├── lib.js
├── node_modules
│   └── ssvm
├── package-lock.json
├── src
│   └── main.rs
Expand Down Expand Up @@ -143,18 +141,18 @@ module.exports.file_demo = function() {
return vm.Start();
};

const ssvm = require('ssvm');
const wasmedge = require('wasmedge-core');
const path = require('path').join(__dirname, 'target/wasm32-wasi/release/file-example.wasm');

vm = new ssvm.VM(path, {"EnableWasiStartFunction": true, env: process.env, args: process.argv, preopens:{'/': __dirname}});
vm = new wasmedge.VM(path, {"EnableWasiStartFunction": true, env: process.env, args: process.argv, preopens:{'/': __dirname}});
```

### Execute and check results

```bash
$ node app.js arg1 arg2

This is a demo application to show how to run a standalone wasi program with ssvm-napi!
This is a demo application to show how to run a standalone wasi program with wasmedge-core!
============================================
Print environment variables
--------------------------------------------
Expand All @@ -176,7 +174,7 @@ arg2

Test filesystem, create a /hello.txt, read and write to it, and then delete it
--------------------------------------------
Output: Hello from SSVM
Output: Hello from WasmEdge
This file is located at wasm binary folder
============================================
```
Expand Down
24 changes: 12 additions & 12 deletions Tutorial_Wasm_Bindgen.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# How to run wasm applications with ssvm-napi (Wasm-Bindgen and interpreter mode)
# How to run wasm applications with wasmedge-core (Wasm-Bindgen and interpreter mode)

## Environment Setup for Rust, Nodejs, and ssvmup
## Environment Setup for Rust, Nodejs, and rustwasmc

```bash
$ sudo apt-get update
Expand All @@ -20,7 +20,7 @@ $ [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
$ nvm install v14.2.0
$ nvm use v14.2.0

$ npm i -g ssvmup
$ npm i -g rustwasmc
```

## Example 1. Hello Application
Expand Down Expand Up @@ -92,39 +92,39 @@ pub fn say_with_json(s: String) -> String {

When given `{"name": "Tim"}` this `say_with_json` function returns `Hello Tim` wrapped in a response object (as valid JSON) like this `{"ssvm_response": ["{\"result\": \"Hello Tim\"}"]}`

### Build the WASM bytecode with ssvmup
### Build the WASM bytecode with rustwasmc

```bash
ssvmup build
rustwasmc build
```

After building, our target wasm file is located at `pkg/hello_bg.wasm`.

### Install SSVM addon for your application
### Install WasmEdge addon for your application

```bash
npm install ssvm
npm install wasmedge-core
```

or if you want to build from source:

```bash
export CXX=g++-9
npm install --build-from-source https://github.com/second-state/ssvm-napi
npm install --build-from-source https://github.com/second-state/wasmedge-core
```

### Use SSVM addon
### Use WasmEdge addon

After installing SSVM addon, we could now interact with `hello_bg.wasm` generated by wasm-pack in Node.js.
After installing WasmEdge addon, we could now interact with `hello_bg.wasm` generated by wasm-pack in Node.js.
Make sure you use the corresponding VM method to the rust return type.

- Create a new folder at any path you want. (e.g. `mkdir application`)
- Copy `hello_bg.wasm` into your application directory. (e.g. `cp hello_gb.wasm <path_to_your_application_folder>`)
- Create js file `main.js` (or whatever you like) with the following content:

```javascript
var ssvm = require('ssvm');
var vm = new ssvm.VM("hello_bg.wasm");
var wasmedge = require('wasmedge-core');
var vm = new wasmedge.VM("hello_bg.wasm");
var ret = vm.RunString("say", "world");
console.log(ret);

Expand Down

0 comments on commit 24b9219

Please sign in to comment.