chore: reorg

This commit is contained in:
2020-10-17 11:47:07 +08:00
parent 9d4d830115
commit a034988643
56 changed files with 13431 additions and 0 deletions

6
__wasm/wasi/Cargo.lock generated Normal file
View File

@@ -0,0 +1,6 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "wasi"
version = "0.1.0"

9
__wasm/wasi/Cargo.toml Normal file
View File

@@ -0,0 +1,9 @@
[package]
name = "wasi"
version = "0.1.0"
authors = ["Hatter Jiang <jht5945@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

42
__wasm/wasi/README.md Normal file
View File

@@ -0,0 +1,42 @@
Prepare:
```shell
rustup target add wasm32-wasi
```
Compile:
```shell
cargo build --target=wasm32-wasi
```
```shell
$ ls target/
debug wasm32-wasi
```
运行时Runtime
> 运行这个文件需要一个运行时Runtime。你也可以把这个理解成一个“容器”“虚拟机”什么的都行。但是准确的叫法是运行时。
> 目前常见的运行时有 wasmtimewasmer 等。
> 我们这次用 wasmtime 来运行吧。
`curl https://wasmtime.dev/install.sh -sSf | bash`
or download from:
https://github.com/bytecodealliance/wasmtime/releases
Run:
```
$ wasmtime --dir=. target/wasm32-wasi/debug/wasi.wasm
Hello, world!
```
<br>
Reference:
https://mp.weixin.qq.com/s/VYkUvD1NpRdx_qoIdCCq8w - _【Rust每周一知】Rust, wasm, wasi 试玩儿_

2
__wasm/wasi/build.sh Executable file
View File

@@ -0,0 +1,2 @@
cargo build --target=wasm32-wasi

1
__wasm/wasi/run.sh Executable file
View File

@@ -0,0 +1 @@
wasmtime --dir=. target/wasm32-wasi/debug/wasi.wasm

10
__wasm/wasi/src/main.rs Normal file
View File

@@ -0,0 +1,10 @@
use std::fs::File;
use std::io::prelude::*;
fn main() -> std::io::Result<()> {
let mut file = File::create("foo.txt")?;
file.write_all(b"Hello, world!\n")?;
println!("Hello, world!");
Ok(())
}