Skip to content

Commit

Permalink
Move examples into separate folders. (#146)
Browse files Browse the repository at this point in the history
Fixes #140.

Signed-off-by: Martijn Swaagman <[email protected]>
  • Loading branch information
Swaagie authored Nov 22, 2022
1 parent 463eed0 commit 8d1f04a
Show file tree
Hide file tree
Showing 43 changed files with 851 additions and 1,204 deletions.
160 changes: 122 additions & 38 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ jobs:
export PATH=$PATH:$(go env GOPATH)/bin
buildifier -mode=check WORKSPACE
buildifier -mode=check BUILD
buildifier -mode=check examples/BUILD
- name: Format (cargo raze)
run: |
Expand All @@ -89,6 +88,9 @@ jobs:
stable:
runs-on: ubuntu-latest

env:
RUSTFLAGS: -D warnings

steps:
- uses: actions/checkout@v2

Expand All @@ -99,23 +101,15 @@ jobs:
rustup target add wasm32-wasi
- name: Build (wasm32-unknown-unknown)
env:
RUSTFLAGS: -D warnings
run: cargo build --release --all-targets --target=wasm32-unknown-unknown

- name: Clippy (wasm32-unknown-unknown)
env:
RUSTFLAGS: -D warnings
run: cargo clippy --release --all-targets --target=wasm32-unknown-unknown

- name: Build (wasm32-wasi)
env:
RUSTFLAGS: -D warnings
run: cargo build --release --all-targets --target=wasm32-wasi

- name: Clippy (wasm32-wasi)
env:
RUSTFLAGS: -D warnings
run: cargo clippy --release --all-targets --target=wasm32-wasi

- name: Format (rustfmt)
Expand All @@ -133,6 +127,9 @@ jobs:
nightly:
runs-on: ubuntu-latest

env:
RUSTFLAGS: -D warnings

steps:
- uses: actions/checkout@v2

Expand All @@ -144,23 +141,15 @@ jobs:
rustup default nightly
- name: Build (wasm32-unknown-unknown)
env:
RUSTFLAGS: -D warnings
run: cargo build --release --all-targets --target=wasm32-unknown-unknown

- name: Clippy (wasm32-unknown-unknown)
env:
RUSTFLAGS: -D warnings
run: cargo clippy --release --all-targets --target=wasm32-unknown-unknown

- name: Build (wasm32-wasi)
env:
RUSTFLAGS: -D warnings
run: cargo build --release --all-targets --target=wasm32-wasi

- name: Clippy (wasm32-wasi)
env:
RUSTFLAGS: -D warnings
run: cargo clippy --release --all-targets --target=wasm32-wasi

- name: Format (rustfmt)
Expand All @@ -175,49 +164,144 @@ jobs:
- name: Package (publish)
run: cargo publish --dry-run --target=wasm32-unknown-unknown

reactor:
outdated:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Update Rust
- name: Run cargo outdated
run: cargo outdated --root-deps-only --exit-code 1

audit:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Run cargo audit
run: |
rustup toolchain install nightly --component clippy
rustup +nightly target add wasm32-wasi
rustup default nightly
cp -p bazel/cargo/Cargo.raze.lock .
cargo audit
- name: Rewrite Cargo.toml examples
example:
runs-on: ubuntu-latest

strategy:
matrix:
example:
- 'hello_world'
- 'http_auth_random'
- 'http_body'
- 'http_config'
- 'http_headers'

defaults:
run:
working-directory: ./examples/${{ matrix.example }}

env:
RUSTFLAGS: -D warnings

steps:
- uses: actions/checkout@v2

- name: Update Rust
run: |
grep -v '^crate-type' Cargo.toml > Cargo.tmp
mv Cargo.tmp Cargo.toml
rustup toolchain install stable --component clippy --component rustfmt
rustup target add wasm32-wasi
- name: Build (wasm32-wasi)
env:
RUSTFLAGS: -D warnings -Z wasi-exec-model=reactor
run: cargo build --release --all-targets --target=wasm32-wasi
run: cargo build --release --target=wasm32-wasi

- name: Clippy (wasm32-wasi)
env:
RUSTFLAGS: -D warnings -Z wasi-exec-model=reactor
run: cargo clippy --release --all-targets --target=wasm32-wasi
run: cargo clippy --release --target=wasm32-wasi

outdated:
runs-on: ubuntu-latest
- name: Format (rustfmt)
run: cargo fmt -- --check

steps:
- uses: actions/checkout@v2
- name: Format (manifest)
run: cargo verify-project

- name: Run cargo audit
run: cargo audit

- name: Run cargo outdated
run: cargo outdated --root-deps-only --exit-code 1

audit:
- name: Validate Envoy config
run: |
docker run --rm \
-v $(pwd)/envoy.yaml:/envoy.yaml \
-v $(pwd)/target/wasm32-wasi/release:/etc/envoy/proxy-wasm-plugins \
envoyproxy/envoy:v1.24-latest \
--mode validate \
-c envoy.yaml
reactor:
runs-on: ubuntu-latest

strategy:
matrix:
example:
- 'hello_world'
- 'http_auth_random'
- 'http_body'
- 'http_config'
- 'http_headers'

defaults:
run:
working-directory: ./examples/${{ matrix.example }}

env:
RUSTFLAGS: -D warnings -Z wasi-exec-model=reactor

steps:
- uses: actions/checkout@v2

- name: Update Rust
run: |
rustup toolchain install nightly --component clippy --component rustfmt
rustup +nightly target add wasm32-wasi
rustup default nightly
- name: Change crate type from library to binary
run: |
grep -v '^\[lib\]' Cargo.toml > Cargo.tmp
grep -v '^crate-type' Cargo.tmp > Cargo.toml
mv src/lib.rs src/main.rs
- name: Build (wasm32-wasi)
run: cargo build --release --target=wasm32-wasi

- name: Clippy (wasm32-wasi)
run: cargo clippy --release --target=wasm32-wasi

- name: Format (rustfmt)
run: cargo fmt -- --check

- name: Format (manifest)
run: cargo verify-project

- name: Run cargo audit
run: cargo audit

- name: Run cargo outdated
run: cargo outdated --root-deps-only --exit-code 1

- name: Rename .wasm to match expected filename
run: |
cp -p bazel/cargo/Cargo.raze.lock .
cargo audit --ignore RUSTSEC-2020-0159
cd target/wasm32-wasi/release
for file in $(ls -1 *.wasm); do \
mv $file $(echo $file | sed 's/-/_/g'); \
done
- name: Validate Envoy config
run: |
docker run --rm \
-v $(pwd)/envoy.yaml:/envoy.yaml \
-v $(pwd)/target/wasm32-wasi/release:/etc/envoy/proxy-wasm-plugins \
envoyproxy/envoy:v1.24-latest \
--mode validate \
-c envoy.yaml
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/bazel-*
/target
/Cargo.lock
target
Cargo.lock
32 changes: 0 additions & 32 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ build = "build.rs"
hashbrown = "0.13"
log = "0.4"

[dev-dependencies]
cfg-if = "1.0"
chrono = { version = "0.4", default-features = false, features = ["clock", "std"] }

[target.'cfg(not(all(target_arch = "wasm32", target_os = "unknown")))'.dev-dependencies]
getrandom = "0.2"

[profile.release]
lto = true
opt-level = 3
Expand All @@ -32,28 +25,3 @@ strip = "debuginfo"
package_aliases_dir = "bazel/cargo"
workspace_path = "//bazel/cargo"
genmode = "Remote"

[[example]]
name = "hello_world"
path = "examples/hello_world.rs"
crate-type = ["cdylib"]

[[example]]
name = "http_auth_random"
path = "examples/http_auth_random.rs"
crate-type = ["cdylib"]

[[example]]
name = "http_headers"
path = "examples/http_headers.rs"
crate-type = ["cdylib"]

[[example]]
name = "http_body"
path = "examples/http_body.rs"
crate-type = ["cdylib"]

[[example]]
name = "http_config"
path = "examples/http_config.rs"
crate-type = ["cdylib"]
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

## Examples

- [Hello World](./examples/hello_world.rs)
- [HTTP Auth random](./examples/http_auth_random.rs)
- [HTTP Headers](./examples/http_headers.rs)
- [HTTP Response body](./examples/http_body.rs)
- [HTTP Configuration](./examples/http_config.rs)
- [Hello World](./examples/hello_world/)
- [HTTP Auth (random)](./examples/http_auth_random/)
- [HTTP Headers](./examples/http_headers/)
- [HTTP Response body](./examples/http_body/)
- [HTTP Configuration](./examples/http_config/)

## Articles & blog posts from the community

Expand Down
27 changes: 0 additions & 27 deletions bazel/cargo/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,6 @@ licenses([
])

# Aliased targets
alias(
name = "cfg_if",
actual = "@raze__cfg_if__1_0_0//:cfg_if",
tags = [
"cargo-raze",
"manual",
],
)

alias(
name = "chrono",
actual = "@raze__chrono__0_4_19//:chrono",
tags = [
"cargo-raze",
"manual",
],
)

alias(
name = "getrandom",
actual = "@raze__getrandom__0_2_6//:getrandom",
tags = [
"cargo-raze",
"manual",
],
)

alias(
name = "hashbrown",
actual = "@raze__hashbrown__0_13_1//:hashbrown",
Expand Down
Loading

0 comments on commit 8d1f04a

Please sign in to comment.