diff --git a/.github/workflows/build-examples.yaml b/.github/workflows/build-examples.yaml new file mode 100644 index 0000000..8426661 --- /dev/null +++ b/.github/workflows/build-examples.yaml @@ -0,0 +1,51 @@ +name: Build Examples + +on: [push] + +permissions: + contents: read + +env: + CARGO_TERM_COLOR: always + +jobs: + build-examples: + runs-on: ubuntu-latest + + steps: + - name: Clone repo + uses: actions/checkout@v5 + with: + submodules: recursive + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + with: + targets: wasm32-wasip1, wasm32-wasip2 + + - name: Build CDN examples (wasm32-wasip1) + run: | + for dir in examples/cdn/*/; do + [ -f "$dir/Cargo.toml" ] || continue + echo "::group::$dir" + (cd "$dir" && cargo build --release --target wasm32-wasip1) + echo "::endgroup::" + done + + - name: Build http/basic examples (wasm32-wasip1) + run: | + for dir in examples/http/basic/*/; do + [ -f "$dir/Cargo.toml" ] || continue + echo "::group::$dir" + (cd "$dir" && cargo build --release --target wasm32-wasip1) + echo "::endgroup::" + done + + - name: Build http/wasi examples (wasm32-wasip2) + run: | + for dir in examples/http/wasi/*/; do + [ -f "$dir/Cargo.toml" ] || continue + echo "::group::$dir" + (cd "$dir" && cargo build --release --target wasm32-wasip2) + echo "::endgroup::" + done diff --git a/build-examples.sh b/build-examples.sh new file mode 100755 index 0000000..8a3870d --- /dev/null +++ b/build-examples.sh @@ -0,0 +1,134 @@ +#!/usr/bin/env bash +# Build all FastEdge SDK examples. +# +# Each example is a standalone crate (its own [workspace] root), so a single +# cargo build from the repo root won't pick them up. This script iterates over +# each example directory and runs `cargo build --release` with the right target. +# +# Targets: +# examples/cdn/* -> wasm32-wasip1 +# examples/http/basic/* -> wasm32-wasip1 +# examples/http/wasi/* -> wasm32-wasip2 +# +# Usage: +# ./build-examples.sh # build everything +# ./build-examples.sh cdn # build only CDN examples +# ./build-examples.sh http-basic # build only http/basic examples +# ./build-examples.sh http-wasi # build only http/wasi examples +# ./build-examples.sh clean # cargo clean every example + +set -u + +REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +cd "$REPO_ROOT" + +GROUP="${1:-all}" + +PASSED=() +FAILED=() +SKIPPED=() + +build_group() { + local label="$1" + local target="$2" + local glob="$3" + + shopt -s nullglob + local dirs=($glob) + shopt -u nullglob + + if [ ${#dirs[@]} -eq 0 ]; then + echo "[$label] no example directories matched: $glob" + return + fi + + echo + echo "==========================================" + echo " Building $label (target: $target)" + echo "==========================================" + + for dir in "${dirs[@]}"; do + [ -f "$dir/Cargo.toml" ] || { SKIPPED+=("$dir (no Cargo.toml)"); continue; } + local name="${dir#$REPO_ROOT/}" + echo + echo "--- $name ---" + if (cd "$dir" && cargo build --release --target "$target"); then + PASSED+=("$name") + else + FAILED+=("$name") + fi + done +} + +clean_group() { + local label="$1" + local glob="$2" + + shopt -s nullglob + local dirs=($glob) + shopt -u nullglob + + if [ ${#dirs[@]} -eq 0 ]; then + echo "[$label] no example directories matched: $glob" + return + fi + + echo + echo "==========================================" + echo " Cleaning $label" + echo "==========================================" + + for dir in "${dirs[@]}"; do + [ -f "$dir/Cargo.toml" ] || { SKIPPED+=("$dir (no Cargo.toml)"); continue; } + local name="${dir#$REPO_ROOT/}" + echo + echo "--- $name ---" + if (cd "$dir" && cargo clean); then + PASSED+=("$name") + else + FAILED+=("$name") + fi + done +} + +case "$GROUP" in + cdn) + build_group "cdn" "wasm32-wasip1" "$REPO_ROOT/examples/cdn/*/" + ;; + http-basic) + build_group "http/basic" "wasm32-wasip1" "$REPO_ROOT/examples/http/basic/*/" + ;; + http-wasi) + build_group "http/wasi" "wasm32-wasip2" "$REPO_ROOT/examples/http/wasi/*/" + ;; + all) + build_group "cdn" "wasm32-wasip1" "$REPO_ROOT/examples/cdn/*/" + build_group "http/basic" "wasm32-wasip1" "$REPO_ROOT/examples/http/basic/*/" + build_group "http/wasi" "wasm32-wasip2" "$REPO_ROOT/examples/http/wasi/*/" + ;; + clean) + clean_group "cdn" "$REPO_ROOT/examples/cdn/*/" + clean_group "http/basic" "$REPO_ROOT/examples/http/basic/*/" + clean_group "http/wasi" "$REPO_ROOT/examples/http/wasi/*/" + ;; + *) + echo "Unknown group: $GROUP" >&2 + echo "Usage: $0 [all|cdn|http-basic|http-wasi|clean]" >&2 + exit 2 + ;; +esac + +echo +echo "==========================================" +echo " Summary" +echo "==========================================" +echo " passed: ${#PASSED[@]}" +echo " failed: ${#FAILED[@]}" +echo " skipped: ${#SKIPPED[@]}" + +if [ ${#FAILED[@]} -gt 0 ]; then + echo + echo "Failed examples:" + for f in "${FAILED[@]}"; do echo " - $f"; done + exit 1 +fi diff --git a/examples/cdn/api_key/Cargo.lock b/examples/cdn/api_key/Cargo.lock index d4a0225..380241c 100644 --- a/examples/cdn/api_key/Cargo.lock +++ b/examples/cdn/api_key/Cargo.lock @@ -2,18 +2,6 @@ # It is not intended for manual editing. version = 4 -[[package]] -name = "ahash" -version = "0.8.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75" -dependencies = [ - "cfg-if", - "once_cell", - "version_check", - "zerocopy", -] - [[package]] name = "allocator-api2" version = "0.2.21" @@ -46,12 +34,6 @@ version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" -[[package]] -name = "cfg-if" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" - [[package]] name = "equivalent" version = "1.0.2" @@ -60,43 +42,136 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" [[package]] name = "fastedge" -version = "0.2.0" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43795490d6e81dd5dc0c9bf5c9d442e0aba1af2de5118fe6e5b0d3beb69cccbe" +checksum = "f9042fccaffdd2171e8ff481e5c21d22f15b8a4454b37273c2f3f902fb3d375e" dependencies = [ "bytes", "fastedge-derive", "http", "mime", "thiserror", - "tracing", "wit-bindgen", ] [[package]] name = "fastedge-derive" -version = "0.2.1" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09bb5f756c87c178d7a6c596eb3848df367cbdce8998a726363b13091655e2cf" +checksum = "acacf180f92cbdf6f2fe1a772b7d92301e430ba207fb15b2fc87ccab4e418ff9" dependencies = [ "proc-macro2", "quote", "syn", ] +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + [[package]] name = "foldhash" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" +[[package]] +name = "futures" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b147ee9d1f6d097cef9ce628cd2ee62288d963e16fb287bd9286455b241382d" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" + +[[package]] +name = "futures-executor" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf29c38818342a3b26b5b923639e7b1f4a61fc5e76102d4b1981c6dc7a7579d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cecba35d7ad927e23624b22ad55235f2239cfa44fd10428eecbeba6d6a717718" + +[[package]] +name = "futures-macro" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e835b70203e41293343137df5c0664546da5745f82ec9b84d40be8336958447b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c39754e157331b013978ec91992bde1ac089843443c49cbc7f46150b0fad0893" + +[[package]] +name = "futures-task" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393" + +[[package]] +name = "futures-util" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "slab", +] + [[package]] name = "hashbrown" -version = "0.14.5" +version = "0.15.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" dependencies = [ - "ahash", + "foldhash 0.1.5", ] [[package]] @@ -107,7 +182,7 @@ checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" dependencies = [ "allocator-api2", "equivalent", - "foldhash", + "foldhash 0.2.0", ] [[package]] @@ -157,10 +232,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" [[package]] -name = "leb128" -version = "0.2.5" +name = "leb128fmt" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" +checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" [[package]] name = "log" @@ -279,19 +354,10 @@ dependencies = [ ] [[package]] -name = "smallvec" -version = "1.15.1" +name = "slab" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" - -[[package]] -name = "spdx" -version = "0.10.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3e17e880bafaeb362a7b751ec46bdc5b61445a188f80e0606e68167cd540fa3" -dependencies = [ - "smallvec", -] +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" [[package]] name = "syn" @@ -306,55 +372,24 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.69" +version = "2.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.69" +version = "2.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" dependencies = [ "proc-macro2", "quote", "syn", ] -[[package]] -name = "tracing" -version = "0.1.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" -dependencies = [ - "pin-project-lite", - "tracing-attributes", - "tracing-core", -] - -[[package]] -name = "tracing-attributes" -version = "0.1.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tracing-core" -version = "0.1.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" -dependencies = [ - "once_cell", -] - [[package]] name = "unicode-ident" version = "1.0.24" @@ -367,86 +402,68 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - [[package]] name = "wasm-encoder" -version = "0.215.0" +version = "0.239.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb56df3e06b8e6b77e37d2969a50ba51281029a9aeb3855e76b7f49b6418847" +checksum = "5be00faa2b4950c76fe618c409d2c3ea5a3c9422013e079482d78544bb2d184c" dependencies = [ - "leb128", + "leb128fmt", "wasmparser", ] [[package]] name = "wasm-metadata" -version = "0.215.0" +version = "0.239.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c6bb07c5576b608f7a2a9baa2294c1a3584a249965d695a9814a496cb6d232f" +checksum = "20b3ec880a9ac69ccd92fbdbcf46ee833071cf09f82bb005b2327c7ae6025ae2" dependencies = [ "anyhow", "indexmap", - "serde", - "serde_derive", - "serde_json", - "spdx", "wasm-encoder", "wasmparser", ] [[package]] name = "wasmparser" -version = "0.215.0" +version = "0.239.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53fbde0881f24199b81cf49b6ff8f9c145ac8eb1b7fc439adb5c099734f7d90e" +checksum = "8c9d90bb93e764f6beabf1d02028c70a2156a6583e63ac4218dd07ef733368b0" dependencies = [ - "ahash", "bitflags", - "hashbrown 0.14.5", + "hashbrown 0.15.5", "indexmap", "semver", ] [[package]] name = "wit-bindgen" -version = "0.30.0" +version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b4bac478334a647374ff24a74b66737a4cb586dc8288bc3080a93252cd1105c" +checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" dependencies = [ - "wit-bindgen-rt", + "bitflags", + "futures", + "once_cell", "wit-bindgen-rust-macro", ] [[package]] name = "wit-bindgen-core" -version = "0.30.0" +version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb7e3df01cd43cfa1cb52602e4fc05cb2b62217655f6705639b6953eb0a3fed2" +checksum = "cabd629f94da277abc739c71353397046401518efb2c707669f805205f0b9890" dependencies = [ "anyhow", "heck", "wit-parser", ] -[[package]] -name = "wit-bindgen-rt" -version = "0.30.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2de7a3b06b9725d129b5cbd1beca968feed919c433305a23da46843185ecdd6" -dependencies = [ - "bitflags", -] - [[package]] name = "wit-bindgen-rust" -version = "0.30.0" +version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61a767d1a8eb4e908bfc53febc48b87ada545703b16fe0148ee7736a29a01417" +checksum = "9a4232e841089fa5f3c4fc732a92e1c74e1a3958db3b12f1de5934da2027f1f4" dependencies = [ "anyhow", "heck", @@ -460,9 +477,9 @@ dependencies = [ [[package]] name = "wit-bindgen-rust-macro" -version = "0.30.0" +version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b185c342d0d27bd83d4080f5a66cf3b4f247fa49d679bceb66e11cc7eb58b99" +checksum = "1e0d4698c2913d8d9c2b220d116409c3f51a7aa8d7765151b886918367179ee9" dependencies = [ "anyhow", "prettyplease", @@ -475,9 +492,9 @@ dependencies = [ [[package]] name = "wit-component" -version = "0.215.0" +version = "0.239.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f725e3885fc5890648be5c5cbc1353b755dc932aa5f1aa7de968b912a3280743" +checksum = "88a866b19dba2c94d706ec58c92a4c62ab63e482b4c935d2a085ac94caecb136" dependencies = [ "anyhow", "bitflags", @@ -494,9 +511,9 @@ dependencies = [ [[package]] name = "wit-parser" -version = "0.215.0" +version = "0.239.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "935a97eaffd57c3b413aa510f8f0b550a4a9fe7d59e79cd8b89a83dcb860321f" +checksum = "55c92c939d667b7bf0c6bf2d1f67196529758f99a2a45a3355cc56964fd5315d" dependencies = [ "anyhow", "id-arena", @@ -510,26 +527,6 @@ dependencies = [ "wasmparser", ] -[[package]] -name = "zerocopy" -version = "0.8.48" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eed437bf9d6692032087e337407a86f04cd8d6a16a37199ed57949d415bd68e9" -dependencies = [ - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.8.48" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70e3cd084b1788766f53af483dd21f93881ff30d7320490ec3ef7526d203bad4" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "zmij" version = "1.0.21" diff --git a/examples/cdn/key_value/src/lib.rs b/examples/cdn/key_value/src/lib.rs index 0a5bac4..5d2203a 100644 --- a/examples/cdn/key_value/src/lib.rs +++ b/examples/cdn/key_value/src/lib.rs @@ -104,9 +104,7 @@ impl HttpContext for KvStoreContext { } }; - if let Err(e) = self.set_http_response_body(0, body_size, body.as_bytes()) { - proxy_wasm::hostcalls::log(LogLevel::Error, &format!("failed to set body: {:?}", e)).ok(); - } + self.set_http_response_body(0, body_size, body.as_bytes()); Action::Continue } @@ -231,6 +229,6 @@ impl KvStoreContext { Some(b"500"), ); let error_body = json!({"error": msg}).to_string(); - self.set_http_response_body(0, body_size, error_body.as_bytes()).ok(); + self.set_http_response_body(0, body_size, error_body.as_bytes()); } }