Skip to content

Commit

Permalink
filestore: add example WASM unknown module written in Rust
Browse files Browse the repository at this point in the history
Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Mar 25, 2024
1 parent cc3de1e commit 8487cd7
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 0 deletions.
Binary file added filestore/modules/pingrs.wasm
Binary file not shown.
5 changes: 5 additions & 0 deletions filestore/modules/pingrs/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[target."wasm32-unknown-unknown"]
rustflags = ["-C", "target-feature=+atomics,+bulk-memory",
"-C", "link-arg=--initial-memory=65536",
"-C", "link-arg=--max-memory=65536",
"-C", "link-arg=-zstack-size=4096"]
1 change: 1 addition & 0 deletions filestore/modules/pingrs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
7 changes: 7 additions & 0 deletions filestore/modules/pingrs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions filestore/modules/pingrs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "pingrs"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

[lib]
crate-type = ["cdylib"]
22 changes: 22 additions & 0 deletions filestore/modules/pingrs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# pingrs

WASM unknown module written in Rust

## How to install

- Install Rust.

- Install the `wasm32-unknown-unknown` target.

```bash
rustup target add wasm32-unknown-unknown
```

## How to build module

```bash
cd modules/pingrs
cargo build --target wasm32-unknown-unknown --release
cd ../..
cp ./modules/pingrs/target/wasm32-unknown-unknown/release/pingrs.wasm ./modules/
```
16 changes: 16 additions & 0 deletions filestore/modules/pingrs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#![no_std]

#[panic_handler]
fn handle_panic(_: &core::panic::PanicInfo) -> ! {
loop {}
}

#[no_mangle]
pub extern fn ping() {
unsafe {pong()};
}

#[link(wasm_import_module = "hosted")]
extern {
fn pong();
}

0 comments on commit 8487cd7

Please sign in to comment.