Skip to content

Commit a9af096

Browse files
committed
Move all examples to a top-level directory
This commit moves all API examples (Rust and C) to a top-level `examples` directory. This is intended to make it more discoverable and conventional as to where examples are located. Additionally all examples are now available in both Rust and C to see how to execute the example in the language you're familiar with. The intention is that as more languages are supported we'd add more languages as examples here too. Each example is also accompanied by either a `*.wat` file which is parsed as input, or a Rust project in a `wasm` folder which is compiled as input. A simple driver crate was also added to `crates/misc` which executes all the examples on CI, ensuring the C and Rust examples all execute successfully.
1 parent dab9ffc commit a9af096

File tree

32 files changed

+1106
-484
lines changed

32 files changed

+1106
-484
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ jobs:
197197
- run: cargo build --manifest-path crates/api/Cargo.toml --features lightbeam
198198
if: matrix.rust == 'nightly'
199199

200+
# Ensure all our examples build and execute
201+
- run: cargo run -p run-examples
202+
200203
# Build and test all features except for lightbeam
201204
- run: cargo test --features test_programs --all --exclude lightbeam --exclude wasmtime-c-api -- --nocapture
202205
env:
@@ -205,7 +208,7 @@ jobs:
205208

206209
# Test debug (DWARF) related functionality.
207210
- run: cargo test test_debug_dwarf_ -- --ignored --nocapture --test-threads 1
208-
if: matrix.os == 'ubuntu-latest'
211+
if: matrix.os == 'ubuntu-latest'
209212
env:
210213
RUST_BACKTRACE: 1
211214
RUSTFLAGS: "-D warnings"

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
path = tests/spec_testsuite
33
url = https://github.com/WebAssembly/testsuite
44
[submodule "crates/c-api/examples/wasm-c-api"]
5-
path = crates/c-api/examples/wasm-c-api
5+
path = crates/c-api/wasm-c-api
66
url = https://github.com/WebAssembly/wasm-c-api
77
[submodule "crates/wasi-common/WASI"]
88
path = crates/wasi-common/wig/WASI

Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,14 @@ opt-level = 0
6363
[workspace]
6464
members = [
6565
"cranelift",
66+
"crates/c-api",
6667
"crates/fuzzing",
67-
"crates/misc/rust",
6868
"crates/misc/py",
69-
"crates/c-api",
70-
"fuzz",
69+
"crates/misc/run-examples",
70+
"crates/misc/rust",
7171
"crates/wiggle",
72+
"examples/fib-debug/wasm",
73+
"fuzz",
7274
]
7375

7476
[features]

ci/build-tarballs.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ mkdir tmp/$api_pkgname/lib
4848
mkdir tmp/$api_pkgname/include
4949
cp LICENSE README.md tmp/$api_pkgname
5050
mv bins-$src/* tmp/$api_pkgname/lib
51-
cp crates/c-api/examples/wasm-c-api/include/wasm.h tmp/$api_pkgname/include
51+
cp crates/c-api/wasm-c-api/include/wasm.h tmp/$api_pkgname/include
5252
cp crates/c-api/include/{wasmtime,wasi}.h tmp/$api_pkgname/include
5353
mktarball $api_pkgname
5454

crates/api/examples/gcd.rs

Lines changed: 0 additions & 60 deletions
This file was deleted.

crates/api/examples/memory.rs

Lines changed: 0 additions & 160 deletions
This file was deleted.

0 commit comments

Comments
 (0)