feat: add __network/html-crawl-parse, __wasm/wasmtime-serde-demo
This commit is contained in:
17
__wasm/wasmtime-serde-demo/docs/examples/README.md
Normal file
17
__wasm/wasmtime-serde-demo/docs/examples/README.md
Normal file
@@ -0,0 +1,17 @@
|
||||
# examples
|
||||
|
||||
add wasm target
|
||||
|
||||
```
|
||||
rustup target add wasm32-unknown-unknown
|
||||
```
|
||||
|
||||
compile guest
|
||||
```
|
||||
(cd guest; cargo build)
|
||||
```
|
||||
|
||||
compile and run host
|
||||
```
|
||||
(cd host; cargo run)
|
||||
```
|
||||
@@ -0,0 +1,2 @@
|
||||
[build]
|
||||
target = "wasm32-unknown-unknown"
|
||||
105
__wasm/wasmtime-serde-demo/docs/examples/guest/Cargo.lock
generated
Normal file
105
__wasm/wasmtime-serde-demo/docs/examples/guest/Cargo.lock
generated
Normal file
@@ -0,0 +1,105 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "bincode"
|
||||
version = "1.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "guest"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"wasmtime_serde_guest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.79"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.35"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.197"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.197"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.55",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.109"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.55"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "002a1b3dbf967edfafc32655d0f377ab0bb7b994aa1d32c8cc7e9b8bf3ebb8f0"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
||||
|
||||
[[package]]
|
||||
name = "wasmtime_serde_guest"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"serde",
|
||||
"wasmtime_serde_guest_macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasmtime_serde_guest_macro"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc93afb7801ed4f05fb2dc4b95c38ed65b65239b1088772e9cf609296d27b909"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
17
__wasm/wasmtime-serde-demo/docs/examples/guest/Cargo.toml
Normal file
17
__wasm/wasmtime-serde-demo/docs/examples/guest/Cargo.toml
Normal file
@@ -0,0 +1,17 @@
|
||||
[package]
|
||||
name = "guest"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
license = "Unlicense OR MIT"
|
||||
|
||||
[lib]
|
||||
crate-type = ['cdylib']
|
||||
|
||||
[dependencies]
|
||||
wasmtime_serde_guest = {path = "../../../crates/guest"}
|
||||
serde = {version = "1.0.159", features = ["derive"]}
|
||||
|
||||
[profile.release]
|
||||
opt-level = "z"
|
||||
lto = true
|
||||
strip = true
|
||||
20
__wasm/wasmtime-serde-demo/docs/examples/guest/src/lib.rs
Normal file
20
__wasm/wasmtime-serde-demo/docs/examples/guest/src/lib.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use wasmtime_serde_guest::*;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
struct Human {
|
||||
name: String,
|
||||
age: u8,
|
||||
}
|
||||
|
||||
#[export_fn]
|
||||
fn add(a: i32, b: i32) -> i32 {
|
||||
let human = get_human();
|
||||
println(format!("{human:?}"));
|
||||
a + b
|
||||
}
|
||||
|
||||
import_fn!(
|
||||
fn get_human() -> Human;
|
||||
fn println(msg: String);
|
||||
);
|
||||
1102
__wasm/wasmtime-serde-demo/docs/examples/host/Cargo.lock
generated
Normal file
1102
__wasm/wasmtime-serde-demo/docs/examples/host/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
14
__wasm/wasmtime-serde-demo/docs/examples/host/Cargo.toml
Normal file
14
__wasm/wasmtime-serde-demo/docs/examples/host/Cargo.toml
Normal file
@@ -0,0 +1,14 @@
|
||||
[package]
|
||||
name = "host"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
license = "Unlicense OR MIT"
|
||||
|
||||
[dependencies]
|
||||
wasmtime_serde_host = {path = "../../../crates/host"}
|
||||
serde = {version = "1.0.159", features = ["derive"]}
|
||||
|
||||
[profile.release]
|
||||
opt-level = "z"
|
||||
lto = true
|
||||
strip = true
|
||||
29
__wasm/wasmtime-serde-demo/docs/examples/host/src/main.rs
Normal file
29
__wasm/wasmtime-serde-demo/docs/examples/host/src/main.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use wasmtime_serde_host::*;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
struct Human {
|
||||
name: String,
|
||||
age: u8,
|
||||
}
|
||||
|
||||
#[export_fn]
|
||||
fn get_human() -> Human {
|
||||
Human {
|
||||
name: "Ferros".to_string(),
|
||||
age: 192,
|
||||
}
|
||||
}
|
||||
|
||||
#[export_fn]
|
||||
fn println(msg: String) {
|
||||
println!("{msg}")
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let host_fns = host_funcs![println, get_human];
|
||||
let runtime = Runtime::from_file("../guest/target/wasm32-unknown-unknown/debug/guest.wasm", host_fns).unwrap();
|
||||
let add_fn = runtime.get_func::<(i32, i32), i32>("add").unwrap();
|
||||
let result = add_fn.call(&(1, 2));
|
||||
println!("{result}");
|
||||
}
|
||||
Reference in New Issue
Block a user