From 8cfcd34fa4accb4ec07c8a701f03d982cce4ef18 Mon Sep 17 00:00:00 2001 From: Jiaxiao Zhou Date: Tue, 14 Mar 2023 08:28:02 -0700 Subject: [PATCH 1/2] Remove restaurant-backend and updated CI to build examples Signed-off-by: Jiaxiao Zhou --- .github/workflows/ci.yaml | 6 + Cargo.lock | 8 +- examples/app-demos/README.md | 32 --- .../app-demos/restaurant-backend/Cargo.lock | 236 ------------------ .../app-demos/restaurant-backend/Cargo.toml | 17 -- .../restaurant-backend/slightfile.toml | 11 - .../app-demos/restaurant-backend/src/main.rs | 47 ---- 7 files changed, 10 insertions(+), 347 deletions(-) delete mode 100644 examples/app-demos/README.md delete mode 100644 examples/app-demos/restaurant-backend/Cargo.lock delete mode 100644 examples/app-demos/restaurant-backend/Cargo.toml delete mode 100644 examples/app-demos/restaurant-backend/slightfile.toml delete mode 100644 examples/app-demos/restaurant-backend/src/main.rs diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 04fb038a..5bb879d6 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -123,6 +123,12 @@ jobs: OPENSSL_DIR: C:\Program Files\OpenSSL-Win64\ OPENSSL_NO_VENDOR: true + # + # Build Examples + # + - name: "Build Examples" + run: make build-rust + # # Run Unit Tests # diff --git a/Cargo.lock b/Cargo.lock index 19006555..3768f953 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -943,9 +943,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.1.8" +version = "4.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d7ae14b20b94cb02149ed21a86c423859cbe18dc7ed69845cace50e52b40a5" +checksum = "a7db700bc935f9e43e88d00b0850dae18a63773cfbec6d8e070fccf7fef89a39" dependencies = [ "bitflags", "clap_derive", @@ -958,9 +958,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.1.8" +version = "4.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44bec8e5c9d09e439c4335b1af0abaab56dcf3b94999a936e1bb47b9134288f0" +checksum = "0177313f9f02afc995627906bbd8967e2be069f5261954222dac78290c2b9014" dependencies = [ "heck 0.4.1", "proc-macro-error", diff --git a/examples/app-demos/README.md b/examples/app-demos/README.md deleted file mode 100644 index 6a33d52a..00000000 --- a/examples/app-demos/README.md +++ /dev/null @@ -1,32 +0,0 @@ -# `app-demos` - -This folder contains a list of more full-fledged examples (i.e., app demos) utilizing SpiderLightning/`slight`. - -## `restaurant-backend` - -`restaurant-backend` is a `slight` app that simulates the operation of a restaurant, where people can order food through a HTTP `POST` request to the `/orders/` route, and a chef can get the next order to prepare through a HTTP `GET` request to the `/orders/next/` route. - -Assuming you've got the latest version of `slight` compiled (i.e., by having ran `make build`), from the root of the repository, run `make build-app-demos` to compile all app demos. After that, run `make run-restaurant-backend` to start the HTTP server that will listen to requests — you should see something like so: - -![](https://i.imgur.com/4etNeMm.png) - -Next up, you can test this service with `curl`. Let's make a HTTP `POST` request like so: -```shell -curl http://localhost:3000/orders/ -d burger -``` - -Looking back on the server output, you should see: -![](https://i.imgur.com/rkadRSp.png) - -To finish off, let's make a HTTP `GET` request to receive that burger order: -```shell -curl http://localhost:3000/orders/next -``` - -On your shell, you should see: -```shell -burger -``` - -On the server output, you should see: -![](https://i.imgur.com/OcZlrsD.png) \ No newline at end of file diff --git a/examples/app-demos/restaurant-backend/Cargo.lock b/examples/app-demos/restaurant-backend/Cargo.lock deleted file mode 100644 index 8c599904..00000000 --- a/examples/app-demos/restaurant-backend/Cargo.lock +++ /dev/null @@ -1,236 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "anyhow" -version = "1.0.62" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1485d4d2cc45e7b201ee3767015c96faa5904387c9d87c6efdd0fb511f12d305" - -[[package]] -name = "async-trait" -version = "0.1.57" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76464446b8bc32758d7e88ee1a804d9914cd9b1cb264c029899680b0be29826f" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "heck" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" -dependencies = [ - "unicode-segmentation", -] - -[[package]] -name = "id-arena" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" - -[[package]] -name = "memchr" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" - -[[package]] -name = "proc-macro2" -version = "1.0.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "pulldown-cmark" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffade02495f22453cd593159ea2f59827aae7f53fa8323f756799b670881dcf8" -dependencies = [ - "bitflags", - "memchr", - "unicase", -] - -[[package]] -name = "quote" -version = "1.0.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "restaurant-backend" -version = "0.1.0" -dependencies = [ - "anyhow", - "slight-http-handler-macro", - "wit-bindgen-rust", - "wit-error-rs", -] - -[[package]] -name = "slight-http-handler-macro" -version = "0.1.0" -dependencies = [ - "anyhow", - "proc-macro2", - "quote", - "syn", - "wit-bindgen-gen-core", - "wit-bindgen-gen-rust-wasm", -] - -[[package]] -name = "syn" -version = "1.0.99" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tinyvec" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" -dependencies = [ - "tinyvec_macros", -] - -[[package]] -name = "tinyvec_macros" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" - -[[package]] -name = "unicase" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" -dependencies = [ - "version_check", -] - -[[package]] -name = "unicode-ident" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" - -[[package]] -name = "unicode-normalization" -version = "0.1.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "854cbdc4f7bc6ae19c820d44abdc3277ac3e1b2b93db20a636825d9322fb60e6" -dependencies = [ - "tinyvec", -] - -[[package]] -name = "unicode-segmentation" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99" - -[[package]] -name = "unicode-xid" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wit-bindgen-gen-core" -version = "0.2.0" -source = "git+https://github.com/bytecodealliance/wit-bindgen?tag=v0.2.0#cb871cfa1ee460b51eb1d144b175b9aab9c50aba" -dependencies = [ - "anyhow", - "wit-parser", -] - -[[package]] -name = "wit-bindgen-gen-rust" -version = "0.2.0" -source = "git+https://github.com/bytecodealliance/wit-bindgen?tag=v0.2.0#cb871cfa1ee460b51eb1d144b175b9aab9c50aba" -dependencies = [ - "heck", - "wit-bindgen-gen-core", -] - -[[package]] -name = "wit-bindgen-gen-rust-wasm" -version = "0.2.0" -source = "git+https://github.com/bytecodealliance/wit-bindgen?tag=v0.2.0#cb871cfa1ee460b51eb1d144b175b9aab9c50aba" -dependencies = [ - "heck", - "wit-bindgen-gen-core", - "wit-bindgen-gen-rust", -] - -[[package]] -name = "wit-bindgen-rust" -version = "0.2.0" -source = "git+https://github.com/bytecodealliance/wit-bindgen?tag=v0.2.0#cb871cfa1ee460b51eb1d144b175b9aab9c50aba" -dependencies = [ - "async-trait", - "bitflags", - "wit-bindgen-rust-impl", -] - -[[package]] -name = "wit-bindgen-rust-impl" -version = "0.2.0" -source = "git+https://github.com/bytecodealliance/wit-bindgen?tag=v0.2.0#cb871cfa1ee460b51eb1d144b175b9aab9c50aba" -dependencies = [ - "proc-macro2", - "syn", - "wit-bindgen-gen-core", - "wit-bindgen-gen-rust-wasm", -] - -[[package]] -name = "wit-error-rs" -version = "0.1.0" -source = "git+https://github.com/danbugs/wit-error-rs?rev=05362f1a4a3a9dc6a1de39195e06d2d5d6491a5e#05362f1a4a3a9dc6a1de39195e06d2d5d6491a5e" -dependencies = [ - "quote", - "syn", -] - -[[package]] -name = "wit-parser" -version = "0.2.0" -source = "git+https://github.com/bytecodealliance/wit-bindgen?tag=v0.2.0#cb871cfa1ee460b51eb1d144b175b9aab9c50aba" -dependencies = [ - "anyhow", - "id-arena", - "pulldown-cmark", - "unicode-normalization", - "unicode-xid", -] diff --git a/examples/app-demos/restaurant-backend/Cargo.toml b/examples/app-demos/restaurant-backend/Cargo.toml deleted file mode 100644 index 4dcb60e0..00000000 --- a/examples/app-demos/restaurant-backend/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "restaurant-backend" -version = "0.1.0" -edition = "2021" -authors = ["DeisLabs Engineering Team"] - -[[bin]] -name = "restaurant-backend" -test = false - -[dependencies] -wit-bindgen-rust = { git = "https://github.com/fermyon/wit-bindgen-backport" } -wit-error-rs = { git = "https://github.com/danbugs/wit-error-rs", rev = "05362f1a4a3a9dc6a1de39195e06d2d5d6491a5e" } -slight-http-handler-macro = { path = "../../../crates/http-handler-macro" } -anyhow = "1" - -[workspace] diff --git a/examples/app-demos/restaurant-backend/slightfile.toml b/examples/app-demos/restaurant-backend/slightfile.toml deleted file mode 100644 index ea631d74..00000000 --- a/examples/app-demos/restaurant-backend/slightfile.toml +++ /dev/null @@ -1,11 +0,0 @@ -specversion = "0.2" - -[[capability]] -resource = "http" -name = "my-rest-api" - # This capability does not require any configs - -[[capability]] -resource = "mq.filesystem" -name = "slight-restaurant" - # This capability does not require any configs \ No newline at end of file diff --git a/examples/app-demos/restaurant-backend/src/main.rs b/examples/app-demos/restaurant-backend/src/main.rs deleted file mode 100644 index a3e9e977..00000000 --- a/examples/app-demos/restaurant-backend/src/main.rs +++ /dev/null @@ -1,47 +0,0 @@ -use anyhow::Result; - -use slight_http_handler_macro::register_handler; - -wit_bindgen_rust::import!("../../../wit/http-server.wit"); -wit_error_rs::impl_error!(http_server::Error); - -wit_bindgen_rust::import!("../../../wit/mq.wit"); -wit_error_rs::impl_error!(mq::Error); - -fn main() -> Result<()> { - let router = http_server::Router::new()?; - let router_with_route = router - .post("/orders/", "handle_make_order")? - .get("/orders/next/", "handle_get_next_order")?; - let _ = http_server::Server::serve("0.0.0.0:3000", &router_with_route)?; - Ok(()) -} - -#[register_handler] -fn handle_make_order(req: Request) -> Result { - let mq = crate::mq::Mq::open("slight-restaurant").expect("failed to open message queue"); - mq.send(&req.body.as_ref().unwrap()) - .expect("failed to make order"); - Ok(Response { - headers: Some(req.headers), - body: None, - status: 200, - }) -} - -#[register_handler] -fn handle_get_next_order(req: Request) -> Result { - let mq = crate::mq::Mq::open("slight-restaurant").expect("failed to open message queue"); - Ok(Response { - headers: Some(req.headers), - body: Some(mq.receive().expect("failed to get next order")), - status: 200, - }) -} - -#[register_handler] -fn handle_http(_req: Request) -> Result { - Err(Error::ErrorWithDescription( - "this is a dummy handler".to_string(), - )) -} From c80aca97ccf8317e8aadd4cb1d52cc1e026d29f2 Mon Sep 17 00:00:00 2001 From: David Justice Date: Wed, 15 Mar 2023 11:55:34 -0400 Subject: [PATCH 2/2] fix lint issues by upgrading clap Signed-off-by: David Justice --- Cargo.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3768f953..19006555 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -943,9 +943,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.0.32" +version = "4.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7db700bc935f9e43e88d00b0850dae18a63773cfbec6d8e070fccf7fef89a39" +checksum = "c3d7ae14b20b94cb02149ed21a86c423859cbe18dc7ed69845cace50e52b40a5" dependencies = [ "bitflags", "clap_derive", @@ -958,9 +958,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.0.21" +version = "4.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0177313f9f02afc995627906bbd8967e2be069f5261954222dac78290c2b9014" +checksum = "44bec8e5c9d09e439c4335b1af0abaab56dcf3b94999a936e1bb47b9134288f0" dependencies = [ "heck 0.4.1", "proc-macro-error",