Skip to content

Commit

Permalink
Move all examples to a top-level directory
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alexcrichton committed Mar 11, 2020
1 parent dab9ffc commit a9af096
Show file tree
Hide file tree
Showing 32 changed files with 1,106 additions and 484 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ jobs:
- run: cargo build --manifest-path crates/api/Cargo.toml --features lightbeam
if: matrix.rust == 'nightly'

# Ensure all our examples build and execute
- run: cargo run -p run-examples

# Build and test all features except for lightbeam
- run: cargo test --features test_programs --all --exclude lightbeam --exclude wasmtime-c-api -- --nocapture
env:
Expand All @@ -205,7 +208,7 @@ jobs:

# Test debug (DWARF) related functionality.
- run: cargo test test_debug_dwarf_ -- --ignored --nocapture --test-threads 1
if: matrix.os == 'ubuntu-latest'
if: matrix.os == 'ubuntu-latest'
env:
RUST_BACKTRACE: 1
RUSTFLAGS: "-D warnings"
Expand Down
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
path = tests/spec_testsuite
url = https://github.com/WebAssembly/testsuite
[submodule "crates/c-api/examples/wasm-c-api"]
path = crates/c-api/examples/wasm-c-api
path = crates/c-api/wasm-c-api
url = https://github.com/WebAssembly/wasm-c-api
[submodule "crates/wasi-common/WASI"]
path = crates/wasi-common/wig/WASI
Expand Down
11 changes: 11 additions & 0 deletions Cargo.lock

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

8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,14 @@ opt-level = 0
[workspace]
members = [
"cranelift",
"crates/c-api",
"crates/fuzzing",
"crates/misc/rust",
"crates/misc/py",
"crates/c-api",
"fuzz",
"crates/misc/run-examples",
"crates/misc/rust",
"crates/wiggle",
"examples/fib-debug/wasm",
"fuzz",
]

[features]
Expand Down
2 changes: 1 addition & 1 deletion ci/build-tarballs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ mkdir tmp/$api_pkgname/lib
mkdir tmp/$api_pkgname/include
cp LICENSE README.md tmp/$api_pkgname
mv bins-$src/* tmp/$api_pkgname/lib
cp crates/c-api/examples/wasm-c-api/include/wasm.h tmp/$api_pkgname/include
cp crates/c-api/wasm-c-api/include/wasm.h tmp/$api_pkgname/include
cp crates/c-api/include/{wasmtime,wasi}.h tmp/$api_pkgname/include
mktarball $api_pkgname

Expand Down
60 changes: 0 additions & 60 deletions crates/api/examples/gcd.rs

This file was deleted.

160 changes: 0 additions & 160 deletions crates/api/examples/memory.rs

This file was deleted.

Loading

0 comments on commit a9af096

Please sign in to comment.