Skip to content

Commit

Permalink
Move all examples to a top-level directory (#1286)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
alexcrichton committed Mar 11, 2020
1 parent d44384d commit 3c51d3a
Show file tree
Hide file tree
Showing 33 changed files with 1,130 additions and 527 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,10 @@ jobs:
Get-Command clang.exe
clang.exe --version
# Install wasm32-wasi target in order to build wasi-common's integration
# tests
# Install wasm32 targets in order to build various tests throughout the
# repo
- run: rustup target add wasm32-wasi
- run: rustup target add wasm32-unknown-unknown

- run: cargo fetch --locked
- run: cargo fetch --locked --manifest-path crates/test-programs/wasi-tests/Cargo.toml
Expand All @@ -197,6 +198,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 +209,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.

38 changes: 0 additions & 38 deletions crates/api/tests/examples.rs

This file was deleted.

Loading

0 comments on commit 3c51d3a

Please sign in to comment.