Skip to content

Commit 8d1f04a

Browse files
authored
Move examples into separate folders. (#146)
Fixes #140. Signed-off-by: Martijn Swaagman <[email protected]>
1 parent 463eed0 commit 8d1f04a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+851
-1204
lines changed

.github/workflows/rust.yml

Lines changed: 122 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ jobs:
7777
export PATH=$PATH:$(go env GOPATH)/bin
7878
buildifier -mode=check WORKSPACE
7979
buildifier -mode=check BUILD
80-
buildifier -mode=check examples/BUILD
8180
8281
- name: Format (cargo raze)
8382
run: |
@@ -89,6 +88,9 @@ jobs:
8988
stable:
9089
runs-on: ubuntu-latest
9190

91+
env:
92+
RUSTFLAGS: -D warnings
93+
9294
steps:
9395
- uses: actions/checkout@v2
9496

@@ -99,23 +101,15 @@ jobs:
99101
rustup target add wasm32-wasi
100102
101103
- name: Build (wasm32-unknown-unknown)
102-
env:
103-
RUSTFLAGS: -D warnings
104104
run: cargo build --release --all-targets --target=wasm32-unknown-unknown
105105

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

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

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

121115
- name: Format (rustfmt)
@@ -133,6 +127,9 @@ jobs:
133127
nightly:
134128
runs-on: ubuntu-latest
135129

130+
env:
131+
RUSTFLAGS: -D warnings
132+
136133
steps:
137134
- uses: actions/checkout@v2
138135

@@ -144,23 +141,15 @@ jobs:
144141
rustup default nightly
145142
146143
- name: Build (wasm32-unknown-unknown)
147-
env:
148-
RUSTFLAGS: -D warnings
149144
run: cargo build --release --all-targets --target=wasm32-unknown-unknown
150145

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

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

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

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

178-
reactor:
167+
outdated:
179168
runs-on: ubuntu-latest
180169

181170
steps:
182171
- uses: actions/checkout@v2
183172

184-
- name: Update Rust
173+
- name: Run cargo outdated
174+
run: cargo outdated --root-deps-only --exit-code 1
175+
176+
audit:
177+
runs-on: ubuntu-latest
178+
179+
steps:
180+
- uses: actions/checkout@v2
181+
182+
- name: Run cargo audit
185183
run: |
186-
rustup toolchain install nightly --component clippy
187-
rustup +nightly target add wasm32-wasi
188-
rustup default nightly
184+
cp -p bazel/cargo/Cargo.raze.lock .
185+
cargo audit
189186
190-
- name: Rewrite Cargo.toml examples
187+
example:
188+
runs-on: ubuntu-latest
189+
190+
strategy:
191+
matrix:
192+
example:
193+
- 'hello_world'
194+
- 'http_auth_random'
195+
- 'http_body'
196+
- 'http_config'
197+
- 'http_headers'
198+
199+
defaults:
200+
run:
201+
working-directory: ./examples/${{ matrix.example }}
202+
203+
env:
204+
RUSTFLAGS: -D warnings
205+
206+
steps:
207+
- uses: actions/checkout@v2
208+
209+
- name: Update Rust
191210
run: |
192-
grep -v '^crate-type' Cargo.toml > Cargo.tmp
193-
mv Cargo.tmp Cargo.toml
211+
rustup toolchain install stable --component clippy --component rustfmt
212+
rustup target add wasm32-wasi
194213
195214
- name: Build (wasm32-wasi)
196-
env:
197-
RUSTFLAGS: -D warnings -Z wasi-exec-model=reactor
198-
run: cargo build --release --all-targets --target=wasm32-wasi
215+
run: cargo build --release --target=wasm32-wasi
199216

200217
- name: Clippy (wasm32-wasi)
201-
env:
202-
RUSTFLAGS: -D warnings -Z wasi-exec-model=reactor
203-
run: cargo clippy --release --all-targets --target=wasm32-wasi
218+
run: cargo clippy --release --target=wasm32-wasi
204219

205-
outdated:
206-
runs-on: ubuntu-latest
220+
- name: Format (rustfmt)
221+
run: cargo fmt -- --check
207222

208-
steps:
209-
- uses: actions/checkout@v2
223+
- name: Format (manifest)
224+
run: cargo verify-project
225+
226+
- name: Run cargo audit
227+
run: cargo audit
210228

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

214-
audit:
232+
- name: Validate Envoy config
233+
run: |
234+
docker run --rm \
235+
-v $(pwd)/envoy.yaml:/envoy.yaml \
236+
-v $(pwd)/target/wasm32-wasi/release:/etc/envoy/proxy-wasm-plugins \
237+
envoyproxy/envoy:v1.24-latest \
238+
--mode validate \
239+
-c envoy.yaml
240+
241+
reactor:
215242
runs-on: ubuntu-latest
216243

244+
strategy:
245+
matrix:
246+
example:
247+
- 'hello_world'
248+
- 'http_auth_random'
249+
- 'http_body'
250+
- 'http_config'
251+
- 'http_headers'
252+
253+
defaults:
254+
run:
255+
working-directory: ./examples/${{ matrix.example }}
256+
257+
env:
258+
RUSTFLAGS: -D warnings -Z wasi-exec-model=reactor
259+
217260
steps:
218261
- uses: actions/checkout@v2
219262

263+
- name: Update Rust
264+
run: |
265+
rustup toolchain install nightly --component clippy --component rustfmt
266+
rustup +nightly target add wasm32-wasi
267+
rustup default nightly
268+
269+
- name: Change crate type from library to binary
270+
run: |
271+
grep -v '^\[lib\]' Cargo.toml > Cargo.tmp
272+
grep -v '^crate-type' Cargo.tmp > Cargo.toml
273+
mv src/lib.rs src/main.rs
274+
275+
- name: Build (wasm32-wasi)
276+
run: cargo build --release --target=wasm32-wasi
277+
278+
- name: Clippy (wasm32-wasi)
279+
run: cargo clippy --release --target=wasm32-wasi
280+
281+
- name: Format (rustfmt)
282+
run: cargo fmt -- --check
283+
284+
- name: Format (manifest)
285+
run: cargo verify-project
286+
220287
- name: Run cargo audit
288+
run: cargo audit
289+
290+
- name: Run cargo outdated
291+
run: cargo outdated --root-deps-only --exit-code 1
292+
293+
- name: Rename .wasm to match expected filename
221294
run: |
222-
cp -p bazel/cargo/Cargo.raze.lock .
223-
cargo audit --ignore RUSTSEC-2020-0159
295+
cd target/wasm32-wasi/release
296+
for file in $(ls -1 *.wasm); do \
297+
mv $file $(echo $file | sed 's/-/_/g'); \
298+
done
299+
300+
- name: Validate Envoy config
301+
run: |
302+
docker run --rm \
303+
-v $(pwd)/envoy.yaml:/envoy.yaml \
304+
-v $(pwd)/target/wasm32-wasi/release:/etc/envoy/proxy-wasm-plugins \
305+
envoyproxy/envoy:v1.24-latest \
306+
--mode validate \
307+
-c envoy.yaml

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
/bazel-*
2-
/target
3-
/Cargo.lock
2+
target
3+
Cargo.lock

Cargo.toml

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@ build = "build.rs"
1414
hashbrown = "0.13"
1515
log = "0.4"
1616

17-
[dev-dependencies]
18-
cfg-if = "1.0"
19-
chrono = { version = "0.4", default-features = false, features = ["clock", "std"] }
20-
21-
[target.'cfg(not(all(target_arch = "wasm32", target_os = "unknown")))'.dev-dependencies]
22-
getrandom = "0.2"
23-
2417
[profile.release]
2518
lto = true
2619
opt-level = 3
@@ -32,28 +25,3 @@ strip = "debuginfo"
3225
package_aliases_dir = "bazel/cargo"
3326
workspace_path = "//bazel/cargo"
3427
genmode = "Remote"
35-
36-
[[example]]
37-
name = "hello_world"
38-
path = "examples/hello_world.rs"
39-
crate-type = ["cdylib"]
40-
41-
[[example]]
42-
name = "http_auth_random"
43-
path = "examples/http_auth_random.rs"
44-
crate-type = ["cdylib"]
45-
46-
[[example]]
47-
name = "http_headers"
48-
path = "examples/http_headers.rs"
49-
crate-type = ["cdylib"]
50-
51-
[[example]]
52-
name = "http_body"
53-
path = "examples/http_body.rs"
54-
crate-type = ["cdylib"]
55-
56-
[[example]]
57-
name = "http_config"
58-
path = "examples/http_config.rs"
59-
crate-type = ["cdylib"]

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616

1717
## Examples
1818

19-
- [Hello World](./examples/hello_world.rs)
20-
- [HTTP Auth random](./examples/http_auth_random.rs)
21-
- [HTTP Headers](./examples/http_headers.rs)
22-
- [HTTP Response body](./examples/http_body.rs)
23-
- [HTTP Configuration](./examples/http_config.rs)
19+
- [Hello World](./examples/hello_world/)
20+
- [HTTP Auth (random)](./examples/http_auth_random/)
21+
- [HTTP Headers](./examples/http_headers/)
22+
- [HTTP Response body](./examples/http_body/)
23+
- [HTTP Configuration](./examples/http_config/)
2424

2525
## Articles & blog posts from the community
2626

bazel/cargo/BUILD.bazel

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,6 @@ licenses([
1212
])
1313

1414
# Aliased targets
15-
alias(
16-
name = "cfg_if",
17-
actual = "@raze__cfg_if__1_0_0//:cfg_if",
18-
tags = [
19-
"cargo-raze",
20-
"manual",
21-
],
22-
)
23-
24-
alias(
25-
name = "chrono",
26-
actual = "@raze__chrono__0_4_19//:chrono",
27-
tags = [
28-
"cargo-raze",
29-
"manual",
30-
],
31-
)
32-
33-
alias(
34-
name = "getrandom",
35-
actual = "@raze__getrandom__0_2_6//:getrandom",
36-
tags = [
37-
"cargo-raze",
38-
"manual",
39-
],
40-
)
41-
4215
alias(
4316
name = "hashbrown",
4417
actual = "@raze__hashbrown__0_13_1//:hashbrown",

0 commit comments

Comments
 (0)