From 78f84e7fc8f19c3a516de2395a399332b6889d67 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Wed, 21 Feb 2024 16:52:54 -0700 Subject: [PATCH] move Rust and Go SDKs to their own repos (#2289) * move Rust and Go SDKs to their own repos These SDKs and their examples have moved to https://github.com/fermyon/spin-rust-sdk and https://github.com/fermyon/spin-go-sdk, respectively. The plan is to begin releasing them on their own cadence, independent of Spin releases. This will allow us to make breaking changes in semver-compatible major releases without tying such releases to a Spin major release, e.g. to target WASI 0.2.0. Note that I've update the integration tests which use the Rust SDK to use the latest stable release (2.2.0) instead of a path-based dependency. Alternatively, we could point it at the `main` branch of the `spin-rust-sdk` Git repo, but that will require close coordination once we start making breaking changes to the API in that repo. We may also want to move the Rust and Go templates to the new repos at some point. I've left them where they are for the time being. Finally, I've removed the SDK-specific bits from release-process.md and the GitHub workflows. We'll need to move those things to their respective SDK repos. Reproducing the automated Go SDK tagging that feeds into the templates may require moving at least the Go templates as noted above. Signed-off-by: Joel Dice * restore accidentally-removed lines from release-process.md Signed-off-by: Joel Dice * update SDK examples links to point to `stable` branches We'll update the `stable` branch of the applicable repo each time we make a new stable release of any of the SDKs so that these links always point to the examples for the latest stable release rather than `main`. Signed-off-by: Joel Dice * re-add (updated version of) `push-templates-tag` to release.yml Unlike the original version, this one does not depend on the Go SDK automation and instead derives the template tag name from the Spin version tag name. Signed-off-by: Joel Dice * re-add `build-and-sign` as dependency of `push-templates-tag` This ensures that we don't tag a broken build. Signed-off-by: Joel Dice --------- Signed-off-by: Joel Dice --- .github/gh-checktags.sh | 7 - .github/workflows/build.yml | 30 - .github/workflows/check-tags.yml | 2 +- .github/workflows/release.yml | 91 +- Cargo.lock | 132 --- Cargo.toml | 2 - Makefile | 8 +- docs/content/release-process.md | 31 +- examples/README.md | 13 + .../http-hello/.cargo/config.toml | 2 - .../http-hello/.gitignore | 1 - .../http-hello/Cargo.lock | 586 ------------- .../http-hello/Cargo.toml | 16 - .../http-hello/src/lib.rs | 10 - .../.cargo/config.toml | 2 - .../outbound-http-to-same-app/Cargo.lock | 585 ------------- .../outbound-http-to-same-app/Cargo.toml | 13 - .../outbound-http-to-same-app/src/lib.rs | 17 - .../outbound-http/.cargo/config.toml | 2 - .../outbound-http/Cargo.lock | 585 ------------- .../outbound-http/Cargo.toml | 13 - .../outbound-http/src/lib.rs | 20 - examples/http-rust-outbound-http/spin.toml | 53 -- .../http-rust-router-macro/.cargo/config.toml | 2 - examples/http-rust-router-macro/.gitignore | 1 - examples/http-rust-router-macro/Cargo.lock | 585 ------------- examples/http-rust-router-macro/Cargo.toml | 15 - examples/http-rust-router-macro/spin.toml | 18 - examples/http-rust-router-macro/src/lib.rs | 28 - examples/http-rust-router/.cargo/config.toml | 2 - examples/http-rust-router/.gitignore | 1 - examples/http-rust-router/Cargo.lock | 585 ------------- examples/http-rust-router/Cargo.toml | 14 - examples/http-rust-router/spin.toml | 18 - examples/http-rust-router/src/lib.rs | 37 - examples/http-rust/Cargo.lock | 8 +- examples/http-rust/Cargo.toml | 2 +- examples/http-tinygo-outbound-http/README.md | 88 -- .../outbound-http-to-same-app/go.mod | 9 - .../outbound-http-to-same-app/go.sum | 2 - .../outbound-http-to-same-app/main.go | 25 - examples/http-tinygo-outbound-http/spin.toml | 33 - .../tinygo-hello/go.mod | 9 - .../tinygo-hello/go.sum | 2 - .../tinygo-hello/main.go | 52 -- examples/http-tinygo-router/README.md | 24 - examples/http-tinygo-router/go.mod | 9 - examples/http-tinygo-router/go.sum | 2 - examples/http-tinygo-router/main.go | 28 - examples/http-tinygo-router/spin.toml | 16 - examples/http-tinygo/README.md | 35 - examples/http-tinygo/go.mod | 9 - examples/http-tinygo/go.sum | 2 - examples/http-tinygo/main.go | 36 - examples/http-tinygo/spin.toml | 16 - examples/json-http-rust/.cargo/config.toml | 2 - examples/json-http-rust/.gitignore | 1 - examples/json-http-rust/Cargo.lock | 587 ------------- examples/json-http-rust/Cargo.toml | 15 - examples/json-http-rust/README.md | 9 - examples/json-http-rust/spin.toml | 18 - examples/json-http-rust/src/lib.rs | 13 - examples/redis-rust/.cargo/config.toml | 2 - examples/redis-rust/Cargo.lock | 586 ------------- examples/redis-rust/Cargo.toml | 16 - examples/redis-rust/spin.toml | 19 - examples/redis-rust/src/lib.rs | 11 - examples/rust-key-value/.cargo/config.toml | 2 - examples/rust-key-value/Cargo.lock | 586 ------------- examples/rust-key-value/Cargo.toml | 14 - examples/rust-key-value/README.md | 31 - examples/rust-key-value/spin.toml | 17 - examples/rust-key-value/src/lib.rs | 44 - .../rust-outbound-mysql/.cargo/config.toml | 2 - examples/rust-outbound-mysql/.gitignore | 1 - examples/rust-outbound-mysql/Cargo.lock | 588 ------------- examples/rust-outbound-mysql/Cargo.toml | 21 - examples/rust-outbound-mysql/db/pets.sql | 4 - examples/rust-outbound-mysql/spin.toml | 18 - examples/rust-outbound-mysql/src/lib.rs | 188 ----- examples/rust-outbound-mysql/src/model.rs | 27 - examples/rust-outbound-pg/.cargo/config.toml | 2 - examples/rust-outbound-pg/Cargo.lock | 586 ------------- examples/rust-outbound-pg/Cargo.toml | 17 - examples/rust-outbound-pg/README.md | 49 -- examples/rust-outbound-pg/db/testdata.sql | 19 - examples/rust-outbound-pg/spin.toml | 17 - examples/rust-outbound-pg/src/lib.rs | 128 --- .../rust-outbound-redis/.cargo/config.toml | 2 - examples/rust-outbound-redis/Cargo.lock | 585 ------------- examples/rust-outbound-redis/Cargo.toml | 15 - examples/rust-outbound-redis/spin.toml | 17 - examples/rust-outbound-redis/src/lib.rs | 51 -- examples/spin-wagi-http/http-rust/Cargo.lock | 8 +- examples/spin-wagi-http/http-rust/Cargo.toml | 2 +- examples/tinygo-key-value/README.md | 36 - examples/tinygo-key-value/go.mod | 9 - examples/tinygo-key-value/go.sum | 2 - examples/tinygo-key-value/main.go | 71 -- examples/tinygo-key-value/spin.toml | 16 - examples/tinygo-llm/.gitignore | 2 - examples/tinygo-llm/go.mod | 9 - examples/tinygo-llm/go.sum | 4 - examples/tinygo-llm/main.go | 34 - examples/tinygo-llm/spin.toml | 19 - examples/tinygo-outbound-mysql/.gitignore | 2 - examples/tinygo-outbound-mysql/db/pets.sql | 4 - examples/tinygo-outbound-mysql/go.mod | 9 - examples/tinygo-outbound-mysql/go.sum | 4 - examples/tinygo-outbound-mysql/main.go | 54 -- examples/tinygo-outbound-mysql/spin.toml | 19 - examples/tinygo-outbound-pg/db/pets.sql | 4 - examples/tinygo-outbound-pg/go.mod | 9 - examples/tinygo-outbound-pg/go.sum | 4 - examples/tinygo-outbound-pg/main.go | 54 -- examples/tinygo-outbound-pg/spin.toml | 19 - examples/tinygo-outbound-redis/README.md | 19 - examples/tinygo-outbound-redis/go.mod | 9 - examples/tinygo-outbound-redis/go.sum | 2 - examples/tinygo-outbound-redis/main.go | 149 ---- examples/tinygo-outbound-redis/spin.toml | 17 - examples/tinygo-redis/README.md | 11 - examples/tinygo-redis/go.mod | 9 - examples/tinygo-redis/go.sum | 1 - examples/tinygo-redis/main.go | 19 - examples/tinygo-redis/spin.toml | 19 - examples/tinygo-sqlite/.gitignore | 2 - examples/tinygo-sqlite/db/pets.sql | 4 - examples/tinygo-sqlite/go.mod | 9 - examples/tinygo-sqlite/go.sum | 4 - examples/tinygo-sqlite/main.go | 48 -- examples/tinygo-sqlite/spin.toml | 19 - examples/variables-rust/.cargo/config.toml | 2 - examples/variables-rust/.env | 1 - examples/variables-rust/.gitignore | 1 - examples/variables-rust/Cargo.lock | 585 ------------- examples/variables-rust/Cargo.toml | 14 - examples/variables-rust/spin.toml | 23 - examples/variables-rust/src/lib.rs | 15 - examples/variables-tinygo/README.md | 17 - examples/variables-tinygo/go.mod | 9 - examples/variables-tinygo/go.sum | 2 - examples/variables-tinygo/main.go | 24 - examples/variables-tinygo/spin.toml | 21 - examples/vault-variable-test/Cargo.lock | 8 +- examples/vault-variable-test/Cargo.toml | 2 +- .../.cargo/config.toml | 2 - .../.gitignore | 1 - .../Cargo.lock | 723 ---------------- .../Cargo.toml | 17 - .../spin.toml | 18 - .../src/lib.rs | 123 --- .../.cargo/config.toml | 2 - examples/wasi-http-streaming-file/.gitignore | 1 - examples/wasi-http-streaming-file/Cargo.lock | 723 ---------------- examples/wasi-http-streaming-file/Cargo.toml | 17 - examples/wasi-http-streaming-file/spin.toml | 18 - examples/wasi-http-streaming-file/src/lib.rs | 44 - sdk/go/.gitignore | 1 - sdk/go/Makefile | 129 --- sdk/go/go.mod | 5 - sdk/go/go.sum | 2 - sdk/go/http/http.go | 116 --- sdk/go/http/internals.go | 140 ---- sdk/go/http/outbound_internals.go | 196 ----- sdk/go/http/response.go | 39 - sdk/go/http/spin-http.c | 141 ---- sdk/go/http/spin-http.h | 85 -- sdk/go/http/testdata/http-tinygo/Makefile | 3 - sdk/go/http/testdata/http-tinygo/main.go | 29 - sdk/go/http/testdata/http-tinygo/spin.toml | 14 - sdk/go/http/testdata/spin-roundtrip/Makefile | 3 - sdk/go/http/testdata/spin-roundtrip/main.go | 32 - sdk/go/http/testdata/spin-roundtrip/spin.toml | 15 - sdk/go/http/wasi-outbound-http.c | 166 ---- sdk/go/http/wasi-outbound-http.h | 85 -- sdk/go/integration_test.go | 170 ---- sdk/go/internal/db/driver.go | 17 - sdk/go/kv/key-value.c | 367 --------- sdk/go/kv/key-value.h | 92 --- sdk/go/kv/kv.go | 148 ---- sdk/go/llm/internals.go | 131 --- sdk/go/llm/llm.c | 213 ----- sdk/go/llm/llm.go | 70 -- sdk/go/llm/llm.h | 107 --- sdk/go/mysql/internals.go | 325 -------- sdk/go/mysql/mysql.go | 173 ---- sdk/go/mysql/outbound-mysql.c | 243 ------ sdk/go/mysql/outbound-mysql.h | 181 ---- sdk/go/pg/internals.go | 325 -------- sdk/go/pg/outbound-pg.c | 243 ------ sdk/go/pg/outbound-pg.h | 174 ---- sdk/go/pg/pg.go | 175 ---- sdk/go/readme.md | 21 - sdk/go/redis/internals.go | 241 ------ sdk/go/redis/internals_test.go | 40 - sdk/go/redis/outbound-redis.c | 320 ------- sdk/go/redis/outbound-redis.h | 77 -- sdk/go/redis/redis.go | 139 ---- sdk/go/redis/spin-redis.c | 105 --- sdk/go/redis/spin-redis.h | 54 -- sdk/go/sdk_version/sdk-version-go-template.c | 14 - sdk/go/sqlite/doc.go | 27 - sdk/go/sqlite/internals.go | 169 ---- sdk/go/sqlite/internals_test.go | 38 - sdk/go/sqlite/sqlite.c | 200 ----- sdk/go/sqlite/sqlite.go | 186 ----- sdk/go/sqlite/sqlite.h | 98 --- sdk/go/variables/internals.go | 42 - sdk/go/variables/spin-config.c | 117 --- sdk/go/variables/spin-config.h | 45 - sdk/go/variables/variables.go | 8 - sdk/go/wit/http-types.wit | 59 -- sdk/go/wit/key-value.wit | 78 -- sdk/go/wit/mysql-types.wit | 10 - sdk/go/wit/outbound-mysql.wit | 8 - sdk/go/wit/outbound-pg.wit | 8 - sdk/go/wit/outbound-redis.wit | 29 - sdk/go/wit/pg-types.wit | 9 - sdk/go/wit/rdbms-types.wit | 63 -- sdk/go/wit/redis-types.wit | 22 - sdk/go/wit/spin-config.wit | 10 - sdk/go/wit/spin-http.wit | 4 - sdk/go/wit/spin-redis.wit | 4 - sdk/go/wit/sqlite.wit | 50 -- sdk/go/wit/wasi-outbound-http.wit | 4 - sdk/rust/Cargo.toml | 43 - sdk/rust/README.md | 112 --- sdk/rust/build.rs | 28 - sdk/rust/macro/Cargo.toml | 26 - sdk/rust/macro/README.md | 3 - sdk/rust/macro/src/lib.rs | 176 ---- .../macro/wit/deps/http/incoming-handler.wit | 24 - .../macro/wit/deps/http/outgoing-handler.wit | 20 - sdk/rust/macro/wit/deps/http/types.wit | 214 ----- sdk/rust/macro/wit/deps/http/world.wit | 1 - sdk/rust/macro/wit/deps/io/poll.wit | 32 - sdk/rust/macro/wit/deps/io/streams.wit | 287 ------- sdk/rust/macro/wit/deps/io/world.wit | 1 - sdk/rust/macro/wit/inbound-redis.wit | 6 - sdk/rust/macro/wit/redis-types.wit | 24 - sdk/rust/macro/wit/world.wit | 10 - sdk/rust/src/bin/version.rs | 3 - sdk/rust/src/http.rs | 778 ------------------ sdk/rust/src/http/conversions.rs | 663 --------------- sdk/rust/src/http/executor.rs | 220 ----- sdk/rust/src/http/router.rs | 585 ------------- sdk/rust/src/key_value.rs | 46 -- sdk/rust/src/lib.rs | 97 --- sdk/rust/src/llm.rs | 77 -- sdk/rust/src/mysql.rs | 280 ------- sdk/rust/src/pg.rs | 196 ----- sdk/rust/src/sqlite.rs | 105 --- sdk/rust/wit | 1 - templates/http-rust/content/Cargo.toml | 2 +- templates/redis-rust/content/Cargo.toml | 2 +- tests/test-components/components/Cargo.lock | 8 +- .../components/headers-dynamic-env/Cargo.toml | 2 +- .../components/hello-world/Cargo.toml | 2 +- .../integration-http-outbound-post/Cargo.toml | 2 +- .../components/integration-simple/Cargo.toml | 2 +- .../integration-variables/Cargo.toml | 2 +- .../Cargo.toml | 2 +- .../components/key-value-simple/Cargo.toml | 2 +- .../components/outbound-http/Cargo.toml | 2 +- .../components/redis-smoke-test/Cargo.toml | 2 +- 266 files changed, 57 insertions(+), 22077 deletions(-) create mode 100644 examples/README.md delete mode 100644 examples/http-rust-outbound-http/http-hello/.cargo/config.toml delete mode 100644 examples/http-rust-outbound-http/http-hello/.gitignore delete mode 100644 examples/http-rust-outbound-http/http-hello/Cargo.lock delete mode 100644 examples/http-rust-outbound-http/http-hello/Cargo.toml delete mode 100644 examples/http-rust-outbound-http/http-hello/src/lib.rs delete mode 100644 examples/http-rust-outbound-http/outbound-http-to-same-app/.cargo/config.toml delete mode 100644 examples/http-rust-outbound-http/outbound-http-to-same-app/Cargo.lock delete mode 100644 examples/http-rust-outbound-http/outbound-http-to-same-app/Cargo.toml delete mode 100644 examples/http-rust-outbound-http/outbound-http-to-same-app/src/lib.rs delete mode 100644 examples/http-rust-outbound-http/outbound-http/.cargo/config.toml delete mode 100644 examples/http-rust-outbound-http/outbound-http/Cargo.lock delete mode 100644 examples/http-rust-outbound-http/outbound-http/Cargo.toml delete mode 100644 examples/http-rust-outbound-http/outbound-http/src/lib.rs delete mode 100644 examples/http-rust-outbound-http/spin.toml delete mode 100644 examples/http-rust-router-macro/.cargo/config.toml delete mode 100644 examples/http-rust-router-macro/.gitignore delete mode 100644 examples/http-rust-router-macro/Cargo.lock delete mode 100644 examples/http-rust-router-macro/Cargo.toml delete mode 100644 examples/http-rust-router-macro/spin.toml delete mode 100644 examples/http-rust-router-macro/src/lib.rs delete mode 100644 examples/http-rust-router/.cargo/config.toml delete mode 100644 examples/http-rust-router/.gitignore delete mode 100644 examples/http-rust-router/Cargo.lock delete mode 100644 examples/http-rust-router/Cargo.toml delete mode 100644 examples/http-rust-router/spin.toml delete mode 100644 examples/http-rust-router/src/lib.rs delete mode 100644 examples/http-tinygo-outbound-http/README.md delete mode 100644 examples/http-tinygo-outbound-http/outbound-http-to-same-app/go.mod delete mode 100644 examples/http-tinygo-outbound-http/outbound-http-to-same-app/go.sum delete mode 100644 examples/http-tinygo-outbound-http/outbound-http-to-same-app/main.go delete mode 100644 examples/http-tinygo-outbound-http/spin.toml delete mode 100644 examples/http-tinygo-outbound-http/tinygo-hello/go.mod delete mode 100644 examples/http-tinygo-outbound-http/tinygo-hello/go.sum delete mode 100644 examples/http-tinygo-outbound-http/tinygo-hello/main.go delete mode 100644 examples/http-tinygo-router/README.md delete mode 100644 examples/http-tinygo-router/go.mod delete mode 100644 examples/http-tinygo-router/go.sum delete mode 100644 examples/http-tinygo-router/main.go delete mode 100644 examples/http-tinygo-router/spin.toml delete mode 100644 examples/http-tinygo/README.md delete mode 100644 examples/http-tinygo/go.mod delete mode 100644 examples/http-tinygo/go.sum delete mode 100644 examples/http-tinygo/main.go delete mode 100644 examples/http-tinygo/spin.toml delete mode 100644 examples/json-http-rust/.cargo/config.toml delete mode 100644 examples/json-http-rust/.gitignore delete mode 100644 examples/json-http-rust/Cargo.lock delete mode 100644 examples/json-http-rust/Cargo.toml delete mode 100644 examples/json-http-rust/README.md delete mode 100644 examples/json-http-rust/spin.toml delete mode 100644 examples/json-http-rust/src/lib.rs delete mode 100644 examples/redis-rust/.cargo/config.toml delete mode 100644 examples/redis-rust/Cargo.lock delete mode 100644 examples/redis-rust/Cargo.toml delete mode 100644 examples/redis-rust/spin.toml delete mode 100644 examples/redis-rust/src/lib.rs delete mode 100644 examples/rust-key-value/.cargo/config.toml delete mode 100644 examples/rust-key-value/Cargo.lock delete mode 100644 examples/rust-key-value/Cargo.toml delete mode 100644 examples/rust-key-value/README.md delete mode 100644 examples/rust-key-value/spin.toml delete mode 100644 examples/rust-key-value/src/lib.rs delete mode 100644 examples/rust-outbound-mysql/.cargo/config.toml delete mode 100644 examples/rust-outbound-mysql/.gitignore delete mode 100644 examples/rust-outbound-mysql/Cargo.lock delete mode 100644 examples/rust-outbound-mysql/Cargo.toml delete mode 100644 examples/rust-outbound-mysql/db/pets.sql delete mode 100644 examples/rust-outbound-mysql/spin.toml delete mode 100644 examples/rust-outbound-mysql/src/lib.rs delete mode 100644 examples/rust-outbound-mysql/src/model.rs delete mode 100644 examples/rust-outbound-pg/.cargo/config.toml delete mode 100644 examples/rust-outbound-pg/Cargo.lock delete mode 100644 examples/rust-outbound-pg/Cargo.toml delete mode 100644 examples/rust-outbound-pg/README.md delete mode 100644 examples/rust-outbound-pg/db/testdata.sql delete mode 100644 examples/rust-outbound-pg/spin.toml delete mode 100644 examples/rust-outbound-pg/src/lib.rs delete mode 100644 examples/rust-outbound-redis/.cargo/config.toml delete mode 100644 examples/rust-outbound-redis/Cargo.lock delete mode 100644 examples/rust-outbound-redis/Cargo.toml delete mode 100644 examples/rust-outbound-redis/spin.toml delete mode 100644 examples/rust-outbound-redis/src/lib.rs delete mode 100644 examples/tinygo-key-value/README.md delete mode 100644 examples/tinygo-key-value/go.mod delete mode 100644 examples/tinygo-key-value/go.sum delete mode 100644 examples/tinygo-key-value/main.go delete mode 100644 examples/tinygo-key-value/spin.toml delete mode 100644 examples/tinygo-llm/.gitignore delete mode 100644 examples/tinygo-llm/go.mod delete mode 100644 examples/tinygo-llm/go.sum delete mode 100644 examples/tinygo-llm/main.go delete mode 100644 examples/tinygo-llm/spin.toml delete mode 100644 examples/tinygo-outbound-mysql/.gitignore delete mode 100644 examples/tinygo-outbound-mysql/db/pets.sql delete mode 100644 examples/tinygo-outbound-mysql/go.mod delete mode 100644 examples/tinygo-outbound-mysql/go.sum delete mode 100644 examples/tinygo-outbound-mysql/main.go delete mode 100644 examples/tinygo-outbound-mysql/spin.toml delete mode 100644 examples/tinygo-outbound-pg/db/pets.sql delete mode 100644 examples/tinygo-outbound-pg/go.mod delete mode 100644 examples/tinygo-outbound-pg/go.sum delete mode 100644 examples/tinygo-outbound-pg/main.go delete mode 100644 examples/tinygo-outbound-pg/spin.toml delete mode 100644 examples/tinygo-outbound-redis/README.md delete mode 100644 examples/tinygo-outbound-redis/go.mod delete mode 100644 examples/tinygo-outbound-redis/go.sum delete mode 100644 examples/tinygo-outbound-redis/main.go delete mode 100644 examples/tinygo-outbound-redis/spin.toml delete mode 100644 examples/tinygo-redis/README.md delete mode 100644 examples/tinygo-redis/go.mod delete mode 100644 examples/tinygo-redis/go.sum delete mode 100644 examples/tinygo-redis/main.go delete mode 100644 examples/tinygo-redis/spin.toml delete mode 100644 examples/tinygo-sqlite/.gitignore delete mode 100644 examples/tinygo-sqlite/db/pets.sql delete mode 100644 examples/tinygo-sqlite/go.mod delete mode 100644 examples/tinygo-sqlite/go.sum delete mode 100644 examples/tinygo-sqlite/main.go delete mode 100644 examples/tinygo-sqlite/spin.toml delete mode 100644 examples/variables-rust/.cargo/config.toml delete mode 100644 examples/variables-rust/.env delete mode 100644 examples/variables-rust/.gitignore delete mode 100644 examples/variables-rust/Cargo.lock delete mode 100644 examples/variables-rust/Cargo.toml delete mode 100644 examples/variables-rust/spin.toml delete mode 100644 examples/variables-rust/src/lib.rs delete mode 100644 examples/variables-tinygo/README.md delete mode 100644 examples/variables-tinygo/go.mod delete mode 100644 examples/variables-tinygo/go.sum delete mode 100644 examples/variables-tinygo/main.go delete mode 100644 examples/variables-tinygo/spin.toml delete mode 100644 examples/wasi-http-rust-streaming-outgoing-body/.cargo/config.toml delete mode 100644 examples/wasi-http-rust-streaming-outgoing-body/.gitignore delete mode 100644 examples/wasi-http-rust-streaming-outgoing-body/Cargo.lock delete mode 100644 examples/wasi-http-rust-streaming-outgoing-body/Cargo.toml delete mode 100644 examples/wasi-http-rust-streaming-outgoing-body/spin.toml delete mode 100644 examples/wasi-http-rust-streaming-outgoing-body/src/lib.rs delete mode 100644 examples/wasi-http-streaming-file/.cargo/config.toml delete mode 100644 examples/wasi-http-streaming-file/.gitignore delete mode 100644 examples/wasi-http-streaming-file/Cargo.lock delete mode 100644 examples/wasi-http-streaming-file/Cargo.toml delete mode 100644 examples/wasi-http-streaming-file/spin.toml delete mode 100644 examples/wasi-http-streaming-file/src/lib.rs delete mode 100644 sdk/go/.gitignore delete mode 100644 sdk/go/Makefile delete mode 100644 sdk/go/go.mod delete mode 100644 sdk/go/go.sum delete mode 100644 sdk/go/http/http.go delete mode 100644 sdk/go/http/internals.go delete mode 100644 sdk/go/http/outbound_internals.go delete mode 100644 sdk/go/http/response.go delete mode 100644 sdk/go/http/spin-http.c delete mode 100644 sdk/go/http/spin-http.h delete mode 100644 sdk/go/http/testdata/http-tinygo/Makefile delete mode 100644 sdk/go/http/testdata/http-tinygo/main.go delete mode 100644 sdk/go/http/testdata/http-tinygo/spin.toml delete mode 100644 sdk/go/http/testdata/spin-roundtrip/Makefile delete mode 100644 sdk/go/http/testdata/spin-roundtrip/main.go delete mode 100644 sdk/go/http/testdata/spin-roundtrip/spin.toml delete mode 100644 sdk/go/http/wasi-outbound-http.c delete mode 100644 sdk/go/http/wasi-outbound-http.h delete mode 100644 sdk/go/integration_test.go delete mode 100644 sdk/go/internal/db/driver.go delete mode 100644 sdk/go/kv/key-value.c delete mode 100644 sdk/go/kv/key-value.h delete mode 100644 sdk/go/kv/kv.go delete mode 100644 sdk/go/llm/internals.go delete mode 100644 sdk/go/llm/llm.c delete mode 100644 sdk/go/llm/llm.go delete mode 100644 sdk/go/llm/llm.h delete mode 100644 sdk/go/mysql/internals.go delete mode 100644 sdk/go/mysql/mysql.go delete mode 100644 sdk/go/mysql/outbound-mysql.c delete mode 100644 sdk/go/mysql/outbound-mysql.h delete mode 100644 sdk/go/pg/internals.go delete mode 100644 sdk/go/pg/outbound-pg.c delete mode 100644 sdk/go/pg/outbound-pg.h delete mode 100644 sdk/go/pg/pg.go delete mode 100644 sdk/go/readme.md delete mode 100644 sdk/go/redis/internals.go delete mode 100644 sdk/go/redis/internals_test.go delete mode 100644 sdk/go/redis/outbound-redis.c delete mode 100644 sdk/go/redis/outbound-redis.h delete mode 100644 sdk/go/redis/redis.go delete mode 100644 sdk/go/redis/spin-redis.c delete mode 100644 sdk/go/redis/spin-redis.h delete mode 100644 sdk/go/sdk_version/sdk-version-go-template.c delete mode 100644 sdk/go/sqlite/doc.go delete mode 100644 sdk/go/sqlite/internals.go delete mode 100644 sdk/go/sqlite/internals_test.go delete mode 100644 sdk/go/sqlite/sqlite.c delete mode 100644 sdk/go/sqlite/sqlite.go delete mode 100644 sdk/go/sqlite/sqlite.h delete mode 100644 sdk/go/variables/internals.go delete mode 100644 sdk/go/variables/spin-config.c delete mode 100644 sdk/go/variables/spin-config.h delete mode 100644 sdk/go/variables/variables.go delete mode 100644 sdk/go/wit/http-types.wit delete mode 100644 sdk/go/wit/key-value.wit delete mode 100644 sdk/go/wit/mysql-types.wit delete mode 100644 sdk/go/wit/outbound-mysql.wit delete mode 100644 sdk/go/wit/outbound-pg.wit delete mode 100644 sdk/go/wit/outbound-redis.wit delete mode 100644 sdk/go/wit/pg-types.wit delete mode 100644 sdk/go/wit/rdbms-types.wit delete mode 100644 sdk/go/wit/redis-types.wit delete mode 100644 sdk/go/wit/spin-config.wit delete mode 100644 sdk/go/wit/spin-http.wit delete mode 100644 sdk/go/wit/spin-redis.wit delete mode 100644 sdk/go/wit/sqlite.wit delete mode 100644 sdk/go/wit/wasi-outbound-http.wit delete mode 100644 sdk/rust/Cargo.toml delete mode 100644 sdk/rust/README.md delete mode 100644 sdk/rust/build.rs delete mode 100644 sdk/rust/macro/Cargo.toml delete mode 100644 sdk/rust/macro/README.md delete mode 100644 sdk/rust/macro/src/lib.rs delete mode 100644 sdk/rust/macro/wit/deps/http/incoming-handler.wit delete mode 100644 sdk/rust/macro/wit/deps/http/outgoing-handler.wit delete mode 100644 sdk/rust/macro/wit/deps/http/types.wit delete mode 100644 sdk/rust/macro/wit/deps/http/world.wit delete mode 100644 sdk/rust/macro/wit/deps/io/poll.wit delete mode 100644 sdk/rust/macro/wit/deps/io/streams.wit delete mode 100644 sdk/rust/macro/wit/deps/io/world.wit delete mode 100644 sdk/rust/macro/wit/inbound-redis.wit delete mode 100644 sdk/rust/macro/wit/redis-types.wit delete mode 100644 sdk/rust/macro/wit/world.wit delete mode 100644 sdk/rust/src/bin/version.rs delete mode 100644 sdk/rust/src/http.rs delete mode 100644 sdk/rust/src/http/conversions.rs delete mode 100644 sdk/rust/src/http/executor.rs delete mode 100644 sdk/rust/src/http/router.rs delete mode 100644 sdk/rust/src/key_value.rs delete mode 100644 sdk/rust/src/lib.rs delete mode 100644 sdk/rust/src/llm.rs delete mode 100644 sdk/rust/src/mysql.rs delete mode 100644 sdk/rust/src/pg.rs delete mode 100644 sdk/rust/src/sqlite.rs delete mode 120000 sdk/rust/wit diff --git a/.github/gh-checktags.sh b/.github/gh-checktags.sh index d6a0dcd3e0..28128f193d 100755 --- a/.github/gh-checktags.sh +++ b/.github/gh-checktags.sh @@ -1,7 +1,6 @@ #!/usr/bin/env bash ## for the release tags v*, check if -## - golang sdk tag exists ## - spin templates tag exists set -e @@ -23,12 +22,6 @@ for tag in $tags; do continue fi - # check golang sdk tag - if [[ -z "$(git tag -l sdk/go/$tag)" ]]; then - echo "tag sdk/go/$tag does not exist" - exit_code=1 - fi - # remove trailing .\d+ from the version major_minor=`echo $tag | sed 's/\.[0-9]*$//g'` diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index de9d2e42c7..12d59aed55 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -167,36 +167,6 @@ jobs: # Only run integration tests on macOS as they will be run on ubuntu separately if: ${{ matrix.runner == 'macos-latest' }} - test-go: - name: Test Spin SDK - Go - runs-on: ubuntu-latest - needs: build-rust-ubuntu - steps: - - uses: actions/checkout@v3 - - - name: Retrieve saved Spin Binary - uses: actions/download-artifact@v3 - with: - name: spin-ubuntu-latest - path: target/debug/ - - - name: Fix Spin Binary permissions - run: | - ls -lah target/ - ls -lah target/debug - chmod +x target/debug/spin - - - name: setup dependencies - uses: ./.github/actions/spin-ci-dependencies - with: - rust: true - golang: true - tinygo: true - wasmtime: true - - - name: "Test Go SDK" - run: make test-sdk-go - all-integration-tests: # run on a larger runner for more SSD/resource access runs-on: ubuntu-22.04-4core-spin diff --git a/.github/workflows/check-tags.yml b/.github/workflows/check-tags.yml index 47b666b994..54dc6d950c 100644 --- a/.github/workflows/check-tags.yml +++ b/.github/workflows/check-tags.yml @@ -1,4 +1,4 @@ -name: Check tags for templates and sdk +name: Check tags for templates on: schedule: - cron: '0 0 * * *' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index defbb6d943..1a29cb4151 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -254,84 +254,17 @@ jobs: --title ${{ github.ref_name }} \ --generate-notes ${{ env.PRERELEASE }} - create-go-sdk-tag: - name: create tag sdk/go/v* - runs-on: ubuntu-latest - needs: build-and-sign - if: startsWith(github.ref, 'refs/tags/v') - steps: - - uses: actions/checkout@v3 - - - name: Set the tag to sdk/go/v* - shell: bash - run: echo "GO_SDK_TAG=sdk/go/${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV - - - name: Tag sdk/go/v* and push it - shell: bash - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - git tag ${{ env.GO_SDK_TAG }} - git push origin ${{ env.GO_SDK_TAG }} - - create-template-sdk-update-pr: - name: Create PR with template SDK updates - runs-on: ubuntu-latest - needs: create-go-sdk-tag - if: startsWith(github.ref, 'refs/tags/v') - steps: - - uses: actions/checkout@v3 - - - name: Set the spin tag - shell: bash - run: | - echo "SPIN_TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV - - - name: Set the PR base branch - shell: bash - run: | - IFS=. read -r major minor patch <<< "${{ env.SPIN_TAG }}" - echo "RELEASE_BRANCH=$major.$minor" >> $GITHUB_ENV - - - name: Change sdk version - shell: bash - run: | - cd templates - SDK_VERSION=${{ env.SPIN_TAG }} make - - - name: Import GPG key - uses: crazy-max/ghaction-import-gpg@v5 - with: - gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} - passphrase: ${{ secrets.PASSPHRASE }} - git_user_signingkey: true - git_commit_gpgsign: true - - - name: Create Pull Request - uses: peter-evans/create-pull-request@v4 - with: - commit-message: "feat(templates): update sdk to ${{ env.SPIN_TAG }}" - title: "feat(templates): update sdk to ${{ env.SPIN_TAG }}" - body: Update the SDK version used by the templates - branch: update-sdk-${{ env.SPIN_TAG }} - base: ${{ env.RELEASE_BRANCH }} - delete-branch: true - committer: fermybot <103076628+fermybot@users.noreply.github.com> - author: fermybot <103076628+fermybot@users.noreply.github.com> - signoff: true - - # This will run when the PR above is approved and merged into main via a merge commit push-templates-tag: runs-on: ubuntu-latest needs: build-and-sign - if: github.event.commits[0].author.name == 'fermybot' && contains(github.event.commits[0].message, 'update sdk') + if: startsWith(github.ref, 'refs/tags/v') steps: - uses: actions/checkout@v3 - name: Set the tag to spin/templates/v* shell: bash run: | - spin_tag=$(echo "${{ github.event.commits[0].message }}" | grep -Eo v[0-9.]+) + spin_tag=$(echo "${{ github.ref }}" | grep -Eo "refs/tags/v[0-9.]+") IFS=. read -r major minor patch <<< "${spin_tag}" echo "TEMPLATE_TAG=spin/templates/$major.$minor" >> $GITHUB_ENV @@ -431,23 +364,3 @@ jobs: with: name: spin path: _dist/spin-${{ env.RELEASE_VERSION }}-static-${{ env.RUNNER_OS }}-${{ matrix.config.arch }}.tar.gz - - crates: - name: Publish to crates.io - runs-on: ubuntu-latest - needs: build-and-sign - if: | - startsWith(github.ref, 'refs/tags/v') && - github.repository_owner == 'fermyon' - steps: - - uses: actions/checkout@v2 - - - name: Publish spin-macro to crates.io - working-directory: ./sdk/rust/macro - run: | - cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }} - - - name: Publish spin-sdk to crates.io - working-directory: ./sdk/rust - run: | - cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }} diff --git a/Cargo.lock b/Cargo.lock index cb1feb794d..bedc0bee7f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2632,9 +2632,6 @@ name = "heck" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -dependencies = [ - "unicode-segmentation", -] [[package]] name = "hermit-abi" @@ -5054,16 +5051,6 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3582f63211428f83597b51b2ddb88e2a91a9d52d12831f9d08f5e624e8977422" -[[package]] -name = "routefinder" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94f8f99b10dedd317514253dda1fa7c14e344aac96e1f78149a64879ce282aca" -dependencies = [ - "smartcow", - "smartstring", -] - [[package]] name = "rpassword" version = "7.3.1" @@ -5597,26 +5584,6 @@ version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" -[[package]] -name = "smartcow" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "656fcb1c1fca8c4655372134ce87d8afdf5ec5949ebabe8d314be0141d8b5da2" -dependencies = [ - "smartstring", -] - -[[package]] -name = "smartstring" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb72c633efbaa2dd666986505016c32c3044395ceaf881518399d2f4127ee29" -dependencies = [ - "autocfg", - "static_assertions", - "version_check", -] - [[package]] name = "snapbox" version = "0.4.14" @@ -6036,18 +6003,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "spin-macro" -version = "2.3.0-pre0" -dependencies = [ - "anyhow", - "bytes", - "http 0.2.11", - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "spin-manifest" version = "2.3.0-pre0" @@ -6131,25 +6086,6 @@ dependencies = [ "url", ] -[[package]] -name = "spin-sdk" -version = "2.3.0-pre0" -dependencies = [ - "anyhow", - "async-trait", - "bytes", - "form_urlencoded", - "futures", - "http 0.2.11", - "once_cell", - "routefinder", - "serde", - "serde_json", - "spin-macro", - "thiserror", - "wit-bindgen", -] - [[package]] name = "spin-serde" version = "2.3.0-pre0" @@ -8453,55 +8389,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "wit-bindgen" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38726c54a5d7c03cac28a2a8de1006cfe40397ddf6def3f836189033a413bc08" -dependencies = [ - "bitflags 2.4.1", - "wit-bindgen-rust-macro", -] - -[[package]] -name = "wit-bindgen-core" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8bf1fddccaff31a1ad57432d8bfb7027a7e552969b6c68d6d8820dcf5c2371f" -dependencies = [ - "anyhow", - "wit-component 0.17.0", - "wit-parser 0.12.2", -] - -[[package]] -name = "wit-bindgen-rust" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e7200e565124801e01b7b5ddafc559e1da1b2e1bed5364d669cd1d96fb88722" -dependencies = [ - "anyhow", - "heck 0.4.1", - "wasm-metadata", - "wit-bindgen-core", - "wit-component 0.17.0", -] - -[[package]] -name = "wit-bindgen-rust-macro" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ae33920ad8119fe72cf59eb00f127c0b256a236b9de029a1a10397b1f38bdbd" -dependencies = [ - "anyhow", - "proc-macro2", - "quote", - "syn 2.0.39", - "wit-bindgen-core", - "wit-bindgen-rust", - "wit-component 0.17.0", -] - [[package]] name = "wit-component" version = "0.16.1" @@ -8521,25 +8408,6 @@ dependencies = [ "wit-parser 0.12.2", ] -[[package]] -name = "wit-component" -version = "0.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "480cc1a078b305c1b8510f7c455c76cbd008ee49935f3a6c5fd5e937d8d95b1e" -dependencies = [ - "anyhow", - "bitflags 2.4.1", - "indexmap 2.1.0", - "log", - "serde", - "serde_derive", - "serde_json", - "wasm-encoder 0.36.2", - "wasm-metadata", - "wasmparser 0.116.1", - "wit-parser 0.12.2", -] - [[package]] name = "wit-component" version = "0.19.0" diff --git a/Cargo.toml b/Cargo.toml index 682355f8ba..fca32b5bc7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -117,8 +117,6 @@ llm-cublas = ["llm", "spin-trigger-http/llm-cublas"] [workspace] members = [ "crates/*", - "sdk/rust", - "sdk/rust/macro", "tests/runtime-tests", "tests/testing-framework", ] diff --git a/Makefile b/Makefile index accfe2d876..0ad38f24b5 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ export PATH := target/debug:target/release:$(HOME)/.cargo/bin:$(PATH) ## overrides for Windows ifeq ($(OS),Windows_NT) - LOG_LEVEL_VAR = + LOG_LEVEL_VAR = endif .PHONY: build @@ -39,7 +39,7 @@ lint-all: lint lint-rust-examples ## Bring all of the checked in `Cargo.lock` files up-to-date .PHONY: update-cargo-locks -update-cargo-locks: +update-cargo-locks: echo "Updating Cargo.toml" cargo update -w --offline; \ for manifest_path in $$(find examples -name Cargo.toml); do \ @@ -71,10 +71,6 @@ test-integration: test-runtime test-integration-full: test-runtime-full cargo test --release integration_tests --no-default-features --features extern-dependencies-tests --no-fail-fast -- --nocapture -.PHONY: test-sdk-go -test-sdk-go: - $(MAKE) -C sdk/go test - # simple convenience for developing with TLS .PHONY: tls tls: ${CERT_NAME}.crt.pem diff --git a/docs/content/release-process.md b/docs/content/release-process.md index 57c76c3f80..d66abc270e 100644 --- a/docs/content/release-process.md +++ b/docs/content/release-process.md @@ -14,7 +14,6 @@ To cut a major / minor release of Spin, you will need to do the following: 1. Switch to the release branch locally and update versions (e.g. `2.0.0-pre0` could be `2.0.0`). - Bump the version in Spin's `Cargo.toml` - - Bump the `spin-macro` version to the same in the spin-sdk's [Cargo.toml](../../sdk/rust/Cargo.toml) - Run `make build update-cargo-locks` so that `Cargo.lock` and example/test `Cargo.lock` files are updated PR these changes to the release branch ensuring that pull request has a base corresponding to the release branch (e.g. `v2.0`). @@ -34,13 +33,6 @@ To cut a major / minor release of Spin, you will need to do the following: # Push the tag to the remote corresponding to fermyon/spin (here 'origin') git push origin v2.0.0 ``` - - **NOTE** - > The Go SDK tag associated with this release (e.g. `sdk/go/v2.0.0`) will be - > created in the [release action] that has been triggered by the tag push. - > - > When the [release action] completes, binary artifacts and checksums will be - > automatically uploaded to the GitHub release. 1. Switch back to `main` and update the `Cargo.toml` and `spin-macro` versions again, this time to e.g. `2.1.0-pre0` if `2.1.0` is the next anticipated release. - Run `make build update-cargo-locks` so that `Cargo.lock` and example/test `Cargo.lock` files are updated @@ -62,7 +54,6 @@ $ ./.github/gh-backport.sh 1. Switch to the release branch locally and update versions (e.g. `2.0.0` could be `2.0.1`). - Bump the version in Spin's `Cargo.toml` - - Bump the `spin-macro` version to the same in the spin-sdk's [Cargo.toml](../../sdk/rust/Cargo.toml) - Run `make build update-cargo-locks` so that `Cargo.lock` and example/test `Cargo.lock` files are updated PR these changes to the release branch ensuring that pull request has a base corresponding to the release branch (e.g. `v2.0`). @@ -83,13 +74,6 @@ $ ./.github/gh-backport.sh git push origin v2.0.1 ``` - **NOTE** - > The Go SDK tag associated with this release (e.g. `sdk/go/v2.0.0`) will be - > created in the [release action] that has been triggered by the tag push. - > - > When the [release action] completes, binary artifacts and checksums will be - > automatically uploaded to the GitHub release. - Follow the [wrapping up](#wrapping-up) section to finish off the release process. ## Release Candidate @@ -101,7 +85,6 @@ Otherwise, switch to the branch locally. 1. Update the Spin version with `-rc.N` where `N` is the release candidate number (e.g. `2.0.0-pre0` could be `2.0.0-rc.1`). - Bump the version in Spin's `Cargo.toml` - - Bump the `spin-macro` version to the same in the spin-sdk's [Cargo.toml](../../sdk/rust/Cargo.toml) - Run `make build update-cargo-locks` so that `Cargo.lock` and example/test `Cargo.lock` files are updated PR these changes to the release branch ensuring that pull request has a base corresponding to the release branch (e.g. `v2.0`). @@ -122,24 +105,12 @@ Otherwise, switch to the branch locally. git push origin v2.0.0-rc.1 ``` - **NOTE** - > The Go SDK tag associated with this release (e.g. `sdk/go/v2.0.0-rc.1`) will be - > created in the [release action] that has been triggered by the tag push. - > - > When the [release action] completes, binary artifacts and checksums will be - > automatically uploaded to the GitHub release. - Follow the [wrapping up](#wrapping-up) section to finish off the release process. ## Wrapping up - -1. A Pull Request will be created by `fermybot` containing changes to the templates per the updated SDK version. Once CI completes, approve this PR and merge via a merge commit (rather than squash or rebase). - - >This will trigger the `push-templates-tag` job in the [release action], pushing the `spin/templates/v2.0` tag. (Note that this tag may be force-pushed for all patch releases of a given minor release.) - 1. Go to the GitHub [tags page](https://github.com/fermyon/spin/releases), edit the release and add the release notes. (This step is optional if a release candidate.) - + 1. Be sure to include instructions for [verifying the signed Spin binary](./sips/012-signing-spin-releases.md). The `--certificate-identity` value should match this release, e.g. diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000000..7a4abf8e5e --- /dev/null +++ b/examples/README.md @@ -0,0 +1,13 @@ +# Spin Application Examples + +This directory contains a few examples of Spin apps written in various +languages, plus an example of writing [a custom Spin trigger](./spin-timer). + +You can also find many more examples in the SDK repositories for various +languages, including: + +- [Rust](https://github.com/fermyon/spin-rust-sdk/tree/stable/examples) +- [Go](https://github.com/fermyon/spin-go-sdk/tree/stable/examples) +- [Python](https://github.com/fermyon/spin-python-sdk/tree/stable/examples) +- [JavaScript and TypeScript](https://github.com/fermyon/spin-js-sdk/tree/stable/examples) +- [.NET](https://github.com/fermyon/spin-dotnet-sdk/tree/stable/samples) diff --git a/examples/http-rust-outbound-http/http-hello/.cargo/config.toml b/examples/http-rust-outbound-http/http-hello/.cargo/config.toml deleted file mode 100644 index 6b77899cb3..0000000000 --- a/examples/http-rust-outbound-http/http-hello/.cargo/config.toml +++ /dev/null @@ -1,2 +0,0 @@ -[build] -target = "wasm32-wasi" diff --git a/examples/http-rust-outbound-http/http-hello/.gitignore b/examples/http-rust-outbound-http/http-hello/.gitignore deleted file mode 100644 index 2f7896d1d1..0000000000 --- a/examples/http-rust-outbound-http/http-hello/.gitignore +++ /dev/null @@ -1 +0,0 @@ -target/ diff --git a/examples/http-rust-outbound-http/http-hello/Cargo.lock b/examples/http-rust-outbound-http/http-hello/Cargo.lock deleted file mode 100644 index 124d1b10bc..0000000000 --- a/examples/http-rust-outbound-http/http-hello/Cargo.lock +++ /dev/null @@ -1,586 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "anyhow" -version = "1.0.75" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" - -[[package]] -name = "async-trait" -version = "0.1.74" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "bitflags" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" - -[[package]] -name = "bytes" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "form_urlencoded" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" -dependencies = [ - "percent-encoding", -] - -[[package]] -name = "futures" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" - -[[package]] -name = "futures-executor" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" - -[[package]] -name = "futures-macro" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "futures-sink" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" - -[[package]] -name = "futures-task" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" - -[[package]] -name = "futures-util" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "hashbrown" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" - -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -dependencies = [ - "unicode-segmentation", -] - -[[package]] -name = "http" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "http-hello" -version = "0.1.0" -dependencies = [ - "anyhow", - "http", - "spin-sdk", -] - -[[package]] -name = "id-arena" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" - -[[package]] -name = "indexmap" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" -dependencies = [ - "equivalent", - "hashbrown", - "serde", -] - -[[package]] -name = "itoa" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" - -[[package]] -name = "leb128" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" - -[[package]] -name = "log" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" - -[[package]] -name = "memchr" -version = "2.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" - -[[package]] -name = "once_cell" -version = "1.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" - -[[package]] -name = "percent-encoding" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" - -[[package]] -name = "pin-project-lite" -version = "0.2.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "routefinder" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94f8f99b10dedd317514253dda1fa7c14e344aac96e1f78149a64879ce282aca" -dependencies = [ - "smartcow", - "smartstring", -] - -[[package]] -name = "ryu" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" - -[[package]] -name = "semver" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" - -[[package]] -name = "serde" -version = "1.0.189" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.189" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "serde_json" -version = "1.0.107" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" - -[[package]] -name = "smartcow" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "656fcb1c1fca8c4655372134ce87d8afdf5ec5949ebabe8d314be0141d8b5da2" -dependencies = [ - "smartstring", -] - -[[package]] -name = "smartstring" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb72c633efbaa2dd666986505016c32c3044395ceaf881518399d2f4127ee29" -dependencies = [ - "autocfg", - "static_assertions", - "version_check", -] - -[[package]] -name = "spdx" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b19b32ed6d899ab23174302ff105c1577e45a06b08d4fe0a9dd13ce804bbbf71" -dependencies = [ - "smallvec", -] - -[[package]] -name = "spin-macro" -version = "2.3.0-pre0" -dependencies = [ - "anyhow", - "bytes", - "http", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "spin-sdk" -version = "2.3.0-pre0" -dependencies = [ - "anyhow", - "async-trait", - "bytes", - "form_urlencoded", - "futures", - "http", - "once_cell", - "routefinder", - "serde", - "serde_json", - "spin-macro", - "thiserror", - "wit-bindgen", -] - -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "thiserror" -version = "1.0.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "unicode-segmentation" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" - -[[package]] -name = "unicode-xid" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wasm-encoder" -version = "0.35.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ca90ba1b5b0a70d3d49473c5579951f3bddc78d47b59256d2f9d4922b150aca" -dependencies = [ - "leb128", -] - -[[package]] -name = "wasm-metadata" -version = "0.10.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14abc161bfda5b519aa229758b68f2a52b45a12b993808665c857d1a9a00223c" -dependencies = [ - "anyhow", - "indexmap", - "serde", - "serde_derive", - "serde_json", - "spdx", - "wasm-encoder", - "wasmparser", -] - -[[package]] -name = "wasmparser" -version = "0.115.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e06c0641a4add879ba71ccb3a1e4278fd546f76f1eafb21d8f7b07733b547cd5" -dependencies = [ - "indexmap", - "semver", -] - -[[package]] -name = "wit-bindgen" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7d92ce0ca6b6074059413a9581a637550c3a740581c854f9847ec293c8aed71" -dependencies = [ - "bitflags", - "wit-bindgen-rust-macro", -] - -[[package]] -name = "wit-bindgen-core" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "565b945ae074886071eccf9cdaf8ccd7b959c2b0d624095bea5fe62003e8b3e0" -dependencies = [ - "anyhow", - "wit-component", - "wit-parser", -] - -[[package]] -name = "wit-bindgen-rust" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5695ff4e41873ed9ce56d2787e6b5772bdad9e70e2c1d2d160621d1762257f4f" -dependencies = [ - "anyhow", - "heck", - "wasm-metadata", - "wit-bindgen-core", - "wit-component", -] - -[[package]] -name = "wit-bindgen-rust-macro" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a91835ea4231da1fe7971679d505ba14be7826e192b6357f08465866ef482e08" -dependencies = [ - "anyhow", - "proc-macro2", - "quote", - "syn 2.0.38", - "wit-bindgen-core", - "wit-bindgen-rust", - "wit-component", -] - -[[package]] -name = "wit-component" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e87488b57a08e2cbbd076b325acbe7f8666965af174d69d5929cd373bd54547f" -dependencies = [ - "anyhow", - "bitflags", - "indexmap", - "log", - "serde", - "serde_derive", - "serde_json", - "wasm-encoder", - "wasm-metadata", - "wasmparser", - "wit-parser", -] - -[[package]] -name = "wit-parser" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ace9943d89bbf3dbbc71b966da0e7302057b311f36a4ac3d65ddfef17b52cf" -dependencies = [ - "anyhow", - "id-arena", - "indexmap", - "log", - "semver", - "serde", - "serde_derive", - "serde_json", - "unicode-xid", -] diff --git a/examples/http-rust-outbound-http/http-hello/Cargo.toml b/examples/http-rust-outbound-http/http-hello/Cargo.toml deleted file mode 100644 index 3d3943d9f0..0000000000 --- a/examples/http-rust-outbound-http/http-hello/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "http-hello" -version = "0.1.0" -edition = "2021" - -[lib] -crate-type = ["cdylib"] - -[dependencies] -# Useful crate to handle errors. -anyhow = "1" -# General-purpose crate with common HTTP types. -http = "0.2" -# The Spin SDK. -spin-sdk = { path = "../../../sdk/rust" } -[workspace] diff --git a/examples/http-rust-outbound-http/http-hello/src/lib.rs b/examples/http-rust-outbound-http/http-hello/src/lib.rs deleted file mode 100644 index 900afda3f2..0000000000 --- a/examples/http-rust-outbound-http/http-hello/src/lib.rs +++ /dev/null @@ -1,10 +0,0 @@ -use anyhow::Result; -use spin_sdk::http_component; - -/// A simple Spin HTTP component. -#[http_component] -fn hello_world(_req: http::Request<()>) -> Result> { - Ok(http::Response::builder() - .status(200) - .body("Hello, Fermyon!\n")?) -} diff --git a/examples/http-rust-outbound-http/outbound-http-to-same-app/.cargo/config.toml b/examples/http-rust-outbound-http/outbound-http-to-same-app/.cargo/config.toml deleted file mode 100644 index bc255e30b9..0000000000 --- a/examples/http-rust-outbound-http/outbound-http-to-same-app/.cargo/config.toml +++ /dev/null @@ -1,2 +0,0 @@ -[build] -target = "wasm32-wasi" \ No newline at end of file diff --git a/examples/http-rust-outbound-http/outbound-http-to-same-app/Cargo.lock b/examples/http-rust-outbound-http/outbound-http-to-same-app/Cargo.lock deleted file mode 100644 index 425a8c7af3..0000000000 --- a/examples/http-rust-outbound-http/outbound-http-to-same-app/Cargo.lock +++ /dev/null @@ -1,585 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "anyhow" -version = "1.0.75" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" - -[[package]] -name = "async-trait" -version = "0.1.74" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "bitflags" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" - -[[package]] -name = "bytes" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "form_urlencoded" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" -dependencies = [ - "percent-encoding", -] - -[[package]] -name = "futures" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" - -[[package]] -name = "futures-executor" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" - -[[package]] -name = "futures-macro" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "futures-sink" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" - -[[package]] -name = "futures-task" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" - -[[package]] -name = "futures-util" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "hashbrown" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" - -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -dependencies = [ - "unicode-segmentation", -] - -[[package]] -name = "http" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "id-arena" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" - -[[package]] -name = "indexmap" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" -dependencies = [ - "equivalent", - "hashbrown", - "serde", -] - -[[package]] -name = "itoa" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" - -[[package]] -name = "leb128" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" - -[[package]] -name = "log" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" - -[[package]] -name = "memchr" -version = "2.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" - -[[package]] -name = "once_cell" -version = "1.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" - -[[package]] -name = "outbound-http-to-same-app" -version = "0.1.0" -dependencies = [ - "anyhow", - "spin-sdk", -] - -[[package]] -name = "percent-encoding" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" - -[[package]] -name = "pin-project-lite" -version = "0.2.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "routefinder" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94f8f99b10dedd317514253dda1fa7c14e344aac96e1f78149a64879ce282aca" -dependencies = [ - "smartcow", - "smartstring", -] - -[[package]] -name = "ryu" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" - -[[package]] -name = "semver" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" - -[[package]] -name = "serde" -version = "1.0.189" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.189" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "serde_json" -version = "1.0.107" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" - -[[package]] -name = "smartcow" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "656fcb1c1fca8c4655372134ce87d8afdf5ec5949ebabe8d314be0141d8b5da2" -dependencies = [ - "smartstring", -] - -[[package]] -name = "smartstring" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb72c633efbaa2dd666986505016c32c3044395ceaf881518399d2f4127ee29" -dependencies = [ - "autocfg", - "static_assertions", - "version_check", -] - -[[package]] -name = "spdx" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b19b32ed6d899ab23174302ff105c1577e45a06b08d4fe0a9dd13ce804bbbf71" -dependencies = [ - "smallvec", -] - -[[package]] -name = "spin-macro" -version = "2.3.0-pre0" -dependencies = [ - "anyhow", - "bytes", - "http", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "spin-sdk" -version = "2.3.0-pre0" -dependencies = [ - "anyhow", - "async-trait", - "bytes", - "form_urlencoded", - "futures", - "http", - "once_cell", - "routefinder", - "serde", - "serde_json", - "spin-macro", - "thiserror", - "wit-bindgen", -] - -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "thiserror" -version = "1.0.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "unicode-segmentation" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" - -[[package]] -name = "unicode-xid" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wasm-encoder" -version = "0.35.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ca90ba1b5b0a70d3d49473c5579951f3bddc78d47b59256d2f9d4922b150aca" -dependencies = [ - "leb128", -] - -[[package]] -name = "wasm-metadata" -version = "0.10.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14abc161bfda5b519aa229758b68f2a52b45a12b993808665c857d1a9a00223c" -dependencies = [ - "anyhow", - "indexmap", - "serde", - "serde_derive", - "serde_json", - "spdx", - "wasm-encoder", - "wasmparser", -] - -[[package]] -name = "wasmparser" -version = "0.115.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e06c0641a4add879ba71ccb3a1e4278fd546f76f1eafb21d8f7b07733b547cd5" -dependencies = [ - "indexmap", - "semver", -] - -[[package]] -name = "wit-bindgen" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7d92ce0ca6b6074059413a9581a637550c3a740581c854f9847ec293c8aed71" -dependencies = [ - "bitflags", - "wit-bindgen-rust-macro", -] - -[[package]] -name = "wit-bindgen-core" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "565b945ae074886071eccf9cdaf8ccd7b959c2b0d624095bea5fe62003e8b3e0" -dependencies = [ - "anyhow", - "wit-component", - "wit-parser", -] - -[[package]] -name = "wit-bindgen-rust" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5695ff4e41873ed9ce56d2787e6b5772bdad9e70e2c1d2d160621d1762257f4f" -dependencies = [ - "anyhow", - "heck", - "wasm-metadata", - "wit-bindgen-core", - "wit-component", -] - -[[package]] -name = "wit-bindgen-rust-macro" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a91835ea4231da1fe7971679d505ba14be7826e192b6357f08465866ef482e08" -dependencies = [ - "anyhow", - "proc-macro2", - "quote", - "syn 2.0.38", - "wit-bindgen-core", - "wit-bindgen-rust", - "wit-component", -] - -[[package]] -name = "wit-component" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e87488b57a08e2cbbd076b325acbe7f8666965af174d69d5929cd373bd54547f" -dependencies = [ - "anyhow", - "bitflags", - "indexmap", - "log", - "serde", - "serde_derive", - "serde_json", - "wasm-encoder", - "wasm-metadata", - "wasmparser", - "wit-parser", -] - -[[package]] -name = "wit-parser" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ace9943d89bbf3dbbc71b966da0e7302057b311f36a4ac3d65ddfef17b52cf" -dependencies = [ - "anyhow", - "id-arena", - "indexmap", - "log", - "semver", - "serde", - "serde_derive", - "serde_json", - "unicode-xid", -] diff --git a/examples/http-rust-outbound-http/outbound-http-to-same-app/Cargo.toml b/examples/http-rust-outbound-http/outbound-http-to-same-app/Cargo.toml deleted file mode 100644 index 2cd5e69075..0000000000 --- a/examples/http-rust-outbound-http/outbound-http-to-same-app/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "outbound-http-to-same-app" -version = "0.1.0" -edition = "2021" - -[lib] -crate-type = ["cdylib"] - -[dependencies] -anyhow = "1" -spin-sdk = { path = "../../../sdk/rust" } - -[workspace] diff --git a/examples/http-rust-outbound-http/outbound-http-to-same-app/src/lib.rs b/examples/http-rust-outbound-http/outbound-http-to-same-app/src/lib.rs deleted file mode 100644 index ff688c86bf..0000000000 --- a/examples/http-rust-outbound-http/outbound-http-to-same-app/src/lib.rs +++ /dev/null @@ -1,17 +0,0 @@ -use anyhow::Result; -use spin_sdk::{ - http::{IntoResponse, Request, Response}, - http_component, -}; - -/// Send an HTTP request and return the response. -#[http_component] -async fn send_outbound(_req: Request) -> Result { - let resp: Response = spin_sdk::http::send(Request::get("/hello")).await?; - let resp = resp - .into_builder() - .header("spin-component", "rust-outbound-http") - .build(); - println!("{resp:?}"); - Ok(resp) -} diff --git a/examples/http-rust-outbound-http/outbound-http/.cargo/config.toml b/examples/http-rust-outbound-http/outbound-http/.cargo/config.toml deleted file mode 100644 index 6b77899cb3..0000000000 --- a/examples/http-rust-outbound-http/outbound-http/.cargo/config.toml +++ /dev/null @@ -1,2 +0,0 @@ -[build] -target = "wasm32-wasi" diff --git a/examples/http-rust-outbound-http/outbound-http/Cargo.lock b/examples/http-rust-outbound-http/outbound-http/Cargo.lock deleted file mode 100644 index 4836d259f2..0000000000 --- a/examples/http-rust-outbound-http/outbound-http/Cargo.lock +++ /dev/null @@ -1,585 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "anyhow" -version = "1.0.75" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" - -[[package]] -name = "async-trait" -version = "0.1.74" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "bitflags" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" - -[[package]] -name = "bytes" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "form_urlencoded" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" -dependencies = [ - "percent-encoding", -] - -[[package]] -name = "futures" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" - -[[package]] -name = "futures-executor" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" - -[[package]] -name = "futures-macro" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "futures-sink" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" - -[[package]] -name = "futures-task" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" - -[[package]] -name = "futures-util" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "hashbrown" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" - -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -dependencies = [ - "unicode-segmentation", -] - -[[package]] -name = "http" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "http-rust-outbound-http" -version = "0.1.0" -dependencies = [ - "anyhow", - "spin-sdk", -] - -[[package]] -name = "id-arena" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" - -[[package]] -name = "indexmap" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" -dependencies = [ - "equivalent", - "hashbrown", - "serde", -] - -[[package]] -name = "itoa" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" - -[[package]] -name = "leb128" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" - -[[package]] -name = "log" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" - -[[package]] -name = "memchr" -version = "2.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" - -[[package]] -name = "once_cell" -version = "1.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" - -[[package]] -name = "percent-encoding" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" - -[[package]] -name = "pin-project-lite" -version = "0.2.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "routefinder" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94f8f99b10dedd317514253dda1fa7c14e344aac96e1f78149a64879ce282aca" -dependencies = [ - "smartcow", - "smartstring", -] - -[[package]] -name = "ryu" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" - -[[package]] -name = "semver" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" - -[[package]] -name = "serde" -version = "1.0.189" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.189" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "serde_json" -version = "1.0.107" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" - -[[package]] -name = "smartcow" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "656fcb1c1fca8c4655372134ce87d8afdf5ec5949ebabe8d314be0141d8b5da2" -dependencies = [ - "smartstring", -] - -[[package]] -name = "smartstring" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb72c633efbaa2dd666986505016c32c3044395ceaf881518399d2f4127ee29" -dependencies = [ - "autocfg", - "static_assertions", - "version_check", -] - -[[package]] -name = "spdx" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b19b32ed6d899ab23174302ff105c1577e45a06b08d4fe0a9dd13ce804bbbf71" -dependencies = [ - "smallvec", -] - -[[package]] -name = "spin-macro" -version = "2.3.0-pre0" -dependencies = [ - "anyhow", - "bytes", - "http", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "spin-sdk" -version = "2.3.0-pre0" -dependencies = [ - "anyhow", - "async-trait", - "bytes", - "form_urlencoded", - "futures", - "http", - "once_cell", - "routefinder", - "serde", - "serde_json", - "spin-macro", - "thiserror", - "wit-bindgen", -] - -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "thiserror" -version = "1.0.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "unicode-segmentation" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" - -[[package]] -name = "unicode-xid" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wasm-encoder" -version = "0.35.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ca90ba1b5b0a70d3d49473c5579951f3bddc78d47b59256d2f9d4922b150aca" -dependencies = [ - "leb128", -] - -[[package]] -name = "wasm-metadata" -version = "0.10.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14abc161bfda5b519aa229758b68f2a52b45a12b993808665c857d1a9a00223c" -dependencies = [ - "anyhow", - "indexmap", - "serde", - "serde_derive", - "serde_json", - "spdx", - "wasm-encoder", - "wasmparser", -] - -[[package]] -name = "wasmparser" -version = "0.115.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e06c0641a4add879ba71ccb3a1e4278fd546f76f1eafb21d8f7b07733b547cd5" -dependencies = [ - "indexmap", - "semver", -] - -[[package]] -name = "wit-bindgen" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7d92ce0ca6b6074059413a9581a637550c3a740581c854f9847ec293c8aed71" -dependencies = [ - "bitflags", - "wit-bindgen-rust-macro", -] - -[[package]] -name = "wit-bindgen-core" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "565b945ae074886071eccf9cdaf8ccd7b959c2b0d624095bea5fe62003e8b3e0" -dependencies = [ - "anyhow", - "wit-component", - "wit-parser", -] - -[[package]] -name = "wit-bindgen-rust" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5695ff4e41873ed9ce56d2787e6b5772bdad9e70e2c1d2d160621d1762257f4f" -dependencies = [ - "anyhow", - "heck", - "wasm-metadata", - "wit-bindgen-core", - "wit-component", -] - -[[package]] -name = "wit-bindgen-rust-macro" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a91835ea4231da1fe7971679d505ba14be7826e192b6357f08465866ef482e08" -dependencies = [ - "anyhow", - "proc-macro2", - "quote", - "syn 2.0.38", - "wit-bindgen-core", - "wit-bindgen-rust", - "wit-component", -] - -[[package]] -name = "wit-component" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e87488b57a08e2cbbd076b325acbe7f8666965af174d69d5929cd373bd54547f" -dependencies = [ - "anyhow", - "bitflags", - "indexmap", - "log", - "serde", - "serde_derive", - "serde_json", - "wasm-encoder", - "wasm-metadata", - "wasmparser", - "wit-parser", -] - -[[package]] -name = "wit-parser" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ace9943d89bbf3dbbc71b966da0e7302057b311f36a4ac3d65ddfef17b52cf" -dependencies = [ - "anyhow", - "id-arena", - "indexmap", - "log", - "semver", - "serde", - "serde_derive", - "serde_json", - "unicode-xid", -] diff --git a/examples/http-rust-outbound-http/outbound-http/Cargo.toml b/examples/http-rust-outbound-http/outbound-http/Cargo.toml deleted file mode 100644 index 11e94221f2..0000000000 --- a/examples/http-rust-outbound-http/outbound-http/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "http-rust-outbound-http" -version = "0.1.0" -edition = "2021" - -[lib] -crate-type = ["cdylib"] - -[dependencies] -anyhow = "1" -spin-sdk = { path = "../../../sdk/rust" } - -[workspace] diff --git a/examples/http-rust-outbound-http/outbound-http/src/lib.rs b/examples/http-rust-outbound-http/outbound-http/src/lib.rs deleted file mode 100644 index 58fa420169..0000000000 --- a/examples/http-rust-outbound-http/outbound-http/src/lib.rs +++ /dev/null @@ -1,20 +0,0 @@ -use anyhow::Result; -use spin_sdk::{ - http::{IntoResponse, Request, Response}, - http_component, -}; - -/// Send an HTTP request and return the response. -#[http_component] -async fn send_outbound(_req: Request) -> Result { - let resp: Response = spin_sdk::http::send(Request::get( - "https://random-data-api.fermyon.app/animals/json", - )) - .await?; - let resp = resp - .into_builder() - .header("spin-component", "rust-outbound-http") - .build(); - println!("{resp:?}"); - Ok(resp) -} diff --git a/examples/http-rust-outbound-http/spin.toml b/examples/http-rust-outbound-http/spin.toml deleted file mode 100644 index d6a53717d5..0000000000 --- a/examples/http-rust-outbound-http/spin.toml +++ /dev/null @@ -1,53 +0,0 @@ -spin_manifest_version = 2 - -[application] -authors = ["Fermyon Engineering "] -description = "Demonstrates outbound HTTP calls" -name = "spin-outbound-http" -version = "1.0.0" - -[[trigger.http]] -route = "/outbound" -component = "outbound-http" - -[[trigger.http]] -route = "/wildcard" -component = "outbound-http-wildcard" - -[[trigger.http]] -route = "/outbound-to-hello-component" -component = "outbound-http-to-same-app" - -[[trigger.http]] -route = "/hello" -component = "hello-component" - -[component.outbound-http] -source = "outbound-http/target/wasm32-wasi/release/http_rust_outbound_http.wasm" -allowed_http_hosts = ["foo.com"] -allowed_outbound_hosts = ["https://random-data-api.fermyon.app"] -[component.outbound-http.build] -workdir = "outbound-http" -command = "cargo build --target wasm32-wasi --release" - -[component.outbound-http-wildcard] -source = "outbound-http/target/wasm32-wasi/release/http_rust_outbound_http.wasm" -allowed_outbound_hosts = ["https://*:*"] -[component.outbound-http-wildcard.build] -workdir = "outbound-http" -command = "cargo build --target wasm32-wasi --release" - -[component.outbound-http-to-same-app] -source = "outbound-http-to-same-app/target/wasm32-wasi/release/outbound_http_to_same_app.wasm" -# To make outbound calls to components in the same Spin app, use the special value self. -allowed_outbound_hosts = ["http://self"] -[component.outbound-http-to-same-app.build] -workdir = "outbound-http-to-same-app" -command = "cargo build --target wasm32-wasi --release" - -[component.hello-component] -source = "http-hello/target/wasm32-wasi/release/http_hello.wasm" -description = "A simple component that returns hello." -[component.hello-component.build] -workdir = "http-hello" -command = "cargo build --target wasm32-wasi --release" diff --git a/examples/http-rust-router-macro/.cargo/config.toml b/examples/http-rust-router-macro/.cargo/config.toml deleted file mode 100644 index 6b77899cb3..0000000000 --- a/examples/http-rust-router-macro/.cargo/config.toml +++ /dev/null @@ -1,2 +0,0 @@ -[build] -target = "wasm32-wasi" diff --git a/examples/http-rust-router-macro/.gitignore b/examples/http-rust-router-macro/.gitignore deleted file mode 100644 index 2f7896d1d1..0000000000 --- a/examples/http-rust-router-macro/.gitignore +++ /dev/null @@ -1 +0,0 @@ -target/ diff --git a/examples/http-rust-router-macro/Cargo.lock b/examples/http-rust-router-macro/Cargo.lock deleted file mode 100644 index 5652e15724..0000000000 --- a/examples/http-rust-router-macro/Cargo.lock +++ /dev/null @@ -1,585 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "anyhow" -version = "1.0.75" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" - -[[package]] -name = "async-trait" -version = "0.1.74" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "bitflags" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" - -[[package]] -name = "bytes" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "form_urlencoded" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" -dependencies = [ - "percent-encoding", -] - -[[package]] -name = "futures" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" - -[[package]] -name = "futures-executor" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" - -[[package]] -name = "futures-macro" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "futures-sink" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" - -[[package]] -name = "futures-task" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" - -[[package]] -name = "futures-util" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "hashbrown" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" - -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -dependencies = [ - "unicode-segmentation", -] - -[[package]] -name = "http" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "http-rust-router-macro" -version = "0.1.0" -dependencies = [ - "anyhow", - "spin-sdk", -] - -[[package]] -name = "id-arena" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" - -[[package]] -name = "indexmap" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" -dependencies = [ - "equivalent", - "hashbrown", - "serde", -] - -[[package]] -name = "itoa" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" - -[[package]] -name = "leb128" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" - -[[package]] -name = "log" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" - -[[package]] -name = "memchr" -version = "2.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" - -[[package]] -name = "once_cell" -version = "1.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" - -[[package]] -name = "percent-encoding" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" - -[[package]] -name = "pin-project-lite" -version = "0.2.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "routefinder" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94f8f99b10dedd317514253dda1fa7c14e344aac96e1f78149a64879ce282aca" -dependencies = [ - "smartcow", - "smartstring", -] - -[[package]] -name = "ryu" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" - -[[package]] -name = "semver" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" - -[[package]] -name = "serde" -version = "1.0.189" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.189" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "serde_json" -version = "1.0.107" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" - -[[package]] -name = "smartcow" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "656fcb1c1fca8c4655372134ce87d8afdf5ec5949ebabe8d314be0141d8b5da2" -dependencies = [ - "smartstring", -] - -[[package]] -name = "smartstring" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb72c633efbaa2dd666986505016c32c3044395ceaf881518399d2f4127ee29" -dependencies = [ - "autocfg", - "static_assertions", - "version_check", -] - -[[package]] -name = "spdx" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b19b32ed6d899ab23174302ff105c1577e45a06b08d4fe0a9dd13ce804bbbf71" -dependencies = [ - "smallvec", -] - -[[package]] -name = "spin-macro" -version = "2.3.0-pre0" -dependencies = [ - "anyhow", - "bytes", - "http", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "spin-sdk" -version = "2.3.0-pre0" -dependencies = [ - "anyhow", - "async-trait", - "bytes", - "form_urlencoded", - "futures", - "http", - "once_cell", - "routefinder", - "serde", - "serde_json", - "spin-macro", - "thiserror", - "wit-bindgen", -] - -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "thiserror" -version = "1.0.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "unicode-segmentation" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" - -[[package]] -name = "unicode-xid" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wasm-encoder" -version = "0.35.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ca90ba1b5b0a70d3d49473c5579951f3bddc78d47b59256d2f9d4922b150aca" -dependencies = [ - "leb128", -] - -[[package]] -name = "wasm-metadata" -version = "0.10.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14abc161bfda5b519aa229758b68f2a52b45a12b993808665c857d1a9a00223c" -dependencies = [ - "anyhow", - "indexmap", - "serde", - "serde_derive", - "serde_json", - "spdx", - "wasm-encoder", - "wasmparser", -] - -[[package]] -name = "wasmparser" -version = "0.115.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e06c0641a4add879ba71ccb3a1e4278fd546f76f1eafb21d8f7b07733b547cd5" -dependencies = [ - "indexmap", - "semver", -] - -[[package]] -name = "wit-bindgen" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7d92ce0ca6b6074059413a9581a637550c3a740581c854f9847ec293c8aed71" -dependencies = [ - "bitflags", - "wit-bindgen-rust-macro", -] - -[[package]] -name = "wit-bindgen-core" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "565b945ae074886071eccf9cdaf8ccd7b959c2b0d624095bea5fe62003e8b3e0" -dependencies = [ - "anyhow", - "wit-component", - "wit-parser", -] - -[[package]] -name = "wit-bindgen-rust" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5695ff4e41873ed9ce56d2787e6b5772bdad9e70e2c1d2d160621d1762257f4f" -dependencies = [ - "anyhow", - "heck", - "wasm-metadata", - "wit-bindgen-core", - "wit-component", -] - -[[package]] -name = "wit-bindgen-rust-macro" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a91835ea4231da1fe7971679d505ba14be7826e192b6357f08465866ef482e08" -dependencies = [ - "anyhow", - "proc-macro2", - "quote", - "syn 2.0.38", - "wit-bindgen-core", - "wit-bindgen-rust", - "wit-component", -] - -[[package]] -name = "wit-component" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e87488b57a08e2cbbd076b325acbe7f8666965af174d69d5929cd373bd54547f" -dependencies = [ - "anyhow", - "bitflags", - "indexmap", - "log", - "serde", - "serde_derive", - "serde_json", - "wasm-encoder", - "wasm-metadata", - "wasmparser", - "wit-parser", -] - -[[package]] -name = "wit-parser" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ace9943d89bbf3dbbc71b966da0e7302057b311f36a4ac3d65ddfef17b52cf" -dependencies = [ - "anyhow", - "id-arena", - "indexmap", - "log", - "semver", - "serde", - "serde_derive", - "serde_json", - "unicode-xid", -] diff --git a/examples/http-rust-router-macro/Cargo.toml b/examples/http-rust-router-macro/Cargo.toml deleted file mode 100644 index 2947b86761..0000000000 --- a/examples/http-rust-router-macro/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "http-rust-router-macro" -version = "0.1.0" -edition = "2021" - -[lib] -crate-type = ["cdylib"] - -[dependencies] -# Useful crate to handle errors. -anyhow = "1" -# The Spin SDK. -spin-sdk = { path = "../../sdk/rust" } - -[workspace] diff --git a/examples/http-rust-router-macro/spin.toml b/examples/http-rust-router-macro/spin.toml deleted file mode 100644 index 6ed7e62ded..0000000000 --- a/examples/http-rust-router-macro/spin.toml +++ /dev/null @@ -1,18 +0,0 @@ -spin_manifest_version = 2 - -[application] -authors = ["Fermyon Engineering "] -description = "An application that demonstrates HTTP routing." -name = "spin-rust-router" -version = "1.0.0" - -[[trigger.http]] -route = "/..." -component = "route" - -[component.route] -source = "target/wasm32-wasi/release/http_rust_router_macro.wasm" -description = "A component that internally routes HTTP requests." -[component.route.build] -command = "cargo build --target wasm32-wasi --release" -watch = ["src/**/*.rs", "Cargo.toml", "spin.toml"] diff --git a/examples/http-rust-router-macro/src/lib.rs b/examples/http-rust-router-macro/src/lib.rs deleted file mode 100644 index d533b6ec55..0000000000 --- a/examples/http-rust-router-macro/src/lib.rs +++ /dev/null @@ -1,28 +0,0 @@ -#![allow(dead_code, unused_imports)] -use spin_sdk::{ - http::{IntoResponse, Params, Request, Response}, - http_component, http_router, -}; - -#[http_component] -fn handle_route(req: Request) -> impl IntoResponse { - let router = http_router! { - GET "/hello/:planet" => api::hello_planet, - _ "/*" => |_req: Request, params| { - let capture = params.wildcard().unwrap_or_default(); - Response::new(200, capture.to_string()) - } - }; - router.handle(req) -} - -mod api { - use super::*; - - // /hello/:planet - pub fn hello_planet(_req: Request, params: Params) -> anyhow::Result { - let planet = params.get("planet").expect("PLANET"); - - Ok(Response::new(200, planet.to_string())) - } -} diff --git a/examples/http-rust-router/.cargo/config.toml b/examples/http-rust-router/.cargo/config.toml deleted file mode 100644 index 6b77899cb3..0000000000 --- a/examples/http-rust-router/.cargo/config.toml +++ /dev/null @@ -1,2 +0,0 @@ -[build] -target = "wasm32-wasi" diff --git a/examples/http-rust-router/.gitignore b/examples/http-rust-router/.gitignore deleted file mode 100644 index 2f7896d1d1..0000000000 --- a/examples/http-rust-router/.gitignore +++ /dev/null @@ -1 +0,0 @@ -target/ diff --git a/examples/http-rust-router/Cargo.lock b/examples/http-rust-router/Cargo.lock deleted file mode 100644 index c875a6622d..0000000000 --- a/examples/http-rust-router/Cargo.lock +++ /dev/null @@ -1,585 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "anyhow" -version = "1.0.75" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" - -[[package]] -name = "async-trait" -version = "0.1.74" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "bitflags" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" - -[[package]] -name = "bytes" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "form_urlencoded" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" -dependencies = [ - "percent-encoding", -] - -[[package]] -name = "futures" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" - -[[package]] -name = "futures-executor" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" - -[[package]] -name = "futures-macro" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "futures-sink" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" - -[[package]] -name = "futures-task" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" - -[[package]] -name = "futures-util" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "hashbrown" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" - -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -dependencies = [ - "unicode-segmentation", -] - -[[package]] -name = "http" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "http-rust-router" -version = "0.1.0" -dependencies = [ - "anyhow", - "spin-sdk", -] - -[[package]] -name = "id-arena" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" - -[[package]] -name = "indexmap" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" -dependencies = [ - "equivalent", - "hashbrown", - "serde", -] - -[[package]] -name = "itoa" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" - -[[package]] -name = "leb128" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" - -[[package]] -name = "log" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" - -[[package]] -name = "memchr" -version = "2.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" - -[[package]] -name = "once_cell" -version = "1.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" - -[[package]] -name = "percent-encoding" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" - -[[package]] -name = "pin-project-lite" -version = "0.2.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "routefinder" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94f8f99b10dedd317514253dda1fa7c14e344aac96e1f78149a64879ce282aca" -dependencies = [ - "smartcow", - "smartstring", -] - -[[package]] -name = "ryu" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" - -[[package]] -name = "semver" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" - -[[package]] -name = "serde" -version = "1.0.189" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.189" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "serde_json" -version = "1.0.107" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" - -[[package]] -name = "smartcow" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "656fcb1c1fca8c4655372134ce87d8afdf5ec5949ebabe8d314be0141d8b5da2" -dependencies = [ - "smartstring", -] - -[[package]] -name = "smartstring" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb72c633efbaa2dd666986505016c32c3044395ceaf881518399d2f4127ee29" -dependencies = [ - "autocfg", - "static_assertions", - "version_check", -] - -[[package]] -name = "spdx" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b19b32ed6d899ab23174302ff105c1577e45a06b08d4fe0a9dd13ce804bbbf71" -dependencies = [ - "smallvec", -] - -[[package]] -name = "spin-macro" -version = "2.3.0-pre0" -dependencies = [ - "anyhow", - "bytes", - "http", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "spin-sdk" -version = "2.3.0-pre0" -dependencies = [ - "anyhow", - "async-trait", - "bytes", - "form_urlencoded", - "futures", - "http", - "once_cell", - "routefinder", - "serde", - "serde_json", - "spin-macro", - "thiserror", - "wit-bindgen", -] - -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "thiserror" -version = "1.0.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "unicode-segmentation" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" - -[[package]] -name = "unicode-xid" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wasm-encoder" -version = "0.35.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ca90ba1b5b0a70d3d49473c5579951f3bddc78d47b59256d2f9d4922b150aca" -dependencies = [ - "leb128", -] - -[[package]] -name = "wasm-metadata" -version = "0.10.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14abc161bfda5b519aa229758b68f2a52b45a12b993808665c857d1a9a00223c" -dependencies = [ - "anyhow", - "indexmap", - "serde", - "serde_derive", - "serde_json", - "spdx", - "wasm-encoder", - "wasmparser", -] - -[[package]] -name = "wasmparser" -version = "0.115.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e06c0641a4add879ba71ccb3a1e4278fd546f76f1eafb21d8f7b07733b547cd5" -dependencies = [ - "indexmap", - "semver", -] - -[[package]] -name = "wit-bindgen" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7d92ce0ca6b6074059413a9581a637550c3a740581c854f9847ec293c8aed71" -dependencies = [ - "bitflags", - "wit-bindgen-rust-macro", -] - -[[package]] -name = "wit-bindgen-core" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "565b945ae074886071eccf9cdaf8ccd7b959c2b0d624095bea5fe62003e8b3e0" -dependencies = [ - "anyhow", - "wit-component", - "wit-parser", -] - -[[package]] -name = "wit-bindgen-rust" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5695ff4e41873ed9ce56d2787e6b5772bdad9e70e2c1d2d160621d1762257f4f" -dependencies = [ - "anyhow", - "heck", - "wasm-metadata", - "wit-bindgen-core", - "wit-component", -] - -[[package]] -name = "wit-bindgen-rust-macro" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a91835ea4231da1fe7971679d505ba14be7826e192b6357f08465866ef482e08" -dependencies = [ - "anyhow", - "proc-macro2", - "quote", - "syn 2.0.38", - "wit-bindgen-core", - "wit-bindgen-rust", - "wit-component", -] - -[[package]] -name = "wit-component" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e87488b57a08e2cbbd076b325acbe7f8666965af174d69d5929cd373bd54547f" -dependencies = [ - "anyhow", - "bitflags", - "indexmap", - "log", - "serde", - "serde_derive", - "serde_json", - "wasm-encoder", - "wasm-metadata", - "wasmparser", - "wit-parser", -] - -[[package]] -name = "wit-parser" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ace9943d89bbf3dbbc71b966da0e7302057b311f36a4ac3d65ddfef17b52cf" -dependencies = [ - "anyhow", - "id-arena", - "indexmap", - "log", - "semver", - "serde", - "serde_derive", - "serde_json", - "unicode-xid", -] diff --git a/examples/http-rust-router/Cargo.toml b/examples/http-rust-router/Cargo.toml deleted file mode 100644 index b9bbcef8e9..0000000000 --- a/examples/http-rust-router/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "http-rust-router" -version = "0.1.0" -edition = "2021" - -[lib] -crate-type = ["cdylib"] - -[dependencies] -# Useful crate to handle errors. -anyhow = "1" -# The Spin SDK. -spin-sdk = { path = "../../sdk/rust" } -[workspace] diff --git a/examples/http-rust-router/spin.toml b/examples/http-rust-router/spin.toml deleted file mode 100644 index 6874012906..0000000000 --- a/examples/http-rust-router/spin.toml +++ /dev/null @@ -1,18 +0,0 @@ -spin_manifest_version = 2 - -[application] -authors = ["Fermyon Engineering "] -description = "An application that demonstrates HTTP routing." -name = "spin-rust-router" -version = "1.0.0" - -[[trigger.http]] -route = "/..." -component = "route" - -[component.route] -source = "target/wasm32-wasi/release/http_rust_router.wasm" -description = "A component that internally routes HTTP requests." -[component.route.build] -command = "cargo build --target wasm32-wasi --release" -watch = ["src/**/*.rs", "Cargo.toml", "spin.toml"] diff --git a/examples/http-rust-router/src/lib.rs b/examples/http-rust-router/src/lib.rs deleted file mode 100644 index d737720d49..0000000000 --- a/examples/http-rust-router/src/lib.rs +++ /dev/null @@ -1,37 +0,0 @@ -use anyhow::Result; -use spin_sdk::{ - http::{IntoResponse, Params, Request, Response, Router}, - http_component, -}; - -/// A Spin HTTP component that internally routes requests. -#[http_component] -fn handle_route(req: Request) -> Response { - let mut router = Router::new(); - router.get("/goodbye/:planet", api::goodbye_planet); - router.get_async("/hello/:planet", api::hello_planet); - router.any_async("/*", api::echo_wildcard); - router.handle(req) -} - -mod api { - use super::*; - - // /goodbye/:planet - pub fn goodbye_planet(_req: Request, params: Params) -> Result { - let planet = params.get("planet").expect("PLANET"); - Ok(Response::new(200, planet.to_string())) - } - - // /hello/:planet - pub async fn hello_planet(_req: Request, params: Params) -> Result { - let planet = params.get("planet").expect("PLANET"); - Ok(Response::new(200, planet.to_string())) - } - - // /* - pub async fn echo_wildcard(_req: Request, params: Params) -> Result { - let capture = params.wildcard().unwrap_or_default(); - Ok(Response::new(200, capture.to_string())) - } -} diff --git a/examples/http-rust/Cargo.lock b/examples/http-rust/Cargo.lock index 2079f20df1..8fc7c54e5d 100644 --- a/examples/http-rust/Cargo.lock +++ b/examples/http-rust/Cargo.lock @@ -365,7 +365,9 @@ dependencies = [ [[package]] name = "spin-macro" -version = "2.3.0-pre0" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13524474ab9f876586e29f954377a66ed14fcb646fc9893e6f0e762213ddbd86" dependencies = [ "anyhow", "bytes", @@ -377,7 +379,9 @@ dependencies = [ [[package]] name = "spin-sdk" -version = "2.3.0-pre0" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f05d0c09c0935fbb586d0a76e0f14b26b23f421c5e11b81d7200d22c4ead1211" dependencies = [ "anyhow", "async-trait", diff --git a/examples/http-rust/Cargo.toml b/examples/http-rust/Cargo.toml index afad911a21..525db0ea45 100644 --- a/examples/http-rust/Cargo.toml +++ b/examples/http-rust/Cargo.toml @@ -10,6 +10,6 @@ crate-type = ["cdylib"] anyhow = "1" http = "0.2.9" serde = { version = "1.0", features = ["derive"] } -spin-sdk = { path = "../../sdk/rust" } +spin-sdk = "2.2.0" [workspace] diff --git a/examples/http-tinygo-outbound-http/README.md b/examples/http-tinygo-outbound-http/README.md deleted file mode 100644 index 14880b3d83..0000000000 --- a/examples/http-tinygo-outbound-http/README.md +++ /dev/null @@ -1,88 +0,0 @@ -# Making outbound HTTP requests from TinyGo Spin components - -The TinyGo SDK for building Spin components allows us to granularly allow -components to send HTTP requests to certain hosts. This is configured in -`spin.toml`. - -> For more information and examples for using TinyGo with WebAssembly, check -> [the official TinyGo documentation](https://tinygo.org/docs/guides/webassembly/) -> and -> [the Wasm examples](https://github.com/tinygo-org/tinygo/tree/release/src/examples/wasm). - -Creating and sending HTTP requests from Spin components closely follows the Go -`net/http` API. See [tinygo-hello/main.go](./tinygo-hello/main.go). - -Building this as a WebAssembly module can be done using the `tinygo` compiler: - -```shell -$ spin build -Building component outbound-http-to-same-app with `tinygo build -target=wasi -gc=leaking -no-debug -o main.wasm main.go` -Working directory: "./outbound-http-to-same-app" -Building component tinygo-hello with `tinygo build -target=wasi -gc=leaking -no-debug -o main.wasm main.go` -Working directory: "./tinygo-hello" -Finished building all Spin components -``` - -The component configuration must contain a list of all hosts allowed to send -HTTP requests to, otherwise sending the request results in an error: - -``` -Cannot send HTTP request: Destination not allowed: -``` - -The `tinygo-hello` component has the following allowed hosts set: - -```toml -[component.tinygo-hello] -source = "tinygo-hello/main.wasm" -allowed_outbound_hosts = [ - "https://random-data-api.fermyon.app", - "https://postman-echo.com", -] -``` - -And the `outbound-http-to-same-app` uses the dedicated `self` keyword to enable making -a request to another component in this same app, via a relative path (in this case, the component -is `tinygo-hello` at `/hello`): - -```toml -[component.outbound-http-to-same-app] -source = "outbound-http-to-same-app/main.wasm" -# Use self to make outbound requests to components in the same Spin application. -allowed_outbound_hosts = ["http://self"] -``` - -At this point, we can execute the application with the `spin` CLI: - -```shell -$ RUST_LOG=spin=trace,wasi_outbound_http=trace spin up -``` - -The application can now receive requests on `http://localhost:3000/hello`: - -```shell -$ curl -i localhost:3000/hello -X POST -d "hello there" -HTTP/1.1 200 OK -content-length: 976 -date: Thu, 26 Oct 2023 18:26:17 GMT - -{{"timestamp":1698344776965,"fact":"Reindeer grow new antlers every year"}} -... -``` - -As well as via the `/outbound-http-to-same-app` path to verify outbound http to the `tinygo-hello` component: - -```shell -$ curl -i localhost:3000/outbound-http-to-same-app -HTTP/1.1 200 OK -content-length: 946 -date: Thu, 26 Oct 2023 18:26:53 GMT - -{{{"timestamp":1698344813408,"fact":"Some hummingbirds weigh less than a penny"}} -... -``` - -## Notes - -- this only implements sending HTTP/1.1 requests -- requests are currently blocking and synchronous diff --git a/examples/http-tinygo-outbound-http/outbound-http-to-same-app/go.mod b/examples/http-tinygo-outbound-http/outbound-http-to-same-app/go.mod deleted file mode 100644 index b0ed451ae6..0000000000 --- a/examples/http-tinygo-outbound-http/outbound-http-to-same-app/go.mod +++ /dev/null @@ -1,9 +0,0 @@ -module outbound-http-to-same-app - -go 1.20 - -require github.com/fermyon/spin/sdk/go/v2 v2.0.0 - -require github.com/julienschmidt/httprouter v1.3.0 // indirect - -replace github.com/fermyon/spin/sdk/go/v2 v2.0.0 => ../../../sdk/go/ diff --git a/examples/http-tinygo-outbound-http/outbound-http-to-same-app/go.sum b/examples/http-tinygo-outbound-http/outbound-http-to-same-app/go.sum deleted file mode 100644 index 096c54e630..0000000000 --- a/examples/http-tinygo-outbound-http/outbound-http-to-same-app/go.sum +++ /dev/null @@ -1,2 +0,0 @@ -github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= -github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= diff --git a/examples/http-tinygo-outbound-http/outbound-http-to-same-app/main.go b/examples/http-tinygo-outbound-http/outbound-http-to-same-app/main.go deleted file mode 100644 index daf21d3620..0000000000 --- a/examples/http-tinygo-outbound-http/outbound-http-to-same-app/main.go +++ /dev/null @@ -1,25 +0,0 @@ -package main - -import ( - "fmt" - "net/http" - - spinhttp "github.com/fermyon/spin/sdk/go/v2/http" -) - -func init() { - spinhttp.Handle(func(w http.ResponseWriter, r *http.Request) { - // Because we included self in `allowed_http_hosts`, we can make outbound - // HTTP requests to our own app using a relative path. - resp, err := spinhttp.Get("/hello") - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - fmt.Fprintln(w, resp.Body) - fmt.Fprintln(w, resp.Header.Get("content-type")) - }) -} - -func main() {} diff --git a/examples/http-tinygo-outbound-http/spin.toml b/examples/http-tinygo-outbound-http/spin.toml deleted file mode 100644 index 0210640eed..0000000000 --- a/examples/http-tinygo-outbound-http/spin.toml +++ /dev/null @@ -1,33 +0,0 @@ -spin_manifest_version = 2 - -[application] -authors = ["Fermyon Engineering "] -description = "A simple Spin application written in (Tiny)Go that performs outbound HTTP requests." -name = "spin-tinygo-outbound-http" -version = "1.0.0" - -[[trigger.http]] -route = "/hello" -component = "tinygo-hello" - -[[trigger.http]] -route = "/outbound-http-to-same-app" -component = "outbound-http-to-same-app" - -[component.tinygo-hello] -source = "tinygo-hello/main.wasm" -allowed_outbound_hosts = [ - "https://random-data-api.fermyon.app:443", - "https://postman-echo.com:443", -] -[component.tinygo-hello.build] -workdir = "tinygo-hello" -command = "tinygo build -target=wasi -gc=leaking -no-debug -o main.wasm main.go" - -[component.outbound-http-to-same-app] -source = "outbound-http-to-same-app/main.wasm" -# Use self to make outbound requests to components in the same Spin application. -allowed_outbound_hosts = ["http://self"] -[component.outbound-http-to-same-app.build] -workdir = "outbound-http-to-same-app" -command = "tinygo build -target=wasi -gc=leaking -no-debug -o main.wasm main.go" diff --git a/examples/http-tinygo-outbound-http/tinygo-hello/go.mod b/examples/http-tinygo-outbound-http/tinygo-hello/go.mod deleted file mode 100644 index 424f13d0fd..0000000000 --- a/examples/http-tinygo-outbound-http/tinygo-hello/go.mod +++ /dev/null @@ -1,9 +0,0 @@ -module github.com/fermyon/spin/templates/spin-http-tinygo-outbound-http - -go 1.20 - -require github.com/fermyon/spin/sdk/go/v2 v2.0.0 - -require github.com/julienschmidt/httprouter v1.3.0 // indirect - -replace github.com/fermyon/spin/sdk/go/v2 v2.0.0 => ../../../sdk/go/ diff --git a/examples/http-tinygo-outbound-http/tinygo-hello/go.sum b/examples/http-tinygo-outbound-http/tinygo-hello/go.sum deleted file mode 100644 index 096c54e630..0000000000 --- a/examples/http-tinygo-outbound-http/tinygo-hello/go.sum +++ /dev/null @@ -1,2 +0,0 @@ -github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= -github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= diff --git a/examples/http-tinygo-outbound-http/tinygo-hello/main.go b/examples/http-tinygo-outbound-http/tinygo-hello/main.go deleted file mode 100644 index 7cf8726c27..0000000000 --- a/examples/http-tinygo-outbound-http/tinygo-hello/main.go +++ /dev/null @@ -1,52 +0,0 @@ -package main - -import ( - "bytes" - "fmt" - "net/http" - "os" - - spinhttp "github.com/fermyon/spin/sdk/go/v2/http" -) - -func init() { - spinhttp.Handle(func(w http.ResponseWriter, r *http.Request) { - r1, err := spinhttp.Get("https://random-data-api.fermyon.app/animals/json") - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - fmt.Fprintln(w, r1.Body) - fmt.Fprintln(w, r1.Header.Get("content-type")) - - r2, err := spinhttp.Post("https://postman-echo.com/post", "text/plain", r.Body) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - fmt.Fprintln(w, r2.Body) - - req, err := http.NewRequest("PUT", "https://postman-echo.com/put", bytes.NewBufferString("General Kenobi!")) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - req.Header.Add("foo", "bar") - r3, err := spinhttp.Send(req) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - fmt.Fprintln(w, r3.Body) - - // `spin.toml` is not configured to allow outbound HTTP requests to this host, - // so this request will fail. - if _, err := spinhttp.Get("https://fermyon.com"); err != nil { - fmt.Fprintf(os.Stderr, "Cannot send HTTP request: %v", err) - } - }) -} - -func main() {} diff --git a/examples/http-tinygo-router/README.md b/examples/http-tinygo-router/README.md deleted file mode 100644 index 1a138fe902..0000000000 --- a/examples/http-tinygo-router/README.md +++ /dev/null @@ -1,24 +0,0 @@ -# Spin component in TinyGo using the Spin router - -```shell -$ go mod tidy -$ RUST_LOG=spin=trace spin build --up -``` - -The application can now receive requests on `http://localhost:3000`: - -```shell -$ curl -i localhost:3000/hello/Fermyon -HTTP/1.1 200 OK -content-length: 16 -date: Thu, 26 Oct 2023 18:30:05 GMT - -hello, Fermyon! - -$ curl -i localhost:3000/this/will/be-special -HTTP/1.1 200 OK -content-length: 24 -date: Thu, 26 Oct 2023 18:30:21 GMT - -catch all: /be-special! -``` diff --git a/examples/http-tinygo-router/go.mod b/examples/http-tinygo-router/go.mod deleted file mode 100644 index b57b194092..0000000000 --- a/examples/http-tinygo-router/go.mod +++ /dev/null @@ -1,9 +0,0 @@ -module github.com/fermyon/spin/templates/spin-http-tinygo - -go 1.20 - -require github.com/fermyon/spin/sdk/go/v2 v2.0.0 - -require github.com/julienschmidt/httprouter v1.3.0 // indirect - -replace github.com/fermyon/spin/sdk/go/v2 v2.0.0 => ../../sdk/go/ diff --git a/examples/http-tinygo-router/go.sum b/examples/http-tinygo-router/go.sum deleted file mode 100644 index 096c54e630..0000000000 --- a/examples/http-tinygo-router/go.sum +++ /dev/null @@ -1,2 +0,0 @@ -github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= -github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= diff --git a/examples/http-tinygo-router/main.go b/examples/http-tinygo-router/main.go deleted file mode 100644 index 140cf5aec5..0000000000 --- a/examples/http-tinygo-router/main.go +++ /dev/null @@ -1,28 +0,0 @@ -package main - -import ( - "fmt" - "net/http" - - spinhttp "github.com/fermyon/spin/sdk/go/v2/http" -) - -func init() { - spinhttp.Handle(func(w http.ResponseWriter, r *http.Request) { - router := spinhttp.NewRouter() - router.GET("/hello/:name", Hello) - router.GET("/this/will/*catchAll", CatchAll) - - router.ServeHTTP(w, r) - }) -} - -func Hello(w http.ResponseWriter, _ *http.Request, ps spinhttp.Params) { - fmt.Fprintf(w, "hello, %s!\n", ps.ByName("name")) -} - -func CatchAll(w http.ResponseWriter, _ *http.Request, ps spinhttp.Params) { - fmt.Fprintf(w, "catch all: %s!\n", ps.ByName("catchAll")) -} - -func main() {} diff --git a/examples/http-tinygo-router/spin.toml b/examples/http-tinygo-router/spin.toml deleted file mode 100644 index 8e63f8c864..0000000000 --- a/examples/http-tinygo-router/spin.toml +++ /dev/null @@ -1,16 +0,0 @@ -spin_manifest_version = 2 - -[application] -authors = ["Fermyon Engineering "] -description = "A simple Spin application written in (Tiny)Go." -name = "spin-hello-tinygo" -version = "1.0.0" - -[[trigger.http]] -route = "/..." -component = "tinygo-hello" - -[component.tinygo-hello] -source = "main.wasm" -[component.tinygo-hello.build] -command = "tinygo build -target=wasi -gc=leaking -no-debug -o main.wasm main.go" diff --git a/examples/http-tinygo/README.md b/examples/http-tinygo/README.md deleted file mode 100644 index 741cddc6f7..0000000000 --- a/examples/http-tinygo/README.md +++ /dev/null @@ -1,35 +0,0 @@ -# Spin component in TinyGo - -```shell -$ go mod tidy -$ RUST_LOG=spin=trace spin build --up -``` - -The application can now receive requests on `http://localhost:3000`: - -```shell -$ curl -i localhost:3000/hello -HTTP/1.1 200 OK -content-type: text/plain -foo: bar -content-length: 440 -date: Thu, 26 Oct 2023 18:18:19 GMT - -== REQUEST == -URL: http://localhost:3000/hello -Method: GET -Headers: - "Host": "localhost:3000" - "User-Agent": "curl/8.1.2" - "Spin-Full-Url": "http://localhost:3000/hello" - "Spin-Base-Path": "/" - "Spin-Client-Addr": "127.0.0.1:52164" - "Accept": "*/*" - "Spin-Path-Info": "" - "Spin-Matched-Route": "/hello" - "Spin-Raw-Component-Route": "/hello" - "Spin-Component-Route": "/hello" -Body: -== RESPONSE == -Hello Fermyon! -``` diff --git a/examples/http-tinygo/go.mod b/examples/http-tinygo/go.mod deleted file mode 100644 index b57b194092..0000000000 --- a/examples/http-tinygo/go.mod +++ /dev/null @@ -1,9 +0,0 @@ -module github.com/fermyon/spin/templates/spin-http-tinygo - -go 1.20 - -require github.com/fermyon/spin/sdk/go/v2 v2.0.0 - -require github.com/julienschmidt/httprouter v1.3.0 // indirect - -replace github.com/fermyon/spin/sdk/go/v2 v2.0.0 => ../../sdk/go/ diff --git a/examples/http-tinygo/go.sum b/examples/http-tinygo/go.sum deleted file mode 100644 index 096c54e630..0000000000 --- a/examples/http-tinygo/go.sum +++ /dev/null @@ -1,2 +0,0 @@ -github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= -github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= diff --git a/examples/http-tinygo/main.go b/examples/http-tinygo/main.go deleted file mode 100644 index 128d63493f..0000000000 --- a/examples/http-tinygo/main.go +++ /dev/null @@ -1,36 +0,0 @@ -package main - -import ( - "fmt" - "io" - "net/http" - - spinhttp "github.com/fermyon/spin/sdk/go/v2/http" -) - -func init() { - spinhttp.Handle(func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.Header().Set("foo", "bar") - - fmt.Fprintln(w, "== REQUEST ==") - fmt.Fprintln(w, "URL: ", r.URL) - fmt.Fprintln(w, "Method: ", r.Method) - fmt.Fprintln(w, "Headers:") - for k, v := range r.Header { - fmt.Fprintf(w, " %q: %q \n", k, v[0]) - } - - body, err := io.ReadAll(r.Body) - if err != nil { - fmt.Fprintln(w, "Body Error: ", err) - } else { - fmt.Fprintln(w, "Body: ", string(body)) - } - - fmt.Fprintln(w, "== RESPONSE ==") - fmt.Fprintln(w, "Hello Fermyon!") - }) -} - -func main() {} diff --git a/examples/http-tinygo/spin.toml b/examples/http-tinygo/spin.toml deleted file mode 100644 index e7442ba3bf..0000000000 --- a/examples/http-tinygo/spin.toml +++ /dev/null @@ -1,16 +0,0 @@ -spin_manifest_version = 2 - -[application] -authors = ["Fermyon Engineering "] -description = "A simple Spin application written in (Tiny)Go." -name = "spin-hello-tinygo" -version = "1.0.0" - -[[trigger.http]] -route = "/hello" -component = "tinygo-hello" - -[component.tinygo-hello] -source = "main.wasm" -[component.tinygo-hello.build] -command = "tinygo build -target=wasi -gc=leaking -no-debug -o main.wasm main.go" diff --git a/examples/json-http-rust/.cargo/config.toml b/examples/json-http-rust/.cargo/config.toml deleted file mode 100644 index 6b77899cb3..0000000000 --- a/examples/json-http-rust/.cargo/config.toml +++ /dev/null @@ -1,2 +0,0 @@ -[build] -target = "wasm32-wasi" diff --git a/examples/json-http-rust/.gitignore b/examples/json-http-rust/.gitignore deleted file mode 100644 index 2f7896d1d1..0000000000 --- a/examples/json-http-rust/.gitignore +++ /dev/null @@ -1 +0,0 @@ -target/ diff --git a/examples/json-http-rust/Cargo.lock b/examples/json-http-rust/Cargo.lock deleted file mode 100644 index 032844f8dd..0000000000 --- a/examples/json-http-rust/Cargo.lock +++ /dev/null @@ -1,587 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "anyhow" -version = "1.0.75" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" - -[[package]] -name = "async-trait" -version = "0.1.74" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "bitflags" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" - -[[package]] -name = "bytes" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "form_urlencoded" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" -dependencies = [ - "percent-encoding", -] - -[[package]] -name = "futures" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" - -[[package]] -name = "futures-executor" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" - -[[package]] -name = "futures-macro" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "futures-sink" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" - -[[package]] -name = "futures-task" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" - -[[package]] -name = "futures-util" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "hashbrown" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" - -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -dependencies = [ - "unicode-segmentation", -] - -[[package]] -name = "http" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "id-arena" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" - -[[package]] -name = "indexmap" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" -dependencies = [ - "equivalent", - "hashbrown", - "serde", -] - -[[package]] -name = "itoa" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" - -[[package]] -name = "json-http-rust" -version = "0.1.0" -dependencies = [ - "anyhow", - "http", - "serde", - "spin-sdk", -] - -[[package]] -name = "leb128" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" - -[[package]] -name = "log" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" - -[[package]] -name = "memchr" -version = "2.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" - -[[package]] -name = "once_cell" -version = "1.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" - -[[package]] -name = "percent-encoding" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" - -[[package]] -name = "pin-project-lite" -version = "0.2.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "routefinder" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94f8f99b10dedd317514253dda1fa7c14e344aac96e1f78149a64879ce282aca" -dependencies = [ - "smartcow", - "smartstring", -] - -[[package]] -name = "ryu" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" - -[[package]] -name = "semver" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" - -[[package]] -name = "serde" -version = "1.0.189" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.189" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "serde_json" -version = "1.0.107" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" - -[[package]] -name = "smartcow" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "656fcb1c1fca8c4655372134ce87d8afdf5ec5949ebabe8d314be0141d8b5da2" -dependencies = [ - "smartstring", -] - -[[package]] -name = "smartstring" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb72c633efbaa2dd666986505016c32c3044395ceaf881518399d2f4127ee29" -dependencies = [ - "autocfg", - "static_assertions", - "version_check", -] - -[[package]] -name = "spdx" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b19b32ed6d899ab23174302ff105c1577e45a06b08d4fe0a9dd13ce804bbbf71" -dependencies = [ - "smallvec", -] - -[[package]] -name = "spin-macro" -version = "2.3.0-pre0" -dependencies = [ - "anyhow", - "bytes", - "http", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "spin-sdk" -version = "2.3.0-pre0" -dependencies = [ - "anyhow", - "async-trait", - "bytes", - "form_urlencoded", - "futures", - "http", - "once_cell", - "routefinder", - "serde", - "serde_json", - "spin-macro", - "thiserror", - "wit-bindgen", -] - -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "thiserror" -version = "1.0.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "unicode-segmentation" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" - -[[package]] -name = "unicode-xid" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wasm-encoder" -version = "0.35.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ca90ba1b5b0a70d3d49473c5579951f3bddc78d47b59256d2f9d4922b150aca" -dependencies = [ - "leb128", -] - -[[package]] -name = "wasm-metadata" -version = "0.10.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14abc161bfda5b519aa229758b68f2a52b45a12b993808665c857d1a9a00223c" -dependencies = [ - "anyhow", - "indexmap", - "serde", - "serde_derive", - "serde_json", - "spdx", - "wasm-encoder", - "wasmparser", -] - -[[package]] -name = "wasmparser" -version = "0.115.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e06c0641a4add879ba71ccb3a1e4278fd546f76f1eafb21d8f7b07733b547cd5" -dependencies = [ - "indexmap", - "semver", -] - -[[package]] -name = "wit-bindgen" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7d92ce0ca6b6074059413a9581a637550c3a740581c854f9847ec293c8aed71" -dependencies = [ - "bitflags", - "wit-bindgen-rust-macro", -] - -[[package]] -name = "wit-bindgen-core" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "565b945ae074886071eccf9cdaf8ccd7b959c2b0d624095bea5fe62003e8b3e0" -dependencies = [ - "anyhow", - "wit-component", - "wit-parser", -] - -[[package]] -name = "wit-bindgen-rust" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5695ff4e41873ed9ce56d2787e6b5772bdad9e70e2c1d2d160621d1762257f4f" -dependencies = [ - "anyhow", - "heck", - "wasm-metadata", - "wit-bindgen-core", - "wit-component", -] - -[[package]] -name = "wit-bindgen-rust-macro" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a91835ea4231da1fe7971679d505ba14be7826e192b6357f08465866ef482e08" -dependencies = [ - "anyhow", - "proc-macro2", - "quote", - "syn 2.0.38", - "wit-bindgen-core", - "wit-bindgen-rust", - "wit-component", -] - -[[package]] -name = "wit-component" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e87488b57a08e2cbbd076b325acbe7f8666965af174d69d5929cd373bd54547f" -dependencies = [ - "anyhow", - "bitflags", - "indexmap", - "log", - "serde", - "serde_derive", - "serde_json", - "wasm-encoder", - "wasm-metadata", - "wasmparser", - "wit-parser", -] - -[[package]] -name = "wit-parser" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ace9943d89bbf3dbbc71b966da0e7302057b311f36a4ac3d65ddfef17b52cf" -dependencies = [ - "anyhow", - "id-arena", - "indexmap", - "log", - "semver", - "serde", - "serde_derive", - "serde_json", - "unicode-xid", -] diff --git a/examples/json-http-rust/Cargo.toml b/examples/json-http-rust/Cargo.toml deleted file mode 100644 index 69730f33a1..0000000000 --- a/examples/json-http-rust/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "json-http-rust" -version = "0.1.0" -edition = "2021" - -[lib] -crate-type = ["cdylib"] - -[dependencies] -anyhow = "1" -http = "0.2.9" -serde = { version = "1.0", features = ["derive"] } -spin-sdk = { path = "../../sdk/rust" } - -[workspace] diff --git a/examples/json-http-rust/README.md b/examples/json-http-rust/README.md deleted file mode 100644 index 6b879d5887..0000000000 --- a/examples/json-http-rust/README.md +++ /dev/null @@ -1,9 +0,0 @@ -## Automatically deserializing JSON request bodies in Rust HTTP - -This sample shows using the `http::Request>` request type to accept JSON and automatically deserialize it into a Rust struct that implements `serde::Deserialize`. - -To test it, run `spin up --build` and then POST to localhost:3000 e.g.: - -``` -curl -X POST -d '{"name": "Vyvyan"}' localhost:3000 -``` diff --git a/examples/json-http-rust/spin.toml b/examples/json-http-rust/spin.toml deleted file mode 100644 index 40098f5ef9..0000000000 --- a/examples/json-http-rust/spin.toml +++ /dev/null @@ -1,18 +0,0 @@ -spin_manifest_version = 2 - -[application] -authors = ["Fermyon Engineering "] -description = "An application which parses a JSON POST body." -name = "json-http-rust" -version = "1.0.0" - -[[trigger.http]] -route = "/..." -component = "json-demo" - -[component.json-demo] -source = "target/wasm32-wasi/release/json_http_rust.wasm" -description = "Parses 'name' from the POST body and responds using it." -[component.json-demo.build] -command = "cargo build --target wasm32-wasi --release" -watch = ["src/**/*.rs", "Cargo.toml"] diff --git a/examples/json-http-rust/src/lib.rs b/examples/json-http-rust/src/lib.rs deleted file mode 100644 index 853d6b02b2..0000000000 --- a/examples/json-http-rust/src/lib.rs +++ /dev/null @@ -1,13 +0,0 @@ -use spin_sdk::http::{IntoResponse, Json, Response}; -use spin_sdk::http_component; - -#[derive(serde::Deserialize, Debug)] -struct Greeted { - name: String, -} - -/// A simple Spin HTTP component. -#[http_component] -async fn hello_world(req: http::Request>) -> anyhow::Result { - Ok(Response::new(200, format!("Hello, {}", req.body().name))) -} diff --git a/examples/redis-rust/.cargo/config.toml b/examples/redis-rust/.cargo/config.toml deleted file mode 100644 index 6b77899cb3..0000000000 --- a/examples/redis-rust/.cargo/config.toml +++ /dev/null @@ -1,2 +0,0 @@ -[build] -target = "wasm32-wasi" diff --git a/examples/redis-rust/Cargo.lock b/examples/redis-rust/Cargo.lock deleted file mode 100644 index 0f5fdd8267..0000000000 --- a/examples/redis-rust/Cargo.lock +++ /dev/null @@ -1,586 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "anyhow" -version = "1.0.75" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" - -[[package]] -name = "async-trait" -version = "0.1.74" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "bitflags" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" - -[[package]] -name = "bytes" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "form_urlencoded" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" -dependencies = [ - "percent-encoding", -] - -[[package]] -name = "futures" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" - -[[package]] -name = "futures-executor" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" - -[[package]] -name = "futures-macro" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "futures-sink" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" - -[[package]] -name = "futures-task" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" - -[[package]] -name = "futures-util" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "hashbrown" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" - -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -dependencies = [ - "unicode-segmentation", -] - -[[package]] -name = "http" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "id-arena" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" - -[[package]] -name = "indexmap" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" -dependencies = [ - "equivalent", - "hashbrown", - "serde", -] - -[[package]] -name = "itoa" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" - -[[package]] -name = "leb128" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" - -[[package]] -name = "log" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" - -[[package]] -name = "memchr" -version = "2.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" - -[[package]] -name = "once_cell" -version = "1.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" - -[[package]] -name = "percent-encoding" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" - -[[package]] -name = "pin-project-lite" -version = "0.2.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "routefinder" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94f8f99b10dedd317514253dda1fa7c14e344aac96e1f78149a64879ce282aca" -dependencies = [ - "smartcow", - "smartstring", -] - -[[package]] -name = "ryu" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" - -[[package]] -name = "semver" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" - -[[package]] -name = "serde" -version = "1.0.189" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.189" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "serde_json" -version = "1.0.107" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" - -[[package]] -name = "smartcow" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "656fcb1c1fca8c4655372134ce87d8afdf5ec5949ebabe8d314be0141d8b5da2" -dependencies = [ - "smartstring", -] - -[[package]] -name = "smartstring" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb72c633efbaa2dd666986505016c32c3044395ceaf881518399d2f4127ee29" -dependencies = [ - "autocfg", - "static_assertions", - "version_check", -] - -[[package]] -name = "spdx" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b19b32ed6d899ab23174302ff105c1577e45a06b08d4fe0a9dd13ce804bbbf71" -dependencies = [ - "smallvec", -] - -[[package]] -name = "spin-macro" -version = "2.3.0-pre0" -dependencies = [ - "anyhow", - "bytes", - "http", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "spin-sdk" -version = "2.3.0-pre0" -dependencies = [ - "anyhow", - "async-trait", - "bytes", - "form_urlencoded", - "futures", - "http", - "once_cell", - "routefinder", - "serde", - "serde_json", - "spin-macro", - "thiserror", - "wit-bindgen", -] - -[[package]] -name = "spinredis" -version = "0.1.0" -dependencies = [ - "anyhow", - "bytes", - "spin-sdk", -] - -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "thiserror" -version = "1.0.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "unicode-segmentation" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" - -[[package]] -name = "unicode-xid" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wasm-encoder" -version = "0.35.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ca90ba1b5b0a70d3d49473c5579951f3bddc78d47b59256d2f9d4922b150aca" -dependencies = [ - "leb128", -] - -[[package]] -name = "wasm-metadata" -version = "0.10.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14abc161bfda5b519aa229758b68f2a52b45a12b993808665c857d1a9a00223c" -dependencies = [ - "anyhow", - "indexmap", - "serde", - "serde_derive", - "serde_json", - "spdx", - "wasm-encoder", - "wasmparser", -] - -[[package]] -name = "wasmparser" -version = "0.115.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e06c0641a4add879ba71ccb3a1e4278fd546f76f1eafb21d8f7b07733b547cd5" -dependencies = [ - "indexmap", - "semver", -] - -[[package]] -name = "wit-bindgen" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7d92ce0ca6b6074059413a9581a637550c3a740581c854f9847ec293c8aed71" -dependencies = [ - "bitflags", - "wit-bindgen-rust-macro", -] - -[[package]] -name = "wit-bindgen-core" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "565b945ae074886071eccf9cdaf8ccd7b959c2b0d624095bea5fe62003e8b3e0" -dependencies = [ - "anyhow", - "wit-component", - "wit-parser", -] - -[[package]] -name = "wit-bindgen-rust" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5695ff4e41873ed9ce56d2787e6b5772bdad9e70e2c1d2d160621d1762257f4f" -dependencies = [ - "anyhow", - "heck", - "wasm-metadata", - "wit-bindgen-core", - "wit-component", -] - -[[package]] -name = "wit-bindgen-rust-macro" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a91835ea4231da1fe7971679d505ba14be7826e192b6357f08465866ef482e08" -dependencies = [ - "anyhow", - "proc-macro2", - "quote", - "syn 2.0.38", - "wit-bindgen-core", - "wit-bindgen-rust", - "wit-component", -] - -[[package]] -name = "wit-component" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e87488b57a08e2cbbd076b325acbe7f8666965af174d69d5929cd373bd54547f" -dependencies = [ - "anyhow", - "bitflags", - "indexmap", - "log", - "serde", - "serde_derive", - "serde_json", - "wasm-encoder", - "wasm-metadata", - "wasmparser", - "wit-parser", -] - -[[package]] -name = "wit-parser" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ace9943d89bbf3dbbc71b966da0e7302057b311f36a4ac3d65ddfef17b52cf" -dependencies = [ - "anyhow", - "id-arena", - "indexmap", - "log", - "semver", - "serde", - "serde_derive", - "serde_json", - "unicode-xid", -] diff --git a/examples/redis-rust/Cargo.toml b/examples/redis-rust/Cargo.toml deleted file mode 100644 index 7bb1658470..0000000000 --- a/examples/redis-rust/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "spinredis" -version = "0.1.0" -edition = "2021" - -[lib] -crate-type = [ "cdylib" ] - -[dependencies] -# Useful crate to handle errors. -anyhow = "1" -# Crate to simplify working with bytes. -bytes = "1" -# The Spin SDK. -spin-sdk = { path = "../../sdk/rust" } -[workspace] \ No newline at end of file diff --git a/examples/redis-rust/spin.toml b/examples/redis-rust/spin.toml deleted file mode 100644 index 2636fda1d6..0000000000 --- a/examples/redis-rust/spin.toml +++ /dev/null @@ -1,19 +0,0 @@ -spin_manifest_version = 2 - -[application] -authors = ["Fermyon Engineering "] -description = "A redis application." -name = "spin-redis" -version = "0.1.0" - -[application.trigger.redis] -address = "redis://localhost:6379" - -[[trigger.redis]] -channel = "messages" -component = "echo-message" - -[component.echo-message] -source = "target/wasm32-wasi/release/spinredis.wasm" -[component.echo-message.build] -command = "cargo build --target wasm32-wasi --release" diff --git a/examples/redis-rust/src/lib.rs b/examples/redis-rust/src/lib.rs deleted file mode 100644 index 7424a8d983..0000000000 --- a/examples/redis-rust/src/lib.rs +++ /dev/null @@ -1,11 +0,0 @@ -use anyhow::Result; -use bytes::Bytes; -use spin_sdk::redis_component; -use std::str::from_utf8; - -/// A simple Spin Redis component. -#[redis_component] -fn on_message(message: Bytes) -> Result<()> { - println!("{}", from_utf8(&message)?); - Ok(()) -} diff --git a/examples/rust-key-value/.cargo/config.toml b/examples/rust-key-value/.cargo/config.toml deleted file mode 100644 index 6b77899cb3..0000000000 --- a/examples/rust-key-value/.cargo/config.toml +++ /dev/null @@ -1,2 +0,0 @@ -[build] -target = "wasm32-wasi" diff --git a/examples/rust-key-value/Cargo.lock b/examples/rust-key-value/Cargo.lock deleted file mode 100644 index 2576dd13f3..0000000000 --- a/examples/rust-key-value/Cargo.lock +++ /dev/null @@ -1,586 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "anyhow" -version = "1.0.75" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" - -[[package]] -name = "async-trait" -version = "0.1.74" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "bitflags" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" - -[[package]] -name = "bytes" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "form_urlencoded" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" -dependencies = [ - "percent-encoding", -] - -[[package]] -name = "futures" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" - -[[package]] -name = "futures-executor" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" - -[[package]] -name = "futures-macro" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "futures-sink" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" - -[[package]] -name = "futures-task" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" - -[[package]] -name = "futures-util" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "hashbrown" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" - -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -dependencies = [ - "unicode-segmentation", -] - -[[package]] -name = "http" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "id-arena" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" - -[[package]] -name = "indexmap" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" -dependencies = [ - "equivalent", - "hashbrown", - "serde", -] - -[[package]] -name = "itoa" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" - -[[package]] -name = "leb128" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" - -[[package]] -name = "log" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" - -[[package]] -name = "memchr" -version = "2.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" - -[[package]] -name = "once_cell" -version = "1.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" - -[[package]] -name = "percent-encoding" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" - -[[package]] -name = "pin-project-lite" -version = "0.2.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "routefinder" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94f8f99b10dedd317514253dda1fa7c14e344aac96e1f78149a64879ce282aca" -dependencies = [ - "smartcow", - "smartstring", -] - -[[package]] -name = "rust-key-value" -version = "0.1.0" -dependencies = [ - "anyhow", - "http", - "spin-sdk", -] - -[[package]] -name = "ryu" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" - -[[package]] -name = "semver" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" - -[[package]] -name = "serde" -version = "1.0.189" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.189" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "serde_json" -version = "1.0.107" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" - -[[package]] -name = "smartcow" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "656fcb1c1fca8c4655372134ce87d8afdf5ec5949ebabe8d314be0141d8b5da2" -dependencies = [ - "smartstring", -] - -[[package]] -name = "smartstring" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb72c633efbaa2dd666986505016c32c3044395ceaf881518399d2f4127ee29" -dependencies = [ - "autocfg", - "static_assertions", - "version_check", -] - -[[package]] -name = "spdx" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b19b32ed6d899ab23174302ff105c1577e45a06b08d4fe0a9dd13ce804bbbf71" -dependencies = [ - "smallvec", -] - -[[package]] -name = "spin-macro" -version = "2.3.0-pre0" -dependencies = [ - "anyhow", - "bytes", - "http", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "spin-sdk" -version = "2.3.0-pre0" -dependencies = [ - "anyhow", - "async-trait", - "bytes", - "form_urlencoded", - "futures", - "http", - "once_cell", - "routefinder", - "serde", - "serde_json", - "spin-macro", - "thiserror", - "wit-bindgen", -] - -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "thiserror" -version = "1.0.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "unicode-segmentation" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" - -[[package]] -name = "unicode-xid" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wasm-encoder" -version = "0.35.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ca90ba1b5b0a70d3d49473c5579951f3bddc78d47b59256d2f9d4922b150aca" -dependencies = [ - "leb128", -] - -[[package]] -name = "wasm-metadata" -version = "0.10.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14abc161bfda5b519aa229758b68f2a52b45a12b993808665c857d1a9a00223c" -dependencies = [ - "anyhow", - "indexmap", - "serde", - "serde_derive", - "serde_json", - "spdx", - "wasm-encoder", - "wasmparser", -] - -[[package]] -name = "wasmparser" -version = "0.115.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e06c0641a4add879ba71ccb3a1e4278fd546f76f1eafb21d8f7b07733b547cd5" -dependencies = [ - "indexmap", - "semver", -] - -[[package]] -name = "wit-bindgen" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7d92ce0ca6b6074059413a9581a637550c3a740581c854f9847ec293c8aed71" -dependencies = [ - "bitflags", - "wit-bindgen-rust-macro", -] - -[[package]] -name = "wit-bindgen-core" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "565b945ae074886071eccf9cdaf8ccd7b959c2b0d624095bea5fe62003e8b3e0" -dependencies = [ - "anyhow", - "wit-component", - "wit-parser", -] - -[[package]] -name = "wit-bindgen-rust" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5695ff4e41873ed9ce56d2787e6b5772bdad9e70e2c1d2d160621d1762257f4f" -dependencies = [ - "anyhow", - "heck", - "wasm-metadata", - "wit-bindgen-core", - "wit-component", -] - -[[package]] -name = "wit-bindgen-rust-macro" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a91835ea4231da1fe7971679d505ba14be7826e192b6357f08465866ef482e08" -dependencies = [ - "anyhow", - "proc-macro2", - "quote", - "syn 2.0.38", - "wit-bindgen-core", - "wit-bindgen-rust", - "wit-component", -] - -[[package]] -name = "wit-component" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e87488b57a08e2cbbd076b325acbe7f8666965af174d69d5929cd373bd54547f" -dependencies = [ - "anyhow", - "bitflags", - "indexmap", - "log", - "serde", - "serde_derive", - "serde_json", - "wasm-encoder", - "wasm-metadata", - "wasmparser", - "wit-parser", -] - -[[package]] -name = "wit-parser" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ace9943d89bbf3dbbc71b966da0e7302057b311f36a4ac3d65ddfef17b52cf" -dependencies = [ - "anyhow", - "id-arena", - "indexmap", - "log", - "semver", - "serde", - "serde_derive", - "serde_json", - "unicode-xid", -] diff --git a/examples/rust-key-value/Cargo.toml b/examples/rust-key-value/Cargo.toml deleted file mode 100644 index 56cf74643c..0000000000 --- a/examples/rust-key-value/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "rust-key-value" -version = "0.1.0" -edition = "2021" - -[lib] -crate-type = ["cdylib"] - -[dependencies] -anyhow = "1" -http = "0.2" -spin-sdk = { path = "../../sdk/rust" } - -[workspace] diff --git a/examples/rust-key-value/README.md b/examples/rust-key-value/README.md deleted file mode 100644 index da6efe9fff..0000000000 --- a/examples/rust-key-value/README.md +++ /dev/null @@ -1,31 +0,0 @@ -# Spin Key Value component in Rust - -```shell -$ RUST_LOG=spin=trace spin build --up -``` - -The application can now receive requests on `http://localhost:3000`: - -```shell -$ curl -i -X POST -d "ok!" localhost:3000/test -HTTP/1.1 200 OK -content-length: 0 -date: Tue, 25 Apr 2023 14:25:43 GMT - -$ curl -i -X GET localhost:3000/test -HTTP/1.1 200 OK -content-length: 3 -date: Tue, 25 Apr 2023 14:25:54 GMT - -ok! - -$ curl -i -X DELETE localhost:3000/test -HTTP/1.1 200 OK -content-length: 0 -date: Tue, 25 Apr 2023 14:26:30 GMT - -$ curl -i -X GET localhost:3000/test -HTTP/1.1 404 Not Found -content-length: 0 -date: Tue, 25 Apr 2023 14:31:53 GMT -``` diff --git a/examples/rust-key-value/spin.toml b/examples/rust-key-value/spin.toml deleted file mode 100644 index 5e68438820..0000000000 --- a/examples/rust-key-value/spin.toml +++ /dev/null @@ -1,17 +0,0 @@ -spin_manifest_version = 2 - -[application] -authors = ["Fermyon Engineering "] -description = "A simple application that exercises key-value storage." -name = "spin-key-value" -version = "1.0.0" - -[[trigger.http]] -route = "/..." -component = "hello" - -[component.hello] -source = "target/wasm32-wasi/release/rust_key_value.wasm" -key_value_stores = ["default"] -[component.hello.build] -command = "cargo build --target wasm32-wasi --release" diff --git a/examples/rust-key-value/src/lib.rs b/examples/rust-key-value/src/lib.rs deleted file mode 100644 index f37cb61e07..0000000000 --- a/examples/rust-key-value/src/lib.rs +++ /dev/null @@ -1,44 +0,0 @@ -use http::{Method, StatusCode}; -use spin_sdk::{ - http::{IntoResponse, Response}, - http_component, - key_value::Store, -}; - -#[http_component] -fn handle_request(req: http::Request>) -> anyhow::Result { - // Open the default key-value store - let store = Store::open_default()?; - - let (status, body) = match *req.method() { - Method::POST => { - // Add the request (URI, body) tuple to the store - store.set(req.uri().path(), req.body().as_slice())?; - (StatusCode::OK, None) - } - Method::GET => { - // Get the value associated with the request URI, or return a 404 if it's not present - match store.get(req.uri().path())? { - Some(value) => (StatusCode::OK, Some(value)), - None => (StatusCode::NOT_FOUND, None), - } - } - Method::DELETE => { - // Delete the value associated with the request URI, if present - store.delete(req.uri().path())?; - (StatusCode::OK, None) - } - Method::HEAD => { - // Like GET, except do not return the value - let code = if store.exists(req.uri().path())? { - StatusCode::OK - } else { - StatusCode::NOT_FOUND - }; - (code, None) - } - // No other methods are currently supported - _ => (StatusCode::METHOD_NOT_ALLOWED, None), - }; - Ok(Response::new(status, body)) -} diff --git a/examples/rust-outbound-mysql/.cargo/config.toml b/examples/rust-outbound-mysql/.cargo/config.toml deleted file mode 100644 index 6b77899cb3..0000000000 --- a/examples/rust-outbound-mysql/.cargo/config.toml +++ /dev/null @@ -1,2 +0,0 @@ -[build] -target = "wasm32-wasi" diff --git a/examples/rust-outbound-mysql/.gitignore b/examples/rust-outbound-mysql/.gitignore deleted file mode 100644 index 2f7896d1d1..0000000000 --- a/examples/rust-outbound-mysql/.gitignore +++ /dev/null @@ -1 +0,0 @@ -target/ diff --git a/examples/rust-outbound-mysql/Cargo.lock b/examples/rust-outbound-mysql/Cargo.lock deleted file mode 100644 index cf62c262e9..0000000000 --- a/examples/rust-outbound-mysql/Cargo.lock +++ /dev/null @@ -1,588 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "anyhow" -version = "1.0.75" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" - -[[package]] -name = "async-trait" -version = "0.1.74" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "bitflags" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" - -[[package]] -name = "bytes" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "form_urlencoded" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" -dependencies = [ - "percent-encoding", -] - -[[package]] -name = "futures" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" - -[[package]] -name = "futures-executor" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" - -[[package]] -name = "futures-macro" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "futures-sink" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" - -[[package]] -name = "futures-task" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" - -[[package]] -name = "futures-util" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "hashbrown" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" - -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -dependencies = [ - "unicode-segmentation", -] - -[[package]] -name = "http" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "id-arena" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" - -[[package]] -name = "indexmap" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" -dependencies = [ - "equivalent", - "hashbrown", - "serde", -] - -[[package]] -name = "itoa" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" - -[[package]] -name = "leb128" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" - -[[package]] -name = "log" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" - -[[package]] -name = "memchr" -version = "2.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" - -[[package]] -name = "once_cell" -version = "1.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" - -[[package]] -name = "percent-encoding" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" - -[[package]] -name = "pin-project-lite" -version = "0.2.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "routefinder" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94f8f99b10dedd317514253dda1fa7c14e344aac96e1f78149a64879ce282aca" -dependencies = [ - "smartcow", - "smartstring", -] - -[[package]] -name = "rust-outbound-mysql" -version = "0.1.0" -dependencies = [ - "anyhow", - "http", - "serde", - "serde_json", - "spin-sdk", -] - -[[package]] -name = "ryu" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" - -[[package]] -name = "semver" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" - -[[package]] -name = "serde" -version = "1.0.189" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.189" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "serde_json" -version = "1.0.107" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" - -[[package]] -name = "smartcow" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "656fcb1c1fca8c4655372134ce87d8afdf5ec5949ebabe8d314be0141d8b5da2" -dependencies = [ - "smartstring", -] - -[[package]] -name = "smartstring" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb72c633efbaa2dd666986505016c32c3044395ceaf881518399d2f4127ee29" -dependencies = [ - "autocfg", - "static_assertions", - "version_check", -] - -[[package]] -name = "spdx" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b19b32ed6d899ab23174302ff105c1577e45a06b08d4fe0a9dd13ce804bbbf71" -dependencies = [ - "smallvec", -] - -[[package]] -name = "spin-macro" -version = "2.3.0-pre0" -dependencies = [ - "anyhow", - "bytes", - "http", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "spin-sdk" -version = "2.3.0-pre0" -dependencies = [ - "anyhow", - "async-trait", - "bytes", - "form_urlencoded", - "futures", - "http", - "once_cell", - "routefinder", - "serde", - "serde_json", - "spin-macro", - "thiserror", - "wit-bindgen", -] - -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "thiserror" -version = "1.0.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "unicode-segmentation" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" - -[[package]] -name = "unicode-xid" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wasm-encoder" -version = "0.35.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ca90ba1b5b0a70d3d49473c5579951f3bddc78d47b59256d2f9d4922b150aca" -dependencies = [ - "leb128", -] - -[[package]] -name = "wasm-metadata" -version = "0.10.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14abc161bfda5b519aa229758b68f2a52b45a12b993808665c857d1a9a00223c" -dependencies = [ - "anyhow", - "indexmap", - "serde", - "serde_derive", - "serde_json", - "spdx", - "wasm-encoder", - "wasmparser", -] - -[[package]] -name = "wasmparser" -version = "0.115.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e06c0641a4add879ba71ccb3a1e4278fd546f76f1eafb21d8f7b07733b547cd5" -dependencies = [ - "indexmap", - "semver", -] - -[[package]] -name = "wit-bindgen" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7d92ce0ca6b6074059413a9581a637550c3a740581c854f9847ec293c8aed71" -dependencies = [ - "bitflags", - "wit-bindgen-rust-macro", -] - -[[package]] -name = "wit-bindgen-core" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "565b945ae074886071eccf9cdaf8ccd7b959c2b0d624095bea5fe62003e8b3e0" -dependencies = [ - "anyhow", - "wit-component", - "wit-parser", -] - -[[package]] -name = "wit-bindgen-rust" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5695ff4e41873ed9ce56d2787e6b5772bdad9e70e2c1d2d160621d1762257f4f" -dependencies = [ - "anyhow", - "heck", - "wasm-metadata", - "wit-bindgen-core", - "wit-component", -] - -[[package]] -name = "wit-bindgen-rust-macro" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a91835ea4231da1fe7971679d505ba14be7826e192b6357f08465866ef482e08" -dependencies = [ - "anyhow", - "proc-macro2", - "quote", - "syn 2.0.38", - "wit-bindgen-core", - "wit-bindgen-rust", - "wit-component", -] - -[[package]] -name = "wit-component" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e87488b57a08e2cbbd076b325acbe7f8666965af174d69d5929cd373bd54547f" -dependencies = [ - "anyhow", - "bitflags", - "indexmap", - "log", - "serde", - "serde_derive", - "serde_json", - "wasm-encoder", - "wasm-metadata", - "wasmparser", - "wit-parser", -] - -[[package]] -name = "wit-parser" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ace9943d89bbf3dbbc71b966da0e7302057b311f36a4ac3d65ddfef17b52cf" -dependencies = [ - "anyhow", - "id-arena", - "indexmap", - "log", - "semver", - "serde", - "serde_derive", - "serde_json", - "unicode-xid", -] diff --git a/examples/rust-outbound-mysql/Cargo.toml b/examples/rust-outbound-mysql/Cargo.toml deleted file mode 100644 index 83b7aa30a0..0000000000 --- a/examples/rust-outbound-mysql/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "rust-outbound-mysql" -authors = ["itowlson "] -description = "Demo of calling MySQL from a Spin application" -version = "0.1.0" -edition = "2021" - -[lib] -crate-type = ["cdylib"] - -[dependencies] -# Useful crate to handle errors. -anyhow = "1" -# General-purpose crate with common HTTP types. -http = "0.2" -serde = "1.0.144" -serde_json = "1.0.85" -# The Spin SDK. -spin-sdk = { path = "../../sdk/rust" } - -[workspace] diff --git a/examples/rust-outbound-mysql/db/pets.sql b/examples/rust-outbound-mysql/db/pets.sql deleted file mode 100644 index bbf91d68ad..0000000000 --- a/examples/rust-outbound-mysql/db/pets.sql +++ /dev/null @@ -1,4 +0,0 @@ -CREATE TABLE pets (id INT PRIMARY KEY, name VARCHAR(100) NOT NULL, prey VARCHAR(100), is_finicky BOOL NOT NULL); -INSERT INTO pets VALUES (1, 'Splodge', NULL, false); -INSERT INTO pets VALUES (2, 'Kiki', 'Cicadas', false); -INSERT INTO pets VALUES (3, 'Slats', 'Temptations', true); diff --git a/examples/rust-outbound-mysql/spin.toml b/examples/rust-outbound-mysql/spin.toml deleted file mode 100644 index ac1855931f..0000000000 --- a/examples/rust-outbound-mysql/spin.toml +++ /dev/null @@ -1,18 +0,0 @@ -spin_manifest_version = 2 - -[application] -authors = ["itowlson "] -description = "Demo of calling MySQL from a Spin application" -name = "rust-outbound-mysql" -version = "0.1.0" - -[[trigger.http]] -route = "/..." -component = "rust-outbound-mysql" - -[component.rust-outbound-mysql] -environment = { DB_URL = "mysql://spin:spin@127.0.0.1/spin_dev" } -source = "target/wasm32-wasi/release/rust_outbound_mysql.wasm" -allowed_outbound_hosts = ["mysql://127.0.0.1"] -[component.rust-outbound-mysql.build] -command = "cargo build --target wasm32-wasi --release" diff --git a/examples/rust-outbound-mysql/src/lib.rs b/examples/rust-outbound-mysql/src/lib.rs deleted file mode 100644 index 60400f56b6..0000000000 --- a/examples/rust-outbound-mysql/src/lib.rs +++ /dev/null @@ -1,188 +0,0 @@ -use anyhow::{anyhow, Result}; -use http::{HeaderValue, Method, Request, Response}; -use spin_sdk::{ - http::Json, - http_component, - mysql::{self, ParameterValue}, -}; -use std::{collections::HashMap, str::FromStr}; - -use crate::model::as_pet; - -mod model; - -// The environment variable set in `spin.toml` that points to the -// address of the MySQL server that the component will write to -const DB_URL_ENV: &str = "DB_URL"; - -enum RequestAction { - List, - Get(i32), - Create(String, Option, bool), - Error(u16), -} - -#[http_component] -fn rust_outbound_mysql( - req: Request>>, -) -> Result>> { - match parse_request(req) { - RequestAction::List => list(), - RequestAction::Get(id) => get(id), - RequestAction::Create(name, prey, is_finicky) => create(name, prey, is_finicky), - RequestAction::Error(status) => error(status), - } -} - -fn parse_request(req: Request>>) -> RequestAction { - match *req.method() { - Method::GET => match req.headers().get("spin-path-info") { - None => RequestAction::Error(500), - Some(header_val) => match header_val_to_int(header_val) { - Ok(None) => RequestAction::List, - Ok(Some(id)) => RequestAction::Get(id), - Err(()) => RequestAction::Error(404), - }, - }, - Method::POST => { - let map = req.body(); - let name = match map.get("name") { - Some(n) => n.to_owned(), - None => return RequestAction::Error(400), // If this were a real app it would have error messages - }; - let prey = map.get("prey").cloned(); - let is_finicky = map - .get("is_finicky") - .map(|s| s == "true") - .unwrap_or_default(); - RequestAction::Create(name, prey, is_finicky) - } - _ => RequestAction::Error(405), - } -} - -fn header_val_to_int(header_val: &HeaderValue) -> Result, ()> { - match header_val.to_str() { - Ok(path) => { - let path_parts = &(path.split('/').skip(1).collect::>()[..]); - match *path_parts { - [""] => Ok(None), - [id_str] => match i32::from_str(id_str) { - Ok(id) => Ok(Some(id)), - Err(_) => Err(()), - }, - _ => Err(()), - } - } - Err(_) => Err(()), - } -} - -fn list() -> Result>> { - let address = std::env::var(DB_URL_ENV)?; - let conn = mysql::Connection::open(&address)?; - - let sql = "SELECT id, name, prey, is_finicky FROM pets"; - let rowset = conn.query(sql, &[])?; - - let column_summary = rowset - .columns - .iter() - .map(format_col) - .collect::>() - .join(", "); - - let mut response_lines = vec![]; - - for row in rowset.rows { - let pet = as_pet(&row); - println!("{:#?}", pet); - response_lines.push(format!("{:#?}", pet)); - } - - let response = format!( - "Found {} pet(s) as follows:\n{}\n\n(Column info: {})\n", - response_lines.len(), - response_lines.join("\n"), - column_summary, - ); - - Ok(http::Response::builder().status(200).body(Some(response))?) -} - -fn get(id: i32) -> Result>> { - let address = std::env::var(DB_URL_ENV)?; - let conn = mysql::Connection::open(&address)?; - - let sql = "SELECT id, name, prey, is_finicky FROM pets WHERE id = ?"; - let params = vec![ParameterValue::Int32(id)]; - let rowset = conn.query(sql, ¶ms)?; - - match rowset.rows.first() { - None => Ok(http::Response::builder().status(404).body(None)?), - Some(row) => { - let pet = as_pet(row)?; - let response = format!("{:?}", pet); - Ok(http::Response::builder().status(200).body(Some(response))?) - } - } -} - -fn create( - name: String, - prey: Option, - is_finicky: bool, -) -> Result>> { - let address = std::env::var(DB_URL_ENV)?; - let conn = mysql::Connection::open(&address)?; - - let id = max_pet_id(&conn)? + 1; - - let prey_param = match prey { - None => ParameterValue::DbNull, - Some(str) => ParameterValue::Str(str), - }; - - let is_finicky_param = ParameterValue::Int8(i8::from(is_finicky)); - - let sql = "INSERT INTO pets (id, name, prey, is_finicky) VALUES (?, ?, ?, ?)"; - let params = vec![ - ParameterValue::Int32(id), - ParameterValue::Str(name), - prey_param, - is_finicky_param, - ]; - conn.execute(sql, ¶ms)?; - - let location_url = format!("/{}", id); - - Ok(http::Response::builder() - .status(201) - .header("Location", location_url) - .body(None)?) -} - -fn error(status: u16) -> Result>> { - Ok(http::Response::builder().status(status).body(None)?) -} - -fn format_col(column: &mysql::Column) -> String { - format!("{}: {:?}", column.name, column.data_type) -} - -fn max_pet_id(conn: &mysql::Connection) -> Result { - let sql = "SELECT MAX(id) FROM pets"; - let rowset = conn.query(sql, &[])?; - - match rowset.rows.first() { - None => Ok(0), - Some(row) => match row.first() { - None => Ok(0), - Some(mysql::DbValue::Int32(i)) => Ok(*i), - Some(other) => Err(anyhow!( - "Unexpected non-integer ID {:?}, can't insert", - other - )), - }, - } -} diff --git a/examples/rust-outbound-mysql/src/model.rs b/examples/rust-outbound-mysql/src/model.rs deleted file mode 100644 index 18dcea0ccb..0000000000 --- a/examples/rust-outbound-mysql/src/model.rs +++ /dev/null @@ -1,27 +0,0 @@ -use anyhow::Result; -use spin_sdk::mysql::{self, Decode}; - -// Such logic, very business - -#[allow(dead_code)] -#[derive(Debug, Clone)] -pub(crate) struct Pet { - id: i32, - name: String, - prey: Option, - is_finicky: bool, -} - -pub(crate) fn as_pet(row: &mysql::Row) -> Result { - let id = i32::decode(&row[0])?; - let name = String::decode(&row[1])?; - let prey = Option::::decode(&row[2])?; - let is_finicky = bool::decode(&row[3])?; - - Ok(Pet { - id, - name, - prey, - is_finicky, - }) -} diff --git a/examples/rust-outbound-pg/.cargo/config.toml b/examples/rust-outbound-pg/.cargo/config.toml deleted file mode 100644 index 6b77899cb3..0000000000 --- a/examples/rust-outbound-pg/.cargo/config.toml +++ /dev/null @@ -1,2 +0,0 @@ -[build] -target = "wasm32-wasi" diff --git a/examples/rust-outbound-pg/Cargo.lock b/examples/rust-outbound-pg/Cargo.lock deleted file mode 100644 index 18b09d72cc..0000000000 --- a/examples/rust-outbound-pg/Cargo.lock +++ /dev/null @@ -1,586 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "anyhow" -version = "1.0.75" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" - -[[package]] -name = "async-trait" -version = "0.1.74" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "bitflags" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" - -[[package]] -name = "bytes" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "form_urlencoded" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" -dependencies = [ - "percent-encoding", -] - -[[package]] -name = "futures" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" - -[[package]] -name = "futures-executor" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" - -[[package]] -name = "futures-macro" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "futures-sink" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" - -[[package]] -name = "futures-task" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" - -[[package]] -name = "futures-util" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "hashbrown" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" - -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -dependencies = [ - "unicode-segmentation", -] - -[[package]] -name = "http" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "id-arena" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" - -[[package]] -name = "indexmap" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" -dependencies = [ - "equivalent", - "hashbrown", - "serde", -] - -[[package]] -name = "itoa" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" - -[[package]] -name = "leb128" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" - -[[package]] -name = "log" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" - -[[package]] -name = "memchr" -version = "2.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" - -[[package]] -name = "once_cell" -version = "1.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" - -[[package]] -name = "percent-encoding" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" - -[[package]] -name = "pin-project-lite" -version = "0.2.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "routefinder" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94f8f99b10dedd317514253dda1fa7c14e344aac96e1f78149a64879ce282aca" -dependencies = [ - "smartcow", - "smartstring", -] - -[[package]] -name = "rust-outbound-pg" -version = "0.1.0" -dependencies = [ - "anyhow", - "http", - "spin-sdk", -] - -[[package]] -name = "ryu" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" - -[[package]] -name = "semver" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" - -[[package]] -name = "serde" -version = "1.0.189" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.189" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "serde_json" -version = "1.0.107" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" - -[[package]] -name = "smartcow" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "656fcb1c1fca8c4655372134ce87d8afdf5ec5949ebabe8d314be0141d8b5da2" -dependencies = [ - "smartstring", -] - -[[package]] -name = "smartstring" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb72c633efbaa2dd666986505016c32c3044395ceaf881518399d2f4127ee29" -dependencies = [ - "autocfg", - "static_assertions", - "version_check", -] - -[[package]] -name = "spdx" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b19b32ed6d899ab23174302ff105c1577e45a06b08d4fe0a9dd13ce804bbbf71" -dependencies = [ - "smallvec", -] - -[[package]] -name = "spin-macro" -version = "2.3.0-pre0" -dependencies = [ - "anyhow", - "bytes", - "http", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "spin-sdk" -version = "2.3.0-pre0" -dependencies = [ - "anyhow", - "async-trait", - "bytes", - "form_urlencoded", - "futures", - "http", - "once_cell", - "routefinder", - "serde", - "serde_json", - "spin-macro", - "thiserror", - "wit-bindgen", -] - -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "thiserror" -version = "1.0.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "unicode-segmentation" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" - -[[package]] -name = "unicode-xid" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wasm-encoder" -version = "0.35.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ca90ba1b5b0a70d3d49473c5579951f3bddc78d47b59256d2f9d4922b150aca" -dependencies = [ - "leb128", -] - -[[package]] -name = "wasm-metadata" -version = "0.10.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14abc161bfda5b519aa229758b68f2a52b45a12b993808665c857d1a9a00223c" -dependencies = [ - "anyhow", - "indexmap", - "serde", - "serde_derive", - "serde_json", - "spdx", - "wasm-encoder", - "wasmparser", -] - -[[package]] -name = "wasmparser" -version = "0.115.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e06c0641a4add879ba71ccb3a1e4278fd546f76f1eafb21d8f7b07733b547cd5" -dependencies = [ - "indexmap", - "semver", -] - -[[package]] -name = "wit-bindgen" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7d92ce0ca6b6074059413a9581a637550c3a740581c854f9847ec293c8aed71" -dependencies = [ - "bitflags", - "wit-bindgen-rust-macro", -] - -[[package]] -name = "wit-bindgen-core" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "565b945ae074886071eccf9cdaf8ccd7b959c2b0d624095bea5fe62003e8b3e0" -dependencies = [ - "anyhow", - "wit-component", - "wit-parser", -] - -[[package]] -name = "wit-bindgen-rust" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5695ff4e41873ed9ce56d2787e6b5772bdad9e70e2c1d2d160621d1762257f4f" -dependencies = [ - "anyhow", - "heck", - "wasm-metadata", - "wit-bindgen-core", - "wit-component", -] - -[[package]] -name = "wit-bindgen-rust-macro" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a91835ea4231da1fe7971679d505ba14be7826e192b6357f08465866ef482e08" -dependencies = [ - "anyhow", - "proc-macro2", - "quote", - "syn 2.0.38", - "wit-bindgen-core", - "wit-bindgen-rust", - "wit-component", -] - -[[package]] -name = "wit-component" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e87488b57a08e2cbbd076b325acbe7f8666965af174d69d5929cd373bd54547f" -dependencies = [ - "anyhow", - "bitflags", - "indexmap", - "log", - "serde", - "serde_derive", - "serde_json", - "wasm-encoder", - "wasm-metadata", - "wasmparser", - "wit-parser", -] - -[[package]] -name = "wit-parser" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ace9943d89bbf3dbbc71b966da0e7302057b311f36a4ac3d65ddfef17b52cf" -dependencies = [ - "anyhow", - "id-arena", - "indexmap", - "log", - "semver", - "serde", - "serde_derive", - "serde_json", - "unicode-xid", -] diff --git a/examples/rust-outbound-pg/Cargo.toml b/examples/rust-outbound-pg/Cargo.toml deleted file mode 100644 index 6822a33e17..0000000000 --- a/examples/rust-outbound-pg/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "rust-outbound-pg" -version = "0.1.0" -edition = "2021" - -[lib] -crate-type = ["cdylib"] - -[dependencies] -# Useful crate to handle errors. -anyhow = "1" -# General-purpose crate with common HTTP types. -http = "0.2" -# The Spin SDK. -spin-sdk = { path = "../../sdk/rust" } - -[workspace] diff --git a/examples/rust-outbound-pg/README.md b/examples/rust-outbound-pg/README.md deleted file mode 100644 index bdbb3034e9..0000000000 --- a/examples/rust-outbound-pg/README.md +++ /dev/null @@ -1,49 +0,0 @@ -# Spin Outbound PostgreSQL example - -This example shows how to access a PostgreSQL database from Spin component. - -## Spin up - -From example root: - -``` -createdb spin_dev -psql -d spin_dev -f db/testdata.sql -RUST_LOG=spin=trace spin build --up -``` - -Curl the read route: - -``` -$ curl -i localhost:3000/read -HTTP/1.1 200 OK -content-length: 501 -date: Sun, 25 Sep 2022 15:45:02 GMT - -Found 2 article(s) as follows: -article: Article { - id: 1, - title: "My Life as a Goat", - content: "I went to Nepal to live as a goat, and it was much better than being a butler.", - authorname: "E. Blackadder", -} -article: Article { - id: 2, - title: "Magnificent Octopus", - content: "Once upon a time there was a lovely little sausage.", - authorname: "S. Baldrick", -} - -(Column info: id:DbDataType::Int32, title:DbDataType::Str, content:DbDataType::Str, authorname:DbDataType::Str) -``` - -Curl the write route: - -``` -$ curl -i localhost:3000/write -HTTP/1.1 200 OK -content-length: 9 -date: Sun, 25 Sep 2022 15:46:22 GMT - -Count: 3 -``` diff --git a/examples/rust-outbound-pg/db/testdata.sql b/examples/rust-outbound-pg/db/testdata.sql deleted file mode 100644 index 6e21a5a7c3..0000000000 --- a/examples/rust-outbound-pg/db/testdata.sql +++ /dev/null @@ -1,19 +0,0 @@ -CREATE TABLE articletest ( - id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, - title varchar(40) NOT NULL, - content text NOT NULL, - authorname varchar(40) NOT NULL, - coauthor text -); - -INSERT INTO articletest (title, content, authorname) VALUES -( - 'My Life as a Goat', - 'I went to Nepal to live as a goat, and it was much better than being a butler.', - 'E. Blackadder' -), -( - 'Magnificent Octopus', - 'Once upon a time there was a lovely little sausage.', - 'S. Baldrick' -); diff --git a/examples/rust-outbound-pg/spin.toml b/examples/rust-outbound-pg/spin.toml deleted file mode 100644 index 4dc305653d..0000000000 --- a/examples/rust-outbound-pg/spin.toml +++ /dev/null @@ -1,17 +0,0 @@ -spin_manifest_version = 2 - -[application] -authors = ["Fermyon Engineering "] -name = "rust-outbound-pg-example" -version = "0.1.0" - -[[trigger.http]] -route = "/..." -component = "outbound-pg" - -[component.outbound-pg] -environment = { DB_URL = "host=localhost user=postgres dbname=spin_dev" } -source = "target/wasm32-wasi/release/rust_outbound_pg.wasm" -allowed_outbound_hosts = ["postgres://localhost"] -[component.outbound-pg.build] -command = "cargo build --target wasm32-wasi --release" diff --git a/examples/rust-outbound-pg/src/lib.rs b/examples/rust-outbound-pg/src/lib.rs deleted file mode 100644 index 94c4f6f1c6..0000000000 --- a/examples/rust-outbound-pg/src/lib.rs +++ /dev/null @@ -1,128 +0,0 @@ -#![allow(dead_code)] -use anyhow::Result; -use http::{Request, Response}; -use spin_sdk::{ - http_component, - pg::{self, Decode}, -}; - -// The environment variable set in `spin.toml` that points to the -// address of the Pg server that the component will write to -const DB_URL_ENV: &str = "DB_URL"; - -#[derive(Debug, Clone)] -struct Article { - id: i32, - title: String, - content: String, - authorname: String, - coauthor: Option, -} - -impl TryFrom<&pg::Row> for Article { - type Error = anyhow::Error; - - fn try_from(row: &pg::Row) -> Result { - let id = i32::decode(&row[0])?; - let title = String::decode(&row[1])?; - let content = String::decode(&row[2])?; - let authorname = String::decode(&row[3])?; - let coauthor = Option::::decode(&row[4])?; - - Ok(Self { - id, - title, - content, - authorname, - coauthor, - }) - } -} - -#[http_component] -fn process(req: Request<()>) -> Result> { - match req.uri().path() { - "/read" => read(req), - "/write" => write(req), - "/pg_backend_pid" => pg_backend_pid(req), - _ => Ok(http::Response::builder() - .status(404) - .body("Not found".into())?), - } -} - -fn read(_req: Request<()>) -> Result> { - let address = std::env::var(DB_URL_ENV)?; - let conn = pg::Connection::open(&address)?; - - let sql = "SELECT id, title, content, authorname, coauthor FROM articletest"; - let rowset = conn.query(sql, &[])?; - - let column_summary = rowset - .columns - .iter() - .map(format_col) - .collect::>() - .join(", "); - - let mut response_lines = vec![]; - - for row in rowset.rows { - let article = Article::try_from(&row)?; - - println!("article: {:#?}", article); - response_lines.push(format!("article: {:#?}", article)); - } - - // use it in business logic - - let response = format!( - "Found {} article(s) as follows:\n{}\n\n(Column info: {})\n", - response_lines.len(), - response_lines.join("\n"), - column_summary, - ); - - Ok(http::Response::builder().status(200).body(response)?) -} - -fn write(_req: Request<()>) -> Result> { - let address = std::env::var(DB_URL_ENV)?; - let conn = pg::Connection::open(&address)?; - - let sql = "INSERT INTO articletest (title, content, authorname) VALUES ('aaa', 'bbb', 'ccc')"; - let nrow_executed = conn.execute(sql, &[])?; - - println!("nrow_executed: {}", nrow_executed); - - let sql = "SELECT COUNT(id) FROM articletest"; - let rowset = conn.query(sql, &[])?; - let row = &rowset.rows[0]; - let count = i64::decode(&row[0])?; - let response = format!("Count: {}\n", count); - - Ok(http::Response::builder().status(200).body(response)?) -} - -fn pg_backend_pid(_req: Request<()>) -> Result> { - let address = std::env::var(DB_URL_ENV)?; - let conn = pg::Connection::open(&address)?; - let sql = "SELECT pg_backend_pid()"; - - let get_pid = || { - let rowset = conn.query(sql, &[])?; - let row = &rowset.rows[0]; - - i32::decode(&row[0]) - }; - - assert_eq!(get_pid()?, get_pid()?); - - let response = format!("pg_backend_pid: {}\n", get_pid()?); - - Ok(http::Response::builder().status(200).body(response)?) -} - -fn format_col(column: &pg::Column) -> String { - format!("{}:{:?}", column.name, column.data_type) -} diff --git a/examples/rust-outbound-redis/.cargo/config.toml b/examples/rust-outbound-redis/.cargo/config.toml deleted file mode 100644 index 6b77899cb3..0000000000 --- a/examples/rust-outbound-redis/.cargo/config.toml +++ /dev/null @@ -1,2 +0,0 @@ -[build] -target = "wasm32-wasi" diff --git a/examples/rust-outbound-redis/Cargo.lock b/examples/rust-outbound-redis/Cargo.lock deleted file mode 100644 index 439225f2a1..0000000000 --- a/examples/rust-outbound-redis/Cargo.lock +++ /dev/null @@ -1,585 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "anyhow" -version = "1.0.75" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" - -[[package]] -name = "async-trait" -version = "0.1.74" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "bitflags" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" - -[[package]] -name = "bytes" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "form_urlencoded" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" -dependencies = [ - "percent-encoding", -] - -[[package]] -name = "futures" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" - -[[package]] -name = "futures-executor" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" - -[[package]] -name = "futures-macro" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "futures-sink" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" - -[[package]] -name = "futures-task" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" - -[[package]] -name = "futures-util" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "hashbrown" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" - -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -dependencies = [ - "unicode-segmentation", -] - -[[package]] -name = "http" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "id-arena" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" - -[[package]] -name = "indexmap" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" -dependencies = [ - "equivalent", - "hashbrown", - "serde", -] - -[[package]] -name = "itoa" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" - -[[package]] -name = "leb128" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" - -[[package]] -name = "log" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" - -[[package]] -name = "memchr" -version = "2.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" - -[[package]] -name = "once_cell" -version = "1.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" - -[[package]] -name = "percent-encoding" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" - -[[package]] -name = "pin-project-lite" -version = "0.2.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "routefinder" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94f8f99b10dedd317514253dda1fa7c14e344aac96e1f78149a64879ce282aca" -dependencies = [ - "smartcow", - "smartstring", -] - -[[package]] -name = "rust-outbound-redis" -version = "0.1.0" -dependencies = [ - "anyhow", - "spin-sdk", -] - -[[package]] -name = "ryu" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" - -[[package]] -name = "semver" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" - -[[package]] -name = "serde" -version = "1.0.189" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.189" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "serde_json" -version = "1.0.107" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" - -[[package]] -name = "smartcow" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "656fcb1c1fca8c4655372134ce87d8afdf5ec5949ebabe8d314be0141d8b5da2" -dependencies = [ - "smartstring", -] - -[[package]] -name = "smartstring" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb72c633efbaa2dd666986505016c32c3044395ceaf881518399d2f4127ee29" -dependencies = [ - "autocfg", - "static_assertions", - "version_check", -] - -[[package]] -name = "spdx" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b19b32ed6d899ab23174302ff105c1577e45a06b08d4fe0a9dd13ce804bbbf71" -dependencies = [ - "smallvec", -] - -[[package]] -name = "spin-macro" -version = "2.3.0-pre0" -dependencies = [ - "anyhow", - "bytes", - "http", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "spin-sdk" -version = "2.3.0-pre0" -dependencies = [ - "anyhow", - "async-trait", - "bytes", - "form_urlencoded", - "futures", - "http", - "once_cell", - "routefinder", - "serde", - "serde_json", - "spin-macro", - "thiserror", - "wit-bindgen", -] - -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "thiserror" -version = "1.0.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "unicode-segmentation" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" - -[[package]] -name = "unicode-xid" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wasm-encoder" -version = "0.35.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ca90ba1b5b0a70d3d49473c5579951f3bddc78d47b59256d2f9d4922b150aca" -dependencies = [ - "leb128", -] - -[[package]] -name = "wasm-metadata" -version = "0.10.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14abc161bfda5b519aa229758b68f2a52b45a12b993808665c857d1a9a00223c" -dependencies = [ - "anyhow", - "indexmap", - "serde", - "serde_derive", - "serde_json", - "spdx", - "wasm-encoder", - "wasmparser", -] - -[[package]] -name = "wasmparser" -version = "0.115.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e06c0641a4add879ba71ccb3a1e4278fd546f76f1eafb21d8f7b07733b547cd5" -dependencies = [ - "indexmap", - "semver", -] - -[[package]] -name = "wit-bindgen" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7d92ce0ca6b6074059413a9581a637550c3a740581c854f9847ec293c8aed71" -dependencies = [ - "bitflags", - "wit-bindgen-rust-macro", -] - -[[package]] -name = "wit-bindgen-core" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "565b945ae074886071eccf9cdaf8ccd7b959c2b0d624095bea5fe62003e8b3e0" -dependencies = [ - "anyhow", - "wit-component", - "wit-parser", -] - -[[package]] -name = "wit-bindgen-rust" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5695ff4e41873ed9ce56d2787e6b5772bdad9e70e2c1d2d160621d1762257f4f" -dependencies = [ - "anyhow", - "heck", - "wasm-metadata", - "wit-bindgen-core", - "wit-component", -] - -[[package]] -name = "wit-bindgen-rust-macro" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a91835ea4231da1fe7971679d505ba14be7826e192b6357f08465866ef482e08" -dependencies = [ - "anyhow", - "proc-macro2", - "quote", - "syn 2.0.38", - "wit-bindgen-core", - "wit-bindgen-rust", - "wit-component", -] - -[[package]] -name = "wit-component" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e87488b57a08e2cbbd076b325acbe7f8666965af174d69d5929cd373bd54547f" -dependencies = [ - "anyhow", - "bitflags", - "indexmap", - "log", - "serde", - "serde_derive", - "serde_json", - "wasm-encoder", - "wasm-metadata", - "wasmparser", - "wit-parser", -] - -[[package]] -name = "wit-parser" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ace9943d89bbf3dbbc71b966da0e7302057b311f36a4ac3d65ddfef17b52cf" -dependencies = [ - "anyhow", - "id-arena", - "indexmap", - "log", - "semver", - "serde", - "serde_derive", - "serde_json", - "unicode-xid", -] diff --git a/examples/rust-outbound-redis/Cargo.toml b/examples/rust-outbound-redis/Cargo.toml deleted file mode 100644 index 1f53f9638f..0000000000 --- a/examples/rust-outbound-redis/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "rust-outbound-redis" -version = "0.1.0" -edition = "2021" - -[lib] -crate-type = ["cdylib"] - -[dependencies] -# Useful crate to handle errors. -anyhow = "1" -# The Spin SDK. -spin-sdk = { path = "../../sdk/rust" } - -[workspace] diff --git a/examples/rust-outbound-redis/spin.toml b/examples/rust-outbound-redis/spin.toml deleted file mode 100644 index 658ed595eb..0000000000 --- a/examples/rust-outbound-redis/spin.toml +++ /dev/null @@ -1,17 +0,0 @@ -spin_manifest_version = 2 - -[application] -authors = ["Fermyon Engineering "] -name = "rust-outbound-redis-example" -version = "0.1.0" - -[[trigger.http]] -route = "/publish" -component = "outbound-redis" - -[component.outbound-redis] -environment = { REDIS_ADDRESS = "redis://127.0.0.1:6379", REDIS_CHANNEL = "messages" } -source = "target/wasm32-wasi/release/rust_outbound_redis.wasm" -allowed_outbound_hosts = ["redis://127.0.0.1"] -[component.outbound-redis.build] -command = "cargo build --target wasm32-wasi --release" diff --git a/examples/rust-outbound-redis/src/lib.rs b/examples/rust-outbound-redis/src/lib.rs deleted file mode 100644 index a9333f8e02..0000000000 --- a/examples/rust-outbound-redis/src/lib.rs +++ /dev/null @@ -1,51 +0,0 @@ -use anyhow::{anyhow, Context, Result}; -use spin_sdk::{ - http::responses::internal_server_error, - http::{IntoResponse, Request, Response}, - http_component, redis, -}; - -// The environment variable set in `spin.toml` that points to the -// address of the Redis server that the component will publish -// a message to. -const REDIS_ADDRESS_ENV: &str = "REDIS_ADDRESS"; - -// The environment variable set in `spin.toml` that specifies -// the Redis channel that the component will publish to. -const REDIS_CHANNEL_ENV: &str = "REDIS_CHANNEL"; - -/// This HTTP component demonstrates fetching a value from Redis -/// by key, setting a key with a value, and publishing a message -/// to a Redis channel. The component is triggered by an HTTP -/// request served on the route configured in the `spin.toml`. -#[http_component] -fn publish(_req: Request) -> Result { - let address = std::env::var(REDIS_ADDRESS_ENV)?; - let channel = std::env::var(REDIS_CHANNEL_ENV)?; - - let conn = redis::Connection::open(&address)?; - - // Get the message to publish from the Redis key "mykey" - let payload = conn - .get("mykey") - .map_err(|_| anyhow!("Error querying Redis"))? - .context("no value for key 'mykey'")?; - - // Set the Redis key "spin-example" to value "Eureka!" - conn.set("spin-example", &"Eureka!".to_owned().into_bytes()) - .map_err(|_| anyhow!("Error executing Redis set command"))?; - - // Set the Redis key "int-key" to value 0 - conn.set("int-key", &format!("{:x}", 0).into_bytes()) - .map_err(|_| anyhow!("Error executing Redis set command"))?; - let int_value = conn - .incr("int-key") - .map_err(|_| anyhow!("Error executing Redis incr command",))?; - assert_eq!(int_value, 1); - - // Publish to Redis - match conn.publish(&channel, &payload) { - Ok(()) => Ok(Response::new(200, ())), - Err(_e) => Ok(internal_server_error()), - } -} diff --git a/examples/spin-wagi-http/http-rust/Cargo.lock b/examples/spin-wagi-http/http-rust/Cargo.lock index 5899e01fb6..264edd0b74 100644 --- a/examples/spin-wagi-http/http-rust/Cargo.lock +++ b/examples/spin-wagi-http/http-rust/Cargo.lock @@ -365,7 +365,9 @@ dependencies = [ [[package]] name = "spin-macro" -version = "2.3.0-pre0" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13524474ab9f876586e29f954377a66ed14fcb646fc9893e6f0e762213ddbd86" dependencies = [ "anyhow", "bytes", @@ -377,7 +379,9 @@ dependencies = [ [[package]] name = "spin-sdk" -version = "2.3.0-pre0" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f05d0c09c0935fbb586d0a76e0f14b26b23f421c5e11b81d7200d22c4ead1211" dependencies = [ "anyhow", "async-trait", diff --git a/examples/spin-wagi-http/http-rust/Cargo.toml b/examples/spin-wagi-http/http-rust/Cargo.toml index c397a782ea..71644ebd08 100644 --- a/examples/spin-wagi-http/http-rust/Cargo.toml +++ b/examples/spin-wagi-http/http-rust/Cargo.toml @@ -14,7 +14,7 @@ bytes = "1" # General-purpose crate with common HTTP types. http = "0.2" # The Spin SDK. -spin-sdk = { path = "../../../sdk/rust" } +spin-sdk = "2.2.0" [workspace] diff --git a/examples/tinygo-key-value/README.md b/examples/tinygo-key-value/README.md deleted file mode 100644 index 1148760299..0000000000 --- a/examples/tinygo-key-value/README.md +++ /dev/null @@ -1,36 +0,0 @@ -# Spin Key Value component in TinyGo - -```shell -$ go mod tidy -$ RUST_LOG=spin=trace spin build --up -``` - -The application can now receive requests on `http://localhost:3000`: - -```shell -$ curl -i -X POST -d "ok!" localhost:3000/test -HTTP/1.1 200 OK -content-length: 0 -date: Tue, 25 Apr 2023 14:25:43 GMT - -$ curl -i -X GET localhost:3000/test -HTTP/1.1 200 OK -content-length: 3 -date: Tue, 25 Apr 2023 14:25:54 GMT - -ok! - -$ curl -i -X DELETE localhost:3000/test -HTTP/1.1 200 OK -content-length: 0 -date: Tue, 25 Apr 2023 14:26:30 GMT - -$ curl -i -X GET localhost:3000/test -HTTP/1.1 500 Internal Server Error -content-type: text/plain; charset=utf-8 -x-content-type-options: nosniff -content-length: 12 -date: Tue, 25 Apr 2023 14:26:32 GMT - -no such key -``` diff --git a/examples/tinygo-key-value/go.mod b/examples/tinygo-key-value/go.mod deleted file mode 100644 index 8810ad5ef3..0000000000 --- a/examples/tinygo-key-value/go.mod +++ /dev/null @@ -1,9 +0,0 @@ -module github.com/fermyon/spin/templates/spin-http-tinygo-key-value - -go 1.20 - -require github.com/fermyon/spin/sdk/go/v2 v2.0.0 - -require github.com/julienschmidt/httprouter v1.3.0 // indirect - -replace github.com/fermyon/spin/sdk/go/v2 v2.0.0 => ../../sdk/go/ diff --git a/examples/tinygo-key-value/go.sum b/examples/tinygo-key-value/go.sum deleted file mode 100644 index 096c54e630..0000000000 --- a/examples/tinygo-key-value/go.sum +++ /dev/null @@ -1,2 +0,0 @@ -github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= -github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= diff --git a/examples/tinygo-key-value/main.go b/examples/tinygo-key-value/main.go deleted file mode 100644 index 1826d4b559..0000000000 --- a/examples/tinygo-key-value/main.go +++ /dev/null @@ -1,71 +0,0 @@ -package main - -import ( - "io" - "net/http" - - spin_http "github.com/fermyon/spin/sdk/go/v2/http" - "github.com/fermyon/spin/sdk/go/v2/kv" -) - -func init() { - // handler for the http trigger - spin_http.Handle(func(w http.ResponseWriter, r *http.Request) { - store, err := kv.OpenStore("default") - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - defer store.Close() - - body, err := io.ReadAll(r.Body) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - switch r.Method { - case http.MethodPost: - err := store.Set(r.URL.Path, body) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - w.WriteHeader(http.StatusOK) - case http.MethodGet: - value, err := store.Get(r.URL.Path) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - w.WriteHeader(http.StatusOK) - w.Write(value) - case http.MethodDelete: - if err := store.Delete(r.URL.Path); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - w.WriteHeader(http.StatusOK) - case http.MethodHead: - exists, err := store.Exists(r.URL.Path) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - if exists { - w.WriteHeader(http.StatusOK) - return - } - - w.WriteHeader(http.StatusNotFound) - default: - http.Error(w, "method not allowed", http.StatusMethodNotAllowed) - } - }) -} - -func main() {} diff --git a/examples/tinygo-key-value/spin.toml b/examples/tinygo-key-value/spin.toml deleted file mode 100644 index 2df57f8871..0000000000 --- a/examples/tinygo-key-value/spin.toml +++ /dev/null @@ -1,16 +0,0 @@ -spin_manifest_version = 2 - -[application] -authors = ["Fermyon Engineering "] -name = "tinygo-key-value-example" -version = "0.1.0" - -[[trigger.http]] -route = "/..." -component = "key-value" - -[component.key-value] -source = "main.wasm" -key_value_stores = ["default"] -[component.key-value.build] -command = "tinygo build -target=wasi -gc=leaking -no-debug -o main.wasm main.go" diff --git a/examples/tinygo-llm/.gitignore b/examples/tinygo-llm/.gitignore deleted file mode 100644 index b565010470..0000000000 --- a/examples/tinygo-llm/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -main.wasm -.spin/ diff --git a/examples/tinygo-llm/go.mod b/examples/tinygo-llm/go.mod deleted file mode 100644 index 9c4ef072c3..0000000000 --- a/examples/tinygo-llm/go.mod +++ /dev/null @@ -1,9 +0,0 @@ -module github.com/tinygo_llm - -go 1.20 - -require github.com/fermyon/spin/sdk/go/v2 v2.0.0 - -require github.com/julienschmidt/httprouter v1.3.0 // indirect - -replace github.com/fermyon/spin/sdk/go/v2 v2.0.0 => ../../sdk/go/ diff --git a/examples/tinygo-llm/go.sum b/examples/tinygo-llm/go.sum deleted file mode 100644 index fcb43438db..0000000000 --- a/examples/tinygo-llm/go.sum +++ /dev/null @@ -1,4 +0,0 @@ -github.com/fermyon/spin/sdk/go v1.4.1 h1:n8KTYTnkErTJdyMBBEtPmJe8dXrvMT6R7iVWbLRjq5E= -github.com/fermyon/spin/sdk/go v1.4.1/go.mod h1:yb8lGesopgj/GwPzLPATxcOeqWZT/HjrzEFfwbztAXE= -github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= -github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= diff --git a/examples/tinygo-llm/main.go b/examples/tinygo-llm/main.go deleted file mode 100644 index f0014619f8..0000000000 --- a/examples/tinygo-llm/main.go +++ /dev/null @@ -1,34 +0,0 @@ -package main - -import ( - "fmt" - "net/http" - - spinhttp "github.com/fermyon/spin/sdk/go/v2/http" - "github.com/fermyon/spin/sdk/go/v2/llm" -) - -func init() { - spinhttp.Handle(func(w http.ResponseWriter, r *http.Request) { - result, err := llm.Infer("llama2-chat", "Tell me a joke", nil) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - fmt.Printf("Prompt tokens: %d\n", result.Usage.PromptTokenCount) - fmt.Printf("Generated tokens: %d\n", result.Usage.GeneratedTokenCount) - fmt.Fprint(w, result.Text) - fmt.Fprintf(w, "\n\n") - - embeddings, err := llm.GenerateEmbeddings("all-minilm-l6-v2", []string{"Hello world"}) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - fmt.Printf("%d\n", len(embeddings.Embeddings[0])) - fmt.Printf("Prompt Tokens: %d\n", embeddings.Usage.PromptTokenCount) - - }) -} - -func main() {} diff --git a/examples/tinygo-llm/spin.toml b/examples/tinygo-llm/spin.toml deleted file mode 100644 index 73f5104fb7..0000000000 --- a/examples/tinygo-llm/spin.toml +++ /dev/null @@ -1,19 +0,0 @@ -spin_manifest_version = 2 - -[application] -authors = ["Fermyon Engineering "] -description = "Simple example using the llm sdk." -name = "tinygo-llm" -version = "0.1.0" - -[[trigger.http]] -route = "/..." -component = "tinygo-llm" - -[component.tinygo-llm] -source = "main.wasm" -allowed_outbound_hosts = [] -ai_models = ["llama2-chat", "all-minilm-l6-v2"] -[component.tinygo-llm.build] -command = "tinygo build -target=wasi -gc=leaking -no-debug -o main.wasm main.go" -watch = ["**/*.go", "go.mod"] diff --git a/examples/tinygo-outbound-mysql/.gitignore b/examples/tinygo-outbound-mysql/.gitignore deleted file mode 100644 index b565010470..0000000000 --- a/examples/tinygo-outbound-mysql/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -main.wasm -.spin/ diff --git a/examples/tinygo-outbound-mysql/db/pets.sql b/examples/tinygo-outbound-mysql/db/pets.sql deleted file mode 100644 index bbf91d68ad..0000000000 --- a/examples/tinygo-outbound-mysql/db/pets.sql +++ /dev/null @@ -1,4 +0,0 @@ -CREATE TABLE pets (id INT PRIMARY KEY, name VARCHAR(100) NOT NULL, prey VARCHAR(100), is_finicky BOOL NOT NULL); -INSERT INTO pets VALUES (1, 'Splodge', NULL, false); -INSERT INTO pets VALUES (2, 'Kiki', 'Cicadas', false); -INSERT INTO pets VALUES (3, 'Slats', 'Temptations', true); diff --git a/examples/tinygo-outbound-mysql/go.mod b/examples/tinygo-outbound-mysql/go.mod deleted file mode 100644 index 65b1fa3674..0000000000 --- a/examples/tinygo-outbound-mysql/go.mod +++ /dev/null @@ -1,9 +0,0 @@ -module github.com/tinygo_mysql - -go 1.20 - -require github.com/fermyon/spin/sdk/go/v2 v2.0.0 - -require github.com/julienschmidt/httprouter v1.3.0 // indirect - -replace github.com/fermyon/spin/sdk/go/v2 v2.0.0 => ../../sdk/go/ diff --git a/examples/tinygo-outbound-mysql/go.sum b/examples/tinygo-outbound-mysql/go.sum deleted file mode 100644 index fcb43438db..0000000000 --- a/examples/tinygo-outbound-mysql/go.sum +++ /dev/null @@ -1,4 +0,0 @@ -github.com/fermyon/spin/sdk/go v1.4.1 h1:n8KTYTnkErTJdyMBBEtPmJe8dXrvMT6R7iVWbLRjq5E= -github.com/fermyon/spin/sdk/go v1.4.1/go.mod h1:yb8lGesopgj/GwPzLPATxcOeqWZT/HjrzEFfwbztAXE= -github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= -github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= diff --git a/examples/tinygo-outbound-mysql/main.go b/examples/tinygo-outbound-mysql/main.go deleted file mode 100644 index 88937c0269..0000000000 --- a/examples/tinygo-outbound-mysql/main.go +++ /dev/null @@ -1,54 +0,0 @@ -package main - -import ( - "encoding/json" - "fmt" - "net/http" - "os" - - spinhttp "github.com/fermyon/spin/sdk/go/v2/http" - "github.com/fermyon/spin/sdk/go/v2/mysql" -) - -type Pet struct { - ID int64 - Name string - Prey *string // nullable field must be a pointer - IsFinicky bool -} - -func init() { - spinhttp.Handle(func(w http.ResponseWriter, r *http.Request) { - - // addr is the environment variable set in `spin.toml` that points to the - // address of the Mysql server. - addr := os.Getenv("DB_URL") - - db := mysql.Open(addr) - defer db.Close() - - _, err := db.Query("REPLACE INTO pets VALUES (?, 'Maya', ?, ?);", 4, "bananas", true) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - rows, err := db.Query("SELECT * FROM pets") - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - var pets []*Pet - for rows.Next() { - var pet Pet - if err := rows.Scan(&pet.ID, &pet.Name, &pet.Prey, &pet.IsFinicky); err != nil { - fmt.Println(err) - } - pets = append(pets, &pet) - } - json.NewEncoder(w).Encode(pets) - }) -} - -func main() {} diff --git a/examples/tinygo-outbound-mysql/spin.toml b/examples/tinygo-outbound-mysql/spin.toml deleted file mode 100644 index af450e75e5..0000000000 --- a/examples/tinygo-outbound-mysql/spin.toml +++ /dev/null @@ -1,19 +0,0 @@ -spin_manifest_version = 2 - -[application] -authors = ["Patrick Jiang "] -description = "" -name = "tinygo-mysql" -version = "0.1.0" - -[[trigger.http]] -route = "/..." -component = "tinygo-mysql" - -[component.tinygo-mysql] -environment = { DB_URL = "mysql://spin:spin@127.0.0.1/spin_dev" } -source = "main.wasm" -allowed_outbound_hosts = ["mysql://127.0.0.1"] -[component.tinygo-mysql.build] -command = "tinygo build -target=wasi -gc=leaking -o main.wasm main.go" -watch = ["**/*.go", "go.mod"] diff --git a/examples/tinygo-outbound-pg/db/pets.sql b/examples/tinygo-outbound-pg/db/pets.sql deleted file mode 100644 index bbf91d68ad..0000000000 --- a/examples/tinygo-outbound-pg/db/pets.sql +++ /dev/null @@ -1,4 +0,0 @@ -CREATE TABLE pets (id INT PRIMARY KEY, name VARCHAR(100) NOT NULL, prey VARCHAR(100), is_finicky BOOL NOT NULL); -INSERT INTO pets VALUES (1, 'Splodge', NULL, false); -INSERT INTO pets VALUES (2, 'Kiki', 'Cicadas', false); -INSERT INTO pets VALUES (3, 'Slats', 'Temptations', true); diff --git a/examples/tinygo-outbound-pg/go.mod b/examples/tinygo-outbound-pg/go.mod deleted file mode 100644 index e1a0d20d86..0000000000 --- a/examples/tinygo-outbound-pg/go.mod +++ /dev/null @@ -1,9 +0,0 @@ -module github.com/tinygo_outbound_pg - -go 1.20 - -require github.com/fermyon/spin/sdk/go/v2 v2.0.0 - -require github.com/julienschmidt/httprouter v1.3.0 // indirect - -replace github.com/fermyon/spin/sdk/go/v2 v2.0.0 => ../../sdk/go/ diff --git a/examples/tinygo-outbound-pg/go.sum b/examples/tinygo-outbound-pg/go.sum deleted file mode 100644 index fcb43438db..0000000000 --- a/examples/tinygo-outbound-pg/go.sum +++ /dev/null @@ -1,4 +0,0 @@ -github.com/fermyon/spin/sdk/go v1.4.1 h1:n8KTYTnkErTJdyMBBEtPmJe8dXrvMT6R7iVWbLRjq5E= -github.com/fermyon/spin/sdk/go v1.4.1/go.mod h1:yb8lGesopgj/GwPzLPATxcOeqWZT/HjrzEFfwbztAXE= -github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= -github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= diff --git a/examples/tinygo-outbound-pg/main.go b/examples/tinygo-outbound-pg/main.go deleted file mode 100644 index ee5a1f5122..0000000000 --- a/examples/tinygo-outbound-pg/main.go +++ /dev/null @@ -1,54 +0,0 @@ -package main - -import ( - "encoding/json" - "fmt" - "net/http" - "os" - - spinhttp "github.com/fermyon/spin/sdk/go/v2/http" - "github.com/fermyon/spin/sdk/go/v2/pg" -) - -type Pet struct { - ID int64 - Name string - Prey *string // nullable field must be a pointer - IsFinicky bool -} - -func init() { - spinhttp.Handle(func(w http.ResponseWriter, r *http.Request) { - - // addr is the environment variable set in `spin.toml` that points to the - // address of the Mysql server. - addr := os.Getenv("DB_URL") - - db := pg.Open(addr) - defer db.Close() - - _, err := db.Query("INSERT INTO pets VALUES ($1, 'Maya', $2, $3);", int32(4), "bananas", true) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - rows, err := db.Query("SELECT * FROM pets") - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - var pets []*Pet - for rows.Next() { - var pet Pet - if err := rows.Scan(&pet.ID, &pet.Name, &pet.Prey, &pet.IsFinicky); err != nil { - fmt.Println(err) - } - pets = append(pets, &pet) - } - json.NewEncoder(w).Encode(pets) - }) -} - -func main() {} diff --git a/examples/tinygo-outbound-pg/spin.toml b/examples/tinygo-outbound-pg/spin.toml deleted file mode 100644 index 1ccebc3be4..0000000000 --- a/examples/tinygo-outbound-pg/spin.toml +++ /dev/null @@ -1,19 +0,0 @@ -spin_manifest_version = 2 - -[application] -authors = ["Patrick Jiang "] -description = "" -name = "tinygo-outbound-pg-example" -version = "0.1.0" - -[[trigger.http]] -route = "/..." -component = "tinygo-outbound-pg-example" - -[component.tinygo-outbound-pg-example] -environment = { DB_URL = "host=localhost user=postgres dbname=spin_dev" } -source = "main.wasm" -allowed_outbound_hosts = ["postgres://localhost"] -[component.tinygo-outbound-pg-example.build] -command = "tinygo build -target=wasi -gc=leaking -o main.wasm main.go" -watch = ["**/*.go", "go.mod"] diff --git a/examples/tinygo-outbound-redis/README.md b/examples/tinygo-outbound-redis/README.md deleted file mode 100644 index fdcb43cfcd..0000000000 --- a/examples/tinygo-outbound-redis/README.md +++ /dev/null @@ -1,19 +0,0 @@ -# Spin component in TinyGo making an outbound http call to Redis - -```shell -$ go mod tidy -$ RUST_LOG=spin=trace spin build --up -``` - -The application can now receive requests on `http://localhost:3000/publish`: - -```shell -$ curl -i localhost:3000/publish -HTTP/1.1 200 OK -content-length: 67 -date: Tue, 29 Nov 2022 07:03:52 GMT - -mykey value was: myvalue -spin-go-incr value: 1 -deleted keys num: 2 -``` diff --git a/examples/tinygo-outbound-redis/go.mod b/examples/tinygo-outbound-redis/go.mod deleted file mode 100644 index 655a88bc85..0000000000 --- a/examples/tinygo-outbound-redis/go.mod +++ /dev/null @@ -1,9 +0,0 @@ -module github.com/fermyon/spin/templates/spin-http-tinygo-outbound-http - -go 1.20 - -require github.com/fermyon/spin/sdk/go/v2 v2.0.0 - -require github.com/julienschmidt/httprouter v1.3.0 // indirect - -replace github.com/fermyon/spin/sdk/go/v2 v2.0.0 => ../../sdk/go/ diff --git a/examples/tinygo-outbound-redis/go.sum b/examples/tinygo-outbound-redis/go.sum deleted file mode 100644 index 096c54e630..0000000000 --- a/examples/tinygo-outbound-redis/go.sum +++ /dev/null @@ -1,2 +0,0 @@ -github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= -github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= diff --git a/examples/tinygo-outbound-redis/main.go b/examples/tinygo-outbound-redis/main.go deleted file mode 100644 index df1bf006d9..0000000000 --- a/examples/tinygo-outbound-redis/main.go +++ /dev/null @@ -1,149 +0,0 @@ -package main - -import ( - "fmt" - "net/http" - "os" - "reflect" - "sort" - "strconv" - - spin_http "github.com/fermyon/spin/sdk/go/v2/http" - "github.com/fermyon/spin/sdk/go/v2/redis" -) - -func init() { - - // handler for the http trigger - spin_http.Handle(func(w http.ResponseWriter, _ *http.Request) { - - // addr is the environment variable set in `spin.toml` that points to the - // address of the Redis server. - addr := os.Getenv("REDIS_ADDRESS") - - // channel is the environment variable set in `spin.toml` that specifies - // the Redis channel that the component will publish to. - channel := os.Getenv("REDIS_CHANNEL") - - // payload is the data publish to the redis channel. - payload := []byte(`Hello redis from tinygo!`) - - rdb := redis.NewClient(addr) - - if err := rdb.Publish(channel, payload); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - // set redis `mykey` = `myvalue` - if err := rdb.Set("mykey", []byte("myvalue")); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - // get redis payload for `mykey` - if payload, err := rdb.Get("mykey"); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } else { - w.Write([]byte("mykey value was: ")) - w.Write(payload) - w.Write([]byte("\n")) - } - - // incr `spin-go-incr` by 1 - if payload, err := rdb.Incr("spin-go-incr"); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } else { - w.Write([]byte("spin-go-incr value: ")) - w.Write([]byte(strconv.FormatInt(payload, 10))) - w.Write([]byte("\n")) - } - - // delete `spin-go-incr` and `mykey` - if payload, err := rdb.Del("spin-go-incr", "mykey", "non-existing-key"); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - } else { - w.Write([]byte("deleted keys num: ")) - w.Write([]byte(strconv.FormatInt(payload, 10))) - w.Write([]byte("\n")) - } - - if _, err := rdb.Sadd("myset", "foo", "bar"); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - { - expected := []string{"bar", "foo"} - payload, err := rdb.Smembers("myset") - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - sort.Strings(payload) - if !reflect.DeepEqual(payload, expected) { - http.Error( - w, - fmt.Sprintf( - "unexpected SMEMBERS result: expected %v, got %v", - expected, - payload, - ), - http.StatusInternalServerError, - ) - return - } - } - - if _, err := rdb.Srem("myset", "bar"); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - { - expected := []string{"foo"} - if payload, err := rdb.Smembers("myset"); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } else if !reflect.DeepEqual(payload, expected) { - http.Error( - w, - fmt.Sprintf( - "unexpected SMEMBERS result: expected %v, got %v", - expected, - payload, - ), - http.StatusInternalServerError, - ) - return - } - } - - if _, err := rdb.Execute("set", "message", "hello"); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - if _, err := rdb.Execute("append", "message", " world"); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - if payload, err := rdb.Execute("get", "message"); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } else if !reflect.DeepEqual( - payload, - []*redis.Result{{ - Kind: redis.ResultKindBinary, - Val: []byte("hello world"), - }}) { - http.Error(w, "unexpected GET result", http.StatusInternalServerError) - return - } - }) -} - -func main() {} diff --git a/examples/tinygo-outbound-redis/spin.toml b/examples/tinygo-outbound-redis/spin.toml deleted file mode 100644 index e7703935b6..0000000000 --- a/examples/tinygo-outbound-redis/spin.toml +++ /dev/null @@ -1,17 +0,0 @@ -spin_manifest_version = 2 - -[application] -authors = ["Fermyon Engineering "] -name = "tinygo-outbound-redis-example" -version = "0.1.0" - -[[trigger.http]] -route = "/publish" -component = "outbound-redis" - -[component.outbound-redis] -source = "main.wasm" -environment = { REDIS_ADDRESS = "redis://127.0.0.1:6379", REDIS_CHANNEL = "messages" } -allowed_outbound_hosts = ["redis://127.0.0.1"] -[component.outbound-redis.build] -command = "tinygo build -target=wasi -gc=leaking -no-debug -o main.wasm main.go" diff --git a/examples/tinygo-redis/README.md b/examples/tinygo-redis/README.md deleted file mode 100644 index 67a7174cf5..0000000000 --- a/examples/tinygo-redis/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# Spin component in TinyGo using the Redis trigger - -```shell -$ RUST_LOG=spin=trace spin build --up -``` - -```shell -$ redis-cli -127.0.0.1:6379> PUBLISH messages test-message -(integer) 1 -``` diff --git a/examples/tinygo-redis/go.mod b/examples/tinygo-redis/go.mod deleted file mode 100644 index 66d7b557fd..0000000000 --- a/examples/tinygo-redis/go.mod +++ /dev/null @@ -1,9 +0,0 @@ -module github.com/fermyon/spin/examples/tinygo-redis - -go 1.20 - -require github.com/fermyon/spin/sdk/go/v2 v2.0.0 - -require github.com/julienschmidt/httprouter v1.3.0 // indirect - -replace github.com/fermyon/spin/sdk/go/v2 v2.0.0 => ../../sdk/go/ diff --git a/examples/tinygo-redis/go.sum b/examples/tinygo-redis/go.sum deleted file mode 100644 index 05ac2a3da6..0000000000 --- a/examples/tinygo-redis/go.sum +++ /dev/null @@ -1 +0,0 @@ -github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= diff --git a/examples/tinygo-redis/main.go b/examples/tinygo-redis/main.go deleted file mode 100644 index 96f897a54d..0000000000 --- a/examples/tinygo-redis/main.go +++ /dev/null @@ -1,19 +0,0 @@ -package main - -import ( - "fmt" - - "github.com/fermyon/spin/sdk/go/v2/redis" -) - -func init() { - // redis.Handle() must be called in the init() function. - redis.Handle(func(payload []byte) error { - fmt.Println("Payload::::") - fmt.Println(string(payload)) - return nil - }) -} - -// main function must be included for the compiler but is not executed. -func main() {} diff --git a/examples/tinygo-redis/spin.toml b/examples/tinygo-redis/spin.toml deleted file mode 100644 index 52cd365572..0000000000 --- a/examples/tinygo-redis/spin.toml +++ /dev/null @@ -1,19 +0,0 @@ -spin_manifest_version = 2 - -[application] -authors = ["Fermyon Engineering "] -description = "A redis application." -name = "spin-redis" -version = "0.1.0" - -[application.trigger.redis] -address = "redis://localhost:6379" - -[[trigger.redis]] -channel = "messages" -component = "echo-message" - -[component.echo-message] -source = "main.wasm" -[component.echo-message.build] -command = "tinygo build -target=wasi -gc=leaking -no-debug -o main.wasm main.go" diff --git a/examples/tinygo-sqlite/.gitignore b/examples/tinygo-sqlite/.gitignore deleted file mode 100644 index b565010470..0000000000 --- a/examples/tinygo-sqlite/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -main.wasm -.spin/ diff --git a/examples/tinygo-sqlite/db/pets.sql b/examples/tinygo-sqlite/db/pets.sql deleted file mode 100644 index bbf91d68ad..0000000000 --- a/examples/tinygo-sqlite/db/pets.sql +++ /dev/null @@ -1,4 +0,0 @@ -CREATE TABLE pets (id INT PRIMARY KEY, name VARCHAR(100) NOT NULL, prey VARCHAR(100), is_finicky BOOL NOT NULL); -INSERT INTO pets VALUES (1, 'Splodge', NULL, false); -INSERT INTO pets VALUES (2, 'Kiki', 'Cicadas', false); -INSERT INTO pets VALUES (3, 'Slats', 'Temptations', true); diff --git a/examples/tinygo-sqlite/go.mod b/examples/tinygo-sqlite/go.mod deleted file mode 100644 index bac8b25988..0000000000 --- a/examples/tinygo-sqlite/go.mod +++ /dev/null @@ -1,9 +0,0 @@ -module github.com/tinygo_sqlite - -go 1.20 - -require github.com/fermyon/spin/sdk/go/v2 v2.0.0 - -require github.com/julienschmidt/httprouter v1.3.0 // indirect - -replace github.com/fermyon/spin/sdk/go/v2 v2.0.0 => ../../sdk/go/ diff --git a/examples/tinygo-sqlite/go.sum b/examples/tinygo-sqlite/go.sum deleted file mode 100644 index fcb43438db..0000000000 --- a/examples/tinygo-sqlite/go.sum +++ /dev/null @@ -1,4 +0,0 @@ -github.com/fermyon/spin/sdk/go v1.4.1 h1:n8KTYTnkErTJdyMBBEtPmJe8dXrvMT6R7iVWbLRjq5E= -github.com/fermyon/spin/sdk/go v1.4.1/go.mod h1:yb8lGesopgj/GwPzLPATxcOeqWZT/HjrzEFfwbztAXE= -github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= -github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= diff --git a/examples/tinygo-sqlite/main.go b/examples/tinygo-sqlite/main.go deleted file mode 100644 index 043f492a8c..0000000000 --- a/examples/tinygo-sqlite/main.go +++ /dev/null @@ -1,48 +0,0 @@ -package main - -import ( - "encoding/json" - "fmt" - "net/http" - - spinhttp "github.com/fermyon/spin/sdk/go/v2/http" - "github.com/fermyon/spin/sdk/go/v2/sqlite" -) - -type Pet struct { - ID int64 - Name string - Prey *string // nullable field must be a pointer - IsFinicky bool -} - -func init() { - spinhttp.Handle(func(w http.ResponseWriter, r *http.Request) { - db := sqlite.Open("default") - defer db.Close() - - _, err := db.Query("REPLACE INTO pets VALUES (4, 'Maya', ?, false);", "bananas") - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - rows, err := db.Query("SELECT * FROM pets") - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - var pets []*Pet - for rows.Next() { - var pet Pet - if err := rows.Scan(&pet.ID, &pet.Name, &pet.Prey, &pet.IsFinicky); err != nil { - fmt.Println(err) - } - pets = append(pets, &pet) - } - json.NewEncoder(w).Encode(pets) - }) -} - -func main() {} diff --git a/examples/tinygo-sqlite/spin.toml b/examples/tinygo-sqlite/spin.toml deleted file mode 100644 index c366f4c8c5..0000000000 --- a/examples/tinygo-sqlite/spin.toml +++ /dev/null @@ -1,19 +0,0 @@ -spin_manifest_version = 2 - -[application] -authors = ["Adam Reese "] -description = "" -name = "tinygo-sqlite" -version = "0.1.0" - -[[trigger.http]] -route = "/..." -component = "tinygo-sqlite" - -[component.tinygo-sqlite] -source = "main.wasm" -allowed_outbound_hosts = [] -sqlite_databases = ["default"] -[component.tinygo-sqlite.build] -command = "tinygo build -target=wasi -gc=leaking -o main.wasm main.go" -watch = ["**/*.go", "go.mod"] diff --git a/examples/variables-rust/.cargo/config.toml b/examples/variables-rust/.cargo/config.toml deleted file mode 100644 index 6b77899cb3..0000000000 --- a/examples/variables-rust/.cargo/config.toml +++ /dev/null @@ -1,2 +0,0 @@ -[build] -target = "wasm32-wasi" diff --git a/examples/variables-rust/.env b/examples/variables-rust/.env deleted file mode 100644 index e88f6f3311..0000000000 --- a/examples/variables-rust/.env +++ /dev/null @@ -1 +0,0 @@ -SPIN_VARIABLE_DOTENV = "dotenv" diff --git a/examples/variables-rust/.gitignore b/examples/variables-rust/.gitignore deleted file mode 100644 index 2f7896d1d1..0000000000 --- a/examples/variables-rust/.gitignore +++ /dev/null @@ -1 +0,0 @@ -target/ diff --git a/examples/variables-rust/Cargo.lock b/examples/variables-rust/Cargo.lock deleted file mode 100644 index cc4564eb62..0000000000 --- a/examples/variables-rust/Cargo.lock +++ /dev/null @@ -1,585 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "anyhow" -version = "1.0.75" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" - -[[package]] -name = "async-trait" -version = "0.1.74" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "bitflags" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" - -[[package]] -name = "bytes" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "form_urlencoded" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" -dependencies = [ - "percent-encoding", -] - -[[package]] -name = "futures" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" - -[[package]] -name = "futures-executor" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" - -[[package]] -name = "futures-macro" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "futures-sink" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" - -[[package]] -name = "futures-task" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" - -[[package]] -name = "futures-util" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "hashbrown" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" - -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -dependencies = [ - "unicode-segmentation", -] - -[[package]] -name = "http" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "id-arena" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" - -[[package]] -name = "indexmap" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" -dependencies = [ - "equivalent", - "hashbrown", - "serde", -] - -[[package]] -name = "itoa" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" - -[[package]] -name = "leb128" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" - -[[package]] -name = "log" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" - -[[package]] -name = "memchr" -version = "2.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" - -[[package]] -name = "once_cell" -version = "1.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" - -[[package]] -name = "percent-encoding" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" - -[[package]] -name = "pin-project-lite" -version = "0.2.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "routefinder" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94f8f99b10dedd317514253dda1fa7c14e344aac96e1f78149a64879ce282aca" -dependencies = [ - "smartcow", - "smartstring", -] - -[[package]] -name = "ryu" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" - -[[package]] -name = "semver" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" - -[[package]] -name = "serde" -version = "1.0.189" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.189" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "serde_json" -version = "1.0.107" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" - -[[package]] -name = "smartcow" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "656fcb1c1fca8c4655372134ce87d8afdf5ec5949ebabe8d314be0141d8b5da2" -dependencies = [ - "smartstring", -] - -[[package]] -name = "smartstring" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb72c633efbaa2dd666986505016c32c3044395ceaf881518399d2f4127ee29" -dependencies = [ - "autocfg", - "static_assertions", - "version_check", -] - -[[package]] -name = "spdx" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b19b32ed6d899ab23174302ff105c1577e45a06b08d4fe0a9dd13ce804bbbf71" -dependencies = [ - "smallvec", -] - -[[package]] -name = "spin-macro" -version = "2.3.0-pre0" -dependencies = [ - "anyhow", - "bytes", - "http", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "spin-sdk" -version = "2.3.0-pre0" -dependencies = [ - "anyhow", - "async-trait", - "bytes", - "form_urlencoded", - "futures", - "http", - "once_cell", - "routefinder", - "serde", - "serde_json", - "spin-macro", - "thiserror", - "wit-bindgen", -] - -[[package]] -name = "spin-variables-example" -version = "0.1.0" -dependencies = [ - "anyhow", - "spin-sdk", -] - -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "thiserror" -version = "1.0.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "unicode-segmentation" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" - -[[package]] -name = "unicode-xid" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wasm-encoder" -version = "0.35.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ca90ba1b5b0a70d3d49473c5579951f3bddc78d47b59256d2f9d4922b150aca" -dependencies = [ - "leb128", -] - -[[package]] -name = "wasm-metadata" -version = "0.10.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14abc161bfda5b519aa229758b68f2a52b45a12b993808665c857d1a9a00223c" -dependencies = [ - "anyhow", - "indexmap", - "serde", - "serde_derive", - "serde_json", - "spdx", - "wasm-encoder", - "wasmparser", -] - -[[package]] -name = "wasmparser" -version = "0.115.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e06c0641a4add879ba71ccb3a1e4278fd546f76f1eafb21d8f7b07733b547cd5" -dependencies = [ - "indexmap", - "semver", -] - -[[package]] -name = "wit-bindgen" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7d92ce0ca6b6074059413a9581a637550c3a740581c854f9847ec293c8aed71" -dependencies = [ - "bitflags", - "wit-bindgen-rust-macro", -] - -[[package]] -name = "wit-bindgen-core" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "565b945ae074886071eccf9cdaf8ccd7b959c2b0d624095bea5fe62003e8b3e0" -dependencies = [ - "anyhow", - "wit-component", - "wit-parser", -] - -[[package]] -name = "wit-bindgen-rust" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5695ff4e41873ed9ce56d2787e6b5772bdad9e70e2c1d2d160621d1762257f4f" -dependencies = [ - "anyhow", - "heck", - "wasm-metadata", - "wit-bindgen-core", - "wit-component", -] - -[[package]] -name = "wit-bindgen-rust-macro" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a91835ea4231da1fe7971679d505ba14be7826e192b6357f08465866ef482e08" -dependencies = [ - "anyhow", - "proc-macro2", - "quote", - "syn 2.0.38", - "wit-bindgen-core", - "wit-bindgen-rust", - "wit-component", -] - -[[package]] -name = "wit-component" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e87488b57a08e2cbbd076b325acbe7f8666965af174d69d5929cd373bd54547f" -dependencies = [ - "anyhow", - "bitflags", - "indexmap", - "log", - "serde", - "serde_derive", - "serde_json", - "wasm-encoder", - "wasm-metadata", - "wasmparser", - "wit-parser", -] - -[[package]] -name = "wit-parser" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ace9943d89bbf3dbbc71b966da0e7302057b311f36a4ac3d65ddfef17b52cf" -dependencies = [ - "anyhow", - "id-arena", - "indexmap", - "log", - "semver", - "serde", - "serde_derive", - "serde_json", - "unicode-xid", -] diff --git a/examples/variables-rust/Cargo.toml b/examples/variables-rust/Cargo.toml deleted file mode 100644 index 526609129d..0000000000 --- a/examples/variables-rust/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "spin-variables-example" -version = "0.1.0" -edition = "2021" - -[lib] -crate-type = ["cdylib"] - -[dependencies] -# Useful crate to handle errors. -anyhow = "1" -# The Spin SDK. -spin-sdk = { path = "../../sdk/rust" } -[workspace] diff --git a/examples/variables-rust/spin.toml b/examples/variables-rust/spin.toml deleted file mode 100644 index 5adf828992..0000000000 --- a/examples/variables-rust/spin.toml +++ /dev/null @@ -1,23 +0,0 @@ -spin_manifest_version = 2 - -[application] -authors = ["Fermyon Engineering "] -description = "A Spin Rust application demonstrating the variables sdk." -name = "spin-variables-rust" -version = "0.1.0" - -[variables] -object = { default = "teapot" } -dotenv = { default = "should-be-replaced" } - -[[trigger.http]] -route = "/..." -component = "spin-variables-rust" - -[component.spin-variables-rust] -source = "target/wasm32-wasi/release/spin_variables_example.wasm" -[component.spin-variables-rust.variables] -message = "I'm a {{object}}" -dotenv = "{{dotenv}}" -[component.spin-variables-rust.build] -command = "cargo build --target wasm32-wasi --release" diff --git a/examples/variables-rust/src/lib.rs b/examples/variables-rust/src/lib.rs deleted file mode 100644 index 5a5b72c075..0000000000 --- a/examples/variables-rust/src/lib.rs +++ /dev/null @@ -1,15 +0,0 @@ -use spin_sdk::{ - http::{Request, Response}, - http_component, variables, -}; - -/// This endpoint returns the config value specified by key. -#[http_component] -fn get(req: Request) -> anyhow::Result { - if req.path().contains("dotenv") { - let val = variables::get("dotenv").expect("Failed to acquire dotenv from spin.toml"); - return Ok(Response::new(200, val)); - } - let val = format!("message: {}", variables::get("message")?); - Ok(Response::new(200, val)) -} diff --git a/examples/variables-tinygo/README.md b/examples/variables-tinygo/README.md deleted file mode 100644 index e56da555fa..0000000000 --- a/examples/variables-tinygo/README.md +++ /dev/null @@ -1,17 +0,0 @@ -# Spin component in TinyGo using variables - -```shell -$ go mod tidy -$ RUST_LOG=spin=trace spin build --up -``` - -The application can now receive requests on `http://localhost:3000`: - -```shell -$ curl -i localhost:3000 -HTTP/1.1 200 OK -content-length: 23 -date: Tue, 29 Nov 2022 06:59:24 GMT - -message: I'm a teapot -``` diff --git a/examples/variables-tinygo/go.mod b/examples/variables-tinygo/go.mod deleted file mode 100644 index b57b194092..0000000000 --- a/examples/variables-tinygo/go.mod +++ /dev/null @@ -1,9 +0,0 @@ -module github.com/fermyon/spin/templates/spin-http-tinygo - -go 1.20 - -require github.com/fermyon/spin/sdk/go/v2 v2.0.0 - -require github.com/julienschmidt/httprouter v1.3.0 // indirect - -replace github.com/fermyon/spin/sdk/go/v2 v2.0.0 => ../../sdk/go/ diff --git a/examples/variables-tinygo/go.sum b/examples/variables-tinygo/go.sum deleted file mode 100644 index 096c54e630..0000000000 --- a/examples/variables-tinygo/go.sum +++ /dev/null @@ -1,2 +0,0 @@ -github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= -github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= diff --git a/examples/variables-tinygo/main.go b/examples/variables-tinygo/main.go deleted file mode 100644 index d3ab6b5102..0000000000 --- a/examples/variables-tinygo/main.go +++ /dev/null @@ -1,24 +0,0 @@ -package main - -import ( - "fmt" - "net/http" - - spinhttp "github.com/fermyon/spin/sdk/go/v2/http" - "github.com/fermyon/spin/sdk/go/v2/variables" -) - -func init() { - spinhttp.Handle(func(w http.ResponseWriter, r *http.Request) { - - // Get variable value `message` defined in spin.toml. - val, err := variables.Get("message") - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - fmt.Fprintln(w, "message: ", val) - }) -} - -func main() {} diff --git a/examples/variables-tinygo/spin.toml b/examples/variables-tinygo/spin.toml deleted file mode 100644 index c3f2ef4520..0000000000 --- a/examples/variables-tinygo/spin.toml +++ /dev/null @@ -1,21 +0,0 @@ -spin_manifest_version = 2 - -[application] -name = "spin-variables-tinygo" -authors = ["Fermyon Engineering "] -description = "A simple Spin application written in (Tiny)Go." -version = "1.0.0" - -[variables] -object = { default = "teapot" } - -[[trigger.http]] -route = "/..." -component = "spin-variables-tinygo" - -[component.spin-variables-tinygo] -source = "main.wasm" -[component.spin-variables-tinygo.variables] -message = "I'm a {{object}}" -[component.spin-variables-tinygo.build] -command = "tinygo build -target=wasi -gc=leaking -no-debug -o main.wasm main.go" diff --git a/examples/vault-variable-test/Cargo.lock b/examples/vault-variable-test/Cargo.lock index 44b57e38b4..90e5ddb7c7 100644 --- a/examples/vault-variable-test/Cargo.lock +++ b/examples/vault-variable-test/Cargo.lock @@ -355,7 +355,9 @@ dependencies = [ [[package]] name = "spin-macro" -version = "2.3.0-pre0" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13524474ab9f876586e29f954377a66ed14fcb646fc9893e6f0e762213ddbd86" dependencies = [ "anyhow", "bytes", @@ -367,7 +369,9 @@ dependencies = [ [[package]] name = "spin-sdk" -version = "2.3.0-pre0" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f05d0c09c0935fbb586d0a76e0f14b26b23f421c5e11b81d7200d22c4ead1211" dependencies = [ "anyhow", "async-trait", diff --git a/examples/vault-variable-test/Cargo.toml b/examples/vault-variable-test/Cargo.toml index 0c06ab5953..7227edd126 100644 --- a/examples/vault-variable-test/Cargo.toml +++ b/examples/vault-variable-test/Cargo.toml @@ -10,6 +10,6 @@ crate-type = ["cdylib"] [dependencies] anyhow = "1" -spin-sdk = { path = "../../sdk/rust" } +spin-sdk = "2.2.0" [workspace] diff --git a/examples/wasi-http-rust-streaming-outgoing-body/.cargo/config.toml b/examples/wasi-http-rust-streaming-outgoing-body/.cargo/config.toml deleted file mode 100644 index 6b77899cb3..0000000000 --- a/examples/wasi-http-rust-streaming-outgoing-body/.cargo/config.toml +++ /dev/null @@ -1,2 +0,0 @@ -[build] -target = "wasm32-wasi" diff --git a/examples/wasi-http-rust-streaming-outgoing-body/.gitignore b/examples/wasi-http-rust-streaming-outgoing-body/.gitignore deleted file mode 100644 index 2f7896d1d1..0000000000 --- a/examples/wasi-http-rust-streaming-outgoing-body/.gitignore +++ /dev/null @@ -1 +0,0 @@ -target/ diff --git a/examples/wasi-http-rust-streaming-outgoing-body/Cargo.lock b/examples/wasi-http-rust-streaming-outgoing-body/Cargo.lock deleted file mode 100644 index d683735cb3..0000000000 --- a/examples/wasi-http-rust-streaming-outgoing-body/Cargo.lock +++ /dev/null @@ -1,723 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "anyhow" -version = "1.0.75" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" - -[[package]] -name = "async-trait" -version = "0.1.74" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "bitflags" -version = "2.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" - -[[package]] -name = "block-buffer" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" -dependencies = [ - "generic-array", -] - -[[package]] -name = "bytes" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "cpufeatures" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" -dependencies = [ - "libc", -] - -[[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] - -[[package]] -name = "digest" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" -dependencies = [ - "block-buffer", - "crypto-common", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "form_urlencoded" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" -dependencies = [ - "percent-encoding", -] - -[[package]] -name = "futures" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" - -[[package]] -name = "futures-executor" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" - -[[package]] -name = "futures-macro" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "futures-sink" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" - -[[package]] -name = "futures-task" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" - -[[package]] -name = "futures-util" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", -] - -[[package]] -name = "hashbrown" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" - -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -dependencies = [ - "unicode-segmentation", -] - -[[package]] -name = "hex" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" - -[[package]] -name = "http" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "id-arena" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" - -[[package]] -name = "idna" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" -dependencies = [ - "unicode-bidi", - "unicode-normalization", -] - -[[package]] -name = "indexmap" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" -dependencies = [ - "equivalent", - "hashbrown", - "serde", -] - -[[package]] -name = "itoa" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" - -[[package]] -name = "leb128" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" - -[[package]] -name = "libc" -version = "0.2.149" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" - -[[package]] -name = "log" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" - -[[package]] -name = "memchr" -version = "2.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" - -[[package]] -name = "once_cell" -version = "1.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" - -[[package]] -name = "percent-encoding" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" - -[[package]] -name = "pin-project-lite" -version = "0.2.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "routefinder" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94f8f99b10dedd317514253dda1fa7c14e344aac96e1f78149a64879ce282aca" -dependencies = [ - "smartcow", - "smartstring", -] - -[[package]] -name = "ryu" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" - -[[package]] -name = "semver" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" - -[[package]] -name = "serde" -version = "1.0.188" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.188" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "serde_json" -version = "1.0.107" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "sha2" -version = "0.10.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" - -[[package]] -name = "smartcow" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "656fcb1c1fca8c4655372134ce87d8afdf5ec5949ebabe8d314be0141d8b5da2" -dependencies = [ - "smartstring", -] - -[[package]] -name = "smartstring" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb72c633efbaa2dd666986505016c32c3044395ceaf881518399d2f4127ee29" -dependencies = [ - "autocfg", - "static_assertions", - "version_check", -] - -[[package]] -name = "spdx" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b19b32ed6d899ab23174302ff105c1577e45a06b08d4fe0a9dd13ce804bbbf71" -dependencies = [ - "smallvec", -] - -[[package]] -name = "spin-macro" -version = "2.3.0-pre0" -dependencies = [ - "anyhow", - "bytes", - "http", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "spin-sdk" -version = "2.3.0-pre0" -dependencies = [ - "anyhow", - "async-trait", - "bytes", - "form_urlencoded", - "futures", - "http", - "once_cell", - "routefinder", - "serde", - "serde_json", - "spin-macro", - "thiserror", - "wit-bindgen", -] - -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "thiserror" -version = "1.0.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[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.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" - -[[package]] -name = "typenum" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" - -[[package]] -name = "unicode-bidi" -version = "0.3.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "unicode-normalization" -version = "0.1.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" -dependencies = [ - "tinyvec", -] - -[[package]] -name = "unicode-segmentation" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" - -[[package]] -name = "unicode-xid" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" - -[[package]] -name = "url" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" -dependencies = [ - "form_urlencoded", - "idna", - "percent-encoding", -] - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wasi-http-rust-streaming-outgoing-body" -version = "0.1.0" -dependencies = [ - "anyhow", - "futures", - "hex", - "sha2", - "spin-sdk", - "url", -] - -[[package]] -name = "wasm-encoder" -version = "0.35.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ca90ba1b5b0a70d3d49473c5579951f3bddc78d47b59256d2f9d4922b150aca" -dependencies = [ - "leb128", -] - -[[package]] -name = "wasm-metadata" -version = "0.10.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14abc161bfda5b519aa229758b68f2a52b45a12b993808665c857d1a9a00223c" -dependencies = [ - "anyhow", - "indexmap", - "serde", - "serde_derive", - "serde_json", - "spdx", - "wasm-encoder", - "wasmparser", -] - -[[package]] -name = "wasmparser" -version = "0.115.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e06c0641a4add879ba71ccb3a1e4278fd546f76f1eafb21d8f7b07733b547cd5" -dependencies = [ - "indexmap", - "semver", -] - -[[package]] -name = "wit-bindgen" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7d92ce0ca6b6074059413a9581a637550c3a740581c854f9847ec293c8aed71" -dependencies = [ - "bitflags", - "wit-bindgen-rust-macro", -] - -[[package]] -name = "wit-bindgen-core" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "565b945ae074886071eccf9cdaf8ccd7b959c2b0d624095bea5fe62003e8b3e0" -dependencies = [ - "anyhow", - "wit-component", - "wit-parser", -] - -[[package]] -name = "wit-bindgen-rust" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5695ff4e41873ed9ce56d2787e6b5772bdad9e70e2c1d2d160621d1762257f4f" -dependencies = [ - "anyhow", - "heck", - "wasm-metadata", - "wit-bindgen-core", - "wit-component", -] - -[[package]] -name = "wit-bindgen-rust-macro" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a91835ea4231da1fe7971679d505ba14be7826e192b6357f08465866ef482e08" -dependencies = [ - "anyhow", - "proc-macro2", - "quote", - "syn 2.0.38", - "wit-bindgen-core", - "wit-bindgen-rust", - "wit-component", -] - -[[package]] -name = "wit-component" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e87488b57a08e2cbbd076b325acbe7f8666965af174d69d5929cd373bd54547f" -dependencies = [ - "anyhow", - "bitflags", - "indexmap", - "log", - "serde", - "serde_derive", - "serde_json", - "wasm-encoder", - "wasm-metadata", - "wasmparser", - "wit-parser", -] - -[[package]] -name = "wit-parser" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ace9943d89bbf3dbbc71b966da0e7302057b311f36a4ac3d65ddfef17b52cf" -dependencies = [ - "anyhow", - "id-arena", - "indexmap", - "log", - "semver", - "serde", - "serde_derive", - "serde_json", - "unicode-xid", -] diff --git a/examples/wasi-http-rust-streaming-outgoing-body/Cargo.toml b/examples/wasi-http-rust-streaming-outgoing-body/Cargo.toml deleted file mode 100644 index b3587d079c..0000000000 --- a/examples/wasi-http-rust-streaming-outgoing-body/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "wasi-http-rust-streaming-outgoing-body" -version = "0.1.0" -edition = "2021" - -[lib] -crate-type = ["cdylib"] - -[dependencies] -anyhow = "1.0.71" -futures = "0.3.28" -hex = "0.4.3" -sha2 = "0.10.6" -url = "2.4.0" -spin-sdk = { path = "../../sdk/rust" } - -[workspace] diff --git a/examples/wasi-http-rust-streaming-outgoing-body/spin.toml b/examples/wasi-http-rust-streaming-outgoing-body/spin.toml deleted file mode 100644 index a09efd4337..0000000000 --- a/examples/wasi-http-rust-streaming-outgoing-body/spin.toml +++ /dev/null @@ -1,18 +0,0 @@ -spin_manifest_version = 2 - -[application] -authors = ["Fermyon Engineering "] -description = "An application that makes concurrent outbound HTTP requests." -name = "spin-wasi-http-async" -version = "1.0.0" - -[[trigger.http]] -route = "/..." -component = "wasi-http-async" - -[component.wasi-http-async] -source = "target/wasm32-wasi/release/wasi_http_rust_streaming_outgoing_body.wasm" -allowed_outbound_hosts = ["http://*:*", "https://*:*"] -[component.wasi-http-async.build] -command = "cargo build --target wasm32-wasi --release" -watch = ["src/**/*.rs", "Cargo.toml"] diff --git a/examples/wasi-http-rust-streaming-outgoing-body/src/lib.rs b/examples/wasi-http-rust-streaming-outgoing-body/src/lib.rs deleted file mode 100644 index 5de425df23..0000000000 --- a/examples/wasi-http-rust-streaming-outgoing-body/src/lib.rs +++ /dev/null @@ -1,123 +0,0 @@ -use futures::{future, Future, SinkExt, StreamExt}; -use spin_sdk::{ - http::{ - self, Headers, IncomingRequest, IncomingResponse, Method, OutgoingBody, OutgoingRequest, - OutgoingResponse, ResponseOutparam, Scheme, - }, - http_component, -}; -use url::Url; - -#[http_component] -async fn handle_request(request: IncomingRequest, response_out: ResponseOutparam) { - let headers = request.headers().entries(); - - match (request.method(), request.path_with_query().as_deref()) { - (Method::Post, Some("/double-echo")) => { - // Pipe the request body to an outgoing request and stream the response back to the client. - - let Some(url) = headers.iter().find_map(|(k, v)| { - (k == "url") - .then_some(v) - .and_then(|v| std::str::from_utf8(v).ok()) - .and_then(|v| Url::parse(v).ok()) - }) else { - bad_request(response_out); - return; - }; - - match double_echo(request, &url).await { - Ok((request_copy, incoming_response)) => { - let mut incoming_response_body = incoming_response.take_body_stream(); - - let outgoing_response = OutgoingResponse::new( - 200, - &Headers::new( - &headers - .into_iter() - .filter(|(k, _)| k == "content-type") - .collect::>(), - ), - ); - - let mut outgoing_response_body = outgoing_response.take_body(); - - response_out.set(outgoing_response); - - let response_copy = async move { - while let Some(chunk) = incoming_response_body.next().await { - outgoing_response_body.send(chunk?).await?; - } - Ok::<_, anyhow::Error>(()) - }; - - let (request_copy, response_copy) = - future::join(request_copy, response_copy).await; - - if let Err(e) = request_copy.and(response_copy) { - eprintln!("error piping to and from {url}: {e}"); - } - } - Err(e) => { - eprintln!("Error sending outgoing request to {url}: {e}"); - server_error(response_out); - } - } - } - _ => method_not_allowed(response_out), - } -} - -async fn double_echo( - incoming_request: IncomingRequest, - url: &Url, -) -> anyhow::Result<(impl Future>, IncomingResponse)> { - let outgoing_request = OutgoingRequest::new( - &Method::Post, - Some(url.path()), - Some(&match url.scheme() { - "http" => Scheme::Http, - "https" => Scheme::Https, - scheme => Scheme::Other(scheme.into()), - }), - Some(url.authority()), - &Headers::new(&[]), - ); - - let mut body = outgoing_request.take_body(); - - let response = http::send::<_, IncomingResponse>(outgoing_request).await?; - - let mut stream = incoming_request.into_body_stream(); - - let copy = async move { - while let Some(chunk) = stream.next().await { - body.send(chunk?).await?; - } - Ok::<_, anyhow::Error>(()) - }; - - Ok((copy, response)) -} - -fn server_error(response_out: ResponseOutparam) { - respond(500, response_out) -} - -fn bad_request(response_out: ResponseOutparam) { - respond(400, response_out) -} - -fn method_not_allowed(response_out: ResponseOutparam) { - respond(405, response_out) -} - -fn respond(status: u16, response_out: ResponseOutparam) { - let response = OutgoingResponse::new(status, &Headers::new(&[])); - - let body = response.write().expect("response should be writable"); - - response_out.set(response); - - OutgoingBody::finish(body, None); -} diff --git a/examples/wasi-http-streaming-file/.cargo/config.toml b/examples/wasi-http-streaming-file/.cargo/config.toml deleted file mode 100644 index 6b77899cb3..0000000000 --- a/examples/wasi-http-streaming-file/.cargo/config.toml +++ /dev/null @@ -1,2 +0,0 @@ -[build] -target = "wasm32-wasi" diff --git a/examples/wasi-http-streaming-file/.gitignore b/examples/wasi-http-streaming-file/.gitignore deleted file mode 100644 index 2f7896d1d1..0000000000 --- a/examples/wasi-http-streaming-file/.gitignore +++ /dev/null @@ -1 +0,0 @@ -target/ diff --git a/examples/wasi-http-streaming-file/Cargo.lock b/examples/wasi-http-streaming-file/Cargo.lock deleted file mode 100644 index 7ca889dd09..0000000000 --- a/examples/wasi-http-streaming-file/Cargo.lock +++ /dev/null @@ -1,723 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "anyhow" -version = "1.0.75" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" - -[[package]] -name = "async-trait" -version = "0.1.74" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "bitflags" -version = "2.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" - -[[package]] -name = "block-buffer" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" -dependencies = [ - "generic-array", -] - -[[package]] -name = "bytes" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "cpufeatures" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" -dependencies = [ - "libc", -] - -[[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] - -[[package]] -name = "digest" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" -dependencies = [ - "block-buffer", - "crypto-common", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "form_urlencoded" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" -dependencies = [ - "percent-encoding", -] - -[[package]] -name = "futures" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" - -[[package]] -name = "futures-executor" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" - -[[package]] -name = "futures-macro" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "futures-sink" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" - -[[package]] -name = "futures-task" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" - -[[package]] -name = "futures-util" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", -] - -[[package]] -name = "hashbrown" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" - -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -dependencies = [ - "unicode-segmentation", -] - -[[package]] -name = "hex" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" - -[[package]] -name = "http" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "id-arena" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" - -[[package]] -name = "idna" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" -dependencies = [ - "unicode-bidi", - "unicode-normalization", -] - -[[package]] -name = "indexmap" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" -dependencies = [ - "equivalent", - "hashbrown", - "serde", -] - -[[package]] -name = "itoa" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" - -[[package]] -name = "leb128" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" - -[[package]] -name = "libc" -version = "0.2.149" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" - -[[package]] -name = "log" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" - -[[package]] -name = "memchr" -version = "2.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" - -[[package]] -name = "once_cell" -version = "1.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" - -[[package]] -name = "percent-encoding" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" - -[[package]] -name = "pin-project-lite" -version = "0.2.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "proc-macro2" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "routefinder" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94f8f99b10dedd317514253dda1fa7c14e344aac96e1f78149a64879ce282aca" -dependencies = [ - "smartcow", - "smartstring", -] - -[[package]] -name = "ryu" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" - -[[package]] -name = "semver" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" - -[[package]] -name = "serde" -version = "1.0.188" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.188" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "serde_json" -version = "1.0.107" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "sha2" -version = "0.10.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" - -[[package]] -name = "smartcow" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "656fcb1c1fca8c4655372134ce87d8afdf5ec5949ebabe8d314be0141d8b5da2" -dependencies = [ - "smartstring", -] - -[[package]] -name = "smartstring" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb72c633efbaa2dd666986505016c32c3044395ceaf881518399d2f4127ee29" -dependencies = [ - "autocfg", - "static_assertions", - "version_check", -] - -[[package]] -name = "spdx" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b19b32ed6d899ab23174302ff105c1577e45a06b08d4fe0a9dd13ce804bbbf71" -dependencies = [ - "smallvec", -] - -[[package]] -name = "spin-macro" -version = "2.3.0-pre0" -dependencies = [ - "anyhow", - "bytes", - "http", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "spin-sdk" -version = "2.3.0-pre0" -dependencies = [ - "anyhow", - "async-trait", - "bytes", - "form_urlencoded", - "futures", - "http", - "once_cell", - "routefinder", - "serde", - "serde_json", - "spin-macro", - "thiserror", - "wit-bindgen", -] - -[[package]] -name = "spin-wasi-http-streaming-file" -version = "0.1.0" -dependencies = [ - "anyhow", - "futures", - "hex", - "sha2", - "spin-sdk", - "url", -] - -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "thiserror" -version = "1.0.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[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.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" - -[[package]] -name = "typenum" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" - -[[package]] -name = "unicode-bidi" -version = "0.3.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "unicode-normalization" -version = "0.1.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" -dependencies = [ - "tinyvec", -] - -[[package]] -name = "unicode-segmentation" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" - -[[package]] -name = "unicode-xid" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" - -[[package]] -name = "url" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" -dependencies = [ - "form_urlencoded", - "idna", - "percent-encoding", -] - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wasm-encoder" -version = "0.35.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ca90ba1b5b0a70d3d49473c5579951f3bddc78d47b59256d2f9d4922b150aca" -dependencies = [ - "leb128", -] - -[[package]] -name = "wasm-metadata" -version = "0.10.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14abc161bfda5b519aa229758b68f2a52b45a12b993808665c857d1a9a00223c" -dependencies = [ - "anyhow", - "indexmap", - "serde", - "serde_derive", - "serde_json", - "spdx", - "wasm-encoder", - "wasmparser", -] - -[[package]] -name = "wasmparser" -version = "0.115.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e06c0641a4add879ba71ccb3a1e4278fd546f76f1eafb21d8f7b07733b547cd5" -dependencies = [ - "indexmap", - "semver", -] - -[[package]] -name = "wit-bindgen" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7d92ce0ca6b6074059413a9581a637550c3a740581c854f9847ec293c8aed71" -dependencies = [ - "bitflags", - "wit-bindgen-rust-macro", -] - -[[package]] -name = "wit-bindgen-core" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "565b945ae074886071eccf9cdaf8ccd7b959c2b0d624095bea5fe62003e8b3e0" -dependencies = [ - "anyhow", - "wit-component", - "wit-parser", -] - -[[package]] -name = "wit-bindgen-rust" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5695ff4e41873ed9ce56d2787e6b5772bdad9e70e2c1d2d160621d1762257f4f" -dependencies = [ - "anyhow", - "heck", - "wasm-metadata", - "wit-bindgen-core", - "wit-component", -] - -[[package]] -name = "wit-bindgen-rust-macro" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a91835ea4231da1fe7971679d505ba14be7826e192b6357f08465866ef482e08" -dependencies = [ - "anyhow", - "proc-macro2", - "quote", - "syn 2.0.38", - "wit-bindgen-core", - "wit-bindgen-rust", - "wit-component", -] - -[[package]] -name = "wit-component" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e87488b57a08e2cbbd076b325acbe7f8666965af174d69d5929cd373bd54547f" -dependencies = [ - "anyhow", - "bitflags", - "indexmap", - "log", - "serde", - "serde_derive", - "serde_json", - "wasm-encoder", - "wasm-metadata", - "wasmparser", - "wit-parser", -] - -[[package]] -name = "wit-parser" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ace9943d89bbf3dbbc71b966da0e7302057b311f36a4ac3d65ddfef17b52cf" -dependencies = [ - "anyhow", - "id-arena", - "indexmap", - "log", - "semver", - "serde", - "serde_derive", - "serde_json", - "unicode-xid", -] diff --git a/examples/wasi-http-streaming-file/Cargo.toml b/examples/wasi-http-streaming-file/Cargo.toml deleted file mode 100644 index f877bcb06e..0000000000 --- a/examples/wasi-http-streaming-file/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "spin-wasi-http-streaming-file" -version = "0.1.0" -edition = "2021" - -[lib] -crate-type = ["cdylib"] - -[dependencies] -anyhow = "1.0.71" -futures = "0.3.28" -hex = "0.4.3" -sha2 = "0.10.6" -url = "2.4.0" -spin-sdk = { path = "../../sdk/rust" } - -[workspace] diff --git a/examples/wasi-http-streaming-file/spin.toml b/examples/wasi-http-streaming-file/spin.toml deleted file mode 100644 index 07eefe21c2..0000000000 --- a/examples/wasi-http-streaming-file/spin.toml +++ /dev/null @@ -1,18 +0,0 @@ -spin_manifest_version = 2 - -[application] -authors = ["Fermyon Engineering "] -description = "An application that streams a chunked file as an HTTP response" -name = "spin-wasi-http-streaming-file" -version = "1.0.0" - -[[trigger.http]] -route = "/..." -component = "spin-wasi-http-streaming-file" - -[component.spin-wasi-http-streaming-file] -source = "target/wasm32-wasi/release/spin_wasi_http_streaming_file.wasm" -files = [{ source = ".", destination = "/" }] -[component.spin-wasi-http-streaming-file.build] -command = "cargo build --target wasm32-wasi --release" -watch = ["src/**/*.rs", "Cargo.toml"] diff --git a/examples/wasi-http-streaming-file/src/lib.rs b/examples/wasi-http-streaming-file/src/lib.rs deleted file mode 100644 index a116d3751d..0000000000 --- a/examples/wasi-http-streaming-file/src/lib.rs +++ /dev/null @@ -1,44 +0,0 @@ -use std::{fs::File, io::Read}; - -use anyhow::Result; -use futures::SinkExt; -use spin_sdk::{ - http::{Headers, IncomingRequest, OutgoingResponse, ResponseOutparam}, - http_component, -}; - -const CHUNK_SIZE: usize = 1024 * 1024; // 1 MB - -#[http_component] -async fn handler(req: IncomingRequest, res: ResponseOutparam) { - stream_file(req, res).await.unwrap(); -} - -async fn stream_file(_req: IncomingRequest, res: ResponseOutparam) -> Result<()> { - let response = OutgoingResponse::new( - 200, - &Headers::new(&[( - "content-type".to_string(), - b"application/octet-stream".to_vec(), - )]), - ); - - let mut body = response.take_body(); - res.set(response); - - let mut file = File::open("target/wasm32-wasi/release/spin_wasi_http_streaming_file.wasm")?; - - let mut buffer = vec![0; CHUNK_SIZE]; - - loop { - let bytes_read = file.read(&mut buffer[..])?; - if bytes_read == 0 { - break; - } - - let data = &buffer[..bytes_read]; - body.send(data.to_vec()).await?; - println!("sent {} bytes", data.len()); - } - Ok(()) -} diff --git a/sdk/go/.gitignore b/sdk/go/.gitignore deleted file mode 100644 index a9477a218f..0000000000 --- a/sdk/go/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*/sdk-version-go.c diff --git a/sdk/go/Makefile b/sdk/go/Makefile deleted file mode 100644 index 3dd9bb4a25..0000000000 --- a/sdk/go/Makefile +++ /dev/null @@ -1,129 +0,0 @@ -# ---------------------------------------------------------------------- -# Test -# ---------------------------------------------------------------------- -.PHONY: test -test: test-integration - tinygo test -target=wasi -gc=leaking -v ./http - tinygo test -target=wasi -gc=leaking -v ./redis - -.PHONY: test-integration -test-integration: http/testdata/http-tinygo/main.wasm - go test -v -count=1 . - -http/testdata/http-tinygo/main.wasm: generate -http/testdata/http-tinygo/main.wasm: http/testdata/http-tinygo/main.go - tinygo build -target=wasi -gc=leaking -no-debug -o http/testdata/http-tinygo/main.wasm http/testdata/http-tinygo/main.go - -# ---------------------------------------------------------------------- -# Build examples -# ---------------------------------------------------------------------- -EXAMPLES_DIR = ../../examples - -.PHONY: build-examples -build-examples: generate -build-examples: $(EXAMPLES_DIR)/http-tinygo-outbound-http/outbound-http-to-same-app/main.wasm -build-examples: $(EXAMPLES_DIR)/http-tinygo-outbound-http/tinygo-hello/main.wasm -build-examples: $(EXAMPLES_DIR)/http-tinygo/main.wasm -build-examples: $(EXAMPLES_DIR)/tinygo-outbound-redis/main.wasm -build-examples: $(EXAMPLES_DIR)/tinygo-redis/main.wasm -build-examples: $(EXAMPLES_DIR)/tinygo-key-value/main.wasm -build-examples: $(EXAMPLES_DIR)/tinygo-sqlite/main.wasm -build-examples: $(EXAMPLES_DIR)/tinygo-llm/main.wasm -build-examples: $(EXAMPLES_DIR)/tinygo-outbound-mysql/main.wasm -build-examples: $(EXAMPLES_DIR)/tinygo-outbound-pg/main.wasm -build-examples: $(EXAMPLES_DIR)/variables-tinygo/main.wasm - -$(EXAMPLES_DIR)/%/main.wasm: $(EXAMPLES_DIR)/%/main.go - tinygo build -target=wasi -gc=leaking -no-debug -o $@ $< - -# ---------------------------------------------------------------------- -# Generate C bindings -# ---------------------------------------------------------------------- -GENERATED_SPIN_VARIABLES = variables/spin-config.c variables/spin-config.h -GENERATED_OUTBOUND_HTTP = http/wasi-outbound-http.c http/wasi-outbound-http.h -GENERATED_SPIN_HTTP = http/spin-http.c http/spin-http.h -GENERATED_OUTBOUND_REDIS = redis/outbound-redis.c redis/outbound-redis.h -GENERATED_SPIN_REDIS = redis/spin-redis.c redis/spin-redis.h -GENERATED_KEY_VALUE = kv/key-value.c kv/key-value.h -GENERATED_SQLITE = sqlite/sqlite.c sqlite/sqlite.h -GENERATED_LLM = llm/llm.c llm/llm.h -GENERATED_OUTBOUND_MYSQL = mysql/outbound-mysql.c mysql/outbound-mysql.h -GENERATED_OUTBOUND_PG = pg/outbound-pg.c pg/outbound-pg.h - -SDK_VERSION_SOURCE_FILE = sdk_version/sdk-version-go-template.c - -# NOTE: Please update this list if you add a new directory to the SDK: -SDK_VERSION_DEST_FILES = variables/sdk-version-go.c http/sdk-version-go.c \ - kv/sdk-version-go.c redis/sdk-version-go.c \ - sqlite/sdk-version-go.c llm/sdk-version-go.c - -# NOTE: To generate the C bindings you need to install a forked version of wit-bindgen. -# -# cargo install wit-bindgen-cli --git https://github.com/fermyon/wit-bindgen-backport --rev "b89d5079ba5b07b319631a1b191d2139f126c976" -# -.PHONY: generate -generate: $(GENERATED_OUTBOUND_HTTP) $(GENERATED_SPIN_HTTP) -generate: $(GENERATED_OUTBOUND_REDIS) $(GENERATED_SPIN_REDIS) -generate: $(GENERATED_SPIN_VARIABLES) $(GENERATED_KEY_VALUE) -generate: $(GENERATED_SQLITE) $(GENERATED_LLM) -generate: $(GENERATED_OUTBOUND_MYSQL) $(GENERATED_OUTBOUND_PG) -generate: $(SDK_VERSION_DEST_FILES) - -$(SDK_VERSION_DEST_FILES): $(SDK_VERSION_SOURCE_FILE) - export version="$$(cd ../rust && cargo run)"; \ - export commit="$$(git rev-parse HEAD)"; \ - sed -e "s/{{VERSION}}/$${version}/" -e "s/{{COMMIT}}/$${commit}/" < $< > $@ - -$(GENERATED_SPIN_VARIABLES): - wit-bindgen c --import wit/spin-config.wit --out-dir ./variables - -$(GENERATED_OUTBOUND_HTTP): - wit-bindgen c --import wit/wasi-outbound-http.wit --out-dir ./http - -$(GENERATED_SPIN_HTTP): - wit-bindgen c --export wit/spin-http.wit --out-dir ./http - -$(GENERATED_OUTBOUND_REDIS): - wit-bindgen c --import wit/outbound-redis.wit --out-dir ./redis - -$(GENERATED_SPIN_REDIS): - wit-bindgen c --export wit/spin-redis.wit --out-dir ./redis - -$(GENERATED_KEY_VALUE): - wit-bindgen c --import wit/key-value.wit --out-dir ./kv - -$(GENERATED_SQLITE): - wit-bindgen c --import wit/sqlite.wit --out-dir ./sqlite - -$(GENERATED_LLM): - wit-bindgen c --import wit/llm.wit --out-dir ./llm - -$(GENERATED_OUTBOUND_MYSQL): - wit-bindgen c --import wit/outbound-mysql.wit --out-dir ./mysql - -$(GENERATED_OUTBOUND_PG): - wit-bindgen c --import wit/outbound-pg.wit --out-dir ./pg - -# ---------------------------------------------------------------------- -# Cleanup -# ---------------------------------------------------------------------- -.PHONY: clean -clean: - rm -f $(GENERATED_SPIN_CONFIG) - rm -f $(GENERATED_OUTBOUND_HTTP) $(GENERATED_SPIN_HTTP) - rm -f $(GENERATED_OUTBOUND_REDIS) $(GENERATED_SPIN_REDIS) - rm -f $(GENERATED_KEY_VALUE) $(GENERATED_SQLITE) - rm -f $(GENERATED_LLM) - rm -f $(GENERATED_OUTBOUND_MYSQL) - rm -f $(GENERATED_SDK_VERSION) - rm -f http/testdata/http-tinygo/main.wasm - rm -f $(EXAMPLES_DIR)/http-tinygo/main.wasm - rm -f $(EXAMPLES_DIR)/http-tinygo-outbound-http/main.wasm - rm -f $(EXAMPLES_DIR)/tinygo-outbound-redis/main.wasm - rm -f $(EXAMPLES_DIR)/tinygo-redis/main.wasm - rm -f $(EXAMPLES_DIR)/tinygo-key-value/main.wasm - rm -f $(EXAMPLES_DIR)/tinygo-sqlite/main.wasm - rm -f $(EXAMPLES_DIR)/tinygo-llm/main.wasm - rm -f $(EXAMPLES_DIR)/tinygo-outbound-mysql/main.wasm - rm -f $(EXAMPLES_DIR)/tinygo-outbound-pg/main.wasm - rm -f $(SDK_VERSION_DEST_FILES) diff --git a/sdk/go/go.mod b/sdk/go/go.mod deleted file mode 100644 index 3cbbf1432f..0000000000 --- a/sdk/go/go.mod +++ /dev/null @@ -1,5 +0,0 @@ -module github.com/fermyon/spin/sdk/go/v2 - -go 1.20 - -require github.com/julienschmidt/httprouter v1.3.0 diff --git a/sdk/go/go.sum b/sdk/go/go.sum deleted file mode 100644 index 096c54e630..0000000000 --- a/sdk/go/go.sum +++ /dev/null @@ -1,2 +0,0 @@ -github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= -github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= diff --git a/sdk/go/http/http.go b/sdk/go/http/http.go deleted file mode 100644 index ba4a22c2b1..0000000000 --- a/sdk/go/http/http.go +++ /dev/null @@ -1,116 +0,0 @@ -// Package http contains the helper functions for writing Spin HTTP components -// in TinyGo, as well as for sending outbound HTTP requests. -package http - -import ( - "fmt" - "io" - "net/http" - "os" - - "github.com/julienschmidt/httprouter" -) - -const ( - // The application base path. - HeaderBasePath = "spin-base-path" - // The component route pattern matched, _excluding_ any wildcard indicator. - HeaderComponentRoot = "spin-component-route" - // The full URL of the request. This includes full host and scheme information. - HeaderFullUrl = "spin-full-url" - // The part of the request path that was matched by the route (including - // the base and wildcard indicator if present). - HeaderMatchedRoute = "spin-matched-route" - // The request path relative to the component route (including any base). - HeaderPathInfo = "spin-path-info" - // The component route pattern matched, as written in the component - // manifest (that is, _excluding_ the base, but including the wildcard - // indicator if present). - HeaderRawComponentRoot = "spin-raw-component-route" - // The client address for the request. - HeaderClientAddr = "spin-client-addr" -) - -// Override the default HTTP client to be compatible with the Spin SDK. -func init() { - http.DefaultClient = NewClient() -} - -// Router is a http.Handler which can be used to dispatch requests to different -// handler functions via configurable routes -type Router = httprouter.Router - -// Params is a Param-slice, as returned by the router. -// The slice is ordered, the first URL parameter is also the first slice value. -// It is therefore safe to read values by the index. -type Params = httprouter.Params - -// Param is a single URL parameter, consisting of a key and a value. -type Param = httprouter.Param - -// RouterHandle is a function that can be registered to a route to handle HTTP -// requests. Like http.HandlerFunc, but has a third parameter for the values of -// wildcards (variables). -type RouterHandle = httprouter.Handle - -// New returns a new initialized Router. -// Path auto-correction, including trailing slashes, is enabled by default. -func NewRouter() *Router { - return httprouter.New() -} - -// NewTransport returns http.RoundTripper backed by Spin SDK -func NewTransport() http.RoundTripper { - return &Transport{} -} - -// Transport implements http.RoundTripper -type Transport struct{} - -// RoundTrip makes roundtrip using Spin SDK -func (r *Transport) RoundTrip(req *http.Request) (*http.Response, error) { - return Send(req) -} - -// NewClient returns a new HTTP client compatible with the Spin SDK -func NewClient() *http.Client { - return &http.Client{ - Transport: &Transport{}, - } -} - -// handler is the function that will be called by the http trigger in Spin. -var handler = defaultHandler - -// defaultHandler is a placeholder for returning a useful error to stderr when -// the handler is not set. -var defaultHandler = func(http.ResponseWriter, *http.Request) { - fmt.Fprintln(os.Stderr, "http handler undefined") -} - -// Handle sets the handler function for the http trigger. -// It must be set in an init() function. -func Handle(fn func(http.ResponseWriter, *http.Request)) { - handler = fn -} - -// Get creates a GET HTTP request to a given URL and returns the HTTP response. -// The destination of the request must be explicitly allowed in the Spin application -// configuration, otherwise the request will not be sent. -func Get(url string) (*http.Response, error) { - return get(url) -} - -// Post creates a POST HTTP request and returns the HTTP response. -// The destination of the request must be explicitly allowed in the Spin application -// configuration, otherwise the request will not be sent. -func Post(url string, contentType string, body io.Reader) (*http.Response, error) { - return post(url, contentType, body) -} - -// Send sends an HTTP request and return the HTTP response. -// The destination of the request must be explicitly allowed in the Spin application -// configuration, otherwise the request will not be sent. -func Send(req *http.Request) (*http.Response, error) { - return send(req) -} diff --git a/sdk/go/http/internals.go b/sdk/go/http/internals.go deleted file mode 100644 index 8256a2a48e..0000000000 --- a/sdk/go/http/internals.go +++ /dev/null @@ -1,140 +0,0 @@ -package http - -// #cgo CFLAGS: -Wno-unused-parameter -Wno-switch-bool -// #include -// #include -import "C" -import ( - "bytes" - "fmt" - "io" - "net/http" - "os" - "unsafe" -) - -//export spin_http_handle_http_request -func handle_http_request(req *C.spin_http_request_t, res *C.spin_http_response_t) { - var body []byte - if req.body.is_some { - body = C.GoBytes(unsafe.Pointer(req.body.val.ptr), C.int(req.body.val.len)) - } - method := methods[req.method] - header := fromSpinHeaders(&req.headers) - url := header.Get(HeaderFullUrl) - - r, err := http.NewRequest(method, url, bytes.NewReader(body)) - if err != nil { - fmt.Fprintln(os.Stderr, err) - res.status = C.uint16_t(http.StatusInternalServerError) - return - } - - r.Header = header - r.Host = r.Header.Get("Host") - r.RequestURI = C.GoStringN(req.uri.ptr, C.int(req.uri.len)) - r.RemoteAddr = r.Header.Get(HeaderClientAddr) - - w := newResponse() - - // call user function - handler(w, r) - - res.status = C.uint16_t(w.status) - if len(w.header) > 0 { - res.headers = C.spin_http_option_headers_t{ - is_some: true, - val: toSpinHeaders(w.header), - } - } else { - res.headers = C.spin_http_option_headers_t{is_some: false} - } - - res.body, err = toSpinBody(w.w) - if err != nil { - fmt.Fprintln(os.Stderr, err) - } -} - -func toSpinHeaders(hm http.Header) C.spin_http_headers_t { - var reqHeaders C.spin_http_headers_t - - headersLen := len(hm) - - if headersLen > 0 { - reqHeaders.len = C.ulong(headersLen) - var x C.spin_http_tuple2_string_string_t - reqHeaders.ptr = (*C.spin_http_tuple2_string_string_t)(C.malloc(C.size_t(headersLen) * C.size_t(unsafe.Sizeof(x)))) - headers := unsafe.Slice(reqHeaders.ptr, headersLen) - - idx := 0 - for k, v := range hm { - headers[idx] = newSpinHeader(k, v[0]) - idx++ - } - } - return reqHeaders -} - -func toSpinBody(body io.Reader) (C.spin_http_option_body_t, error) { - var spinBody C.spin_http_option_body_t - spinBody.is_some = false - - if body == nil { - return spinBody, nil - } - - buf := new(bytes.Buffer) - len, err := buf.ReadFrom(body) - if err != nil { - return spinBody, err - } - - if len > 0 { - bodyPtr := (*C.uint8_t)(C.malloc(C.size_t(len))) - copy(unsafe.Slice(bodyPtr, len), buf.Bytes()) - - spinBody.is_some = true - spinBody.val = C.spin_http_body_t{ - ptr: bodyPtr, - len: C.size_t(len), - } - } - - return spinBody, nil -} - -// newSpinHeader creates a new spinHeader with the given key/value. -func newSpinHeader(k, v string) C.spin_http_tuple2_string_string_t { - return C.spin_http_tuple2_string_string_t{ - f0: C.spin_http_string_t{ptr: C.CString(k), len: C.size_t(len(k))}, - f1: C.spin_http_string_t{ptr: C.CString(v), len: C.size_t(len(v))}, - } -} - -var methods = [...]string{ - "GET", - "POST", - "PUT", - "DELETE", - "PATCH", - "HEAD", - "OPTIONS", -} - -func fromSpinHeaders(hm *C.spin_http_headers_t) http.Header { - headersLen := int(hm.len) - headers := make(http.Header, headersLen) - - var headersArr *C.spin_http_tuple2_string_string_t = hm.ptr - headersSlice := unsafe.Slice(headersArr, headersLen) - for i := 0; i < headersLen; i++ { - tuple := headersSlice[i] - k := C.GoStringN(tuple.f0.ptr, C.int(tuple.f0.len)) - v := C.GoStringN(tuple.f1.ptr, C.int(tuple.f1.len)) - - headers.Add(k, v) - } - - return headers -} diff --git a/sdk/go/http/outbound_internals.go b/sdk/go/http/outbound_internals.go deleted file mode 100644 index c371f673ee..0000000000 --- a/sdk/go/http/outbound_internals.go +++ /dev/null @@ -1,196 +0,0 @@ -//nolint:staticcheck - -// This file contains the manual conversions between Go HTTP objects -// and Spin HTTP objects, through the auto-generated C bindings for -// the outbound HTTP API. - -package http - -// #cgo CFLAGS: -Wno-unused-parameter -Wno-switch-bool -// #include "wasi-outbound-http.h" -// #include -import "C" - -import ( - "bytes" - "fmt" - "io" - "io/ioutil" - "net/http" - "strings" - "unsafe" -) - -func get(url string) (*http.Response, error) { - req, err := http.NewRequest("GET", url, nil) - if err != nil { - return nil, err - } - - return send(req) -} - -func post(url string, contentType string, body io.Reader) (*http.Response, error) { - req, err := http.NewRequest("POST", url, body) - if err != nil { - return nil, err - } - req.Header.Set("Content-Type", contentType) - - return send(req) -} - -func send(req *http.Request) (*http.Response, error) { - var spinReq C.wasi_outbound_http_request_t - var spinRes C.wasi_outbound_http_response_t - - m, err := method(req.Method) - if err != nil { - return nil, err - } - spinReq.method = uint8(m) - spinReq.uri = C.wasi_outbound_http_uri_t{ - ptr: C.CString(req.URL.String()), - len: C.ulong(len(req.URL.String())), - } - spinReq.headers = toOutboundHeaders(req.Header) - spinReq.body, err = toOutboundReqBody(req.Body) - if err != nil { - return nil, err - } - - code := C.wasi_outbound_http_request(&spinReq, &spinRes) - - if err := toErr(code, req.URL.String()); err != nil { - return nil, err - } - return toResponse(&spinRes) -} - -func method(m string) (int, error) { - switch strings.ToUpper(m) { - case "GET": - return 0, nil - case "POST": - return 1, nil - case "PUT": - return 2, nil - case "DELETE": - return 3, nil - case "PATCH": - return 4, nil - case "HEAD": - return 5, nil - case "OPTIONS": - return 6, nil - default: - return -1, fmt.Errorf("Unknown HTTP method %v", m) - } -} - -// Transform a C outbound HTTP response to a Go *http.Response. -func toResponse(res *C.wasi_outbound_http_response_t) (*http.Response, error) { - var body []byte - if res.body.is_some { - body = C.GoBytes(unsafe.Pointer(res.body.val.ptr), C.int(res.body.val.len)) - } - - t := &http.Response{ - Status: fmt.Sprintf("%v %v", res.status, http.StatusText(int(res.status))), - StatusCode: int(res.status), - Proto: "HTTP/1.1", - ProtoMajor: 1, - ProtoMinor: 1, - Body: ioutil.NopCloser(bytes.NewBuffer(body)), - ContentLength: int64(len(body)), - Request: nil, // we don't really have a request to populate with here - Header: toHeaders(&res.headers), - } - return t, nil -} - -func toOutboundHeaders(hm http.Header) C.wasi_outbound_http_headers_t { - var reqHeaders C.wasi_outbound_http_headers_t - - headersLen := len(hm) - - if headersLen > 0 { - reqHeaders.len = C.ulong(headersLen) - var x C.wasi_outbound_http_tuple2_string_string_t - reqHeaders.ptr = (*C.wasi_outbound_http_tuple2_string_string_t)(C.malloc(C.size_t(headersLen) * C.size_t(unsafe.Sizeof(x)))) - headers := unsafe.Slice(reqHeaders.ptr, headersLen) - - idx := 0 - for k, v := range hm { - headers[idx] = newOutboundHeader(k, v[0]) - idx++ - } - } - return reqHeaders -} - -func toOutboundReqBody(body io.Reader) (C.wasi_outbound_http_option_body_t, error) { - var spinBody C.wasi_outbound_http_option_body_t - spinBody.is_some = false - - if body != nil { - buf := new(bytes.Buffer) - len, err := buf.ReadFrom(body) - if err != nil { - return spinBody, err - } - - if len > 0 { - spinBody.is_some = true - spinBody.val = C.wasi_outbound_http_body_t{ - ptr: &buf.Bytes()[0], - len: C.size_t(len), - } - } - } - - return spinBody, nil -} - -func toHeaders(hm *C.wasi_outbound_http_option_headers_t) http.Header { - if !hm.is_some { - return make(map[string][]string, 0) - } - headersLen := int(hm.val.len) - headers := make(http.Header, headersLen) - - var headersArr *C.wasi_outbound_http_tuple2_string_string_t = hm.val.ptr - headersSlice := unsafe.Slice(headersArr, headersLen) - for i := 0; i < headersLen; i++ { - tuple := headersSlice[i] - k := C.GoStringN(tuple.f0.ptr, C.int(tuple.f0.len)) - v := C.GoStringN(tuple.f1.ptr, C.int(tuple.f1.len)) - - headers.Add(k, v) - } - - return headers -} - -func toErr(code C.uint8_t, url string) error { - switch code { - case 1: - return fmt.Errorf("Destination not allowed: %v", url) - case 2: - return fmt.Errorf("Invalid URL: %v", url) - case 3: - return fmt.Errorf("Error sending request to URL: %v", url) - case 4: - return fmt.Errorf("Runtime error") - default: - return nil - } -} - -// newOutboundHeader creates a new outboundHeader with the given key/value. -func newOutboundHeader(k, v string) C.wasi_outbound_http_tuple2_string_string_t { - return C.wasi_outbound_http_tuple2_string_string_t{ - f0: C.wasi_outbound_http_string_t{ptr: C.CString(k), len: C.size_t(len(k))}, - f1: C.wasi_outbound_http_string_t{ptr: C.CString(v), len: C.size_t(len(v))}, - } -} diff --git a/sdk/go/http/response.go b/sdk/go/http/response.go deleted file mode 100644 index a1b2559c9b..0000000000 --- a/sdk/go/http/response.go +++ /dev/null @@ -1,39 +0,0 @@ -package http - -import ( - "bytes" - "net/http" -) - -var _ http.ResponseWriter = (*response)(nil) - -// response implements http.ResponseWriter -type response struct { - // status code passed to WriteHeader - status int - - header http.Header - w *bytes.Buffer -} - -func newResponse() *response { - return &response{ - // set default status to StatusOK - status: http.StatusOK, - - header: make(http.Header), - w: new(bytes.Buffer), - } -} - -func (r *response) Header() http.Header { - return r.header -} - -func (r *response) WriteHeader(statusCode int) { - r.status = statusCode -} - -func (r *response) Write(data []byte) (int, error) { - return r.w.Write(data) -} diff --git a/sdk/go/http/spin-http.c b/sdk/go/http/spin-http.c deleted file mode 100644 index 780a4adf36..0000000000 --- a/sdk/go/http/spin-http.c +++ /dev/null @@ -1,141 +0,0 @@ -#include -#include - -__attribute__((weak, export_name("canonical_abi_realloc"))) -void *canonical_abi_realloc( -void *ptr, -size_t orig_size, -size_t align, -size_t new_size -) { - if (new_size == 0) - return (void*) align; - void *ret = realloc(ptr, new_size); - if (!ret) - abort(); - return ret; -} - -__attribute__((weak, export_name("canonical_abi_free"))) -void canonical_abi_free( -void *ptr, -size_t size, -size_t align -) { - if (size == 0) - return; - free(ptr); -} -#include - -void spin_http_string_set(spin_http_string_t *ret, const char *s) { - ret->ptr = (char*) s; - ret->len = strlen(s); -} - -void spin_http_string_dup(spin_http_string_t *ret, const char *s) { - ret->len = strlen(s); - ret->ptr = canonical_abi_realloc(NULL, 0, 1, ret->len); - memcpy(ret->ptr, s, ret->len); -} - -void spin_http_string_free(spin_http_string_t *ret) { - canonical_abi_free(ret->ptr, ret->len, 1); - ret->ptr = NULL; - ret->len = 0; -} -void spin_http_body_free(spin_http_body_t *ptr) { - canonical_abi_free(ptr->ptr, ptr->len * 1, 1); -} -void spin_http_tuple2_string_string_free(spin_http_tuple2_string_string_t *ptr) { - spin_http_string_free(&ptr->f0); - spin_http_string_free(&ptr->f1); -} -void spin_http_headers_free(spin_http_headers_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - spin_http_tuple2_string_string_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 16, 4); -} -void spin_http_params_free(spin_http_params_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - spin_http_tuple2_string_string_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 16, 4); -} -void spin_http_uri_free(spin_http_uri_t *ptr) { - spin_http_string_free(ptr); -} -void spin_http_option_body_free(spin_http_option_body_t *ptr) { - if (ptr->is_some) { - spin_http_body_free(&ptr->val); - } -} -void spin_http_request_free(spin_http_request_t *ptr) { - spin_http_uri_free(&ptr->uri); - spin_http_headers_free(&ptr->headers); - spin_http_params_free(&ptr->params); - spin_http_option_body_free(&ptr->body); -} -void spin_http_option_headers_free(spin_http_option_headers_t *ptr) { - if (ptr->is_some) { - spin_http_headers_free(&ptr->val); - } -} -void spin_http_response_free(spin_http_response_t *ptr) { - spin_http_option_headers_free(&ptr->headers); - spin_http_option_body_free(&ptr->body); -} - -__attribute__((aligned(4))) -static uint8_t RET_AREA[28]; -__attribute__((export_name("handle-http-request"))) -int32_t __wasm_export_spin_http_handle_http_request(int32_t arg, int32_t arg0, int32_t arg1, int32_t arg2, int32_t arg3, int32_t arg4, int32_t arg5, int32_t arg6, int32_t arg7, int32_t arg8) { - spin_http_option_body_t option; - switch (arg6) { - case 0: { - option.is_some = false; - - break; - } - case 1: { - option.is_some = true; - - option.val = (spin_http_body_t) { (uint8_t*)(arg7), (size_t)(arg8) }; - break; - } - }spin_http_request_t arg9 = (spin_http_request_t) { - arg, - (spin_http_string_t) { (char*)(arg0), (size_t)(arg1) }, - (spin_http_headers_t) { (spin_http_tuple2_string_string_t*)(arg2), (size_t)(arg3) }, - (spin_http_params_t) { (spin_http_tuple2_string_string_t*)(arg4), (size_t)(arg5) }, - option, - }; - spin_http_response_t ret; - spin_http_handle_http_request(&arg9, &ret); - int32_t ptr = (int32_t) &RET_AREA; - *((int16_t*)(ptr + 0)) = (int32_t) ((ret).status); - - if (((ret).headers).is_some) { - const spin_http_headers_t *payload10 = &((ret).headers).val; - *((int8_t*)(ptr + 4)) = 1; - *((int32_t*)(ptr + 12)) = (int32_t) (*payload10).len; - *((int32_t*)(ptr + 8)) = (int32_t) (*payload10).ptr; - - } else { - *((int8_t*)(ptr + 4)) = 0; - - } - - if (((ret).body).is_some) { - const spin_http_body_t *payload12 = &((ret).body).val; - *((int8_t*)(ptr + 16)) = 1; - *((int32_t*)(ptr + 24)) = (int32_t) (*payload12).len; - *((int32_t*)(ptr + 20)) = (int32_t) (*payload12).ptr; - - } else { - *((int8_t*)(ptr + 16)) = 0; - - } - return ptr; -} diff --git a/sdk/go/http/spin-http.h b/sdk/go/http/spin-http.h deleted file mode 100644 index cd47c95c5e..0000000000 --- a/sdk/go/http/spin-http.h +++ /dev/null @@ -1,85 +0,0 @@ -#ifndef __BINDINGS_SPIN_HTTP_H -#define __BINDINGS_SPIN_HTTP_H -#ifdef __cplusplus -extern "C" -{ - #endif - - #include - #include - - typedef struct { - char *ptr; - size_t len; - } spin_http_string_t; - - void spin_http_string_set(spin_http_string_t *ret, const char *s); - void spin_http_string_dup(spin_http_string_t *ret, const char *s); - void spin_http_string_free(spin_http_string_t *ret); - typedef struct { - uint8_t *ptr; - size_t len; - } spin_http_body_t; - void spin_http_body_free(spin_http_body_t *ptr); - typedef struct { - spin_http_string_t f0; - spin_http_string_t f1; - } spin_http_tuple2_string_string_t; - void spin_http_tuple2_string_string_free(spin_http_tuple2_string_string_t *ptr); - typedef struct { - spin_http_tuple2_string_string_t *ptr; - size_t len; - } spin_http_headers_t; - void spin_http_headers_free(spin_http_headers_t *ptr); - typedef uint8_t spin_http_http_error_t; - #define SPIN_HTTP_HTTP_ERROR_SUCCESS 0 - #define SPIN_HTTP_HTTP_ERROR_DESTINATION_NOT_ALLOWED 1 - #define SPIN_HTTP_HTTP_ERROR_INVALID_URL 2 - #define SPIN_HTTP_HTTP_ERROR_REQUEST_ERROR 3 - #define SPIN_HTTP_HTTP_ERROR_RUNTIME_ERROR 4 - #define SPIN_HTTP_HTTP_ERROR_TOO_MANY_REQUESTS 5 - typedef uint16_t spin_http_http_status_t; - typedef uint8_t spin_http_method_t; - #define SPIN_HTTP_METHOD_GET 0 - #define SPIN_HTTP_METHOD_POST 1 - #define SPIN_HTTP_METHOD_PUT 2 - #define SPIN_HTTP_METHOD_DELETE 3 - #define SPIN_HTTP_METHOD_PATCH 4 - #define SPIN_HTTP_METHOD_HEAD 5 - #define SPIN_HTTP_METHOD_OPTIONS 6 - typedef struct { - spin_http_tuple2_string_string_t *ptr; - size_t len; - } spin_http_params_t; - void spin_http_params_free(spin_http_params_t *ptr); - typedef spin_http_string_t spin_http_uri_t; - void spin_http_uri_free(spin_http_uri_t *ptr); - typedef struct { - bool is_some; - spin_http_body_t val; - } spin_http_option_body_t; - void spin_http_option_body_free(spin_http_option_body_t *ptr); - typedef struct { - spin_http_method_t method; - spin_http_uri_t uri; - spin_http_headers_t headers; - spin_http_params_t params; - spin_http_option_body_t body; - } spin_http_request_t; - void spin_http_request_free(spin_http_request_t *ptr); - typedef struct { - bool is_some; - spin_http_headers_t val; - } spin_http_option_headers_t; - void spin_http_option_headers_free(spin_http_option_headers_t *ptr); - typedef struct { - spin_http_http_status_t status; - spin_http_option_headers_t headers; - spin_http_option_body_t body; - } spin_http_response_t; - void spin_http_response_free(spin_http_response_t *ptr); - void spin_http_handle_http_request(spin_http_request_t *req, spin_http_response_t *ret0); - #ifdef __cplusplus -} -#endif -#endif diff --git a/sdk/go/http/testdata/http-tinygo/Makefile b/sdk/go/http/testdata/http-tinygo/Makefile deleted file mode 100644 index 3e71525144..0000000000 --- a/sdk/go/http/testdata/http-tinygo/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -.PHONY: build -build: - tinygo build -target=wasi -gc=leaking -o main.wasm main.go diff --git a/sdk/go/http/testdata/http-tinygo/main.go b/sdk/go/http/testdata/http-tinygo/main.go deleted file mode 100644 index 33777209c6..0000000000 --- a/sdk/go/http/testdata/http-tinygo/main.go +++ /dev/null @@ -1,29 +0,0 @@ -package main - -import ( - "fmt" - "net/http" - - spinhttp "github.com/fermyon/spin/sdk/go/v2/http" -) - -func init() { - spinhttp.Handle(func(w http.ResponseWriter, r *http.Request) { - if r.Header.Get("Spin-Raw-Component-Route") != "/hello/..." { - http.Error(w, "Spin-Raw-Component-Route is not /hello/...", http.StatusInternalServerError) - return - } - - if r.Method != "GET" { - http.Error(w, "Method should be GET", http.StatusInternalServerError) - return - } - - w.Header().Set("spin-path-info", r.Header.Get("spin-path-info")) - w.Header().Set("foo", "bar") - - fmt.Fprintln(w, "Hello world!") - }) -} - -func main() {} diff --git a/sdk/go/http/testdata/http-tinygo/spin.toml b/sdk/go/http/testdata/http-tinygo/spin.toml deleted file mode 100644 index 10f42ca6e5..0000000000 --- a/sdk/go/http/testdata/http-tinygo/spin.toml +++ /dev/null @@ -1,14 +0,0 @@ -spin_version = "1" -authors = ["Fermyon Engineering "] -description = "A simple Spin application written in (Tiny)Go." -name = "spin-http-tinygo-test" -trigger = { type = "http" } -version = "1.0.0" - -[[component]] -id = "http-tinygo-test" -source = "main.wasm" -[component.trigger] -route = "/hello/..." -[component.build] -command = "tinygo build -target=wasi -gc=leaking -no-debug -o main.wasm main.go" diff --git a/sdk/go/http/testdata/spin-roundtrip/Makefile b/sdk/go/http/testdata/spin-roundtrip/Makefile deleted file mode 100644 index 3e71525144..0000000000 --- a/sdk/go/http/testdata/spin-roundtrip/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -.PHONY: build -build: - tinygo build -target=wasi -gc=leaking -o main.wasm main.go diff --git a/sdk/go/http/testdata/spin-roundtrip/main.go b/sdk/go/http/testdata/spin-roundtrip/main.go deleted file mode 100644 index f8ee4e8500..0000000000 --- a/sdk/go/http/testdata/spin-roundtrip/main.go +++ /dev/null @@ -1,32 +0,0 @@ -package main - -import ( - "fmt" - "net/http" - - spinhttp "github.com/fermyon/spin/sdk/go/v2/http" -) - -func init() { - spinhttp.Handle(func(w http.ResponseWriter, r *http.Request) { - transport := spinhttp.NewTransport() - - // or you can also do client := spinhttp.NewClient() - client := &http.Client{ - Transport: transport, - } - - resp, err := client.Get("https://example.com") - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - w.WriteHeader(resp.StatusCode) - w.Header().Set("spin-path-info", r.Header.Get("spin-path-info")) - w.Header().Set("foo", "bar") - fmt.Fprintln(w, "Hello world!") - }) -} - -func main() {} diff --git a/sdk/go/http/testdata/spin-roundtrip/spin.toml b/sdk/go/http/testdata/spin-roundtrip/spin.toml deleted file mode 100644 index 4613d21ace..0000000000 --- a/sdk/go/http/testdata/spin-roundtrip/spin.toml +++ /dev/null @@ -1,15 +0,0 @@ -spin_version = "1" -authors = ["Fermyon Engineering "] -description = "A simple Spin application written in (Tiny)Go." -name = "spin-roundtrip-test" -trigger = { type = "http" } -version = "1.0.0" - -[[component]] -id = "http-roundtrip-test" -source = "main.wasm" -allowed_outbound_hosts = ["https://example.com"] -[component.trigger] -route = "/hello/..." -[component.build] -command = "tinygo build -target=wasi -gc=leaking -no-debug -o main.wasm main.go" diff --git a/sdk/go/http/wasi-outbound-http.c b/sdk/go/http/wasi-outbound-http.c deleted file mode 100644 index f767585047..0000000000 --- a/sdk/go/http/wasi-outbound-http.c +++ /dev/null @@ -1,166 +0,0 @@ -#include -#include - -__attribute__((weak, export_name("canonical_abi_realloc"))) -void *canonical_abi_realloc( -void *ptr, -size_t orig_size, -size_t align, -size_t new_size -) { - if (new_size == 0) - return (void*) align; - void *ret = realloc(ptr, new_size); - if (!ret) - abort(); - return ret; -} - -__attribute__((weak, export_name("canonical_abi_free"))) -void canonical_abi_free( -void *ptr, -size_t size, -size_t align -) { - if (size == 0) - return; - free(ptr); -} -#include - -void wasi_outbound_http_string_set(wasi_outbound_http_string_t *ret, const char *s) { - ret->ptr = (char*) s; - ret->len = strlen(s); -} - -void wasi_outbound_http_string_dup(wasi_outbound_http_string_t *ret, const char *s) { - ret->len = strlen(s); - ret->ptr = canonical_abi_realloc(NULL, 0, 1, ret->len); - memcpy(ret->ptr, s, ret->len); -} - -void wasi_outbound_http_string_free(wasi_outbound_http_string_t *ret) { - canonical_abi_free(ret->ptr, ret->len, 1); - ret->ptr = NULL; - ret->len = 0; -} -void wasi_outbound_http_body_free(wasi_outbound_http_body_t *ptr) { - canonical_abi_free(ptr->ptr, ptr->len * 1, 1); -} -void wasi_outbound_http_tuple2_string_string_free(wasi_outbound_http_tuple2_string_string_t *ptr) { - wasi_outbound_http_string_free(&ptr->f0); - wasi_outbound_http_string_free(&ptr->f1); -} -void wasi_outbound_http_headers_free(wasi_outbound_http_headers_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - wasi_outbound_http_tuple2_string_string_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 16, 4); -} -void wasi_outbound_http_params_free(wasi_outbound_http_params_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - wasi_outbound_http_tuple2_string_string_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 16, 4); -} -void wasi_outbound_http_uri_free(wasi_outbound_http_uri_t *ptr) { - wasi_outbound_http_string_free(ptr); -} -void wasi_outbound_http_option_body_free(wasi_outbound_http_option_body_t *ptr) { - if (ptr->is_some) { - wasi_outbound_http_body_free(&ptr->val); - } -} -void wasi_outbound_http_request_free(wasi_outbound_http_request_t *ptr) { - wasi_outbound_http_uri_free(&ptr->uri); - wasi_outbound_http_headers_free(&ptr->headers); - wasi_outbound_http_params_free(&ptr->params); - wasi_outbound_http_option_body_free(&ptr->body); -} -void wasi_outbound_http_option_headers_free(wasi_outbound_http_option_headers_t *ptr) { - if (ptr->is_some) { - wasi_outbound_http_headers_free(&ptr->val); - } -} -void wasi_outbound_http_response_free(wasi_outbound_http_response_t *ptr) { - wasi_outbound_http_option_headers_free(&ptr->headers); - wasi_outbound_http_option_body_free(&ptr->body); -} -typedef struct { - bool is_err; - union { - wasi_outbound_http_response_t ok; - wasi_outbound_http_http_error_t err; - } val; -} wasi_outbound_http_expected_response_http_error_t; - -__attribute__((aligned(4))) -static uint8_t RET_AREA[32]; -__attribute__((import_module("wasi-outbound-http"), import_name("request"))) -void __wasm_import_wasi_outbound_http_request(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); -wasi_outbound_http_http_error_t wasi_outbound_http_request(wasi_outbound_http_request_t *req, wasi_outbound_http_response_t *ret0) { - int32_t option; - int32_t option1; - int32_t option2; - - if (((*req).body).is_some) { - const wasi_outbound_http_body_t *payload0 = &((*req).body).val; - option = 1; - option1 = (int32_t) (*payload0).ptr; - option2 = (int32_t) (*payload0).len; - - } else { - option = 0; - option1 = 0; - option2 = 0; - - } - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_wasi_outbound_http_request((int32_t) (*req).method, (int32_t) ((*req).uri).ptr, (int32_t) ((*req).uri).len, (int32_t) ((*req).headers).ptr, (int32_t) ((*req).headers).len, (int32_t) ((*req).params).ptr, (int32_t) ((*req).params).len, option, option1, option2, ptr); - wasi_outbound_http_expected_response_http_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - wasi_outbound_http_option_headers_t option3; - switch ((int32_t) (*((uint8_t*) (ptr + 8)))) { - case 0: { - option3.is_some = false; - - break; - } - case 1: { - option3.is_some = true; - - option3.val = (wasi_outbound_http_headers_t) { (wasi_outbound_http_tuple2_string_string_t*)(*((int32_t*) (ptr + 12))), (size_t)(*((int32_t*) (ptr + 16))) }; - break; - } - }wasi_outbound_http_option_body_t option4; - switch ((int32_t) (*((uint8_t*) (ptr + 20)))) { - case 0: { - option4.is_some = false; - - break; - } - case 1: { - option4.is_some = true; - - option4.val = (wasi_outbound_http_body_t) { (uint8_t*)(*((int32_t*) (ptr + 24))), (size_t)(*((int32_t*) (ptr + 28))) }; - break; - } - } - expected.val.ok = (wasi_outbound_http_response_t) { - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 4)))), - option3, - option4, - }; - break; - } - case 1: { - expected.is_err = true; - - expected.val.err = (int32_t) (*((uint8_t*) (ptr + 4))); - break; - } - }*ret0 = expected.val.ok; - return expected.is_err ? expected.val.err : -1; -} diff --git a/sdk/go/http/wasi-outbound-http.h b/sdk/go/http/wasi-outbound-http.h deleted file mode 100644 index ccaac543da..0000000000 --- a/sdk/go/http/wasi-outbound-http.h +++ /dev/null @@ -1,85 +0,0 @@ -#ifndef __BINDINGS_WASI_OUTBOUND_HTTP_H -#define __BINDINGS_WASI_OUTBOUND_HTTP_H -#ifdef __cplusplus -extern "C" -{ - #endif - - #include - #include - - typedef struct { - char *ptr; - size_t len; - } wasi_outbound_http_string_t; - - void wasi_outbound_http_string_set(wasi_outbound_http_string_t *ret, const char *s); - void wasi_outbound_http_string_dup(wasi_outbound_http_string_t *ret, const char *s); - void wasi_outbound_http_string_free(wasi_outbound_http_string_t *ret); - typedef struct { - uint8_t *ptr; - size_t len; - } wasi_outbound_http_body_t; - void wasi_outbound_http_body_free(wasi_outbound_http_body_t *ptr); - typedef struct { - wasi_outbound_http_string_t f0; - wasi_outbound_http_string_t f1; - } wasi_outbound_http_tuple2_string_string_t; - void wasi_outbound_http_tuple2_string_string_free(wasi_outbound_http_tuple2_string_string_t *ptr); - typedef struct { - wasi_outbound_http_tuple2_string_string_t *ptr; - size_t len; - } wasi_outbound_http_headers_t; - void wasi_outbound_http_headers_free(wasi_outbound_http_headers_t *ptr); - typedef uint8_t wasi_outbound_http_http_error_t; - #define WASI_OUTBOUND_HTTP_HTTP_ERROR_SUCCESS 0 - #define WASI_OUTBOUND_HTTP_HTTP_ERROR_DESTINATION_NOT_ALLOWED 1 - #define WASI_OUTBOUND_HTTP_HTTP_ERROR_INVALID_URL 2 - #define WASI_OUTBOUND_HTTP_HTTP_ERROR_REQUEST_ERROR 3 - #define WASI_OUTBOUND_HTTP_HTTP_ERROR_RUNTIME_ERROR 4 - #define WASI_OUTBOUND_HTTP_HTTP_ERROR_TOO_MANY_REQUESTS 5 - typedef uint16_t wasi_outbound_http_http_status_t; - typedef uint8_t wasi_outbound_http_method_t; - #define WASI_OUTBOUND_HTTP_METHOD_GET 0 - #define WASI_OUTBOUND_HTTP_METHOD_POST 1 - #define WASI_OUTBOUND_HTTP_METHOD_PUT 2 - #define WASI_OUTBOUND_HTTP_METHOD_DELETE 3 - #define WASI_OUTBOUND_HTTP_METHOD_PATCH 4 - #define WASI_OUTBOUND_HTTP_METHOD_HEAD 5 - #define WASI_OUTBOUND_HTTP_METHOD_OPTIONS 6 - typedef struct { - wasi_outbound_http_tuple2_string_string_t *ptr; - size_t len; - } wasi_outbound_http_params_t; - void wasi_outbound_http_params_free(wasi_outbound_http_params_t *ptr); - typedef wasi_outbound_http_string_t wasi_outbound_http_uri_t; - void wasi_outbound_http_uri_free(wasi_outbound_http_uri_t *ptr); - typedef struct { - bool is_some; - wasi_outbound_http_body_t val; - } wasi_outbound_http_option_body_t; - void wasi_outbound_http_option_body_free(wasi_outbound_http_option_body_t *ptr); - typedef struct { - wasi_outbound_http_method_t method; - wasi_outbound_http_uri_t uri; - wasi_outbound_http_headers_t headers; - wasi_outbound_http_params_t params; - wasi_outbound_http_option_body_t body; - } wasi_outbound_http_request_t; - void wasi_outbound_http_request_free(wasi_outbound_http_request_t *ptr); - typedef struct { - bool is_some; - wasi_outbound_http_headers_t val; - } wasi_outbound_http_option_headers_t; - void wasi_outbound_http_option_headers_free(wasi_outbound_http_option_headers_t *ptr); - typedef struct { - wasi_outbound_http_http_status_t status; - wasi_outbound_http_option_headers_t headers; - wasi_outbound_http_option_body_t body; - } wasi_outbound_http_response_t; - void wasi_outbound_http_response_free(wasi_outbound_http_response_t *ptr); - wasi_outbound_http_http_error_t wasi_outbound_http_request(wasi_outbound_http_request_t *req, wasi_outbound_http_response_t *ret0); - #ifdef __cplusplus -} -#endif -#endif diff --git a/sdk/go/integration_test.go b/sdk/go/integration_test.go deleted file mode 100644 index 12591daed1..0000000000 --- a/sdk/go/integration_test.go +++ /dev/null @@ -1,170 +0,0 @@ -package http - -import ( - "bytes" - "context" - "fmt" - "io" - "net" - "net/http" - "os/exec" - "testing" - "time" -) - -const spinBinary = "../../target/debug/spin" - -func retryGet(t *testing.T, url string) *http.Response { - t.Helper() - - const maxTries = 600 // (10min) - for i := 1; i < maxTries; i++ { - // Catch call to `Fail` in other goroutine - if t.Failed() { - t.FailNow() - } - if res, err := http.Get(url); err != nil { - t.Log(err) - } else { - return res - } - time.Sleep(1 * time.Second) - } - t.Fatal("Get request timeout: ", url) - return nil -} - -type testSpin struct { - cancel func() - url string - cmd *exec.Cmd -} - -func startSpin(t *testing.T, spinfile string) *testSpin { - // long timeout because... ci - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute) - - url := getFreePort(t) - - cmd := exec.CommandContext(ctx, spinBinary, "up", "--build", "--file", spinfile, "--listen", url) - stderr := new(bytes.Buffer) - cmd.Stderr = stderr - if err := cmd.Start(); err != nil { - t.Log(stderr.String()) - t.Fatal(err) - } - - go func() { - cmd.Wait() - if ctx.Err() == nil { - t.Log("spin exited before the test finished:", cmd.ProcessState) - t.Log("stderr:\n", stderr.String()) - t.Fail() - } - }() - - return &testSpin{ - cancel: cancel, - url: fmt.Sprintf("http://%s", url), - cmd: cmd, - } -} - -func build(t *testing.T, dir string) { - t.Helper() - - t.Log("building example: ", dir) - - cmd := exec.Command(spinBinary, "build") - cmd.Dir = dir - - stderr := new(bytes.Buffer) - cmd.Stderr = stderr - if err := cmd.Run(); err != nil { - t.Log(stderr.String()) - t.Errorf("Failed to build %q, %v", dir, err) - } -} - -func TestSpinRoundTrip(t *testing.T) { - spin := startSpin(t, "http/testdata/spin-roundtrip/spin.toml") - defer spin.cancel() - - resp := retryGet(t, spin.url+"/hello") - spin.cancel() - if resp.Body == nil { - t.Fatal("body is nil") - } - t.Log(resp.Status) - b, err := io.ReadAll(resp.Body) - resp.Body.Close() - if err != nil { - t.Fatal(err) - } - - // assert response body - want := "Hello world!\n" - got := string(b) - if want != got { - t.Fatalf("body is not equal: want = %q got = %q", want, got) - } -} - -func TestHTTPTriger(t *testing.T) { - spin := startSpin(t, "http/testdata/http-tinygo/spin.toml") - defer spin.cancel() - - resp := retryGet(t, spin.url+"/hello") - spin.cancel() - if resp.Body == nil { - t.Fatal("body is nil") - } - t.Log(resp.Status) - b, err := io.ReadAll(resp.Body) - resp.Body.Close() - if err != nil { - t.Fatal(err) - } - - // assert response body - want := "Hello world!\n" - got := string(b) - if want != got { - t.Fatalf("body is not equal: want = %q got = %q", want, got) - } - - // assert response header - if resp.Header.Get("foo") != "bar" { - t.Fatal("header 'foo' was not set") - } -} - -// TestBuildExamples ensures that the tinygo examples will build successfully. -func TestBuildExamples(t *testing.T) { - for _, example := range []string{ - "../../examples/http-tinygo", - "../../examples/http-tinygo-outbound-http", - "../../examples/tinygo-outbound-redis", - "../../examples/tinygo-redis", - "../../examples/tinygo-key-value", - "../../examples/variables-tinygo", - } { - build(t, example) - } -} - -func getFreePort(t *testing.T) string { - t.Helper() - - a, err := net.ResolveTCPAddr("tcp", "127.0.0.1:0") - if err != nil { - t.Fatal("failed to get free port: ", err) - } - - l, err := net.ListenTCP("tcp", a) - if err != nil { - t.Fatal("failed to get free port: ", err) - } - l.Close() - return l.Addr().String() -} diff --git a/sdk/go/internal/db/driver.go b/sdk/go/internal/db/driver.go deleted file mode 100644 index 2b3ab75719..0000000000 --- a/sdk/go/internal/db/driver.go +++ /dev/null @@ -1,17 +0,0 @@ -package db - -import ( - "database/sql/driver" -) - -// GlobalParameterConverter is a global valueConverter instance to convert parameters. -var GlobalParameterConverter = &valueConverter{} - -var _ driver.ValueConverter = (*valueConverter)(nil) - -// valueConverter is a no-op value converter. -type valueConverter struct{} - -func (c *valueConverter) ConvertValue(v any) (driver.Value, error) { - return driver.Value(v), nil -} diff --git a/sdk/go/kv/key-value.c b/sdk/go/kv/key-value.c deleted file mode 100644 index bcb03cc88e..0000000000 --- a/sdk/go/kv/key-value.c +++ /dev/null @@ -1,367 +0,0 @@ -#include -#include - -__attribute__((weak, export_name("canonical_abi_realloc"))) -void *canonical_abi_realloc( -void *ptr, -size_t orig_size, -size_t align, -size_t new_size -) { - if (new_size == 0) - return (void*) align; - void *ret = realloc(ptr, new_size); - if (!ret) - abort(); - return ret; -} - -__attribute__((weak, export_name("canonical_abi_free"))) -void canonical_abi_free( -void *ptr, -size_t size, -size_t align -) { - if (size == 0) - return; - free(ptr); -} -#include - -void key_value_string_set(key_value_string_t *ret, const char *s) { - ret->ptr = (char*) s; - ret->len = strlen(s); -} - -void key_value_string_dup(key_value_string_t *ret, const char *s) { - ret->len = strlen(s); - ret->ptr = canonical_abi_realloc(NULL, 0, 1, ret->len); - memcpy(ret->ptr, s, ret->len); -} - -void key_value_string_free(key_value_string_t *ret) { - canonical_abi_free(ret->ptr, ret->len, 1); - ret->ptr = NULL; - ret->len = 0; -} -void key_value_error_free(key_value_error_t *ptr) { - switch ((int32_t) ptr->tag) { - case 5: { - key_value_string_free(&ptr->val.io); - break; - } - } -} -void key_value_expected_store_error_free(key_value_expected_store_error_t *ptr) { - if (!ptr->is_err) { - } else { - key_value_error_free(&ptr->val.err); - } -} -void key_value_list_u8_free(key_value_list_u8_t *ptr) { - canonical_abi_free(ptr->ptr, ptr->len * 1, 1); -} -void key_value_expected_list_u8_error_free(key_value_expected_list_u8_error_t *ptr) { - if (!ptr->is_err) { - key_value_list_u8_free(&ptr->val.ok); - } else { - key_value_error_free(&ptr->val.err); - } -} -void key_value_expected_unit_error_free(key_value_expected_unit_error_t *ptr) { - if (!ptr->is_err) { - } else { - key_value_error_free(&ptr->val.err); - } -} -void key_value_expected_bool_error_free(key_value_expected_bool_error_t *ptr) { - if (!ptr->is_err) { - } else { - key_value_error_free(&ptr->val.err); - } -} -void key_value_list_string_free(key_value_list_string_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - key_value_string_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 8, 4); -} -void key_value_expected_list_string_error_free(key_value_expected_list_string_error_t *ptr) { - if (!ptr->is_err) { - key_value_list_string_free(&ptr->val.ok); - } else { - key_value_error_free(&ptr->val.err); - } -} - -__attribute__((aligned(4))) -static uint8_t RET_AREA[16]; -__attribute__((import_module("key-value"), import_name("open"))) -void __wasm_import_key_value_open(int32_t, int32_t, int32_t); -void key_value_open(key_value_string_t *name, key_value_expected_store_error_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_key_value_open((int32_t) (*name).ptr, (int32_t) (*name).len, ptr); - key_value_expected_store_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = (uint32_t) (*((int32_t*) (ptr + 4))); - break; - } - case 1: { - expected.is_err = true; - key_value_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant.tag) { - case 0: { - break; - } - case 1: { - break; - } - case 2: { - break; - } - case 3: { - break; - } - case 4: { - break; - } - case 5: { - variant.val.io = (key_value_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - } - - expected.val.err = variant; - break; - } - }*ret0 = expected; -} -__attribute__((import_module("key-value"), import_name("get"))) -void __wasm_import_key_value_get(int32_t, int32_t, int32_t, int32_t); -void key_value_get(key_value_store_t store, key_value_string_t *key, key_value_expected_list_u8_error_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_key_value_get((int32_t) (store), (int32_t) (*key).ptr, (int32_t) (*key).len, ptr); - key_value_expected_list_u8_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = (key_value_list_u8_t) { (uint8_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }; - break; - } - case 1: { - expected.is_err = true; - key_value_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant.tag) { - case 0: { - break; - } - case 1: { - break; - } - case 2: { - break; - } - case 3: { - break; - } - case 4: { - break; - } - case 5: { - variant.val.io = (key_value_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - } - - expected.val.err = variant; - break; - } - }*ret0 = expected; -} -__attribute__((import_module("key-value"), import_name("set"))) -void __wasm_import_key_value_set(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); -void key_value_set(key_value_store_t store, key_value_string_t *key, key_value_list_u8_t *value, key_value_expected_unit_error_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_key_value_set((int32_t) (store), (int32_t) (*key).ptr, (int32_t) (*key).len, (int32_t) (*value).ptr, (int32_t) (*value).len, ptr); - key_value_expected_unit_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - - break; - } - case 1: { - expected.is_err = true; - key_value_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant.tag) { - case 0: { - break; - } - case 1: { - break; - } - case 2: { - break; - } - case 3: { - break; - } - case 4: { - break; - } - case 5: { - variant.val.io = (key_value_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - } - - expected.val.err = variant; - break; - } - }*ret0 = expected; -} -__attribute__((import_module("key-value"), import_name("delete"))) -void __wasm_import_key_value_delete(int32_t, int32_t, int32_t, int32_t); -void key_value_delete(key_value_store_t store, key_value_string_t *key, key_value_expected_unit_error_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_key_value_delete((int32_t) (store), (int32_t) (*key).ptr, (int32_t) (*key).len, ptr); - key_value_expected_unit_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - - break; - } - case 1: { - expected.is_err = true; - key_value_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant.tag) { - case 0: { - break; - } - case 1: { - break; - } - case 2: { - break; - } - case 3: { - break; - } - case 4: { - break; - } - case 5: { - variant.val.io = (key_value_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - } - - expected.val.err = variant; - break; - } - }*ret0 = expected; -} -__attribute__((import_module("key-value"), import_name("exists"))) -void __wasm_import_key_value_exists(int32_t, int32_t, int32_t, int32_t); -void key_value_exists(key_value_store_t store, key_value_string_t *key, key_value_expected_bool_error_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_key_value_exists((int32_t) (store), (int32_t) (*key).ptr, (int32_t) (*key).len, ptr); - key_value_expected_bool_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = (int32_t) (*((uint8_t*) (ptr + 4))); - break; - } - case 1: { - expected.is_err = true; - key_value_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant.tag) { - case 0: { - break; - } - case 1: { - break; - } - case 2: { - break; - } - case 3: { - break; - } - case 4: { - break; - } - case 5: { - variant.val.io = (key_value_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - } - - expected.val.err = variant; - break; - } - }*ret0 = expected; -} -__attribute__((import_module("key-value"), import_name("get-keys"))) -void __wasm_import_key_value_get_keys(int32_t, int32_t); -void key_value_get_keys(key_value_store_t store, key_value_expected_list_string_error_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_key_value_get_keys((int32_t) (store), ptr); - key_value_expected_list_string_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = (key_value_list_string_t) { (key_value_string_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }; - break; - } - case 1: { - expected.is_err = true; - key_value_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant.tag) { - case 0: { - break; - } - case 1: { - break; - } - case 2: { - break; - } - case 3: { - break; - } - case 4: { - break; - } - case 5: { - variant.val.io = (key_value_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - } - - expected.val.err = variant; - break; - } - }*ret0 = expected; -} -__attribute__((import_module("key-value"), import_name("close"))) -void __wasm_import_key_value_close(int32_t); -void key_value_close(key_value_store_t store) { - __wasm_import_key_value_close((int32_t) (store)); -} diff --git a/sdk/go/kv/key-value.h b/sdk/go/kv/key-value.h deleted file mode 100644 index 7b78b032c6..0000000000 --- a/sdk/go/kv/key-value.h +++ /dev/null @@ -1,92 +0,0 @@ -#ifndef __BINDINGS_KEY_VALUE_H -#define __BINDINGS_KEY_VALUE_H -#ifdef __cplusplus -extern "C" -{ - #endif - - #include - #include - - typedef struct { - char *ptr; - size_t len; - } key_value_string_t; - - void key_value_string_set(key_value_string_t *ret, const char *s); - void key_value_string_dup(key_value_string_t *ret, const char *s); - void key_value_string_free(key_value_string_t *ret); - typedef uint32_t key_value_store_t; - typedef struct { - uint8_t tag; - union { - key_value_string_t io; - } val; - } key_value_error_t; - #define KEY_VALUE_ERROR_STORE_TABLE_FULL 0 - #define KEY_VALUE_ERROR_NO_SUCH_STORE 1 - #define KEY_VALUE_ERROR_ACCESS_DENIED 2 - #define KEY_VALUE_ERROR_INVALID_STORE 3 - #define KEY_VALUE_ERROR_NO_SUCH_KEY 4 - #define KEY_VALUE_ERROR_IO 5 - void key_value_error_free(key_value_error_t *ptr); - typedef struct { - bool is_err; - union { - key_value_store_t ok; - key_value_error_t err; - } val; - } key_value_expected_store_error_t; - void key_value_expected_store_error_free(key_value_expected_store_error_t *ptr); - typedef struct { - uint8_t *ptr; - size_t len; - } key_value_list_u8_t; - void key_value_list_u8_free(key_value_list_u8_t *ptr); - typedef struct { - bool is_err; - union { - key_value_list_u8_t ok; - key_value_error_t err; - } val; - } key_value_expected_list_u8_error_t; - void key_value_expected_list_u8_error_free(key_value_expected_list_u8_error_t *ptr); - typedef struct { - bool is_err; - union { - key_value_error_t err; - } val; - } key_value_expected_unit_error_t; - void key_value_expected_unit_error_free(key_value_expected_unit_error_t *ptr); - typedef struct { - bool is_err; - union { - bool ok; - key_value_error_t err; - } val; - } key_value_expected_bool_error_t; - void key_value_expected_bool_error_free(key_value_expected_bool_error_t *ptr); - typedef struct { - key_value_string_t *ptr; - size_t len; - } key_value_list_string_t; - void key_value_list_string_free(key_value_list_string_t *ptr); - typedef struct { - bool is_err; - union { - key_value_list_string_t ok; - key_value_error_t err; - } val; - } key_value_expected_list_string_error_t; - void key_value_expected_list_string_error_free(key_value_expected_list_string_error_t *ptr); - void key_value_open(key_value_string_t *name, key_value_expected_store_error_t *ret0); - void key_value_get(key_value_store_t store, key_value_string_t *key, key_value_expected_list_u8_error_t *ret0); - void key_value_set(key_value_store_t store, key_value_string_t *key, key_value_list_u8_t *value, key_value_expected_unit_error_t *ret0); - void key_value_delete(key_value_store_t store, key_value_string_t *key, key_value_expected_unit_error_t *ret0); - void key_value_exists(key_value_store_t store, key_value_string_t *key, key_value_expected_bool_error_t *ret0); - void key_value_get_keys(key_value_store_t store, key_value_expected_list_string_error_t *ret0); - void key_value_close(key_value_store_t store); - #ifdef __cplusplus -} -#endif -#endif diff --git a/sdk/go/kv/kv.go b/sdk/go/kv/kv.go deleted file mode 100644 index c521660031..0000000000 --- a/sdk/go/kv/kv.go +++ /dev/null @@ -1,148 +0,0 @@ -// Package kv provides access to key value stores within Spin -// components. -package kv - -// #include "key-value.h" -import "C" -import ( - "errors" - "fmt" - "unsafe" -) - -// Store is the Key/Value backend storage. -type Store struct { - name string - active bool - ptr C.key_value_store_t -} - -// OpenStore creates a new instance of Store and opens a connection. -func OpenStore(name string) (*Store, error) { - s := &Store{name: name} - if err := s.open(); err != nil { - return nil, err - } - return s, nil -} - -// Close terminates the connection to Store. -func (s *Store) Close() { - if s.active { - C.key_value_close(C.uint32_t(s.ptr)) - } - s.active = false -} - -// Get retrieves a value from Store. -func (s *Store) Get(key string) ([]byte, error) { - ckey := toCStr(key) - var ret C.key_value_expected_list_u8_error_t - C.key_value_get(C.uint32_t(s.ptr), &ckey, &ret) - if ret.is_err { - return nil, toErr((*C.key_value_error_t)(unsafe.Pointer(&ret.val))) - } - list := (*C.key_value_list_u8_t)(unsafe.Pointer(&ret.val)) - return C.GoBytes(unsafe.Pointer(list.ptr), C.int(list.len)), nil -} - -// Delete removes a value from Store. -func (s *Store) Delete(key string) error { - ckey := toCStr(key) - var ret C.key_value_expected_unit_error_t - C.key_value_delete(C.uint32_t(s.ptr), &ckey, &ret) - if ret.is_err { - return toErr((*C.key_value_error_t)(unsafe.Pointer(&ret.val))) - } - return nil -} - -// Set creates a new key/value in Store. -func (s *Store) Set(key string, value []byte) error { - ckey := toCStr(key) - cbytes := toCBytes(value) - var ret C.key_value_expected_unit_error_t - C.key_value_set(C.uint32_t(s.ptr), &ckey, &cbytes, &ret) - if ret.is_err { - return toErr((*C.key_value_error_t)(unsafe.Pointer(&ret.val))) - } - return nil -} - -// Exists checks if a key exists within Store. -func (s *Store) Exists(key string) (bool, error) { - ckey := toCStr(key) - var ret C.key_value_expected_bool_error_t - C.key_value_exists(C.uint32_t(s.ptr), &ckey, &ret) - if ret.is_err { - return false, toErr((*C.key_value_error_t)(unsafe.Pointer(&ret.val))) - } - return *(*bool)(unsafe.Pointer(&ret.val)), nil -} - -// GetKeys retrieves the list of keys from Store. -func (s *Store) GetKeys() ([]string, error) { - var ret C.key_value_expected_list_string_error_t - C.key_value_get_keys(C.uint32_t(s.ptr), &ret) - if ret.is_err { - return nil, toErr((*C.key_value_error_t)(unsafe.Pointer(&ret.val))) - } - list := (*C.key_value_list_string_t)(unsafe.Pointer(&ret.val)) - return fromCStrList(list), nil -} - -func (s *Store) open() error { - if s.active { - return nil - } - cname := toCStr(s.name) - var ret C.key_value_expected_store_error_t - C.key_value_open(&cname, &ret) - if ret.is_err { - return toErr((*C.key_value_error_t)(unsafe.Pointer(&ret.val))) - } - s.ptr = *(*C.key_value_store_t)(unsafe.Pointer(&ret.val)) - s.active = true - return nil -} - -func toCBytes(x []byte) C.key_value_list_u8_t { - return C.key_value_list_u8_t{ptr: (*C.uint8_t)(unsafe.Pointer(&x[0])), len: C.size_t(len(x))} -} - -func toCStr(x string) C.key_value_string_t { - return C.key_value_string_t{ptr: C.CString(x), len: C.size_t(len(x))} -} - -func fromCStrList(list *C.key_value_list_string_t) []string { - var result []string - - listLen := int(list.len) - slice := unsafe.Slice(list.ptr, listLen) - for i := 0; i < listLen; i++ { - str := slice[i] - result = append(result, C.GoStringN(str.ptr, C.int(str.len))) - } - - return result -} - -func toErr(err *C.key_value_error_t) error { - switch err.tag { - case 0: - return errors.New("store table full") - case 1: - return errors.New("no such store") - case 2: - return errors.New("access denied") - case 3: - return errors.New("invalid store") - case 4: - return errors.New("no such key") - case 5: - str := (*C.key_value_string_t)(unsafe.Pointer(&err.val)) - return fmt.Errorf("io error: %s", C.GoStringN(str.ptr, C.int(str.len))) - default: - return fmt.Errorf("unrecognized error: %v", err.tag) - } -} diff --git a/sdk/go/llm/internals.go b/sdk/go/llm/internals.go deleted file mode 100644 index 4c64427348..0000000000 --- a/sdk/go/llm/internals.go +++ /dev/null @@ -1,131 +0,0 @@ -package llm - -// #include "llm.h" -import "C" -import ( - "errors" - "fmt" - "unsafe" -) - -func infer(model, prompt string, params *InferencingParams) (*InferencingResult, error) { - llmModel := toLLMModel(model) - llmPrompt := toLLMString(prompt) - llmParams := toLLMInferencingParams(params) - - var ret C.llm_expected_inferencing_result_error_t - defer C.llm_expected_inferencing_result_error_free(&ret) - - C.llm_infer(&llmModel, &llmPrompt, &llmParams, &ret) - if ret.is_err { - return nil, toErr((*C.llm_error_t)(unsafe.Pointer(&ret.val))) - } - - result := (*C.llm_inferencing_result_t)(unsafe.Pointer(&ret.val)) - - r := &InferencingResult{ - Text: C.GoStringN(result.text.ptr, C.int(result.text.len)), - Usage: &InferencingUsage{ - PromptTokenCount: int(result.usage.prompt_token_count), - GeneratedTokenCount: int(result.usage.generated_token_count), - }, - } - return r, nil -} - -func toErr(err *C.llm_error_t) error { - switch err.tag { - case 0: - return errors.New("model not supported") - case 1: - str := (*C.llm_string_t)(unsafe.Pointer(&err.val)) - return fmt.Errorf("runtime error: %s", C.GoStringN(str.ptr, C.int(str.len))) - case 2: - str := (*C.llm_string_t)(unsafe.Pointer(&err.val)) - return fmt.Errorf("invalid input error: %s", C.GoStringN(str.ptr, C.int(str.len))) - default: - return fmt.Errorf("unrecognized error: %v", err.tag) - } -} - -func toLLMModel(name string) C.llm_inferencing_model_t { - llmString := toLLMString(name) - return *(*C.llm_inferencing_model_t)(unsafe.Pointer(&llmString.ptr)) -} - -func toLLMString(x string) C.llm_string_t { - return C.llm_string_t{ptr: C.CString(x), len: C.size_t(len(x))} -} - -func toLLMInferencingParams(p *InferencingParams) C.llm_option_inferencing_params_t { - if p == nil { - return C.llm_option_inferencing_params_t{is_some: false} - } - llmParams := C.llm_inferencing_params_t{ - max_tokens: C.uint32_t(p.MaxTokens), - repeat_penalty: C.float(p.RepeatPenalty), - repeat_penalty_last_n_token_count: C.uint32_t(p.RepeatPenaltyLastNTokenCount), - temperature: C.float(p.Temperature), - top_k: C.uint32_t(p.TopK), - top_p: C.float(p.TopP), - } - return C.llm_option_inferencing_params_t{is_some: true, val: llmParams} -} - -func generateEmbeddings(model string, text []string) (*EmbeddingsResult, error) { - llmModel := toLLMEmbeddingModel(model) - llmListString := toLLMListString(text) - - var ret C.llm_expected_embeddings_result_error_t - defer C.llm_expected_embeddings_result_error_free(&ret) - - C.llm_generate_embeddings(&llmModel, &llmListString, &ret) - if ret.is_err { - return nil, toErr((*C.llm_error_t)(unsafe.Pointer(&ret.val))) - } - - result := (*C.llm_embeddings_result_t)(unsafe.Pointer(&ret.val)) - - r := &EmbeddingsResult{ - Embeddings: fromLLMListListFloat32(result.embeddings), - Usage: &EmbeddingsUsage{ - PromptTokenCount: int(result.usage.prompt_token_count), - }, - } - return r, nil -} - -func toLLMEmbeddingModel(name string) C.llm_embedding_model_t { - llmString := toLLMString(name) - return *(*C.llm_embedding_model_t)(unsafe.Pointer(&llmString.ptr)) -} - -func toLLMListString(xs []string) C.llm_list_string_t { - cxs := make([]C.llm_string_t, len(xs)) - for i := 0; i < len(xs); i++ { - cxs[i] = toLLMString(xs[i]) - } - return C.llm_list_string_t{ptr: &cxs[0], len: C.size_t(len(cxs))} -} - -func fromLLMListListFloat32(list C.llm_list_list_float32_t) [][]float32 { - listLen := int(list.len) - ret := make([][]float32, listLen) - slice := unsafe.Slice(list.ptr, listLen) - for i := 0; i < listLen; i++ { - row := *((*C.llm_list_float32_t)(unsafe.Pointer(&slice[i]))) - ret[i] = fromLLMListFloat32(row) - } - return ret -} - -func fromLLMListFloat32(list C.llm_list_float32_t) []float32 { - listLen := int(list.len) - ret := make([]float32, listLen) - slice := unsafe.Slice(list.ptr, listLen) - for i := 0; i < listLen; i++ { - v := *((*C.float)(unsafe.Pointer(&slice[i]))) - ret[i] = float32(v) - } - return ret -} diff --git a/sdk/go/llm/llm.c b/sdk/go/llm/llm.c deleted file mode 100644 index 474202980a..0000000000 --- a/sdk/go/llm/llm.c +++ /dev/null @@ -1,213 +0,0 @@ -#include -#include - -__attribute__((weak, export_name("canonical_abi_realloc"))) -void *canonical_abi_realloc( -void *ptr, -size_t orig_size, -size_t align, -size_t new_size -) { - if (new_size == 0) - return (void*) align; - void *ret = realloc(ptr, new_size); - if (!ret) - abort(); - return ret; -} - -__attribute__((weak, export_name("canonical_abi_free"))) -void canonical_abi_free( -void *ptr, -size_t size, -size_t align -) { - if (size == 0) - return; - free(ptr); -} -#include - -void llm_string_set(llm_string_t *ret, const char *s) { - ret->ptr = (char*) s; - ret->len = strlen(s); -} - -void llm_string_dup(llm_string_t *ret, const char *s) { - ret->len = strlen(s); - ret->ptr = canonical_abi_realloc(NULL, 0, 1, ret->len); - memcpy(ret->ptr, s, ret->len); -} - -void llm_string_free(llm_string_t *ret) { - canonical_abi_free(ret->ptr, ret->len, 1); - ret->ptr = NULL; - ret->len = 0; -} -void llm_inferencing_model_free(llm_inferencing_model_t *ptr) { - llm_string_free(ptr); -} -void llm_error_free(llm_error_t *ptr) { - switch ((int32_t) ptr->tag) { - case 1: { - llm_string_free(&ptr->val.runtime_error); - break; - } - case 2: { - llm_string_free(&ptr->val.invalid_input); - break; - } - } -} -void llm_inferencing_result_free(llm_inferencing_result_t *ptr) { - llm_string_free(&ptr->text); -} -void llm_embedding_model_free(llm_embedding_model_t *ptr) { - llm_string_free(ptr); -} -void llm_list_float32_free(llm_list_float32_t *ptr) { - canonical_abi_free(ptr->ptr, ptr->len * 4, 4); -} -void llm_list_list_float32_free(llm_list_list_float32_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - llm_list_float32_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 8, 4); -} -void llm_embeddings_result_free(llm_embeddings_result_t *ptr) { - llm_list_list_float32_free(&ptr->embeddings); -} -void llm_expected_inferencing_result_error_free(llm_expected_inferencing_result_error_t *ptr) { - if (!ptr->is_err) { - llm_inferencing_result_free(&ptr->val.ok); - } else { - llm_error_free(&ptr->val.err); - } -} -void llm_list_string_free(llm_list_string_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - llm_string_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 8, 4); -} -void llm_expected_embeddings_result_error_free(llm_expected_embeddings_result_error_t *ptr) { - if (!ptr->is_err) { - llm_embeddings_result_free(&ptr->val.ok); - } else { - llm_error_free(&ptr->val.err); - } -} - -__attribute__((aligned(4))) -static uint8_t RET_AREA[20]; -__attribute__((import_module("llm"), import_name("infer"))) -void __wasm_import_llm_infer(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, float, int32_t, float, int32_t, float, int32_t); -void llm_infer(llm_inferencing_model_t *model, llm_string_t *prompt, llm_option_inferencing_params_t *params, llm_expected_inferencing_result_error_t *ret0) { - int32_t option; - int32_t option1; - float option2; - int32_t option3; - float option4; - int32_t option5; - float option6; - - if ((*params).is_some) { - const llm_inferencing_params_t *payload0 = &(*params).val; - option = 1; - option1 = (int32_t) ((*payload0).max_tokens); - option2 = (*payload0).repeat_penalty; - option3 = (int32_t) ((*payload0).repeat_penalty_last_n_token_count); - option4 = (*payload0).temperature; - option5 = (int32_t) ((*payload0).top_k); - option6 = (*payload0).top_p; - - } else { - option = 0; - option1 = 0; - option2 = 0; - option3 = 0; - option4 = 0; - option5 = 0; - option6 = 0; - - } - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_llm_infer((int32_t) (*model).ptr, (int32_t) (*model).len, (int32_t) (*prompt).ptr, (int32_t) (*prompt).len, option, option1, option2, option3, option4, option5, option6, ptr); - llm_expected_inferencing_result_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = (llm_inferencing_result_t) { - (llm_string_t) { (char*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }, - (llm_inferencing_usage_t) { - (uint32_t) (*((int32_t*) (ptr + 12))), - (uint32_t) (*((int32_t*) (ptr + 16))), - }, - }; - break; - } - case 1: { - expected.is_err = true; - llm_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant.tag) { - case 0: { - break; - } - case 1: { - variant.val.runtime_error = (llm_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - case 2: { - variant.val.invalid_input = (llm_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - } - - expected.val.err = variant; - break; - } - }*ret0 = expected; -} -__attribute__((import_module("llm"), import_name("generate-embeddings"))) -void __wasm_import_llm_generate_embeddings(int32_t, int32_t, int32_t, int32_t, int32_t); -void llm_generate_embeddings(llm_embedding_model_t *model, llm_list_string_t *text, llm_expected_embeddings_result_error_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_llm_generate_embeddings((int32_t) (*model).ptr, (int32_t) (*model).len, (int32_t) (*text).ptr, (int32_t) (*text).len, ptr); - llm_expected_embeddings_result_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = (llm_embeddings_result_t) { - (llm_list_list_float32_t) { (llm_list_float32_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }, - (llm_embeddings_usage_t) { - (uint32_t) (*((int32_t*) (ptr + 12))), - }, - }; - break; - } - case 1: { - expected.is_err = true; - llm_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant.tag) { - case 0: { - break; - } - case 1: { - variant.val.runtime_error = (llm_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - case 2: { - variant.val.invalid_input = (llm_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - } - - expected.val.err = variant; - break; - } - }*ret0 = expected; -} diff --git a/sdk/go/llm/llm.go b/sdk/go/llm/llm.go deleted file mode 100644 index 292c906892..0000000000 --- a/sdk/go/llm/llm.go +++ /dev/null @@ -1,70 +0,0 @@ -// Package llm provides the interface to use Large Language Models in Spin. -package llm - -// InferenceParams is the optional request parameters. -type InferencingParams struct { - // MaxTokens is the maximum tokens that should be inferred. - // Default: 100 - // - // Note: the backing implementation may return less tokens. - MaxTokens int32 - // RepeatPenalty is the amount the model should avoid repeating tokens. - // Default: 1.1 - RepeatPenalty float32 - // RepeatPenaltyLastNTokenCount the number of tokens the model should - // apply the repeat penalty to. - // Default: 64 - RepeatPenaltyLastNTokenCount int32 - // Temperature is the randomness with which the next token is selected. - // Default: 0.8 - Temperature float32 - // TopK is the number of possible next tokens the model will choose from. - // Default: 40 - TopK int32 - // TopP is the probability total of next tokens the model will choose - // from. - // Default: 0.9 - TopP float32 -} - -// InferencingResult is the result of an inference. -type InferencingResult struct { - // Text is the text generated by the model. - Text string - // Usage is information about the inferencing request. - Usage *InferencingUsage -} - -// InferencingUsage represents information related to the inferencing result. -type InferencingUsage struct { - // PromptTokenCount is the number of tokens in the prompt. - PromptTokenCount int - // GeneratedTokenCount is the number of tokens generated by the - // inferencing operation. - GeneratedTokenCount int -} - -// Infer performs inferencing using the provided model and prompt with the -// given optional parameters. -func Infer(model, prompt string, params *InferencingParams) (*InferencingResult, error) { - return infer(model, prompt, params) -} - -// EmbeddingsResult of generating embeddings. -type EmbeddingsResult struct { - // Embeddings are the embeddings generated by the request. - Embeddings [][]float32 - // Usage is usage related to an embeddings generation request. - Usage *EmbeddingsUsage -} - -// Embeddings is usage related to an embeddings generation request. -type EmbeddingsUsage struct { - // PromptTokenCount is number of tokens in the prompt. - PromptTokenCount int -} - -// GenerateEmbeddings generates the embeddings for the supplied list of text. -func GenerateEmbeddings(model string, text []string) (*EmbeddingsResult, error) { - return generateEmbeddings(model, text) -} diff --git a/sdk/go/llm/llm.h b/sdk/go/llm/llm.h deleted file mode 100644 index 57c5a49f7b..0000000000 --- a/sdk/go/llm/llm.h +++ /dev/null @@ -1,107 +0,0 @@ -#ifndef __BINDINGS_LLM_H -#define __BINDINGS_LLM_H -#ifdef __cplusplus -extern "C" -{ - #endif - - #include - #include - - typedef struct { - char *ptr; - size_t len; - } llm_string_t; - - void llm_string_set(llm_string_t *ret, const char *s); - void llm_string_dup(llm_string_t *ret, const char *s); - void llm_string_free(llm_string_t *ret); - // A Large Language Model. - typedef llm_string_t llm_inferencing_model_t; - void llm_inferencing_model_free(llm_inferencing_model_t *ptr); - // Inference request parameters - typedef struct { - uint32_t max_tokens; - float repeat_penalty; - uint32_t repeat_penalty_last_n_token_count; - float temperature; - uint32_t top_k; - float top_p; - } llm_inferencing_params_t; - // The set of errors which may be raised by functions in this interface - typedef struct { - uint8_t tag; - union { - llm_string_t runtime_error; - llm_string_t invalid_input; - } val; - } llm_error_t; - #define LLM_ERROR_MODEL_NOT_SUPPORTED 0 - #define LLM_ERROR_RUNTIME_ERROR 1 - #define LLM_ERROR_INVALID_INPUT 2 - void llm_error_free(llm_error_t *ptr); - // Usage information related to the inferencing result - typedef struct { - uint32_t prompt_token_count; - uint32_t generated_token_count; - } llm_inferencing_usage_t; - // An inferencing result - typedef struct { - llm_string_t text; - llm_inferencing_usage_t usage; - } llm_inferencing_result_t; - void llm_inferencing_result_free(llm_inferencing_result_t *ptr); - // The model used for generating embeddings - typedef llm_string_t llm_embedding_model_t; - void llm_embedding_model_free(llm_embedding_model_t *ptr); - typedef struct { - float *ptr; - size_t len; - } llm_list_float32_t; - void llm_list_float32_free(llm_list_float32_t *ptr); - typedef struct { - llm_list_float32_t *ptr; - size_t len; - } llm_list_list_float32_t; - void llm_list_list_float32_free(llm_list_list_float32_t *ptr); - // Usage related to an embeddings generation request - typedef struct { - uint32_t prompt_token_count; - } llm_embeddings_usage_t; - // Result of generating embeddings - typedef struct { - llm_list_list_float32_t embeddings; - llm_embeddings_usage_t usage; - } llm_embeddings_result_t; - void llm_embeddings_result_free(llm_embeddings_result_t *ptr); - typedef struct { - bool is_some; - llm_inferencing_params_t val; - } llm_option_inferencing_params_t; - typedef struct { - bool is_err; - union { - llm_inferencing_result_t ok; - llm_error_t err; - } val; - } llm_expected_inferencing_result_error_t; - void llm_expected_inferencing_result_error_free(llm_expected_inferencing_result_error_t *ptr); - typedef struct { - llm_string_t *ptr; - size_t len; - } llm_list_string_t; - void llm_list_string_free(llm_list_string_t *ptr); - typedef struct { - bool is_err; - union { - llm_embeddings_result_t ok; - llm_error_t err; - } val; - } llm_expected_embeddings_result_error_t; - void llm_expected_embeddings_result_error_free(llm_expected_embeddings_result_error_t *ptr); - void llm_infer(llm_inferencing_model_t *model, llm_string_t *prompt, llm_option_inferencing_params_t *params, llm_expected_inferencing_result_error_t *ret0); - void llm_generate_embeddings(llm_embedding_model_t *model, llm_list_string_t *text, llm_expected_embeddings_result_error_t *ret0); - #ifdef __cplusplus -} -#endif -#endif diff --git a/sdk/go/mysql/internals.go b/sdk/go/mysql/internals.go deleted file mode 100644 index 9b03331079..0000000000 --- a/sdk/go/mysql/internals.go +++ /dev/null @@ -1,325 +0,0 @@ -package mysql - -// #include "outbound-mysql.h" -// #include -import "C" -import ( - "errors" - "fmt" - "reflect" - "unsafe" -) - -func execute(address string, statement string, args []any) error { - var ret C.outbound_mysql_expected_unit_mysql_error_t - defer C.outbound_mysql_expected_unit_mysql_error_free(&ret) - - mysqlAddress := outboundMysqlStr(address) - mysqlStatement := outboundMysqlStr(statement) - params := toOutboundMysqlParameterListValue(args) - - C.outbound_mysql_execute(&mysqlAddress, &mysqlStatement, ¶ms, &ret) - - if ret.is_err { - spinErr := (*C.outbound_mysql_mysql_error_t)(unsafe.Pointer(&ret.val)) - return toErr(spinErr) - } - - return nil -} - -func query(address string, statement string, args []any) (*rows, error) { - var ret C.outbound_mysql_expected_row_set_mysql_error_t - defer C.outbound_mysql_expected_row_set_mysql_error_free(&ret) - - mysqlAddress := outboundMysqlStr(address) - mysqlStatement := outboundMysqlStr(statement) - params := toOutboundMysqlParameterListValue(args) - - C.outbound_mysql_query(&mysqlAddress, &mysqlStatement, ¶ms, &ret) - - if ret.is_err { - spinErr := (*C.outbound_mysql_mysql_error_t)(unsafe.Pointer(&ret.val)) - return nil, toErr(spinErr) - } - - qr := (*C.outbound_mysql_row_set_t)(unsafe.Pointer(&ret.val)) - - columns, columnType := fromOutboundMysqlListColoum(qr.columns) - - rs, err := fromOutboundMysqlListRow(qr.rows) - if err != nil { - return nil, err - } - - result := &rows{ - columns: columns, - columnType: columnType, - rows: rs, - len: int(qr.rows.len), - } - - return result, nil -} - -func fromOutboundMysqlListRow(list C.outbound_mysql_list_row_t) ([][]any, error) { - var err error - listLen := int(list.len) - ret := make([][]any, listLen) - slice := unsafe.Slice(list.ptr, listLen) - for i := 0; i < listLen; i++ { - row := *((*C.outbound_mysql_row_t)(unsafe.Pointer(&slice[i]))) - ret[i], err = fromOutboundMysqlRow(row) - if err != nil { - return nil, err - } - } - return ret, nil - -} - -func fromOutboundMysqlRow(row C.outbound_mysql_row_t) ([]any, error) { - var err error - rowLen := int(row.len) - ret := make([]any, rowLen) - slice := unsafe.Slice(row.ptr, rowLen) - for i := 0; i < rowLen; i++ { - value := *((*C.outbound_mysql_db_value_t)(unsafe.Pointer(&slice[i]))) - ret[i], err = fromOutboundMysqlDbValue(value) - if err != nil { - return nil, err - } - } - return ret, err -} - -func fromOutboundMysqlListColoum(list C.outbound_mysql_list_column_t) ([]string, []uint8) { - coloumLen := int(list.len) - ret := make([]string, coloumLen) - retType := make([]uint8, coloumLen) - slice := unsafe.Slice(list.ptr, coloumLen) - for i := 0; i < coloumLen; i++ { - column := *((*C.outbound_mysql_column_t)(unsafe.Pointer(&slice[i]))) - ret[i], retType[i] = fromOutboundMysqlDbColumn(column) - } - return ret, retType -} - -func fromOutboundMysqlDbColumn(c C.outbound_mysql_column_t) (string, uint8) { - return C.GoStringN(c.name.ptr, C.int(c.name.len)), uint8(*(*C.uint8_t)(unsafe.Pointer(&c.data_type))) -} - -func outboundMysqlStr(x string) C.outbound_mysql_string_t { - return C.outbound_mysql_string_t{ptr: C.CString(x), len: C.size_t(len(x))} -} - -func toOutboundMysqlParameterListValue(xv []any) C.outbound_mysql_list_parameter_value_t { - if len(xv) == 0 { - return C.outbound_mysql_list_parameter_value_t{} - } - cxv := make([]C.outbound_mysql_parameter_value_t, len(xv)) - for i := 0; i < len(xv); i++ { - cxv[i] = toOutboundMysqlParameterValue(xv[i]) - } - return C.outbound_mysql_list_parameter_value_t{ptr: &cxv[0], len: C.size_t(len(cxv))} -} - -const ( - dbValueBoolean uint8 = iota - dbValueInt8 - dbValueInt16 - dbValueInt32 - dbValueInt64 - dbValueUint8 - dbValueUint16 - dbValueUint32 - dbValueUint64 - dbValueFloat32 - dbValueFloat64 - dbValueStr - dbValueBinary - dbValueNull - dbValueUnsupported -) - -func fromOutboundMysqlDbValue(x C.outbound_mysql_db_value_t) (any, error) { - switch x.tag { - case dbValueBoolean: - return *(*bool)(unsafe.Pointer(&x.val)), nil - case dbValueInt8: - return int8(*(*C.int8_t)(unsafe.Pointer(&x.val))), nil - case dbValueInt16: - return int16(*(*C.int16_t)(unsafe.Pointer(&x.val))), nil - case dbValueInt32: - return int32(*(*C.int32_t)(unsafe.Pointer(&x.val))), nil - case dbValueInt64: - return int64(*(*C.int64_t)(unsafe.Pointer(&x.val))), nil - case dbValueUint8: - return uint8(*(*C.uint8_t)(unsafe.Pointer(&x.val))), nil - case dbValueUint16: - return uint16(*(*C.uint16_t)(unsafe.Pointer(&x.val))), nil - case dbValueUint32: - return uint32(*(*C.uint32_t)(unsafe.Pointer(&x.val))), nil - case dbValueUint64: - return uint64(*(*C.uint64_t)(unsafe.Pointer(&x.val))), nil - case dbValueFloat32: - return float32(*(*C.float)(unsafe.Pointer(&x.val))), nil - case dbValueFloat64: - return float64(*(*C.double)(unsafe.Pointer(&x.val))), nil - case dbValueBinary: - blob := (*C.outbound_mysql_list_u8_t)(unsafe.Pointer(&x.val)) - return C.GoBytes(unsafe.Pointer(blob.ptr), C.int(blob.len)), nil - case dbValueStr: - str := (*C.outbound_mysql_string_t)(unsafe.Pointer(&x.val)) - return C.GoStringN(str.ptr, C.int(str.len)), nil - case dbValueNull: - return nil, nil - case dbValueUnsupported: - return nil, errors.New("db return value type unsupported") - } - return nil, errors.New("db return value unknown type") -} - -const ( - paramValueBoolean uint8 = iota - paramValueInt8 - paramValueInt16 - paramValueInt32 - paramValueInt64 - paramValueUint8 - paramValueUint16 - paramValueUint32 - paramValueUint64 - paramValueFloat32 - paramValueFloat64 - paramValueStr - paramValueBinary - paramValueNull - paramValueUnspported -) - -func toOutboundMysqlParameterValue(x any) C.outbound_mysql_parameter_value_t { - var ret C.outbound_mysql_parameter_value_t - switch v := x.(type) { - case bool: - *(*bool)(unsafe.Pointer(&ret.val)) = bool(v) - ret.tag = paramValueBoolean - case int8: - *(*C.int8_t)(unsafe.Pointer(&ret.val)) = int8(v) - ret.tag = paramValueInt8 - case int16: - *(*C.int16_t)(unsafe.Pointer(&ret.val)) = int16(v) - ret.tag = paramValueInt16 - case int32: - *(*C.int32_t)(unsafe.Pointer(&ret.val)) = int32(v) - ret.tag = paramValueInt32 - case int64: - *(*C.int64_t)(unsafe.Pointer(&ret.val)) = int64(v) - ret.tag = paramValueInt64 - case int: - *(*C.int64_t)(unsafe.Pointer(&ret.val)) = int64(v) - ret.tag = paramValueInt64 - case uint8: - *(*C.uint8_t)(unsafe.Pointer(&ret.val)) = uint8(v) - ret.tag = paramValueUint8 - case uint16: - *(*C.uint16_t)(unsafe.Pointer(&ret.val)) = uint16(v) - ret.tag = paramValueUint16 - case uint32: - *(*C.uint32_t)(unsafe.Pointer(&ret.val)) = uint32(v) - ret.tag = paramValueUint32 - case uint64: - *(*C.uint64_t)(unsafe.Pointer(&ret.val)) = uint64(v) - ret.tag = paramValueUint64 - case float32: - *(*C.float)(unsafe.Pointer(&ret.val)) = float32(v) - ret.tag = paramValueFloat32 - case float64: - *(*C.double)(unsafe.Pointer(&ret.val)) = float64(v) - ret.tag = paramValueFloat64 - case string: - str := outboundMysqlStr(v) - *(*C.outbound_mysql_string_t)(unsafe.Pointer(&ret.val)) = str - ret.tag = paramValueStr - case []byte: - blob := C.outbound_mysql_list_u8_t{ptr: &v[0], len: C.size_t(len(v))} - *(*C.outbound_mysql_list_u8_t)(unsafe.Pointer(&ret.val)) = blob - ret.tag = paramValueBinary - case nil: - ret.tag = paramValueNull - default: - ret.tag = paramValueUnspported - } - return ret -} - -func toErr(err *C.outbound_mysql_mysql_error_t) error { - switch err.tag { - case 0: - return nil - case 1: - str := (*C.outbound_mysql_string_t)(unsafe.Pointer(&err.val)) - return fmt.Errorf("connection failed: %s", C.GoStringN(str.ptr, C.int(str.len))) - case 2: - str := (*C.outbound_mysql_string_t)(unsafe.Pointer(&err.val)) - return fmt.Errorf("bad parameter: %s", C.GoStringN(str.ptr, C.int(str.len))) - case 3: - str := (*C.outbound_mysql_string_t)(unsafe.Pointer(&err.val)) - return fmt.Errorf("query failed: %s", C.GoStringN(str.ptr, C.int(str.len))) - case 4: - str := (*C.outbound_mysql_string_t)(unsafe.Pointer(&err.val)) - return fmt.Errorf(fmt.Sprintf("value conversion failed: %s", C.GoStringN(str.ptr, C.int(str.len)))) - case 5: - str := (*C.outbound_mysql_string_t)(unsafe.Pointer(&err.val)) - return fmt.Errorf(fmt.Sprintf("other error: %s", C.GoStringN(str.ptr, C.int(str.len)))) - default: - return fmt.Errorf("unrecognized error: %v", err.tag) - } -} - -const ( - dbDataTypeBoolean uint8 = iota - dbDataTypeInt8 - dbDataTypeInt16 - dbDataTypeInt32 - dbDataTypeInt64 - dbDataTypeUint8 - dbDataTypeUint16 - dbDataTypeUint32 - dbDataTypeUint64 - dbDataTypeFloating32 - dbDataTypeFloating64 - dbDataTypeStr - dbDataTypeBinary - dbDataTypeOther -) - -func colTypeToReflectType(typ uint8) reflect.Type { - switch typ { - case dbDataTypeBoolean: - return reflect.TypeOf(false) - case dbDataTypeInt8: - return reflect.TypeOf(int8(0)) - case dbDataTypeInt16: - return reflect.TypeOf(int16(0)) - case dbDataTypeInt32: - return reflect.TypeOf(int32(0)) - case dbDataTypeInt64: - return reflect.TypeOf(int64(0)) - case dbDataTypeUint8: - return reflect.TypeOf(uint8(0)) - case dbDataTypeUint16: - return reflect.TypeOf(uint16(0)) - case dbDataTypeUint32: - return reflect.TypeOf(uint32(0)) - case dbDataTypeUint64: - return reflect.TypeOf(uint64(0)) - case dbDataTypeStr: - return reflect.TypeOf("") - case dbDataTypeBinary: - return reflect.TypeOf(new([]byte)) - case dbDataTypeOther: - return reflect.TypeOf(new(any)).Elem() - } - panic("invalid db column type of " + string(typ)) -} diff --git a/sdk/go/mysql/mysql.go b/sdk/go/mysql/mysql.go deleted file mode 100644 index 33a2c60e7b..0000000000 --- a/sdk/go/mysql/mysql.go +++ /dev/null @@ -1,173 +0,0 @@ -package mysql - -import ( - "context" - "database/sql" - "database/sql/driver" - "errors" - "io" - "reflect" - - spindb "github.com/fermyon/spin/sdk/go/v2/internal/db" -) - -// Open returns a new connection to the database. -func Open(address string) *sql.DB { - return sql.OpenDB(&connector{address}) -} - -// connector implements driver.Connector. -type connector struct { - address string -} - -// Connect returns a connection to the database. -func (d *connector) Connect(_ context.Context) (driver.Conn, error) { - return d.Open(d.address) -} - -// Driver returns the underlying Driver of the Connector. -func (d *connector) Driver() driver.Driver { - return d -} - -// Open returns a new connection to the database. -func (d *connector) Open(address string) (driver.Conn, error) { - return &conn{address: address}, nil -} - -// conn implements driver.Conn -type conn struct { - address string -} - -var _ driver.Conn = (*conn)(nil) - -// Prepare returns a prepared statement, bound to this connection. -func (c *conn) Prepare(query string) (driver.Stmt, error) { - return &stmt{c: c, query: query}, nil -} - -func (c *conn) Close() error { - return nil -} - -func (c *conn) Begin() (driver.Tx, error) { - return nil, errors.New("transactions are unsupported by this driver") -} - -type stmt struct { - c *conn - query string -} - -var _ driver.Stmt = (*stmt)(nil) -var _ driver.ColumnConverter = (*stmt)(nil) - -// Close closes the statement. -func (s *stmt) Close() error { - return nil -} - -// NumInput returns the number of placeholder parameters. -func (s *stmt) NumInput() int { - // Golang sql won't sanity check argument counts before Query. - return -1 -} - -// Query executes a query that may return rows, such as a SELECT. -func (s *stmt) Query(args []driver.Value) (driver.Rows, error) { - params := make([]any, len(args)) - for i := range args { - params[i] = args[i] - } - return query(s.c.address, s.query, params) -} - -// Exec executes a query that doesn't return rows, such as an INSERT or -// UPDATE. -func (s *stmt) Exec(args []driver.Value) (driver.Result, error) { - params := make([]any, len(args)) - for i := range args { - params[i] = args[i] - } - err := execute(s.c.address, s.query, params) - return &result{}, err -} - -// ColumnConverter returns GlobalParameterConverter to prevent using driver.DefaultParameterConverter. -func (s *stmt) ColumnConverter(_ int) driver.ValueConverter { - return spindb.GlobalParameterConverter -} - -type result struct{} - -func (r result) LastInsertId() (int64, error) { - return -1, errors.New("LastInsertId is unsupported by this driver") -} - -func (r result) RowsAffected() (int64, error) { - return -1, errors.New("RowsAffected is unsupported by this driver") -} - -type rows struct { - columns []string - columnType []uint8 - pos int - len int - rows [][]any - closed bool -} - -var _ driver.Rows = (*rows)(nil) -var _ driver.RowsColumnTypeScanType = (*rows)(nil) -var _ driver.RowsNextResultSet = (*rows)(nil) - -// Columns return column names. -func (r *rows) Columns() []string { - return r.columns -} - -// Close closes the rows iterator. -func (r *rows) Close() error { - r.rows = nil - r.pos = 0 - r.len = 0 - r.closed = true - return nil -} - -// Next moves the cursor to the next row. -func (r *rows) Next(dest []driver.Value) error { - if !r.HasNextResultSet() { - return io.EOF - } - for i := 0; i != len(r.columns); i++ { - dest[i] = driver.Value(r.rows[r.pos][i]) - } - r.pos++ - return nil -} - -// HasNextResultSet is called at the end of the current result set and -// reports whether there is another result set after the current one. -func (r *rows) HasNextResultSet() bool { - return r.pos < r.len -} - -// NextResultSet advances the driver to the next result set even -// if there are remaining rows in the current result set. -// -// NextResultSet should return io.EOF when there are no more result sets. -func (r *rows) NextResultSet() error { - if r.HasNextResultSet() { - r.pos++ - return nil - } - return io.EOF // Per interface spec. -} - -// ColumnTypeScanType return the value type that can be used to scan types into. -func (r *rows) ColumnTypeScanType(index int) reflect.Type { - return colTypeToReflectType(r.columnType[index]) -} diff --git a/sdk/go/mysql/outbound-mysql.c b/sdk/go/mysql/outbound-mysql.c deleted file mode 100644 index f83753f20f..0000000000 --- a/sdk/go/mysql/outbound-mysql.c +++ /dev/null @@ -1,243 +0,0 @@ -#include -#include - -__attribute__((weak, export_name("canonical_abi_realloc"))) -void *canonical_abi_realloc( -void *ptr, -size_t orig_size, -size_t align, -size_t new_size -) { - if (new_size == 0) - return (void*) align; - void *ret = realloc(ptr, new_size); - if (!ret) - abort(); - return ret; -} - -__attribute__((weak, export_name("canonical_abi_free"))) -void canonical_abi_free( -void *ptr, -size_t size, -size_t align -) { - if (size == 0) - return; - free(ptr); -} -#include - -void outbound_mysql_string_set(outbound_mysql_string_t *ret, const char *s) { - ret->ptr = (char*) s; - ret->len = strlen(s); -} - -void outbound_mysql_string_dup(outbound_mysql_string_t *ret, const char *s) { - ret->len = strlen(s); - ret->ptr = canonical_abi_realloc(NULL, 0, 1, ret->len); - memcpy(ret->ptr, s, ret->len); -} - -void outbound_mysql_string_free(outbound_mysql_string_t *ret) { - canonical_abi_free(ret->ptr, ret->len, 1); - ret->ptr = NULL; - ret->len = 0; -} -void outbound_mysql_mysql_error_free(outbound_mysql_mysql_error_t *ptr) { - switch ((int32_t) ptr->tag) { - case 1: { - outbound_mysql_string_free(&ptr->val.connection_failed); - break; - } - case 2: { - outbound_mysql_string_free(&ptr->val.bad_parameter); - break; - } - case 3: { - outbound_mysql_string_free(&ptr->val.query_failed); - break; - } - case 4: { - outbound_mysql_string_free(&ptr->val.value_conversion_failed); - break; - } - case 5: { - outbound_mysql_string_free(&ptr->val.other_error); - break; - } - } -} -void outbound_mysql_column_free(outbound_mysql_column_t *ptr) { - outbound_mysql_string_free(&ptr->name); -} -void outbound_mysql_list_u8_free(outbound_mysql_list_u8_t *ptr) { - canonical_abi_free(ptr->ptr, ptr->len * 1, 1); -} -void outbound_mysql_db_value_free(outbound_mysql_db_value_t *ptr) { - switch ((int32_t) ptr->tag) { - case 11: { - outbound_mysql_string_free(&ptr->val.str); - break; - } - case 12: { - outbound_mysql_list_u8_free(&ptr->val.binary); - break; - } - } -} -void outbound_mysql_parameter_value_free(outbound_mysql_parameter_value_t *ptr) { - switch ((int32_t) ptr->tag) { - case 11: { - outbound_mysql_string_free(&ptr->val.str); - break; - } - case 12: { - outbound_mysql_list_u8_free(&ptr->val.binary); - break; - } - } -} -void outbound_mysql_row_free(outbound_mysql_row_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - outbound_mysql_db_value_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 16, 8); -} -void outbound_mysql_list_column_free(outbound_mysql_list_column_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - outbound_mysql_column_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 12, 4); -} -void outbound_mysql_list_row_free(outbound_mysql_list_row_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - outbound_mysql_row_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 8, 4); -} -void outbound_mysql_row_set_free(outbound_mysql_row_set_t *ptr) { - outbound_mysql_list_column_free(&ptr->columns); - outbound_mysql_list_row_free(&ptr->rows); -} -void outbound_mysql_list_parameter_value_free(outbound_mysql_list_parameter_value_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - outbound_mysql_parameter_value_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 16, 8); -} -void outbound_mysql_expected_row_set_mysql_error_free(outbound_mysql_expected_row_set_mysql_error_t *ptr) { - if (!ptr->is_err) { - outbound_mysql_row_set_free(&ptr->val.ok); - } else { - outbound_mysql_mysql_error_free(&ptr->val.err); - } -} -void outbound_mysql_expected_unit_mysql_error_free(outbound_mysql_expected_unit_mysql_error_t *ptr) { - if (!ptr->is_err) { - } else { - outbound_mysql_mysql_error_free(&ptr->val.err); - } -} - -__attribute__((aligned(4))) -static uint8_t RET_AREA[20]; -__attribute__((import_module("outbound-mysql"), import_name("query"))) -void __wasm_import_outbound_mysql_query(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); -void outbound_mysql_query(outbound_mysql_string_t *address, outbound_mysql_string_t *statement, outbound_mysql_list_parameter_value_t *params, outbound_mysql_expected_row_set_mysql_error_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_outbound_mysql_query((int32_t) (*address).ptr, (int32_t) (*address).len, (int32_t) (*statement).ptr, (int32_t) (*statement).len, (int32_t) (*params).ptr, (int32_t) (*params).len, ptr); - outbound_mysql_expected_row_set_mysql_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = (outbound_mysql_row_set_t) { - (outbound_mysql_list_column_t) { (outbound_mysql_column_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }, - (outbound_mysql_list_row_t) { (outbound_mysql_row_t*)(*((int32_t*) (ptr + 12))), (size_t)(*((int32_t*) (ptr + 16))) }, - }; - break; - } - case 1: { - expected.is_err = true; - outbound_mysql_mysql_error_t variant13; - variant13.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant13.tag) { - case 0: { - break; - } - case 1: { - variant13.val.connection_failed = (outbound_mysql_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - case 2: { - variant13.val.bad_parameter = (outbound_mysql_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - case 3: { - variant13.val.query_failed = (outbound_mysql_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - case 4: { - variant13.val.value_conversion_failed = (outbound_mysql_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - case 5: { - variant13.val.other_error = (outbound_mysql_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - } - - expected.val.err = variant13; - break; - } - }*ret0 = expected; -} -__attribute__((import_module("outbound-mysql"), import_name("execute"))) -void __wasm_import_outbound_mysql_execute(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); -void outbound_mysql_execute(outbound_mysql_string_t *address, outbound_mysql_string_t *statement, outbound_mysql_list_parameter_value_t *params, outbound_mysql_expected_unit_mysql_error_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_outbound_mysql_execute((int32_t) (*address).ptr, (int32_t) (*address).len, (int32_t) (*statement).ptr, (int32_t) (*statement).len, (int32_t) (*params).ptr, (int32_t) (*params).len, ptr); - outbound_mysql_expected_unit_mysql_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - - break; - } - case 1: { - expected.is_err = true; - outbound_mysql_mysql_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant.tag) { - case 0: { - break; - } - case 1: { - variant.val.connection_failed = (outbound_mysql_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - case 2: { - variant.val.bad_parameter = (outbound_mysql_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - case 3: { - variant.val.query_failed = (outbound_mysql_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - case 4: { - variant.val.value_conversion_failed = (outbound_mysql_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - case 5: { - variant.val.other_error = (outbound_mysql_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - } - - expected.val.err = variant; - break; - } - }*ret0 = expected; -} diff --git a/sdk/go/mysql/outbound-mysql.h b/sdk/go/mysql/outbound-mysql.h deleted file mode 100644 index 2615ff7131..0000000000 --- a/sdk/go/mysql/outbound-mysql.h +++ /dev/null @@ -1,181 +0,0 @@ -#ifndef __BINDINGS_OUTBOUND_MYSQL_H -#define __BINDINGS_OUTBOUND_MYSQL_H -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -typedef struct { - char *ptr; - size_t len; -} outbound_mysql_string_t; - -void outbound_mysql_string_set(outbound_mysql_string_t *ret, const char *s); -void outbound_mysql_string_dup(outbound_mysql_string_t *ret, const char *s); -void outbound_mysql_string_free(outbound_mysql_string_t *ret); -typedef struct { - uint8_t tag; - union { - outbound_mysql_string_t connection_failed; - outbound_mysql_string_t bad_parameter; - outbound_mysql_string_t query_failed; - outbound_mysql_string_t value_conversion_failed; - outbound_mysql_string_t other_error; - } val; -} outbound_mysql_mysql_error_t; -#define OUTBOUND_MYSQL_MYSQL_ERROR_SUCCESS 0 -#define OUTBOUND_MYSQL_MYSQL_ERROR_CONNECTION_FAILED 1 -#define OUTBOUND_MYSQL_MYSQL_ERROR_BAD_PARAMETER 2 -#define OUTBOUND_MYSQL_MYSQL_ERROR_QUERY_FAILED 3 -#define OUTBOUND_MYSQL_MYSQL_ERROR_VALUE_CONVERSION_FAILED 4 -#define OUTBOUND_MYSQL_MYSQL_ERROR_OTHER_ERROR 5 -void outbound_mysql_mysql_error_free(outbound_mysql_mysql_error_t *ptr); -typedef uint8_t outbound_mysql_db_data_type_t; -#define OUTBOUND_MYSQL_DB_DATA_TYPE_BOOLEAN 0 -#define OUTBOUND_MYSQL_DB_DATA_TYPE_INT8 1 -#define OUTBOUND_MYSQL_DB_DATA_TYPE_INT16 2 -#define OUTBOUND_MYSQL_DB_DATA_TYPE_INT32 3 -#define OUTBOUND_MYSQL_DB_DATA_TYPE_INT64 4 -#define OUTBOUND_MYSQL_DB_DATA_TYPE_UINT8 5 -#define OUTBOUND_MYSQL_DB_DATA_TYPE_UINT16 6 -#define OUTBOUND_MYSQL_DB_DATA_TYPE_UINT32 7 -#define OUTBOUND_MYSQL_DB_DATA_TYPE_UINT64 8 -#define OUTBOUND_MYSQL_DB_DATA_TYPE_FLOATING32 9 -#define OUTBOUND_MYSQL_DB_DATA_TYPE_FLOATING64 10 -#define OUTBOUND_MYSQL_DB_DATA_TYPE_STR 11 -#define OUTBOUND_MYSQL_DB_DATA_TYPE_BINARY 12 -#define OUTBOUND_MYSQL_DB_DATA_TYPE_OTHER 13 -typedef struct { - outbound_mysql_string_t name; - outbound_mysql_db_data_type_t data_type; -} outbound_mysql_column_t; -void outbound_mysql_column_free(outbound_mysql_column_t *ptr); -typedef struct { - uint8_t *ptr; - size_t len; -} outbound_mysql_list_u8_t; -void outbound_mysql_list_u8_free(outbound_mysql_list_u8_t *ptr); -typedef struct { - uint8_t tag; - union { - bool boolean; - int8_t int8; - int16_t int16; - int32_t int32; - int64_t int64; - uint8_t uint8; - uint16_t uint16; - uint32_t uint32; - uint64_t uint64; - float floating32; - double floating64; - outbound_mysql_string_t str; - outbound_mysql_list_u8_t binary; - } val; -} outbound_mysql_db_value_t; -#define OUTBOUND_MYSQL_DB_VALUE_BOOLEAN 0 -#define OUTBOUND_MYSQL_DB_VALUE_INT8 1 -#define OUTBOUND_MYSQL_DB_VALUE_INT16 2 -#define OUTBOUND_MYSQL_DB_VALUE_INT32 3 -#define OUTBOUND_MYSQL_DB_VALUE_INT64 4 -#define OUTBOUND_MYSQL_DB_VALUE_UINT8 5 -#define OUTBOUND_MYSQL_DB_VALUE_UINT16 6 -#define OUTBOUND_MYSQL_DB_VALUE_UINT32 7 -#define OUTBOUND_MYSQL_DB_VALUE_UINT64 8 -#define OUTBOUND_MYSQL_DB_VALUE_FLOATING32 9 -#define OUTBOUND_MYSQL_DB_VALUE_FLOATING64 10 -#define OUTBOUND_MYSQL_DB_VALUE_STR 11 -#define OUTBOUND_MYSQL_DB_VALUE_BINARY 12 -#define OUTBOUND_MYSQL_DB_VALUE_DB_NULL 13 -#define OUTBOUND_MYSQL_DB_VALUE_UNSUPPORTED 14 -void outbound_mysql_db_value_free(outbound_mysql_db_value_t *ptr); -typedef struct { - uint8_t tag; - union { - bool boolean; - int8_t int8; - int16_t int16; - int32_t int32; - int64_t int64; - uint8_t uint8; - uint16_t uint16; - uint32_t uint32; - uint64_t uint64; - float floating32; - double floating64; - outbound_mysql_string_t str; - outbound_mysql_list_u8_t binary; - } val; -} outbound_mysql_parameter_value_t; -#define OUTBOUND_MYSQL_PARAMETER_VALUE_BOOLEAN 0 -#define OUTBOUND_MYSQL_PARAMETER_VALUE_INT8 1 -#define OUTBOUND_MYSQL_PARAMETER_VALUE_INT16 2 -#define OUTBOUND_MYSQL_PARAMETER_VALUE_INT32 3 -#define OUTBOUND_MYSQL_PARAMETER_VALUE_INT64 4 -#define OUTBOUND_MYSQL_PARAMETER_VALUE_UINT8 5 -#define OUTBOUND_MYSQL_PARAMETER_VALUE_UINT16 6 -#define OUTBOUND_MYSQL_PARAMETER_VALUE_UINT32 7 -#define OUTBOUND_MYSQL_PARAMETER_VALUE_UINT64 8 -#define OUTBOUND_MYSQL_PARAMETER_VALUE_FLOATING32 9 -#define OUTBOUND_MYSQL_PARAMETER_VALUE_FLOATING64 10 -#define OUTBOUND_MYSQL_PARAMETER_VALUE_STR 11 -#define OUTBOUND_MYSQL_PARAMETER_VALUE_BINARY 12 -#define OUTBOUND_MYSQL_PARAMETER_VALUE_DB_NULL 13 -void outbound_mysql_parameter_value_free(outbound_mysql_parameter_value_t *ptr); -typedef struct { - outbound_mysql_db_value_t *ptr; - size_t len; -} outbound_mysql_row_t; -void outbound_mysql_row_free(outbound_mysql_row_t *ptr); -typedef struct { - outbound_mysql_column_t *ptr; - size_t len; -} outbound_mysql_list_column_t; -void outbound_mysql_list_column_free(outbound_mysql_list_column_t *ptr); -typedef struct { - outbound_mysql_row_t *ptr; - size_t len; -} outbound_mysql_list_row_t; -void outbound_mysql_list_row_free(outbound_mysql_list_row_t *ptr); -typedef struct { - outbound_mysql_list_column_t columns; - outbound_mysql_list_row_t rows; -} outbound_mysql_row_set_t; -void outbound_mysql_row_set_free(outbound_mysql_row_set_t *ptr); -typedef struct { - outbound_mysql_parameter_value_t *ptr; - size_t len; -} outbound_mysql_list_parameter_value_t; -void outbound_mysql_list_parameter_value_free( - outbound_mysql_list_parameter_value_t *ptr); -typedef struct { - bool is_err; - union { - outbound_mysql_row_set_t ok; - outbound_mysql_mysql_error_t err; - } val; -} outbound_mysql_expected_row_set_mysql_error_t; -void outbound_mysql_expected_row_set_mysql_error_free( - outbound_mysql_expected_row_set_mysql_error_t *ptr); -typedef struct { - bool is_err; - union { - outbound_mysql_mysql_error_t err; - } val; -} outbound_mysql_expected_unit_mysql_error_t; -void outbound_mysql_expected_unit_mysql_error_free( - outbound_mysql_expected_unit_mysql_error_t *ptr); -void outbound_mysql_query(outbound_mysql_string_t *address, - outbound_mysql_string_t *statement, - outbound_mysql_list_parameter_value_t *params, - outbound_mysql_expected_row_set_mysql_error_t *ret0); -void outbound_mysql_execute(outbound_mysql_string_t *address, - outbound_mysql_string_t *statement, - outbound_mysql_list_parameter_value_t *params, - outbound_mysql_expected_unit_mysql_error_t *ret0); -#ifdef __cplusplus -} -#endif -#endif diff --git a/sdk/go/pg/internals.go b/sdk/go/pg/internals.go deleted file mode 100644 index 959626ea56..0000000000 --- a/sdk/go/pg/internals.go +++ /dev/null @@ -1,325 +0,0 @@ -package pg - -// #include "outbound-pg.h" -// #include -import "C" - -import ( - "errors" - "fmt" - "reflect" - "unsafe" -) - -func execute(address string, statement string, args []any) (uint64, error) { - var ret C.outbound_pg_expected_u64_pg_error_t - defer C.outbound_pg_expected_u64_pg_error_free(&ret) - - pgAddress := outboundPgStr(address) - pgStatement := outboundPgStr(statement) - params := toOutboundPgParameterListValue(args) - - C.outbound_pg_execute(&pgAddress, &pgStatement, ¶ms, &ret) - - if ret.is_err { - spinErr := (*C.outbound_pg_pg_error_t)(unsafe.Pointer(&ret.val)) - return 0, toErr(spinErr) - } - return uint64(*(*C.uint64_t)(unsafe.Pointer(&ret.val))), nil -} - -func query(address string, statement string, args []any) (*rows, error) { - var ret C.outbound_pg_expected_row_set_pg_error_t - defer C.outbound_pg_expected_row_set_pg_error_free(&ret) - - pgAddress := outboundPgStr(address) - pgStatement := outboundPgStr(statement) - params := toOutboundPgParameterListValue(args) - - C.outbound_pg_query(&pgAddress, &pgStatement, ¶ms, &ret) - - if ret.is_err { - spinErr := (*C.outbound_pg_pg_error_t)(unsafe.Pointer(&ret.val)) - return nil, toErr(spinErr) - } - - qr := (*C.outbound_pg_row_set_t)(unsafe.Pointer(&ret.val)) - - columns, columnType := fromOutboundPgListColoum(qr.columns) - - rs, err := fromOutboundPgListRow(qr.rows) - if err != nil { - return nil, err - } - - result := &rows{ - columns: columns, - columnType: columnType, - rows: rs, - len: int(qr.rows.len), - } - - return result, nil -} - -func fromOutboundPgListRow(list C.outbound_pg_list_row_t) ([][]any, error) { - var err error - listLen := int(list.len) - ret := make([][]any, listLen) - slice := unsafe.Slice(list.ptr, listLen) - for i := 0; i < listLen; i++ { - row := *((*C.outbound_pg_row_t)(unsafe.Pointer(&slice[i]))) - ret[i], err = fromOutboundPgRow(row) - if err != nil { - return nil, err - } - } - return ret, nil - -} - -func fromOutboundPgRow(row C.outbound_pg_row_t) ([]any, error) { - var err error - rowLen := int(row.len) - ret := make([]any, rowLen) - slice := unsafe.Slice(row.ptr, rowLen) - for i := 0; i < rowLen; i++ { - value := *((*C.outbound_pg_db_value_t)(unsafe.Pointer(&slice[i]))) - ret[i], err = fromOutboundPgDbValue(value) - if err != nil { - return nil, err - } - } - return ret, err -} - -func fromOutboundPgListColoum(list C.outbound_pg_list_column_t) ([]string, []uint8) { - coloumLen := int(list.len) - ret := make([]string, coloumLen) - retType := make([]uint8, coloumLen) - slice := unsafe.Slice(list.ptr, coloumLen) - for i := 0; i < coloumLen; i++ { - column := *((*C.outbound_pg_column_t)(unsafe.Pointer(&slice[i]))) - ret[i], retType[i] = fromOutboundPgDbColumn(column) - } - return ret, retType -} - -func fromOutboundPgDbColumn(c C.outbound_pg_column_t) (string, uint8) { - return C.GoStringN(c.name.ptr, C.int(c.name.len)), uint8(*(*C.uint8_t)(unsafe.Pointer(&c.data_type))) -} - -func toOutboundPgParameterListValue(xv []any) C.outbound_pg_list_parameter_value_t { - if len(xv) == 0 { - return C.outbound_pg_list_parameter_value_t{} - } - cxv := make([]C.outbound_pg_parameter_value_t, len(xv)) - for i := 0; i < len(xv); i++ { - cxv[i] = toOutboundPgParameterValue(xv[i]) - } - return C.outbound_pg_list_parameter_value_t{ptr: &cxv[0], len: C.size_t(len(cxv))} -} - -func outboundPgStr(x string) C.outbound_pg_string_t { - return C.outbound_pg_string_t{ptr: C.CString(x), len: C.size_t(len(x))} -} - -func toErr(err *C.outbound_pg_pg_error_t) error { - switch err.tag { - case 0: - return nil - case 1: - str := (*C.outbound_pg_string_t)(unsafe.Pointer(&err.val)) - return fmt.Errorf("connection failed: %s", C.GoStringN(str.ptr, C.int(str.len))) - case 2: - str := (*C.outbound_pg_string_t)(unsafe.Pointer(&err.val)) - return fmt.Errorf("bad parameter: %s", C.GoStringN(str.ptr, C.int(str.len))) - case 3: - str := (*C.outbound_pg_string_t)(unsafe.Pointer(&err.val)) - return fmt.Errorf("query failed: %s", C.GoStringN(str.ptr, C.int(str.len))) - case 4: - str := (*C.outbound_pg_string_t)(unsafe.Pointer(&err.val)) - return fmt.Errorf(fmt.Sprintf("value conversion failed: %s", C.GoStringN(str.ptr, C.int(str.len)))) - case 5: - str := (*C.outbound_pg_string_t)(unsafe.Pointer(&err.val)) - return fmt.Errorf(fmt.Sprintf("other error: %s", C.GoStringN(str.ptr, C.int(str.len)))) - default: - return fmt.Errorf("unrecognized error: %v", err.tag) - } -} - -const ( - dbValueBoolean uint8 = iota - dbValueInt8 - dbValueInt16 - dbValueInt32 - dbValueInt64 - dbValueUint8 - dbValueUint16 - dbValueUint32 - dbValueUint64 - dbValueFloat32 - dbValueFloat64 - dbValueStr - dbValueBinary - dbValueNull - dbValueUnsupported -) - -func fromOutboundPgDbValue(x C.outbound_pg_db_value_t) (any, error) { - switch x.tag { - case dbValueBoolean: - return *(*bool)(unsafe.Pointer(&x.val)), nil - case dbValueInt8: - return int8(*(*C.int8_t)(unsafe.Pointer(&x.val))), nil - case dbValueInt16: - return int16(*(*C.int16_t)(unsafe.Pointer(&x.val))), nil - case dbValueInt32: - return int32(*(*C.int32_t)(unsafe.Pointer(&x.val))), nil - case dbValueInt64: - return int64(*(*C.int64_t)(unsafe.Pointer(&x.val))), nil - case dbValueUint8: - return uint8(*(*C.uint8_t)(unsafe.Pointer(&x.val))), nil - case dbValueUint16: - return uint16(*(*C.uint16_t)(unsafe.Pointer(&x.val))), nil - case dbValueUint32: - return uint32(*(*C.uint32_t)(unsafe.Pointer(&x.val))), nil - case dbValueUint64: - return uint64(*(*C.uint64_t)(unsafe.Pointer(&x.val))), nil - case dbValueFloat32: - return float32(*(*C.float)(unsafe.Pointer(&x.val))), nil - case dbValueFloat64: - return float64(*(*C.double)(unsafe.Pointer(&x.val))), nil - case dbValueBinary: - blob := (*C.outbound_pg_list_u8_t)(unsafe.Pointer(&x.val)) - return C.GoBytes(unsafe.Pointer(blob.ptr), C.int(blob.len)), nil - case dbValueStr: - str := (*C.outbound_pg_string_t)(unsafe.Pointer(&x.val)) - return C.GoStringN(str.ptr, C.int(str.len)), nil - case dbValueNull: - return nil, nil - case dbValueUnsupported: - return nil, errors.New("db return value type unsupported") - } - return nil, errors.New("db return value unknown type") -} - -const ( - paramValueBoolean uint8 = iota - paramValueInt8 - paramValueInt16 - paramValueInt32 - paramValueInt64 - paramValueUint8 - paramValueUint16 - paramValueUint32 - paramValueUint64 - paramValueFloat32 - paramValueFloat64 - paramValueStr - paramValueBinary - paramValueNull - paramValueUnspported -) - -func toOutboundPgParameterValue(x any) C.outbound_pg_parameter_value_t { - var ret C.outbound_pg_parameter_value_t - switch v := x.(type) { - case bool: - *(*bool)(unsafe.Pointer(&ret.val)) = bool(v) - ret.tag = paramValueBoolean - case int8: - *(*C.int8_t)(unsafe.Pointer(&ret.val)) = int8(v) - ret.tag = paramValueInt8 - case int16: - *(*C.int16_t)(unsafe.Pointer(&ret.val)) = int16(v) - ret.tag = paramValueInt16 - case int32: - *(*C.int32_t)(unsafe.Pointer(&ret.val)) = int32(v) - ret.tag = paramValueInt32 - case int64: - *(*C.int64_t)(unsafe.Pointer(&ret.val)) = int64(v) - ret.tag = paramValueInt64 - case int: - *(*C.int64_t)(unsafe.Pointer(&ret.val)) = int64(v) - ret.tag = paramValueInt64 - case uint8: - *(*C.uint8_t)(unsafe.Pointer(&ret.val)) = uint8(v) - ret.tag = paramValueUint8 - case uint16: - *(*C.uint16_t)(unsafe.Pointer(&ret.val)) = uint16(v) - ret.tag = paramValueUint16 - case uint32: - *(*C.uint32_t)(unsafe.Pointer(&ret.val)) = uint32(v) - ret.tag = paramValueUint32 - case uint64: - *(*C.uint64_t)(unsafe.Pointer(&ret.val)) = uint64(v) - ret.tag = paramValueUint64 - case float32: - *(*C.float)(unsafe.Pointer(&ret.val)) = float32(v) - ret.tag = paramValueFloat32 - case float64: - *(*C.double)(unsafe.Pointer(&ret.val)) = float64(v) - ret.tag = paramValueFloat64 - case string: - str := outboundPgStr(v) - *(*C.outbound_pg_string_t)(unsafe.Pointer(&ret.val)) = str - ret.tag = paramValueStr - case []byte: - blob := C.outbound_pg_list_u8_t{ptr: &v[0], len: C.size_t(len(v))} - *(*C.outbound_pg_list_u8_t)(unsafe.Pointer(&ret.val)) = blob - ret.tag = paramValueBinary - case nil: - ret.tag = paramValueNull - default: - ret.tag = paramValueUnspported - } - return ret -} - -const ( - dbDataTypeBoolean uint8 = iota - dbDataTypeInt8 - dbDataTypeInt16 - dbDataTypeInt32 - dbDataTypeInt64 - dbDataTypeUint8 - dbDataTypeUint16 - dbDataTypeUint32 - dbDataTypeUint64 - dbDataTypeFloating32 - dbDataTypeFloating64 - dbDataTypeStr - dbDataTypeBinary - dbDataTypeOther -) - -func colTypeToReflectType(typ uint8) reflect.Type { - switch typ { - case dbDataTypeBoolean: - return reflect.TypeOf(false) - case dbDataTypeInt8: - return reflect.TypeOf(int8(0)) - case dbDataTypeInt16: - return reflect.TypeOf(int16(0)) - case dbDataTypeInt32: - return reflect.TypeOf(int32(0)) - case dbDataTypeInt64: - return reflect.TypeOf(int64(0)) - case dbDataTypeUint8: - return reflect.TypeOf(uint8(0)) - case dbDataTypeUint16: - return reflect.TypeOf(uint16(0)) - case dbDataTypeUint32: - return reflect.TypeOf(uint32(0)) - case dbDataTypeUint64: - return reflect.TypeOf(uint64(0)) - case dbDataTypeStr: - return reflect.TypeOf("") - case dbDataTypeBinary: - return reflect.TypeOf(new([]byte)) - case dbDataTypeOther: - return reflect.TypeOf(new(any)).Elem() - } - panic("invalid db column type of " + string(typ)) -} diff --git a/sdk/go/pg/outbound-pg.c b/sdk/go/pg/outbound-pg.c deleted file mode 100644 index 151867af49..0000000000 --- a/sdk/go/pg/outbound-pg.c +++ /dev/null @@ -1,243 +0,0 @@ -#include -#include - -__attribute__((weak, export_name("canonical_abi_realloc"))) -void *canonical_abi_realloc( -void *ptr, -size_t orig_size, -size_t align, -size_t new_size -) { - if (new_size == 0) - return (void*) align; - void *ret = realloc(ptr, new_size); - if (!ret) - abort(); - return ret; -} - -__attribute__((weak, export_name("canonical_abi_free"))) -void canonical_abi_free( -void *ptr, -size_t size, -size_t align -) { - if (size == 0) - return; - free(ptr); -} -#include - -void outbound_pg_string_set(outbound_pg_string_t *ret, const char *s) { - ret->ptr = (char*) s; - ret->len = strlen(s); -} - -void outbound_pg_string_dup(outbound_pg_string_t *ret, const char *s) { - ret->len = strlen(s); - ret->ptr = canonical_abi_realloc(NULL, 0, 1, ret->len); - memcpy(ret->ptr, s, ret->len); -} - -void outbound_pg_string_free(outbound_pg_string_t *ret) { - canonical_abi_free(ret->ptr, ret->len, 1); - ret->ptr = NULL; - ret->len = 0; -} -void outbound_pg_pg_error_free(outbound_pg_pg_error_t *ptr) { - switch ((int32_t) ptr->tag) { - case 1: { - outbound_pg_string_free(&ptr->val.connection_failed); - break; - } - case 2: { - outbound_pg_string_free(&ptr->val.bad_parameter); - break; - } - case 3: { - outbound_pg_string_free(&ptr->val.query_failed); - break; - } - case 4: { - outbound_pg_string_free(&ptr->val.value_conversion_failed); - break; - } - case 5: { - outbound_pg_string_free(&ptr->val.other_error); - break; - } - } -} -void outbound_pg_column_free(outbound_pg_column_t *ptr) { - outbound_pg_string_free(&ptr->name); -} -void outbound_pg_list_u8_free(outbound_pg_list_u8_t *ptr) { - canonical_abi_free(ptr->ptr, ptr->len * 1, 1); -} -void outbound_pg_db_value_free(outbound_pg_db_value_t *ptr) { - switch ((int32_t) ptr->tag) { - case 11: { - outbound_pg_string_free(&ptr->val.str); - break; - } - case 12: { - outbound_pg_list_u8_free(&ptr->val.binary); - break; - } - } -} -void outbound_pg_parameter_value_free(outbound_pg_parameter_value_t *ptr) { - switch ((int32_t) ptr->tag) { - case 11: { - outbound_pg_string_free(&ptr->val.str); - break; - } - case 12: { - outbound_pg_list_u8_free(&ptr->val.binary); - break; - } - } -} -void outbound_pg_row_free(outbound_pg_row_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - outbound_pg_db_value_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 16, 8); -} -void outbound_pg_list_column_free(outbound_pg_list_column_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - outbound_pg_column_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 12, 4); -} -void outbound_pg_list_row_free(outbound_pg_list_row_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - outbound_pg_row_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 8, 4); -} -void outbound_pg_row_set_free(outbound_pg_row_set_t *ptr) { - outbound_pg_list_column_free(&ptr->columns); - outbound_pg_list_row_free(&ptr->rows); -} -void outbound_pg_list_parameter_value_free(outbound_pg_list_parameter_value_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - outbound_pg_parameter_value_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 16, 8); -} -void outbound_pg_expected_row_set_pg_error_free(outbound_pg_expected_row_set_pg_error_t *ptr) { - if (!ptr->is_err) { - outbound_pg_row_set_free(&ptr->val.ok); - } else { - outbound_pg_pg_error_free(&ptr->val.err); - } -} -void outbound_pg_expected_u64_pg_error_free(outbound_pg_expected_u64_pg_error_t *ptr) { - if (!ptr->is_err) { - } else { - outbound_pg_pg_error_free(&ptr->val.err); - } -} - -__attribute__((aligned(8))) -static uint8_t RET_AREA[20]; -__attribute__((import_module("outbound-pg"), import_name("query"))) -void __wasm_import_outbound_pg_query(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); -void outbound_pg_query(outbound_pg_string_t *address, outbound_pg_string_t *statement, outbound_pg_list_parameter_value_t *params, outbound_pg_expected_row_set_pg_error_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_outbound_pg_query((int32_t) (*address).ptr, (int32_t) (*address).len, (int32_t) (*statement).ptr, (int32_t) (*statement).len, (int32_t) (*params).ptr, (int32_t) (*params).len, ptr); - outbound_pg_expected_row_set_pg_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = (outbound_pg_row_set_t) { - (outbound_pg_list_column_t) { (outbound_pg_column_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }, - (outbound_pg_list_row_t) { (outbound_pg_row_t*)(*((int32_t*) (ptr + 12))), (size_t)(*((int32_t*) (ptr + 16))) }, - }; - break; - } - case 1: { - expected.is_err = true; - outbound_pg_pg_error_t variant13; - variant13.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant13.tag) { - case 0: { - break; - } - case 1: { - variant13.val.connection_failed = (outbound_pg_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - case 2: { - variant13.val.bad_parameter = (outbound_pg_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - case 3: { - variant13.val.query_failed = (outbound_pg_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - case 4: { - variant13.val.value_conversion_failed = (outbound_pg_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - case 5: { - variant13.val.other_error = (outbound_pg_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - } - - expected.val.err = variant13; - break; - } - }*ret0 = expected; -} -__attribute__((import_module("outbound-pg"), import_name("execute"))) -void __wasm_import_outbound_pg_execute(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); -void outbound_pg_execute(outbound_pg_string_t *address, outbound_pg_string_t *statement, outbound_pg_list_parameter_value_t *params, outbound_pg_expected_u64_pg_error_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_outbound_pg_execute((int32_t) (*address).ptr, (int32_t) (*address).len, (int32_t) (*statement).ptr, (int32_t) (*statement).len, (int32_t) (*params).ptr, (int32_t) (*params).len, ptr); - outbound_pg_expected_u64_pg_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = (uint64_t) (*((int64_t*) (ptr + 8))); - break; - } - case 1: { - expected.is_err = true; - outbound_pg_pg_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 8))); - switch ((int32_t) variant.tag) { - case 0: { - break; - } - case 1: { - variant.val.connection_failed = (outbound_pg_string_t) { (char*)(*((int32_t*) (ptr + 12))), (size_t)(*((int32_t*) (ptr + 16))) }; - break; - } - case 2: { - variant.val.bad_parameter = (outbound_pg_string_t) { (char*)(*((int32_t*) (ptr + 12))), (size_t)(*((int32_t*) (ptr + 16))) }; - break; - } - case 3: { - variant.val.query_failed = (outbound_pg_string_t) { (char*)(*((int32_t*) (ptr + 12))), (size_t)(*((int32_t*) (ptr + 16))) }; - break; - } - case 4: { - variant.val.value_conversion_failed = (outbound_pg_string_t) { (char*)(*((int32_t*) (ptr + 12))), (size_t)(*((int32_t*) (ptr + 16))) }; - break; - } - case 5: { - variant.val.other_error = (outbound_pg_string_t) { (char*)(*((int32_t*) (ptr + 12))), (size_t)(*((int32_t*) (ptr + 16))) }; - break; - } - } - - expected.val.err = variant; - break; - } - }*ret0 = expected; -} diff --git a/sdk/go/pg/outbound-pg.h b/sdk/go/pg/outbound-pg.h deleted file mode 100644 index 4284e161e5..0000000000 --- a/sdk/go/pg/outbound-pg.h +++ /dev/null @@ -1,174 +0,0 @@ -#ifndef __BINDINGS_OUTBOUND_PG_H -#define __BINDINGS_OUTBOUND_PG_H -#ifdef __cplusplus -extern "C" -{ - #endif - - #include - #include - - typedef struct { - char *ptr; - size_t len; - } outbound_pg_string_t; - - void outbound_pg_string_set(outbound_pg_string_t *ret, const char *s); - void outbound_pg_string_dup(outbound_pg_string_t *ret, const char *s); - void outbound_pg_string_free(outbound_pg_string_t *ret); - typedef struct { - uint8_t tag; - union { - outbound_pg_string_t connection_failed; - outbound_pg_string_t bad_parameter; - outbound_pg_string_t query_failed; - outbound_pg_string_t value_conversion_failed; - outbound_pg_string_t other_error; - } val; - } outbound_pg_pg_error_t; - #define OUTBOUND_PG_PG_ERROR_SUCCESS 0 - #define OUTBOUND_PG_PG_ERROR_CONNECTION_FAILED 1 - #define OUTBOUND_PG_PG_ERROR_BAD_PARAMETER 2 - #define OUTBOUND_PG_PG_ERROR_QUERY_FAILED 3 - #define OUTBOUND_PG_PG_ERROR_VALUE_CONVERSION_FAILED 4 - #define OUTBOUND_PG_PG_ERROR_OTHER_ERROR 5 - void outbound_pg_pg_error_free(outbound_pg_pg_error_t *ptr); - typedef uint8_t outbound_pg_db_data_type_t; - #define OUTBOUND_PG_DB_DATA_TYPE_BOOLEAN 0 - #define OUTBOUND_PG_DB_DATA_TYPE_INT8 1 - #define OUTBOUND_PG_DB_DATA_TYPE_INT16 2 - #define OUTBOUND_PG_DB_DATA_TYPE_INT32 3 - #define OUTBOUND_PG_DB_DATA_TYPE_INT64 4 - #define OUTBOUND_PG_DB_DATA_TYPE_UINT8 5 - #define OUTBOUND_PG_DB_DATA_TYPE_UINT16 6 - #define OUTBOUND_PG_DB_DATA_TYPE_UINT32 7 - #define OUTBOUND_PG_DB_DATA_TYPE_UINT64 8 - #define OUTBOUND_PG_DB_DATA_TYPE_FLOATING32 9 - #define OUTBOUND_PG_DB_DATA_TYPE_FLOATING64 10 - #define OUTBOUND_PG_DB_DATA_TYPE_STR 11 - #define OUTBOUND_PG_DB_DATA_TYPE_BINARY 12 - #define OUTBOUND_PG_DB_DATA_TYPE_OTHER 13 - typedef struct { - outbound_pg_string_t name; - outbound_pg_db_data_type_t data_type; - } outbound_pg_column_t; - void outbound_pg_column_free(outbound_pg_column_t *ptr); - typedef struct { - uint8_t *ptr; - size_t len; - } outbound_pg_list_u8_t; - void outbound_pg_list_u8_free(outbound_pg_list_u8_t *ptr); - typedef struct { - uint8_t tag; - union { - bool boolean; - int8_t int8; - int16_t int16; - int32_t int32; - int64_t int64; - uint8_t uint8; - uint16_t uint16; - uint32_t uint32; - uint64_t uint64; - float floating32; - double floating64; - outbound_pg_string_t str; - outbound_pg_list_u8_t binary; - } val; - } outbound_pg_db_value_t; - #define OUTBOUND_PG_DB_VALUE_BOOLEAN 0 - #define OUTBOUND_PG_DB_VALUE_INT8 1 - #define OUTBOUND_PG_DB_VALUE_INT16 2 - #define OUTBOUND_PG_DB_VALUE_INT32 3 - #define OUTBOUND_PG_DB_VALUE_INT64 4 - #define OUTBOUND_PG_DB_VALUE_UINT8 5 - #define OUTBOUND_PG_DB_VALUE_UINT16 6 - #define OUTBOUND_PG_DB_VALUE_UINT32 7 - #define OUTBOUND_PG_DB_VALUE_UINT64 8 - #define OUTBOUND_PG_DB_VALUE_FLOATING32 9 - #define OUTBOUND_PG_DB_VALUE_FLOATING64 10 - #define OUTBOUND_PG_DB_VALUE_STR 11 - #define OUTBOUND_PG_DB_VALUE_BINARY 12 - #define OUTBOUND_PG_DB_VALUE_DB_NULL 13 - #define OUTBOUND_PG_DB_VALUE_UNSUPPORTED 14 - void outbound_pg_db_value_free(outbound_pg_db_value_t *ptr); - typedef struct { - uint8_t tag; - union { - bool boolean; - int8_t int8; - int16_t int16; - int32_t int32; - int64_t int64; - uint8_t uint8; - uint16_t uint16; - uint32_t uint32; - uint64_t uint64; - float floating32; - double floating64; - outbound_pg_string_t str; - outbound_pg_list_u8_t binary; - } val; - } outbound_pg_parameter_value_t; - #define OUTBOUND_PG_PARAMETER_VALUE_BOOLEAN 0 - #define OUTBOUND_PG_PARAMETER_VALUE_INT8 1 - #define OUTBOUND_PG_PARAMETER_VALUE_INT16 2 - #define OUTBOUND_PG_PARAMETER_VALUE_INT32 3 - #define OUTBOUND_PG_PARAMETER_VALUE_INT64 4 - #define OUTBOUND_PG_PARAMETER_VALUE_UINT8 5 - #define OUTBOUND_PG_PARAMETER_VALUE_UINT16 6 - #define OUTBOUND_PG_PARAMETER_VALUE_UINT32 7 - #define OUTBOUND_PG_PARAMETER_VALUE_UINT64 8 - #define OUTBOUND_PG_PARAMETER_VALUE_FLOATING32 9 - #define OUTBOUND_PG_PARAMETER_VALUE_FLOATING64 10 - #define OUTBOUND_PG_PARAMETER_VALUE_STR 11 - #define OUTBOUND_PG_PARAMETER_VALUE_BINARY 12 - #define OUTBOUND_PG_PARAMETER_VALUE_DB_NULL 13 - void outbound_pg_parameter_value_free(outbound_pg_parameter_value_t *ptr); - typedef struct { - outbound_pg_db_value_t *ptr; - size_t len; - } outbound_pg_row_t; - void outbound_pg_row_free(outbound_pg_row_t *ptr); - typedef struct { - outbound_pg_column_t *ptr; - size_t len; - } outbound_pg_list_column_t; - void outbound_pg_list_column_free(outbound_pg_list_column_t *ptr); - typedef struct { - outbound_pg_row_t *ptr; - size_t len; - } outbound_pg_list_row_t; - void outbound_pg_list_row_free(outbound_pg_list_row_t *ptr); - typedef struct { - outbound_pg_list_column_t columns; - outbound_pg_list_row_t rows; - } outbound_pg_row_set_t; - void outbound_pg_row_set_free(outbound_pg_row_set_t *ptr); - typedef struct { - outbound_pg_parameter_value_t *ptr; - size_t len; - } outbound_pg_list_parameter_value_t; - void outbound_pg_list_parameter_value_free(outbound_pg_list_parameter_value_t *ptr); - typedef struct { - bool is_err; - union { - outbound_pg_row_set_t ok; - outbound_pg_pg_error_t err; - } val; - } outbound_pg_expected_row_set_pg_error_t; - void outbound_pg_expected_row_set_pg_error_free(outbound_pg_expected_row_set_pg_error_t *ptr); - typedef struct { - bool is_err; - union { - uint64_t ok; - outbound_pg_pg_error_t err; - } val; - } outbound_pg_expected_u64_pg_error_t; - void outbound_pg_expected_u64_pg_error_free(outbound_pg_expected_u64_pg_error_t *ptr); - void outbound_pg_query(outbound_pg_string_t *address, outbound_pg_string_t *statement, outbound_pg_list_parameter_value_t *params, outbound_pg_expected_row_set_pg_error_t *ret0); - void outbound_pg_execute(outbound_pg_string_t *address, outbound_pg_string_t *statement, outbound_pg_list_parameter_value_t *params, outbound_pg_expected_u64_pg_error_t *ret0); - #ifdef __cplusplus -} -#endif -#endif diff --git a/sdk/go/pg/pg.go b/sdk/go/pg/pg.go deleted file mode 100644 index db7c859e5e..0000000000 --- a/sdk/go/pg/pg.go +++ /dev/null @@ -1,175 +0,0 @@ -package pg - -import ( - "context" - "database/sql" - "database/sql/driver" - "errors" - "io" - "reflect" - - spindb "github.com/fermyon/spin/sdk/go/v2/internal/db" -) - -// Open returns a new connection to the database. -func Open(address string) *sql.DB { - return sql.OpenDB(&connector{address}) -} - -// connector implements driver.Connector. -type connector struct { - address string -} - -// Connect returns a connection to the database. -func (d *connector) Connect(_ context.Context) (driver.Conn, error) { - return d.Open(d.address) -} - -// Driver returns the underlying Driver of the Connector. -func (d *connector) Driver() driver.Driver { - return d -} - -// Open returns a new connection to the database. -func (d *connector) Open(address string) (driver.Conn, error) { - return &conn{address: address}, nil -} - -// conn implements driver.Conn -type conn struct { - address string -} - -var _ driver.Conn = (*conn)(nil) - -// Prepare returns a prepared statement, bound to this connection. -func (c *conn) Prepare(query string) (driver.Stmt, error) { - return &stmt{c: c, query: query}, nil -} - -func (c *conn) Close() error { - return nil -} - -func (c *conn) Begin() (driver.Tx, error) { - return nil, errors.New("transactions are unsupported by this driver") -} - -type stmt struct { - c *conn - query string -} - -var _ driver.Stmt = (*stmt)(nil) -var _ driver.ColumnConverter = (*stmt)(nil) - -// Close closes the statement. -func (s *stmt) Close() error { - return nil -} - -// NumInput returns the number of placeholder parameters. -func (s *stmt) NumInput() int { - // Golang sql won't sanity check argument counts before Query. - return -1 -} - -// Query executes a query that may return rows, such as a SELECT. -func (s *stmt) Query(args []driver.Value) (driver.Rows, error) { - params := make([]any, len(args)) - for i := range args { - params[i] = args[i] - } - return query(s.c.address, s.query, params) -} - -// Exec executes a query that doesn't return rows, such as an INSERT or -// UPDATE. -func (s *stmt) Exec(args []driver.Value) (driver.Result, error) { - params := make([]any, len(args)) - for i := range args { - params[i] = args[i] - } - n, err := execute(s.c.address, s.query, params) - return &result{rowsAffected: int64(n)}, err -} - -// ColumnConverter returns GlobalParameterConverter to prevent using driver.DefaultParameterConverter. -func (s *stmt) ColumnConverter(_ int) driver.ValueConverter { - return spindb.GlobalParameterConverter -} - -type result struct { - rowsAffected int64 -} - -func (r result) LastInsertId() (int64, error) { - return -1, errors.New("LastInsertId is unsupported by this driver") -} - -func (r result) RowsAffected() (int64, error) { - return r.rowsAffected, nil -} - -type rows struct { - columns []string - columnType []uint8 - pos int - len int - rows [][]any - closed bool -} - -var _ driver.Rows = (*rows)(nil) -var _ driver.RowsColumnTypeScanType = (*rows)(nil) -var _ driver.RowsNextResultSet = (*rows)(nil) - -// Columns return column names. -func (r *rows) Columns() []string { - return r.columns -} - -// Close closes the rows iterator. -func (r *rows) Close() error { - r.rows = nil - r.pos = 0 - r.len = 0 - r.closed = true - return nil -} - -// Next moves the cursor to the next row. -func (r *rows) Next(dest []driver.Value) error { - if !r.HasNextResultSet() { - return io.EOF - } - for i := 0; i != len(r.columns); i++ { - dest[i] = driver.Value(r.rows[r.pos][i]) - } - r.pos++ - return nil -} - -// HasNextResultSet is called at the end of the current result set and -// reports whether there is another result set after the current one. -func (r *rows) HasNextResultSet() bool { - return r.pos < r.len -} - -// NextResultSet advances the driver to the next result set even -// if there are remaining rows in the current result set. -// -// NextResultSet should return io.EOF when there are no more result sets. -func (r *rows) NextResultSet() error { - if r.HasNextResultSet() { - r.pos++ - return nil - } - return io.EOF // Per interface spec. -} - -// ColumnTypeScanType return the value type that can be used to scan types into. -func (r *rows) ColumnTypeScanType(index int) reflect.Type { - return colTypeToReflectType(r.columnType[index]) -} diff --git a/sdk/go/readme.md b/sdk/go/readme.md deleted file mode 100644 index 908af0c506..0000000000 --- a/sdk/go/readme.md +++ /dev/null @@ -1,21 +0,0 @@ -# The (Tiny)Go SDK for Spin - -This package contains an SDK that facilitates building Spin components in -(Tiny)Go. It allows building HTTP components that target the Spin -executor. - -```go -import ( - "fmt" - spinhttp "github.com/fermyon/spin/sdk/go/v2/http" -) - -func init() { - // call the Handle function - spinhttp.Handle(func(w http.ResponseWriter, r *http.Request) { - fmt.Fprintln(w, "Hello, Fermyon!") - }) -} - -func main() {} -``` diff --git a/sdk/go/redis/internals.go b/sdk/go/redis/internals.go deleted file mode 100644 index 4b71ab6308..0000000000 --- a/sdk/go/redis/internals.go +++ /dev/null @@ -1,241 +0,0 @@ -package redis - -// #include "outbound-redis.h" -// #include "spin-redis.h" -// #include -import "C" -import ( - "errors" - "fmt" - "unsafe" -) - -// argumentKind represents a type of a argument for executing a Redis command. -type argumentKind uint8 - -const ( - argumentKindInt argumentKind = iota - argumentKindBinary -) - -// argument represents an argument for a Redis command. -type argument struct { - kind argumentKind - val any -} - -func createParameter(x any) (*argument, error) { - var p argument - switch v := x.(type) { - case int: - p.kind = argumentKindInt - p.val = int64(v) - case int32: - p.kind = argumentKindInt - p.val = int64(v) - case int64: - p.kind = argumentKindInt - p.val = v - case string: - p.kind = argumentKindBinary - p.val = []byte(v) - case []byte: - p.kind = argumentKindBinary - p.val = v - default: - return &p, fmt.Errorf("unsupported parameter type: %T", x) - } - return &p, nil -} - -//export spin_redis_handle_redis_message -func handleRedisMessage(payload *C.spin_redis_payload_t) C.spin_redis_error_t { - bytes := C.GoBytes(unsafe.Pointer(payload.ptr), C.int(payload.len)) - if err := handler(bytes); err != nil { - return C.uint8_t(1) - - } - return C.uint8_t(0) -} - -func publish(addr, channel string, payload []byte) error { - caddr := redisStr(addr) - cchannel := redisStr(channel) - cpayload := C.outbound_redis_payload_t{ptr: &payload[0], len: C.size_t(len(payload))} - - err := C.outbound_redis_publish(&caddr, &cchannel, &cpayload) - return toErr(err) -} - -func get(addr, key string) ([]byte, error) { - caddr := redisStr(addr) - ckey := redisStr(key) - - var cpayload C.outbound_redis_payload_t - - err := C.outbound_redis_get(&caddr, &ckey, &cpayload) - payload := C.GoBytes(unsafe.Pointer(cpayload.ptr), C.int(cpayload.len)) - return payload, toErr(err) -} - -func set(addr, key string, payload []byte) error { - caddr := redisStr(addr) - ckey := redisStr(key) - cpayload := C.outbound_redis_payload_t{ptr: &payload[0], len: C.size_t(len(payload))} - - err := C.outbound_redis_set(&caddr, &ckey, &cpayload) - return toErr(err) -} - -func incr(addr, key string) (int64, error) { - caddr := redisStr(addr) - ckey := redisStr(key) - - var cpayload C.int64_t - - err := C.outbound_redis_incr(&caddr, &ckey, &cpayload) - return int64(cpayload), toErr(err) -} - -func del(addr string, keys []string) (int64, error) { - caddr := redisStr(addr) - ckeys := redisListStr(keys) - - var cpayload C.int64_t - - err := C.outbound_redis_del(&caddr, &ckeys, &cpayload) - return int64(cpayload), toErr(err) -} - -func sadd(addr, key string, values []string) (int64, error) { - caddr := redisStr(addr) - ckey := redisStr(key) - cvalues := redisListStr(values) - - var cpayload C.int64_t - - err := C.outbound_redis_sadd(&caddr, &ckey, &cvalues, &cpayload) - return int64(cpayload), toErr(err) -} - -func smembers(addr, key string) ([]string, error) { - caddr := redisStr(addr) - ckey := redisStr(key) - - var cpayload C.outbound_redis_list_string_t - - err := C.outbound_redis_smembers(&caddr, &ckey, &cpayload) - return fromRedisListStr(&cpayload), toErr(err) -} - -func srem(addr, key string, values []string) (int64, error) { - caddr := redisStr(addr) - ckey := redisStr(key) - cvalues := redisListStr(values) - - var cpayload C.int64_t - - err := C.outbound_redis_srem(&caddr, &ckey, &cvalues, &cpayload) - return int64(cpayload), toErr(err) -} - -func execute(addr, command string, arguments []*argument) ([]*Result, error) { - caddr := redisStr(addr) - ccommand := redisStr(command) - carguments := redisListParameter(arguments) - - var cpayload C.outbound_redis_list_redis_result_t - - err := C.outbound_redis_execute(&caddr, &ccommand, &carguments, &cpayload) - return fromRedisListResult(&cpayload), toErr(err) -} - -func redisStr(x string) C.outbound_redis_string_t { - return C.outbound_redis_string_t{ptr: C.CString(x), len: C.size_t(len(x))} -} - -func redisListStr(xs []string) C.outbound_redis_list_string_t { - if len(xs) == 0 { - return C.outbound_redis_list_string_t{} - } - cxs := make([]C.outbound_redis_string_t, 0, len(xs)) - for i := 0; i < len(xs); i++ { - cxs = append(cxs, redisStr(xs[i])) - } - return C.outbound_redis_list_string_t{ptr: &cxs[0], len: C.size_t(len(cxs))} -} - -func fromRedisListStr(list *C.outbound_redis_list_string_t) []string { - listLen := int(list.len) - result := make([]string, 0, listLen) - - slice := unsafe.Slice(list.ptr, listLen) - for i := 0; i < listLen; i++ { - str := slice[i] - result = append(result, C.GoStringN(str.ptr, C.int(str.len))) - } - return result -} - -func redisParameter(x *argument) C.outbound_redis_redis_parameter_t { - var ret C.outbound_redis_redis_parameter_t - switch x.kind { - case argumentKindInt: - *(*C.int64_t)(unsafe.Pointer(&ret.val)) = x.val.(int64) - case argumentKindBinary: - value := x.val.([]byte) - payload := C.outbound_redis_payload_t{ptr: &value[0], len: C.size_t(len(value))} - *(*C.outbound_redis_payload_t)(unsafe.Pointer(&ret.val)) = payload - } - ret.tag = C.uint8_t(x.kind) - return ret -} - -func redisListParameter(xs []*argument) C.outbound_redis_list_redis_parameter_t { - if len(xs) == 0 { - return C.outbound_redis_list_redis_parameter_t{} - } - - cxs := make([]C.outbound_redis_redis_parameter_t, 0, len(xs)) - for i := 0; i < len(xs); i++ { - cxs = append(cxs, redisParameter(xs[i])) - } - return C.outbound_redis_list_redis_parameter_t{ptr: &cxs[0], len: C.size_t(len(cxs))} -} - -func fromRedisResult(result *C.outbound_redis_redis_result_t) *Result { - var val any - switch ResultKind(result.tag) { - case ResultKindNil: - val = nil - case ResultKindStatus: - str := (*C.outbound_redis_string_t)(unsafe.Pointer(&result.val)) - val = C.GoStringN(str.ptr, C.int(str.len)) - case ResultKindInt64: - val = int64(*(*C.int64_t)(unsafe.Pointer(&result.val))) - case ResultKindBinary: - payload := (*C.outbound_redis_payload_t)(unsafe.Pointer(&result.val)) - val = C.GoBytes(unsafe.Pointer(payload.ptr), C.int(payload.len)) - } - - return &Result{Kind: ResultKind(result.tag), Val: val} -} - -func fromRedisListResult(list *C.outbound_redis_list_redis_result_t) []*Result { - listLen := int(list.len) - result := make([]*Result, 0, listLen) - - slice := unsafe.Slice(list.ptr, listLen) - for i := 0; i < listLen; i++ { - result = append(result, fromRedisResult(&slice[i])) - } - - return result -} - -func toErr(code C.uint8_t) error { - if code == 1 { - return errors.New("internal server error") - } - return nil -} diff --git a/sdk/go/redis/internals_test.go b/sdk/go/redis/internals_test.go deleted file mode 100644 index 191fa6eedb..0000000000 --- a/sdk/go/redis/internals_test.go +++ /dev/null @@ -1,40 +0,0 @@ -package redis - -import ( - "reflect" - "testing" -) - -func TestCreateParameter(t *testing.T) { - tests := []struct { - in any - want argumentKind - }{ - {in: "a", want: argumentKindBinary}, - {in: []byte("b"), want: argumentKindBinary}, - {in: 1, want: argumentKindInt}, - {in: int64(2), want: argumentKindInt}, - {in: int32(3), want: argumentKindInt}, - } - - for _, tc := range tests { - p, err := createParameter(tc.in) - if err != nil { - t.Error(err) - } - if p.kind != tc.want { - t.Errorf("want %s, got %s", tc.want, p.kind) - } - } -} - -func TestRedisListString(t *testing.T) { - list := []string{"a", "b", "c"} - - rlist := redisListStr(list) - got := fromRedisListStr(&rlist) - - if !reflect.DeepEqual(list, got) { - t.Errorf("want %s, got %s", list, got) - } -} diff --git a/sdk/go/redis/outbound-redis.c b/sdk/go/redis/outbound-redis.c deleted file mode 100644 index 40feb7263e..0000000000 --- a/sdk/go/redis/outbound-redis.c +++ /dev/null @@ -1,320 +0,0 @@ -#include -#include - -__attribute__((weak, export_name("canonical_abi_realloc"))) -void *canonical_abi_realloc( -void *ptr, -size_t orig_size, -size_t align, -size_t new_size -) { - if (new_size == 0) - return (void*) align; - void *ret = realloc(ptr, new_size); - if (!ret) - abort(); - return ret; -} - -__attribute__((weak, export_name("canonical_abi_free"))) -void canonical_abi_free( -void *ptr, -size_t size, -size_t align -) { - if (size == 0) - return; - free(ptr); -} -#include - -void outbound_redis_string_set(outbound_redis_string_t *ret, const char *s) { - ret->ptr = (char*) s; - ret->len = strlen(s); -} - -void outbound_redis_string_dup(outbound_redis_string_t *ret, const char *s) { - ret->len = strlen(s); - ret->ptr = canonical_abi_realloc(NULL, 0, 1, ret->len); - memcpy(ret->ptr, s, ret->len); -} - -void outbound_redis_string_free(outbound_redis_string_t *ret) { - canonical_abi_free(ret->ptr, ret->len, 1); - ret->ptr = NULL; - ret->len = 0; -} -void outbound_redis_payload_free(outbound_redis_payload_t *ptr) { - canonical_abi_free(ptr->ptr, ptr->len * 1, 1); -} -void outbound_redis_redis_parameter_free(outbound_redis_redis_parameter_t *ptr) { - switch ((int32_t) ptr->tag) { - case 1: { - outbound_redis_payload_free(&ptr->val.binary); - break; - } - } -} -void outbound_redis_redis_result_free(outbound_redis_redis_result_t *ptr) { - switch ((int32_t) ptr->tag) { - case 1: { - outbound_redis_string_free(&ptr->val.status); - break; - } - case 3: { - outbound_redis_payload_free(&ptr->val.binary); - break; - } - } -} -typedef struct { - bool is_err; - union { - outbound_redis_error_t err; - } val; -} outbound_redis_expected_unit_error_t; -typedef struct { - bool is_err; - union { - outbound_redis_payload_t ok; - outbound_redis_error_t err; - } val; -} outbound_redis_expected_payload_error_t; -typedef struct { - bool is_err; - union { - int64_t ok; - outbound_redis_error_t err; - } val; -} outbound_redis_expected_s64_error_t; -void outbound_redis_list_string_free(outbound_redis_list_string_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - outbound_redis_string_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 8, 4); -} -typedef struct { - bool is_err; - union { - outbound_redis_list_string_t ok; - outbound_redis_error_t err; - } val; -} outbound_redis_expected_list_string_error_t; -void outbound_redis_list_redis_parameter_free(outbound_redis_list_redis_parameter_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - outbound_redis_redis_parameter_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 16, 8); -} -void outbound_redis_list_redis_result_free(outbound_redis_list_redis_result_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - outbound_redis_redis_result_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 16, 8); -} -typedef struct { - bool is_err; - union { - outbound_redis_list_redis_result_t ok; - outbound_redis_error_t err; - } val; -} outbound_redis_expected_list_redis_result_error_t; - -__attribute__((aligned(8))) -static uint8_t RET_AREA[16]; -__attribute__((import_module("outbound-redis"), import_name("publish"))) -void __wasm_import_outbound_redis_publish(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); -outbound_redis_error_t outbound_redis_publish(outbound_redis_string_t *address, outbound_redis_string_t *channel, outbound_redis_payload_t *payload) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_outbound_redis_publish((int32_t) (*address).ptr, (int32_t) (*address).len, (int32_t) (*channel).ptr, (int32_t) (*channel).len, (int32_t) (*payload).ptr, (int32_t) (*payload).len, ptr); - outbound_redis_expected_unit_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - - break; - } - case 1: { - expected.is_err = true; - - expected.val.err = (int32_t) (*((uint8_t*) (ptr + 1))); - break; - } - }return expected.is_err ? expected.val.err : -1; -} -__attribute__((import_module("outbound-redis"), import_name("get"))) -void __wasm_import_outbound_redis_get(int32_t, int32_t, int32_t, int32_t, int32_t); -outbound_redis_error_t outbound_redis_get(outbound_redis_string_t *address, outbound_redis_string_t *key, outbound_redis_payload_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_outbound_redis_get((int32_t) (*address).ptr, (int32_t) (*address).len, (int32_t) (*key).ptr, (int32_t) (*key).len, ptr); - outbound_redis_expected_payload_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = (outbound_redis_payload_t) { (uint8_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }; - break; - } - case 1: { - expected.is_err = true; - - expected.val.err = (int32_t) (*((uint8_t*) (ptr + 4))); - break; - } - }*ret0 = expected.val.ok; - return expected.is_err ? expected.val.err : -1; -} -__attribute__((import_module("outbound-redis"), import_name("set"))) -void __wasm_import_outbound_redis_set(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); -outbound_redis_error_t outbound_redis_set(outbound_redis_string_t *address, outbound_redis_string_t *key, outbound_redis_payload_t *value) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_outbound_redis_set((int32_t) (*address).ptr, (int32_t) (*address).len, (int32_t) (*key).ptr, (int32_t) (*key).len, (int32_t) (*value).ptr, (int32_t) (*value).len, ptr); - outbound_redis_expected_unit_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - - break; - } - case 1: { - expected.is_err = true; - - expected.val.err = (int32_t) (*((uint8_t*) (ptr + 1))); - break; - } - }return expected.is_err ? expected.val.err : -1; -} -__attribute__((import_module("outbound-redis"), import_name("incr"))) -void __wasm_import_outbound_redis_incr(int32_t, int32_t, int32_t, int32_t, int32_t); -outbound_redis_error_t outbound_redis_incr(outbound_redis_string_t *address, outbound_redis_string_t *key, int64_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_outbound_redis_incr((int32_t) (*address).ptr, (int32_t) (*address).len, (int32_t) (*key).ptr, (int32_t) (*key).len, ptr); - outbound_redis_expected_s64_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = *((int64_t*) (ptr + 8)); - break; - } - case 1: { - expected.is_err = true; - - expected.val.err = (int32_t) (*((uint8_t*) (ptr + 8))); - break; - } - }*ret0 = expected.val.ok; - return expected.is_err ? expected.val.err : -1; -} -__attribute__((import_module("outbound-redis"), import_name("del"))) -void __wasm_import_outbound_redis_del(int32_t, int32_t, int32_t, int32_t, int32_t); -outbound_redis_error_t outbound_redis_del(outbound_redis_string_t *address, outbound_redis_list_string_t *keys, int64_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_outbound_redis_del((int32_t) (*address).ptr, (int32_t) (*address).len, (int32_t) (*keys).ptr, (int32_t) (*keys).len, ptr); - outbound_redis_expected_s64_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = *((int64_t*) (ptr + 8)); - break; - } - case 1: { - expected.is_err = true; - - expected.val.err = (int32_t) (*((uint8_t*) (ptr + 8))); - break; - } - }*ret0 = expected.val.ok; - return expected.is_err ? expected.val.err : -1; -} -__attribute__((import_module("outbound-redis"), import_name("sadd"))) -void __wasm_import_outbound_redis_sadd(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); -outbound_redis_error_t outbound_redis_sadd(outbound_redis_string_t *address, outbound_redis_string_t *key, outbound_redis_list_string_t *values, int64_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_outbound_redis_sadd((int32_t) (*address).ptr, (int32_t) (*address).len, (int32_t) (*key).ptr, (int32_t) (*key).len, (int32_t) (*values).ptr, (int32_t) (*values).len, ptr); - outbound_redis_expected_s64_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = *((int64_t*) (ptr + 8)); - break; - } - case 1: { - expected.is_err = true; - - expected.val.err = (int32_t) (*((uint8_t*) (ptr + 8))); - break; - } - }*ret0 = expected.val.ok; - return expected.is_err ? expected.val.err : -1; -} -__attribute__((import_module("outbound-redis"), import_name("smembers"))) -void __wasm_import_outbound_redis_smembers(int32_t, int32_t, int32_t, int32_t, int32_t); -outbound_redis_error_t outbound_redis_smembers(outbound_redis_string_t *address, outbound_redis_string_t *key, outbound_redis_list_string_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_outbound_redis_smembers((int32_t) (*address).ptr, (int32_t) (*address).len, (int32_t) (*key).ptr, (int32_t) (*key).len, ptr); - outbound_redis_expected_list_string_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = (outbound_redis_list_string_t) { (outbound_redis_string_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }; - break; - } - case 1: { - expected.is_err = true; - - expected.val.err = (int32_t) (*((uint8_t*) (ptr + 4))); - break; - } - }*ret0 = expected.val.ok; - return expected.is_err ? expected.val.err : -1; -} -__attribute__((import_module("outbound-redis"), import_name("srem"))) -void __wasm_import_outbound_redis_srem(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); -outbound_redis_error_t outbound_redis_srem(outbound_redis_string_t *address, outbound_redis_string_t *key, outbound_redis_list_string_t *values, int64_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_outbound_redis_srem((int32_t) (*address).ptr, (int32_t) (*address).len, (int32_t) (*key).ptr, (int32_t) (*key).len, (int32_t) (*values).ptr, (int32_t) (*values).len, ptr); - outbound_redis_expected_s64_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = *((int64_t*) (ptr + 8)); - break; - } - case 1: { - expected.is_err = true; - - expected.val.err = (int32_t) (*((uint8_t*) (ptr + 8))); - break; - } - }*ret0 = expected.val.ok; - return expected.is_err ? expected.val.err : -1; -} -__attribute__((import_module("outbound-redis"), import_name("execute"))) -void __wasm_import_outbound_redis_execute(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); -outbound_redis_error_t outbound_redis_execute(outbound_redis_string_t *address, outbound_redis_string_t *command, outbound_redis_list_redis_parameter_t *arguments, outbound_redis_list_redis_result_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_outbound_redis_execute((int32_t) (*address).ptr, (int32_t) (*address).len, (int32_t) (*command).ptr, (int32_t) (*command).len, (int32_t) (*arguments).ptr, (int32_t) (*arguments).len, ptr); - outbound_redis_expected_list_redis_result_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = (outbound_redis_list_redis_result_t) { (outbound_redis_redis_result_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }; - break; - } - case 1: { - expected.is_err = true; - - expected.val.err = (int32_t) (*((uint8_t*) (ptr + 4))); - break; - } - }*ret0 = expected.val.ok; - return expected.is_err ? expected.val.err : -1; -} diff --git a/sdk/go/redis/outbound-redis.h b/sdk/go/redis/outbound-redis.h deleted file mode 100644 index 4281bd97ed..0000000000 --- a/sdk/go/redis/outbound-redis.h +++ /dev/null @@ -1,77 +0,0 @@ -#ifndef __BINDINGS_OUTBOUND_REDIS_H -#define __BINDINGS_OUTBOUND_REDIS_H -#ifdef __cplusplus -extern "C" -{ - #endif - - #include - #include - - typedef struct { - char *ptr; - size_t len; - } outbound_redis_string_t; - - void outbound_redis_string_set(outbound_redis_string_t *ret, const char *s); - void outbound_redis_string_dup(outbound_redis_string_t *ret, const char *s); - void outbound_redis_string_free(outbound_redis_string_t *ret); - typedef uint8_t outbound_redis_error_t; - #define OUTBOUND_REDIS_ERROR_SUCCESS 0 - #define OUTBOUND_REDIS_ERROR_ERROR 1 - typedef struct { - uint8_t *ptr; - size_t len; - } outbound_redis_payload_t; - void outbound_redis_payload_free(outbound_redis_payload_t *ptr); - typedef struct { - uint8_t tag; - union { - int64_t int64; - outbound_redis_payload_t binary; - } val; - } outbound_redis_redis_parameter_t; - #define OUTBOUND_REDIS_REDIS_PARAMETER_INT64 0 - #define OUTBOUND_REDIS_REDIS_PARAMETER_BINARY 1 - void outbound_redis_redis_parameter_free(outbound_redis_redis_parameter_t *ptr); - typedef struct { - uint8_t tag; - union { - outbound_redis_string_t status; - int64_t int64; - outbound_redis_payload_t binary; - } val; - } outbound_redis_redis_result_t; - #define OUTBOUND_REDIS_REDIS_RESULT_NIL 0 - #define OUTBOUND_REDIS_REDIS_RESULT_STATUS 1 - #define OUTBOUND_REDIS_REDIS_RESULT_INT64 2 - #define OUTBOUND_REDIS_REDIS_RESULT_BINARY 3 - void outbound_redis_redis_result_free(outbound_redis_redis_result_t *ptr); - typedef struct { - outbound_redis_string_t *ptr; - size_t len; - } outbound_redis_list_string_t; - void outbound_redis_list_string_free(outbound_redis_list_string_t *ptr); - typedef struct { - outbound_redis_redis_parameter_t *ptr; - size_t len; - } outbound_redis_list_redis_parameter_t; - void outbound_redis_list_redis_parameter_free(outbound_redis_list_redis_parameter_t *ptr); - typedef struct { - outbound_redis_redis_result_t *ptr; - size_t len; - } outbound_redis_list_redis_result_t; - void outbound_redis_list_redis_result_free(outbound_redis_list_redis_result_t *ptr); - outbound_redis_error_t outbound_redis_publish(outbound_redis_string_t *address, outbound_redis_string_t *channel, outbound_redis_payload_t *payload); - outbound_redis_error_t outbound_redis_get(outbound_redis_string_t *address, outbound_redis_string_t *key, outbound_redis_payload_t *ret0); - outbound_redis_error_t outbound_redis_set(outbound_redis_string_t *address, outbound_redis_string_t *key, outbound_redis_payload_t *value); - outbound_redis_error_t outbound_redis_incr(outbound_redis_string_t *address, outbound_redis_string_t *key, int64_t *ret0); - outbound_redis_error_t outbound_redis_del(outbound_redis_string_t *address, outbound_redis_list_string_t *keys, int64_t *ret0); - outbound_redis_error_t outbound_redis_sadd(outbound_redis_string_t *address, outbound_redis_string_t *key, outbound_redis_list_string_t *values, int64_t *ret0); - outbound_redis_error_t outbound_redis_smembers(outbound_redis_string_t *address, outbound_redis_string_t *key, outbound_redis_list_string_t *ret0); - outbound_redis_error_t outbound_redis_srem(outbound_redis_string_t *address, outbound_redis_string_t *key, outbound_redis_list_string_t *values, int64_t *ret0); - outbound_redis_error_t outbound_redis_execute(outbound_redis_string_t *address, outbound_redis_string_t *command, outbound_redis_list_redis_parameter_t *arguments, outbound_redis_list_redis_result_t *ret0); - #ifdef __cplusplus -} -#endif -#endif diff --git a/sdk/go/redis/redis.go b/sdk/go/redis/redis.go deleted file mode 100644 index a5b03736eb..0000000000 --- a/sdk/go/redis/redis.go +++ /dev/null @@ -1,139 +0,0 @@ -// Package redis provides the handler function for the Redis trigger, as well -// as access to Redis within Spin components. -package redis - -import ( - "errors" - "fmt" - "os" -) - -// handler is the function that will be called by the Redis trigger in Spin. -var handler = defaultHandler - -// defaultHandler is a placeholder for returning a useful error to stdout when -// the handler is not set. -var defaultHandler = func(payload []byte) error { - fmt.Fprintln(os.Stderr, "redis handler undefined") - return nil -} - -// Handle sets the handler function for redis. -// It must be set in an init() function. -func Handle(fn func(payload []byte) error) { - handler = fn -} - -// Client is a Redis client. -type Client struct { - addr string -} - -// NewClient returns a Redis client. -func NewClient(address string) *Client { - return &Client{addr: address} -} - -// Publish a Redis message to the specified channel. -func (c *Client) Publish(channel string, payload []byte) error { - if len(payload) == 0 { - return errors.New("payload is empty") - } - return publish(c.addr, channel, payload) -} - -// Get the value of a key. An error is returned if the value stored at key is -// not a string. -func (c *Client) Get(key string) ([]byte, error) { - return get(c.addr, key) -} - -// Set key to value. If key alreads holds a value, it is overwritten. -func (c *Client) Set(key string, payload []byte) error { - if len(payload) == 0 { - return errors.New("payload is empty") - } - return set(c.addr, key, payload) -} - -// Incr increments the number stored at key by one. If the key does not exist, -// it is set to 0 before performing the operation. An error is returned if -// the key contains a value of the wrong type or contains a string that can not -// be represented as integer. -func (c *Client) Incr(key string) (int64, error) { - return incr(c.addr, key) -} - -// Del removes the specified keys. A key is ignored if it does not exist. -func (c *Client) Del(keys ...string) (int64, error) { - return del(c.addr, keys) -} - -// Sadd adds the specified values to the set for the specified key, creating -// it if it does not already exist. -func (c *Client) Sadd(key string, values ...string) (int64, error) { - return sadd(c.addr, key, values) -} - -// Smembers gets the elements of the set for the specified key. -func (c *Client) Smembers(key string) ([]string, error) { - return smembers(c.addr, key) -} - -// Srem removes the specified elements from the set for the specified key. -// This has no effect if the key does not exist. -func (c *Client) Srem(key string, values ...string) (int64, error) { - return srem(c.addr, key, values) -} - -// ResultKind represents a result type returned from executing a Redis command. -type ResultKind uint8 - -const ( - ResultKindNil ResultKind = iota - ResultKindStatus - ResultKindInt64 - ResultKindBinary -) - -// String implements fmt.Stringer. -func (r ResultKind) String() string { - switch r { - case ResultKindNil: - return "nil" - case ResultKindStatus: - return "status" - case ResultKindInt64: - return "int64" - case ResultKindBinary: - return "binary" - default: - return "unknown" - } -} - -// GoString implements fmt.GoStringer. -func (r ResultKind) GoString() string { return r.String() } - -// Result represents a value returned from a Redis command. -type Result struct { - Kind ResultKind - Val any -} - -// Execute runs the specified Redis command with the specified arguments, -// returning zero or more results. This is a general-purpose function which -// should work with any Redis command. -// -// Arguments must be string, []byte, int, int64, or int32. -func (c *Client) Execute(command string, arguments ...any) ([]*Result, error) { - var params []*argument - for _, a := range arguments { - p, err := createParameter(a) - if err != nil { - return nil, err - } - params = append(params, p) - } - return execute(c.addr, command, params) -} diff --git a/sdk/go/redis/spin-redis.c b/sdk/go/redis/spin-redis.c deleted file mode 100644 index 665d4ebdbf..0000000000 --- a/sdk/go/redis/spin-redis.c +++ /dev/null @@ -1,105 +0,0 @@ -#include -#include - -__attribute__((weak, export_name("canonical_abi_realloc"))) -void *canonical_abi_realloc( -void *ptr, -size_t orig_size, -size_t align, -size_t new_size -) { - if (new_size == 0) - return (void*) align; - void *ret = realloc(ptr, new_size); - if (!ret) - abort(); - return ret; -} - -__attribute__((weak, export_name("canonical_abi_free"))) -void canonical_abi_free( -void *ptr, -size_t size, -size_t align -) { - if (size == 0) - return; - free(ptr); -} -#include - -void spin_redis_string_set(spin_redis_string_t *ret, const char *s) { - ret->ptr = (char*) s; - ret->len = strlen(s); -} - -void spin_redis_string_dup(spin_redis_string_t *ret, const char *s) { - ret->len = strlen(s); - ret->ptr = canonical_abi_realloc(NULL, 0, 1, ret->len); - memcpy(ret->ptr, s, ret->len); -} - -void spin_redis_string_free(spin_redis_string_t *ret) { - canonical_abi_free(ret->ptr, ret->len, 1); - ret->ptr = NULL; - ret->len = 0; -} -void spin_redis_payload_free(spin_redis_payload_t *ptr) { - canonical_abi_free(ptr->ptr, ptr->len * 1, 1); -} -void spin_redis_redis_parameter_free(spin_redis_redis_parameter_t *ptr) { - switch ((int32_t) ptr->tag) { - case 1: { - spin_redis_payload_free(&ptr->val.binary); - break; - } - } -} -void spin_redis_redis_result_free(spin_redis_redis_result_t *ptr) { - switch ((int32_t) ptr->tag) { - case 1: { - spin_redis_string_free(&ptr->val.status); - break; - } - case 3: { - spin_redis_payload_free(&ptr->val.binary); - break; - } - } -} -typedef struct { - bool is_err; - union { - spin_redis_error_t err; - } val; -} spin_redis_expected_unit_error_t; - -__attribute__((aligned(1))) -static uint8_t RET_AREA[2]; -__attribute__((export_name("handle-redis-message"))) -int32_t __wasm_export_spin_redis_handle_redis_message(int32_t arg, int32_t arg0) { - spin_redis_payload_t arg1 = (spin_redis_payload_t) { (uint8_t*)(arg), (size_t)(arg0) }; - spin_redis_error_t ret = spin_redis_handle_redis_message(&arg1); - - spin_redis_expected_unit_error_t ret2; - if (ret <= 2) { - ret2.is_err = true; - ret2.val.err = ret; - } else { - ret2.is_err = false; - - } - int32_t ptr = (int32_t) &RET_AREA; - - if ((ret2).is_err) { - const spin_redis_error_t *payload3 = &(ret2).val.err; - *((int8_t*)(ptr + 0)) = 1; - *((int8_t*)(ptr + 1)) = (int32_t) *payload3; - - } else { - - *((int8_t*)(ptr + 0)) = 0; - - } - return ptr; -} diff --git a/sdk/go/redis/spin-redis.h b/sdk/go/redis/spin-redis.h deleted file mode 100644 index 9f73ba4061..0000000000 --- a/sdk/go/redis/spin-redis.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef __BINDINGS_SPIN_REDIS_H -#define __BINDINGS_SPIN_REDIS_H -#ifdef __cplusplus -extern "C" -{ - #endif - - #include - #include - - typedef struct { - char *ptr; - size_t len; - } spin_redis_string_t; - - void spin_redis_string_set(spin_redis_string_t *ret, const char *s); - void spin_redis_string_dup(spin_redis_string_t *ret, const char *s); - void spin_redis_string_free(spin_redis_string_t *ret); - typedef uint8_t spin_redis_error_t; - #define SPIN_REDIS_ERROR_SUCCESS 0 - #define SPIN_REDIS_ERROR_ERROR 1 - typedef struct { - uint8_t *ptr; - size_t len; - } spin_redis_payload_t; - void spin_redis_payload_free(spin_redis_payload_t *ptr); - typedef struct { - uint8_t tag; - union { - int64_t int64; - spin_redis_payload_t binary; - } val; - } spin_redis_redis_parameter_t; - #define SPIN_REDIS_REDIS_PARAMETER_INT64 0 - #define SPIN_REDIS_REDIS_PARAMETER_BINARY 1 - void spin_redis_redis_parameter_free(spin_redis_redis_parameter_t *ptr); - typedef struct { - uint8_t tag; - union { - spin_redis_string_t status; - int64_t int64; - spin_redis_payload_t binary; - } val; - } spin_redis_redis_result_t; - #define SPIN_REDIS_REDIS_RESULT_NIL 0 - #define SPIN_REDIS_REDIS_RESULT_STATUS 1 - #define SPIN_REDIS_REDIS_RESULT_INT64 2 - #define SPIN_REDIS_REDIS_RESULT_BINARY 3 - void spin_redis_redis_result_free(spin_redis_redis_result_t *ptr); - spin_redis_error_t spin_redis_handle_redis_message(spin_redis_payload_t *message); - #ifdef __cplusplus -} -#endif -#endif diff --git a/sdk/go/sdk_version/sdk-version-go-template.c b/sdk/go/sdk_version/sdk-version-go-template.c deleted file mode 100644 index ebddb4b125..0000000000 --- a/sdk/go/sdk_version/sdk-version-go-template.c +++ /dev/null @@ -1,14 +0,0 @@ -__attribute__((weak, export_name("spin-sdk-version-{{VERSION}}"))) -void __spin_sdk_version(void) { - -} - -__attribute__((weak, export_name("spin-sdk-language-go"))) -void __spin_sdk_language(void) { - -} - -__attribute__((weak, export_name("spin-sdk-commit-{{COMMIT}}"))) -void __spin_sdk_commit(void) { - -} diff --git a/sdk/go/sqlite/doc.go b/sdk/go/sqlite/doc.go deleted file mode 100644 index 739f29c7a0..0000000000 --- a/sdk/go/sqlite/doc.go +++ /dev/null @@ -1,27 +0,0 @@ -// Package sqlite provides an interface to sqlite database stores within Spin -// components. -// -// This package is implemented as a driver that conforms to the built-in -// database/sql interface. -// -// db := sqlite.Open("default") -// defer db.Close() -// -// s, err := db.Prepare("REPLACE INTO pets VALUES (4, 'Maya', ?, false);") -// // if err != nil { ... } -// -// _, err = s.Query("bananas") -// // if err != nil { ... } -// -// rows, err := db.Query("SELECT * FROM pets") -// // if err != nil { ... } -// -// var pets []*Pet -// for rows.Next() { -// var pet Pet -// if err := rows.Scan(&pet.ID, &pet.Name, &pet.Prey, &pet.IsFinicky); err != nil { -// ... -// } -// pets = append(pets, &pet) -// } -package sqlite diff --git a/sdk/go/sqlite/internals.go b/sdk/go/sqlite/internals.go deleted file mode 100644 index 441710f37b..0000000000 --- a/sdk/go/sqlite/internals.go +++ /dev/null @@ -1,169 +0,0 @@ -package sqlite - -// #include "sqlite.h" -import "C" -import ( - "errors" - "fmt" - "unsafe" -) - -func open(name string) (*conn, error) { - var dbname C.sqlite_string_t - var ret C.sqlite_expected_connection_error_t - - dbname = sqliteStr(name) - C.sqlite_open(&dbname, &ret) - - if ret.is_err { - return nil, toErr((*C.sqlite_error_t)(unsafe.Pointer(&ret.val))) - } - - sqliteConn := *((*C.sqlite_connection_t)(unsafe.Pointer(&ret.val))) - return &conn{_ptr: sqliteConn}, nil -} - -func (db *conn) close() { - C.sqlite_close(db._ptr) -} - -func (db *conn) execute(statement string, args []any) (*rows, error) { - var ret C.sqlite_expected_query_result_error_t - defer C.sqlite_expected_query_result_error_free(&ret) - - sqliteStatement := sqliteStr(statement) - params := toSqliteListValue(args) - - C.sqlite_execute(db._ptr, &sqliteStatement, ¶ms, &ret) - - if ret.is_err { - spinErr := (*C.sqlite_error_t)(unsafe.Pointer(&ret.val)) - return nil, toErr(spinErr) - } - - qr := (*C.sqlite_query_result_t)(unsafe.Pointer(&ret.val)) - - result := &rows{ - columns: fromSqliteListString(qr.columns), - rows: fromSqliteListRowResult(qr.rows), - len: int(qr.rows.len), - } - - return result, nil -} - -func fromSqliteListRowResult(list C.sqlite_list_row_result_t) [][]any { - listLen := int(list.len) - ret := make([][]any, listLen) - slice := unsafe.Slice(list.ptr, listLen) - for i := 0; i < listLen; i++ { - row := *((*C.sqlite_list_value_t)(unsafe.Pointer(&slice[i]))) - ret[i] = fromSqliteListValue(row) - } - return ret - -} - -func fromSqliteListString(list C.sqlite_list_string_t) []string { - listLen := int(list.len) - ret := make([]string, listLen) - slice := unsafe.Slice(list.ptr, listLen) - for i := 0; i < listLen; i++ { - str := slice[i] - ret[i] = C.GoStringN(str.ptr, C.int(str.len)) - } - return ret -} - -func fromSqliteListValue(list C.sqlite_list_value_t) []any { - listLen := int(list.len) - ret := make([]any, listLen) - slice := unsafe.Slice(list.ptr, listLen) - for i := 0; i < listLen; i++ { - ret[i] = fromSqliteValue(slice[i]) - } - return ret -} - -func toSqliteListValue(xv []any) C.sqlite_list_value_t { - if len(xv) == 0 { - return C.sqlite_list_value_t{} - } - cxv := make([]C.sqlite_value_t, len(xv)) - for i := 0; i < len(xv); i++ { - cxv[i] = toSqliteValue(xv[i]) - } - return C.sqlite_list_value_t{ptr: &cxv[0], len: C.size_t(len(cxv))} -} - -const ( - valueInt uint8 = iota - valueReal - valueText - valueBlob - valueNull -) - -func toSqliteValue(x any) C.sqlite_value_t { - var ret C.sqlite_value_t - switch v := x.(type) { - case int: - *(*C.int64_t)(unsafe.Pointer(&ret.val)) = int64(v) - ret.tag = valueInt - case int64: - *(*C.int64_t)(unsafe.Pointer(&ret.val)) = v - ret.tag = valueInt - case float64: - *(*C.double)(unsafe.Pointer(&ret.val)) = v - ret.tag = valueReal - case string: - str := sqliteStr(v) - *(*C.sqlite_string_t)(unsafe.Pointer(&ret.val)) = str - ret.tag = valueText - case []byte: - blob := C.sqlite_list_u8_t{ptr: &v[0], len: C.size_t(len(v))} - *(*C.sqlite_list_u8_t)(unsafe.Pointer(&ret.val)) = blob - ret.tag = valueBlob - default: - ret.tag = valueNull - } - return ret -} - -func fromSqliteValue(x C.sqlite_value_t) any { - switch x.tag { - case valueInt: - return int64(*(*C.int64_t)(unsafe.Pointer(&x.val))) - case valueReal: - return float64(*(*C.double)(unsafe.Pointer(&x.val))) - case valueBlob: - blob := (*C.sqlite_list_u8_t)(unsafe.Pointer(&x.val)) - return C.GoBytes(unsafe.Pointer(blob.ptr), C.int(blob.len)) - case valueText: - str := (*C.sqlite_string_t)(unsafe.Pointer(&x.val)) - return C.GoStringN(str.ptr, C.int(str.len)) - } - return nil -} - -func sqliteStr(x string) C.sqlite_string_t { - return C.sqlite_string_t{ptr: C.CString(x), len: C.size_t(len(x))} -} - -func toErr(err *C.sqlite_error_t) error { - switch err.tag { - case 0: - return errors.New("no such database") - case 1: - return errors.New("access denied") - case 2: - return errors.New("invalid connection") - case 3: - return errors.New("database full") - case 4: - str := (*C.sqlite_string_t)(unsafe.Pointer(&err.val)) - return errors.New(fmt.Sprintf("io error: %s", C.GoStringN(str.ptr, C.int(str.len)))) - default: - return errors.New(fmt.Sprintf("unrecognized error: %v", err.tag)) - } -} diff --git a/sdk/go/sqlite/internals_test.go b/sdk/go/sqlite/internals_test.go deleted file mode 100644 index 7e85bb0546..0000000000 --- a/sdk/go/sqlite/internals_test.go +++ /dev/null @@ -1,38 +0,0 @@ -package sqlite - -import ( - "reflect" - "testing" -) - -func TestValue(t *testing.T) { - tests := []any{ - int64(1234), - 3.14, - "foo", - []byte("bar"), - nil, - } - - for _, tc := range tests { - got := fromSqliteValue(toSqliteValue(tc)) - if !reflect.DeepEqual(tc, got) { - t.Errorf("want %T(%#v), got %T(%#v)", tc, tc, got, got) - } - } -} - -func TestValueList(t *testing.T) { - tc := []any{ - int64(1234), - 3.14, - "foo", - []byte("bar"), - nil, - } - - got := fromSqliteListValue(toSqliteListValue(tc)) - if !reflect.DeepEqual(tc, got) { - t.Errorf("want %v, got %v", tc, got) - } -} diff --git a/sdk/go/sqlite/sqlite.c b/sdk/go/sqlite/sqlite.c deleted file mode 100644 index 62e08af8f6..0000000000 --- a/sdk/go/sqlite/sqlite.c +++ /dev/null @@ -1,200 +0,0 @@ -#include -#include - -__attribute__((weak, export_name("canonical_abi_realloc"))) -void *canonical_abi_realloc( -void *ptr, -size_t orig_size, -size_t align, -size_t new_size -) { - if (new_size == 0) - return (void*) align; - void *ret = realloc(ptr, new_size); - if (!ret) - abort(); - return ret; -} - -__attribute__((weak, export_name("canonical_abi_free"))) -void canonical_abi_free( -void *ptr, -size_t size, -size_t align -) { - if (size == 0) - return; - free(ptr); -} -#include - -void sqlite_string_set(sqlite_string_t *ret, const char *s) { - ret->ptr = (char*) s; - ret->len = strlen(s); -} - -void sqlite_string_dup(sqlite_string_t *ret, const char *s) { - ret->len = strlen(s); - ret->ptr = canonical_abi_realloc(NULL, 0, 1, ret->len); - memcpy(ret->ptr, s, ret->len); -} - -void sqlite_string_free(sqlite_string_t *ret) { - canonical_abi_free(ret->ptr, ret->len, 1); - ret->ptr = NULL; - ret->len = 0; -} -void sqlite_error_free(sqlite_error_t *ptr) { - switch ((int32_t) ptr->tag) { - case 4: { - sqlite_string_free(&ptr->val.io); - break; - } - } -} -void sqlite_list_string_free(sqlite_list_string_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - sqlite_string_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 8, 4); -} -void sqlite_list_u8_free(sqlite_list_u8_t *ptr) { - canonical_abi_free(ptr->ptr, ptr->len * 1, 1); -} -void sqlite_value_free(sqlite_value_t *ptr) { - switch ((int32_t) ptr->tag) { - case 2: { - sqlite_string_free(&ptr->val.text); - break; - } - case 3: { - sqlite_list_u8_free(&ptr->val.blob); - break; - } - } -} -void sqlite_list_value_free(sqlite_list_value_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - sqlite_value_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 16, 8); -} -void sqlite_row_result_free(sqlite_row_result_t *ptr) { - sqlite_list_value_free(&ptr->values); -} -void sqlite_list_row_result_free(sqlite_list_row_result_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - sqlite_row_result_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 8, 4); -} -void sqlite_query_result_free(sqlite_query_result_t *ptr) { - sqlite_list_string_free(&ptr->columns); - sqlite_list_row_result_free(&ptr->rows); -} -void sqlite_expected_connection_error_free(sqlite_expected_connection_error_t *ptr) { - if (!ptr->is_err) { - } else { - sqlite_error_free(&ptr->val.err); - } -} -void sqlite_expected_query_result_error_free(sqlite_expected_query_result_error_t *ptr) { - if (!ptr->is_err) { - sqlite_query_result_free(&ptr->val.ok); - } else { - sqlite_error_free(&ptr->val.err); - } -} - -__attribute__((aligned(4))) -static uint8_t RET_AREA[20]; -__attribute__((import_module("sqlite"), import_name("open"))) -void __wasm_import_sqlite_open(int32_t, int32_t, int32_t); -void sqlite_open(sqlite_string_t *name, sqlite_expected_connection_error_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_sqlite_open((int32_t) (*name).ptr, (int32_t) (*name).len, ptr); - sqlite_expected_connection_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = (uint32_t) (*((int32_t*) (ptr + 4))); - break; - } - case 1: { - expected.is_err = true; - sqlite_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant.tag) { - case 0: { - break; - } - case 1: { - break; - } - case 2: { - break; - } - case 3: { - break; - } - case 4: { - variant.val.io = (sqlite_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - } - - expected.val.err = variant; - break; - } - }*ret0 = expected; -} -__attribute__((import_module("sqlite"), import_name("execute"))) -void __wasm_import_sqlite_execute(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); -void sqlite_execute(sqlite_connection_t conn, sqlite_string_t *statement, sqlite_list_value_t *parameters, sqlite_expected_query_result_error_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_sqlite_execute((int32_t) (conn), (int32_t) (*statement).ptr, (int32_t) (*statement).len, (int32_t) (*parameters).ptr, (int32_t) (*parameters).len, ptr); - sqlite_expected_query_result_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = (sqlite_query_result_t) { - (sqlite_list_string_t) { (sqlite_string_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }, - (sqlite_list_row_result_t) { (sqlite_row_result_t*)(*((int32_t*) (ptr + 12))), (size_t)(*((int32_t*) (ptr + 16))) }, - }; - break; - } - case 1: { - expected.is_err = true; - sqlite_error_t variant4; - variant4.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant4.tag) { - case 0: { - break; - } - case 1: { - break; - } - case 2: { - break; - } - case 3: { - break; - } - case 4: { - variant4.val.io = (sqlite_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - } - - expected.val.err = variant4; - break; - } - }*ret0 = expected; -} -__attribute__((import_module("sqlite"), import_name("close"))) -void __wasm_import_sqlite_close(int32_t); -void sqlite_close(sqlite_connection_t conn) { - __wasm_import_sqlite_close((int32_t) (conn)); -} diff --git a/sdk/go/sqlite/sqlite.go b/sdk/go/sqlite/sqlite.go deleted file mode 100644 index b4778e53e9..0000000000 --- a/sdk/go/sqlite/sqlite.go +++ /dev/null @@ -1,186 +0,0 @@ -package sqlite - -import ( - "context" - "database/sql" - "database/sql/driver" - "errors" - "io" - - spindb "github.com/fermyon/spin/sdk/go/v2/internal/db" -) - -// Open returns a new connection to the database. -func Open(name string) *sql.DB { - return sql.OpenDB(&connector{name: name}) -} - -// conn represents a database connection. -type conn struct { - _ptr uint32 -} - -// Close the connection. -func (c *conn) Close() error { - c.close() - return nil -} - -// Prepare returns a prepared statement, bound to this connection. -func (c *conn) Prepare(query string) (driver.Stmt, error) { - return &stmt{c: c, query: query}, nil -} - -// Begin isn't supported. -func (c *conn) Begin() (driver.Tx, error) { - return nil, errors.New("transactions are unsupported by this driver") -} - -// connector implements driver.Connector. -type connector struct { - conn *conn - name string -} - -// Connect returns a connection to the database. -func (d *connector) Connect(_ context.Context) (driver.Conn, error) { - if d.conn != nil { - return d.conn, nil - } - - return d.Open(d.name) -} - -// Driver returns the underlying Driver of the Connector. -func (d *connector) Driver() driver.Driver { - return d -} - -// Open returns a new connection to the database. -func (d *connector) Open(name string) (driver.Conn, error) { - conn, err := open(name) - if err != nil { - return nil, err - } - - d.conn = conn - - return conn, err -} - -// Close closes the connection to the database. -func (d *connector) Close() error { - if d.conn != nil { - d.conn.Close() - } - - return nil -} - -type rows struct { - columns []string - pos int - len int - rows [][]any - closed bool -} - -var _ driver.Rows = (*rows)(nil) - -// Columns return column names. -func (r *rows) Columns() []string { - return r.columns -} - -// Close closes the rows iterator. -func (r *rows) Close() error { - r.rows = nil - r.pos = 0 - r.len = 0 - r.closed = true - return nil -} - -// Next moves the cursor to the next row. -func (r *rows) Next(dest []driver.Value) error { - if !r.HasNextResultSet() { - return io.EOF - } - for i := 0; i != len(r.columns); i++ { - dest[i] = driver.Value(r.rows[r.pos][i]) - } - r.pos++ - return nil -} - -// HasNextResultSet is called at the end of the current result set and -// reports whether there is another result set after the current one. -func (r *rows) HasNextResultSet() bool { - return r.pos < r.len -} - -// NextResultSet advances the driver to the next result set even -// if there are remaining rows in the current result set. -// -// NextResultSet should return io.EOF when there are no more result sets. -func (r *rows) NextResultSet() error { - if r.HasNextResultSet() { - r.pos++ - return nil - } - return io.EOF // Per interface spec. -} - -type stmt struct { - c *conn - query string -} - -var _ driver.Stmt = (*stmt)(nil) -var _ driver.ColumnConverter = (*stmt)(nil) - -// Close closes the statement. -func (s *stmt) Close() error { - return nil -} - -// NumInput returns the number of placeholder parameters. -func (s *stmt) NumInput() int { - // Golang sql won't sanity check argument counts before Query. - return -1 -} - -// Query executes a query that may return rows, such as a SELECT. -func (s *stmt) Query(args []driver.Value) (driver.Rows, error) { - params := make([]any, len(args)) - for i := range args { - params[i] = args[i] - } - return s.c.execute(s.query, params) -} - -// Exec executes a query that doesn't return rows, such as an INSERT or -// UPDATE. -func (s *stmt) Exec(args []driver.Value) (driver.Result, error) { - params := make([]any, len(args)) - for i := range args { - params[i] = args[i] - } - _, err := s.c.execute(s.query, params) - return &result{}, err -} - -// ColumnConverter returns GlobalParameterConverter to prevent using driver.DefaultParameterConverter. -func (s *stmt) ColumnConverter(_ int) driver.ValueConverter { - return spindb.GlobalParameterConverter -} - -type result struct{} - -func (r result) LastInsertId() (int64, error) { - return -1, errors.New("LastInsertId is unsupported by this driver") -} - -func (r result) RowsAffected() (int64, error) { - return -1, errors.New("RowsAffected is unsupported by this driver") -} diff --git a/sdk/go/sqlite/sqlite.h b/sdk/go/sqlite/sqlite.h deleted file mode 100644 index 7d2e0cd29e..0000000000 --- a/sdk/go/sqlite/sqlite.h +++ /dev/null @@ -1,98 +0,0 @@ -#ifndef __BINDINGS_SQLITE_H -#define __BINDINGS_SQLITE_H -#ifdef __cplusplus -extern "C" -{ - #endif - - #include - #include - - typedef struct { - char *ptr; - size_t len; - } sqlite_string_t; - - void sqlite_string_set(sqlite_string_t *ret, const char *s); - void sqlite_string_dup(sqlite_string_t *ret, const char *s); - void sqlite_string_free(sqlite_string_t *ret); - typedef uint32_t sqlite_connection_t; - typedef struct { - uint8_t tag; - union { - sqlite_string_t io; - } val; - } sqlite_error_t; - #define SQLITE_ERROR_NO_SUCH_DATABASE 0 - #define SQLITE_ERROR_ACCESS_DENIED 1 - #define SQLITE_ERROR_INVALID_CONNECTION 2 - #define SQLITE_ERROR_DATABASE_FULL 3 - #define SQLITE_ERROR_IO 4 - void sqlite_error_free(sqlite_error_t *ptr); - typedef struct { - sqlite_string_t *ptr; - size_t len; - } sqlite_list_string_t; - void sqlite_list_string_free(sqlite_list_string_t *ptr); - typedef struct { - uint8_t *ptr; - size_t len; - } sqlite_list_u8_t; - void sqlite_list_u8_free(sqlite_list_u8_t *ptr); - typedef struct { - uint8_t tag; - union { - int64_t integer; - double real; - sqlite_string_t text; - sqlite_list_u8_t blob; - } val; - } sqlite_value_t; - #define SQLITE_VALUE_INTEGER 0 - #define SQLITE_VALUE_REAL 1 - #define SQLITE_VALUE_TEXT 2 - #define SQLITE_VALUE_BLOB 3 - #define SQLITE_VALUE_NULL 4 - void sqlite_value_free(sqlite_value_t *ptr); - typedef struct { - sqlite_value_t *ptr; - size_t len; - } sqlite_list_value_t; - void sqlite_list_value_free(sqlite_list_value_t *ptr); - typedef struct { - sqlite_list_value_t values; - } sqlite_row_result_t; - void sqlite_row_result_free(sqlite_row_result_t *ptr); - typedef struct { - sqlite_row_result_t *ptr; - size_t len; - } sqlite_list_row_result_t; - void sqlite_list_row_result_free(sqlite_list_row_result_t *ptr); - typedef struct { - sqlite_list_string_t columns; - sqlite_list_row_result_t rows; - } sqlite_query_result_t; - void sqlite_query_result_free(sqlite_query_result_t *ptr); - typedef struct { - bool is_err; - union { - sqlite_connection_t ok; - sqlite_error_t err; - } val; - } sqlite_expected_connection_error_t; - void sqlite_expected_connection_error_free(sqlite_expected_connection_error_t *ptr); - typedef struct { - bool is_err; - union { - sqlite_query_result_t ok; - sqlite_error_t err; - } val; - } sqlite_expected_query_result_error_t; - void sqlite_expected_query_result_error_free(sqlite_expected_query_result_error_t *ptr); - void sqlite_open(sqlite_string_t *name, sqlite_expected_connection_error_t *ret0); - void sqlite_execute(sqlite_connection_t conn, sqlite_string_t *statement, sqlite_list_value_t *parameters, sqlite_expected_query_result_error_t *ret0); - void sqlite_close(sqlite_connection_t conn); - #ifdef __cplusplus -} -#endif -#endif diff --git a/sdk/go/variables/internals.go b/sdk/go/variables/internals.go deleted file mode 100644 index 97ab580b81..0000000000 --- a/sdk/go/variables/internals.go +++ /dev/null @@ -1,42 +0,0 @@ -package variables - -// #cgo CFLAGS: -Wno-unused-parameter -Wno-switch-bool -// #include -// #include -import "C" -import ( - "errors" - "unsafe" -) - -func get(key string) (string, error) { - var spinResponse C.spin_config_expected_string_error_t - - spinKey := C.spin_config_string_t{ptr: C.CString(key), len: C.size_t(len(key))} - defer func() { - C.spin_config_expected_string_error_free(&spinResponse) - C.spin_config_string_free(&spinKey) - }() - - C.spin_config_get_config(&spinKey, &spinResponse) - - if spinResponse.is_err { // error response from spin - spinErr := (*C.spin_config_error_t)(unsafe.Pointer(&spinResponse.val)) - return "", toError(spinErr) - } - - ok := (*spinString)(unsafe.Pointer(&spinResponse.val)) - return ok.String(), nil -} - -func toError(err *C.spin_config_error_t) error { - spinErr := (*spinString)(unsafe.Pointer(&err.val)) - return errors.New(spinErr.String()) -} - -type spinString C.spin_config_string_t - -// String returns the spinString as a go string. -func (ss spinString) String() string { - return C.GoStringN(ss.ptr, C.int(ss.len)) -} diff --git a/sdk/go/variables/spin-config.c b/sdk/go/variables/spin-config.c deleted file mode 100644 index b2d1ab02e3..0000000000 --- a/sdk/go/variables/spin-config.c +++ /dev/null @@ -1,117 +0,0 @@ -#include -#include - -__attribute__((weak, export_name("canonical_abi_realloc"))) -void *canonical_abi_realloc( -void *ptr, -size_t orig_size, -size_t align, -size_t new_size -) { - if (new_size == 0) - return (void*) align; - void *ret = realloc(ptr, new_size); - if (!ret) - abort(); - return ret; -} - -__attribute__((weak, export_name("canonical_abi_free"))) -void canonical_abi_free( -void *ptr, -size_t size, -size_t align -) { - if (size == 0) - return; - free(ptr); -} -#include - -void spin_config_string_set(spin_config_string_t *ret, const char *s) { - ret->ptr = (char*) s; - ret->len = strlen(s); -} - -void spin_config_string_dup(spin_config_string_t *ret, const char *s) { - ret->len = strlen(s); - ret->ptr = canonical_abi_realloc(NULL, 0, 1, ret->len); - memcpy(ret->ptr, s, ret->len); -} - -void spin_config_string_free(spin_config_string_t *ret) { - canonical_abi_free(ret->ptr, ret->len, 1); - ret->ptr = NULL; - ret->len = 0; -} -void spin_config_error_free(spin_config_error_t *ptr) { - switch ((int32_t) ptr->tag) { - case 0: { - spin_config_string_free(&ptr->val.provider); - break; - } - case 1: { - spin_config_string_free(&ptr->val.invalid_key); - break; - } - case 2: { - spin_config_string_free(&ptr->val.invalid_schema); - break; - } - case 3: { - spin_config_string_free(&ptr->val.other); - break; - } - } -} -void spin_config_expected_string_error_free(spin_config_expected_string_error_t *ptr) { - if (!ptr->is_err) { - spin_config_string_free(&ptr->val.ok); - } else { - spin_config_error_free(&ptr->val.err); - } -} - -__attribute__((aligned(4))) -static uint8_t RET_AREA[16]; -__attribute__((import_module("spin-config"), import_name("get-config"))) -void __wasm_import_spin_config_get_config(int32_t, int32_t, int32_t); -void spin_config_get_config(spin_config_string_t *key, spin_config_expected_string_error_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_spin_config_get_config((int32_t) (*key).ptr, (int32_t) (*key).len, ptr); - spin_config_expected_string_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = (spin_config_string_t) { (char*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }; - break; - } - case 1: { - expected.is_err = true; - spin_config_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant.tag) { - case 0: { - variant.val.provider = (spin_config_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - case 1: { - variant.val.invalid_key = (spin_config_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - case 2: { - variant.val.invalid_schema = (spin_config_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - case 3: { - variant.val.other = (spin_config_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - } - - expected.val.err = variant; - break; - } - }*ret0 = expected; -} diff --git a/sdk/go/variables/spin-config.h b/sdk/go/variables/spin-config.h deleted file mode 100644 index 46be58d4d4..0000000000 --- a/sdk/go/variables/spin-config.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef __BINDINGS_SPIN_CONFIG_H -#define __BINDINGS_SPIN_CONFIG_H -#ifdef __cplusplus -extern "C" -{ - #endif - - #include - #include - - typedef struct { - char *ptr; - size_t len; - } spin_config_string_t; - - void spin_config_string_set(spin_config_string_t *ret, const char *s); - void spin_config_string_dup(spin_config_string_t *ret, const char *s); - void spin_config_string_free(spin_config_string_t *ret); - typedef struct { - uint8_t tag; - union { - spin_config_string_t provider; - spin_config_string_t invalid_key; - spin_config_string_t invalid_schema; - spin_config_string_t other; - } val; - } spin_config_error_t; - #define SPIN_CONFIG_ERROR_PROVIDER 0 - #define SPIN_CONFIG_ERROR_INVALID_KEY 1 - #define SPIN_CONFIG_ERROR_INVALID_SCHEMA 2 - #define SPIN_CONFIG_ERROR_OTHER 3 - void spin_config_error_free(spin_config_error_t *ptr); - typedef struct { - bool is_err; - union { - spin_config_string_t ok; - spin_config_error_t err; - } val; - } spin_config_expected_string_error_t; - void spin_config_expected_string_error_free(spin_config_expected_string_error_t *ptr); - void spin_config_get_config(spin_config_string_t *key, spin_config_expected_string_error_t *ret0); - #ifdef __cplusplus -} -#endif -#endif diff --git a/sdk/go/variables/variables.go b/sdk/go/variables/variables.go deleted file mode 100644 index 5a669a14b4..0000000000 --- a/sdk/go/variables/variables.go +++ /dev/null @@ -1,8 +0,0 @@ -package variables - -// Get an application variable value for the current component. -// -// The name must match one defined in in the component manifest. -func Get(key string) (string, error) { - return get(key) -} diff --git a/sdk/go/wit/http-types.wit b/sdk/go/wit/http-types.wit deleted file mode 100644 index e062695429..0000000000 --- a/sdk/go/wit/http-types.wit +++ /dev/null @@ -1,59 +0,0 @@ -// This is a temporary workaround very similar to https://github.com/deislabs/wasi-experimental-http. -// Once asynchronous functions, streams, and the upstream HTTP API are available, this should be removed. - -// The HTTP status code. -// This is currently an unsigned 16-bit integer, -// but it could be represented as an enum containing -// all possible HTTP status codes. -type http-status = u16 - -// The HTTP body. -// Currently, this is a synchonous byte array, but it should be -// possible to have a stream for both request and response bodies. -type body = list - -// The HTTP headers represented as a list of (name, value) pairs. -type headers = list> - -// The HTTP parameter queries, represented as a list of (name, value) pairs. -type params = list> - -// The HTTP URI of the current request. -type uri = string - -// The HTTP method. -enum method { - get, - post, - put, - delete, - patch, - head, - options, -} - -// An HTTP request. -record request { - method: method, - uri: uri, - headers: headers, - params: params, - body: option, -} - -// An HTTP response. -record response { - status: http-status, - headers: option, - body: option, -} - -// HTTP errors returned by the runtime. -enum http-error { - success, - destination-not-allowed, - invalid-url, - request-error, - runtime-error, - too-many-requests, -} diff --git a/sdk/go/wit/key-value.wit b/sdk/go/wit/key-value.wit deleted file mode 100644 index a37b1d4825..0000000000 --- a/sdk/go/wit/key-value.wit +++ /dev/null @@ -1,78 +0,0 @@ -// A handle to an open key-value store -type store = u32 - -// The set of errors which may be raised by functions in this interface -variant error { - // Too many stores have been opened simultaneously. Closing one or more - // stores prior to retrying may address this. - store-table-full, - - // The host does not recognize the store name requested. Defining and - // configuring a store with that name in a runtime configuration file - // may address this. - no-such-store, - - // The requesting component does not have access to the specified store - // (which may or may not exist). - access-denied, - - // The store handle provided is not recognized, i.e. it was either never - // opened or has been closed. - invalid-store, - - // No key-value tuple exists for the specified key in the specified - // store. - no-such-key, - - // Some implementation-specific error has occurred (e.g. I/O) - io(string) -} - -// Open the store with the specified name. -// -// If `name` is "default", the default store is opened. Otherwise, -// `name` must refer to a store defined and configured in a runtime -// configuration file supplied with the application. -// -// `error::no-such-store` will be raised if the `name` is not recognized. -open: func(name: string) -> expected - -// Get the value associated with the specified `key` from the specified -// `store`. -// -// `error::invalid-store` will be raised if `store` is not a valid handle -// to an open store, and `error::no-such-key` will be raised if there is no -// tuple for `key` in `store`. -get: func(store: store, key: string) -> expected, error> - -// Set the `value` associated with the specified `key` in the specified -// `store`, overwriting any existing value. -// -// `error::invalid-store` will be raised if `store` is not a valid handle -// to an open store. -set: func(store: store, key: string, value: list) -> expected - -// Delete the tuple with the specified `key` from the specified `store`. -// -// `error::invalid-store` will be raised if `store` is not a valid handle -// to an open store. No error is raised if a tuple did not previously -// exist for `key`. -delete: func(store: store, key: string) -> expected - -// Return whether a tuple exists for the specified `key` in the specified -// `store`. -// -// `error::invalid-store` will be raised if `store` is not a valid handle -// to an open store. -exists: func(store: store, key: string) -> expected - -// Return a list of all the keys in the specified `store`. -// -// `error::invalid-store` will be raised if `store` is not a valid handle -// to an open store. -get-keys: func(store: store) -> expected, error> - -// Close the specified `store`. -// -// This has no effect if `store` is not a valid handle to an open store. -close: func(store: store) diff --git a/sdk/go/wit/mysql-types.wit b/sdk/go/wit/mysql-types.wit deleted file mode 100644 index a18f5d7375..0000000000 --- a/sdk/go/wit/mysql-types.wit +++ /dev/null @@ -1,10 +0,0 @@ -// General purpose error. -// TODO: We can provide richer info than this: https://docs.rs/mysql/latest/mysql/error/enum.Error.html -variant mysql-error { - success, - connection-failed(string), - bad-parameter(string), - query-failed(string), - value-conversion-failed(string), - other-error(string) -} diff --git a/sdk/go/wit/outbound-mysql.wit b/sdk/go/wit/outbound-mysql.wit deleted file mode 100644 index 8cd0727754..0000000000 --- a/sdk/go/wit/outbound-mysql.wit +++ /dev/null @@ -1,8 +0,0 @@ -use * from mysql-types -use * from rdbms-types - -// query the database: select -query: func(address: string, statement: string, params: list) -> expected - -// execute command to the database: insert, update, delete -execute: func(address: string, statement: string, params: list) -> expected diff --git a/sdk/go/wit/outbound-pg.wit b/sdk/go/wit/outbound-pg.wit deleted file mode 100644 index 94a7c7994b..0000000000 --- a/sdk/go/wit/outbound-pg.wit +++ /dev/null @@ -1,8 +0,0 @@ -use * from pg-types -use * from rdbms-types - -// query the database: select -query: func(address: string, statement: string, params: list) -> expected - -// execute command to the database: insert, update, delete -execute: func(address: string, statement: string, params: list) -> expected diff --git a/sdk/go/wit/outbound-redis.wit b/sdk/go/wit/outbound-redis.wit deleted file mode 100644 index 5a7cbd4c26..0000000000 --- a/sdk/go/wit/outbound-redis.wit +++ /dev/null @@ -1,29 +0,0 @@ -use * from redis-types - -// Publish a Redis message to the specificed channel and return an error, if any. -publish: func(address: string, channel: string, payload: payload) -> expected - -// Get the value of a key. -get: func(address: string, key: string) -> expected - -// Set key to value. If key alreads holds a value, it is overwritten. -set: func(address: string, key: string, value: payload) -> expected - -// Increments the number stored at key by one. If the key does not exist, it is set to 0 before performing the operation. -// An error is returned if the key contains a value of the wrong type or contains a string that can not be represented as integer. -incr: func(address: string, key: string) -> expected - -// Removes the specified keys. A key is ignored if it does not exist. -del: func(address: string, keys: list) -> expected - -// Add the specified `values` to the set named `key`, returning the number of newly-added values. -sadd: func(address: string, key: string, values: list) -> expected - -// Retrieve the contents of the set named `key`. -smembers: func(address: string, key: string) -> expected, error> - -// Remove the specified `values` from the set named `key`, returning the number of newly-removed values. -srem: func(address: string, key: string, values: list) -> expected - -// Execute an arbitrary Redis command and receive the result. -execute: func(address: string, command: string, arguments: list) -> expected, error> diff --git a/sdk/go/wit/pg-types.wit b/sdk/go/wit/pg-types.wit deleted file mode 100644 index 8e0336b6b5..0000000000 --- a/sdk/go/wit/pg-types.wit +++ /dev/null @@ -1,9 +0,0 @@ -// General purpose error. -variant pg-error { - success, - connection-failed(string), - bad-parameter(string), - query-failed(string), - value-conversion-failed(string), - other-error(string) -} diff --git a/sdk/go/wit/rdbms-types.wit b/sdk/go/wit/rdbms-types.wit deleted file mode 100644 index 393479ae2c..0000000000 --- a/sdk/go/wit/rdbms-types.wit +++ /dev/null @@ -1,63 +0,0 @@ -enum db-data-type { - boolean, - int8, - int16, - int32, - int64, - uint8, - uint16, - uint32, - uint64, - floating32, - floating64, - str, - binary, - other, -} - -variant db-value { - boolean(bool), - int8(s8), - int16(s16), - int32(s32), - int64(s64), - uint8(u8), - uint16(u16), - uint32(u32), - uint64(u64), - floating32(float32), - floating64(float64), - str(string), - binary(list), - db-null, - unsupported, -} - -variant parameter-value { - boolean(bool), - int8(s8), - int16(s16), - int32(s32), - int64(s64), - uint8(u8), - uint16(u16), - uint32(u32), - uint64(u64), - floating32(float32), - floating64(float64), - str(string), - binary(list), - db-null, -} - -record column { - name: string, - data-type: db-data-type, -} - -type row = list - -record row-set { - columns: list, - rows: list, -} diff --git a/sdk/go/wit/redis-types.wit b/sdk/go/wit/redis-types.wit deleted file mode 100644 index 2f45ddfff7..0000000000 --- a/sdk/go/wit/redis-types.wit +++ /dev/null @@ -1,22 +0,0 @@ -// General purpose error. -enum error { - success, - error, -} - -// The message payload. -type payload = list - -// A parameter type for the general-purpose `execute` function. -variant redis-parameter { - int64(s64), - binary(payload) -} - -// A return type for the general-purpose `execute` function. -variant redis-result { - nil, - status(string), - int64(s64), - binary(payload) -} diff --git a/sdk/go/wit/spin-config.wit b/sdk/go/wit/spin-config.wit deleted file mode 100644 index d4788522c2..0000000000 --- a/sdk/go/wit/spin-config.wit +++ /dev/null @@ -1,10 +0,0 @@ -// Get a configuration value for the current component. -// The config key must match one defined in in the component manifest. -get-config: func(key: string) -> expected - -variant error { - provider(string), - invalid-key(string), - invalid-schema(string), - other(string), -} \ No newline at end of file diff --git a/sdk/go/wit/spin-http.wit b/sdk/go/wit/spin-http.wit deleted file mode 100644 index 27da74272b..0000000000 --- a/sdk/go/wit/spin-http.wit +++ /dev/null @@ -1,4 +0,0 @@ -use * from http-types - -// The entrypoint for an HTTP handler. -handle-http-request: func(req: request) -> response diff --git a/sdk/go/wit/spin-redis.wit b/sdk/go/wit/spin-redis.wit deleted file mode 100644 index c51c3b47e6..0000000000 --- a/sdk/go/wit/spin-redis.wit +++ /dev/null @@ -1,4 +0,0 @@ -use * from redis-types - -// The entrypoint for a Redis handler. -handle-redis-message: func(message: payload) -> expected diff --git a/sdk/go/wit/sqlite.wit b/sdk/go/wit/sqlite.wit deleted file mode 100644 index 8bf9384b55..0000000000 --- a/sdk/go/wit/sqlite.wit +++ /dev/null @@ -1,50 +0,0 @@ -// A handle to an open sqlite instance -type connection = u32 - -// The set of errors which may be raised by functions in this interface -variant error { - // The host does not recognize the database name requested. - no-such-database, - // The requesting component does not have access to the specified database (which may or may not exist). - access-denied, - // The provided connection is not valid - invalid-connection, - // The database has reached its capacity - database-full, - // Some implementation-specific error has occurred (e.g. I/O) - io(string) -} - -// Open a connection to a named database instance. -// -// If `database` is "default", the default instance is opened. -// -// `error::no-such-database` will be raised if the `name` is not recognized. -open: func(name: string) -> expected - -// Execute a statement -execute: func(conn: connection, statement: string, parameters: list) -> expected - -// Close the specified `connection`. -close: func(conn: connection) - -// A result of a query -record query-result { - // The names of the columns retrieved in the query - columns: list, - // the row results each containing the values for all the columns for a given row - rows: list, -} - -// A set of values for each of the columns in a query-result -record row-result { - values: list -} - -variant value { - integer(s64), - real(float64), - text(string), - blob(list), - null -} diff --git a/sdk/go/wit/wasi-outbound-http.wit b/sdk/go/wit/wasi-outbound-http.wit deleted file mode 100644 index 0502129d63..0000000000 --- a/sdk/go/wit/wasi-outbound-http.wit +++ /dev/null @@ -1,4 +0,0 @@ -use * from http-types - -// Send an HTTP request and return a response or a potential error. -request: func(req: request) -> expected diff --git a/sdk/rust/Cargo.toml b/sdk/rust/Cargo.toml deleted file mode 100644 index 48273b0896..0000000000 --- a/sdk/rust/Cargo.toml +++ /dev/null @@ -1,43 +0,0 @@ -[package] -name = "spin-sdk" -version = { workspace = true } -authors = { workspace = true } -edition = { workspace = true } -license = { workspace = true } -homepage = { workspace = true } -repository = { workspace = true } -documentation = "https://docs.rs/spin-sdk" -readme = "README.md" -rust-version = { workspace = true } - -description = """ -The Spin Rust SDK makes it easy to build Spin components in Rust. -""" - -[lib] -name = "spin_sdk" - -[dependencies] -anyhow = "1" -async-trait = "0.1.74" -form_urlencoded = "1.0" -spin-macro = { version = "2.3.0-pre0", path = "macro" } -thiserror = "1.0.37" -wit-bindgen = "0.13.0" -routefinder = "0.5.3" -once_cell = "1.18.0" -futures = "0.3.28" -bytes = "1" -hyperium = { package = "http", version = "0.2" } -serde_json = { version = "1.0.96", optional = true } -serde = { version = "1.0.163", optional = true } - -[features] -default = ["export-sdk-language", "json"] -experimental = [] -export-sdk-language = [] -json = ["dep:serde", "dep:serde_json"] -# This was a default feature in the 2.0.0 release but couldn't be disabled -# without breakage. Retained here for backward compat and future reuse. -# TODO: Consider removing in a future release if it remains unused. -http = [] diff --git a/sdk/rust/README.md b/sdk/rust/README.md deleted file mode 100644 index 1e23a4e362..0000000000 --- a/sdk/rust/README.md +++ /dev/null @@ -1,112 +0,0 @@ -# The Spin Rust SDK - -The Spin Rust SDK makes it easy to build Spin components in Rust. - -## Fermyon Developer Home - -This `README` file provides a few examples, such as writing Spin HTTP components in Rust and making outbound HTTP requests. For comprehensive information, visit the official [Fermyon Developer Home](https://developer.fermyon.com/). This resource includes [a page on installing Spin](https://developer.fermyon.com/spin/v2/install#installing-spin), [a quickstart guide](https://developer.fermyon.com/spin/v2/quickstart), and [a language support overview page](https://developer.fermyon.com/spin/v2/language-support-overview). The latter lists all of Spin's features—including key-value storage, SQLite, MySQL, Redis, Serverless AI, etc.—and their implementation in specific languages such as Rust, TS/JS, Python, and TinyGo. - -### Writing Spin HTTP Components in Rust - -This library simplifies writing Spin HTTP components. Below is an example of -such a component: - -```rust -// lib.rs -use spin_sdk::http::{IntoResponse, Request, Response}; -use spin_sdk::http_component; - -/// A simple Spin HTTP component. -#[http_component] -fn handle_hello_world(req: Request) -> anyhow::Result { - println!("Handling request to {:?}", req.header("spin-full-url")); - Ok(Response::builder() - .status(200) - .header("content-type", "text/plain") - .body("Hello, Fermyon") - .build()) -} -``` - -The important things to note about the function above are: - -- the `spin_sdk::http_component` macro marks the function as the entry point for the Spin component, -- in the function signature (`fn handle_hello_world(req: Request) -> anyhow::Result`), `req` can be any number of types, including the built-in `Request` type or the `http::Request` type from the popular `http` crate -- in the function signature, the response type can be anything that implements `IntoResponse` meaning the return type can any number of things including `anyhow::Result` (as shown above), `impl IntoResponse`, `Response`, `anyhow::Result`, or even the `http::Response` type from the `http` crate. - - Note: Using the `http` crate will require you to add it to your Cargo.toml manifest (i.e., `cargo add http`). - -### Making Outbound HTTP Requests - -Let's see an example where the component makes an outbound HTTP request to a server, modifies the result, and then returns it: - -```rust -use spin_sdk::{ - http::{IntoResponse, Request, Method, Response}, - http_component, -}; - -#[http_component] -async fn handle_hello_world(_req: Request) -> Result { - // Create the outbound request object - let req = Request::builder() - .method(Method::Get) - .uri("https://random-data-api.fermyon.app/animals/json") - .build(); - - // Send the request and await the response - let res: Response = spin_sdk::http::send(req).await?; - - println!("{:?}", res); // log the response - Ok(res) -} -``` - -For the component above to be allowed to make the outbound HTTP request, the destination host must be declared, using the `allowed_outbound_hosts` configuration, in the Spin application's manifest (the `spin.toml` file): - -```toml -spin_manifest_version = 2 - -[application] -name = "hello_world" -version = "0.1.0" -authors = ["Your Name "] -description = "An example application" - -[[trigger.http]] -route = "/..." -component = "hello-world" - -[component.hello-world] -source = "target/wasm32-wasi/release/hello_world.wasm" -allowed_outbound_hosts = ["https://random-data-api.fermyon.app"] -[component.hello-world.build] -command = "cargo build --target wasm32-wasi --release" -watch = ["src/**/*.rs", "Cargo.toml"] -``` - -### Building and Running the Spin Application - -Spin build can be used to build all components defined in the Spin manifest file at the same time, and also has a flag that starts the application after finishing the compilation, `spin build --up`: - -```bash -$ spin build --up -Building component hello-world with `cargo build --target wasm32-wasi --release` - Finished release [optimized] target(s) in 0.12s -Finished building all Spin components -Logging component stdio to ".spin/logs/" - -Serving http://127.0.0.1:3000 -Available Routes: - hello-world: http://127.0.0.1:3000 (wildcard) -``` - -Once our application is running, we can make a request (by visiting `http://localhost:3000/` in a web browser) or using `curl` as shown below: - -```bash -$ curl -i localhost:3000 -HTTP/1.1 200 OK -content-length: 77 -content-type: application/json - -{"timestamp":1702599575198,"fact":"Sharks lay the biggest eggs in the world"} -``` diff --git a/sdk/rust/build.rs b/sdk/rust/build.rs deleted file mode 100644 index 5e27b420e2..0000000000 --- a/sdk/rust/build.rs +++ /dev/null @@ -1,28 +0,0 @@ -use std::process::Command; - -fn main() { - let pre = env!("CARGO_PKG_VERSION_PRE"); - let pre = if pre.is_empty() { - String::new() - } else { - format!("-{pre}") - }; - - let commit = Command::new("git") - .arg("rev-parse") - .arg("HEAD") - .output() - .ok() - .filter(|o| o.status.success()) - .map(|o| String::from_utf8_lossy(&o.stdout).to_string()) - .unwrap_or(String::from("unknown")); - - let commit = commit.trim(); - - println!( - "cargo:rustc-env=SDK_VERSION={}-{}{pre}", - env!("CARGO_PKG_VERSION_MAJOR"), - env!("CARGO_PKG_VERSION_MINOR"), - ); - println!("cargo:rustc-env=SDK_COMMIT={commit}"); -} diff --git a/sdk/rust/macro/Cargo.toml b/sdk/rust/macro/Cargo.toml deleted file mode 100644 index 97e1e7953b..0000000000 --- a/sdk/rust/macro/Cargo.toml +++ /dev/null @@ -1,26 +0,0 @@ -[package] -name = "spin-macro" -version = { workspace = true } -edition = { workspace = true } -authors = { workspace = true } -license = { workspace = true } -homepage = { workspace = true } -repository = { workspace = true } -documentation = "https://docs.rs/spin-macro" -readme = "README.md" - -description = """ -Rust procedural macros for Spin and associated WIT files -""" - -[lib] -name = "spin_macro" -proc-macro = true - -[dependencies] -anyhow = "1" -bytes = "1" -http = "0.2" -proc-macro2 = "1" -quote = "1.0" -syn = { version = "1.0", features = [ "full" ]} diff --git a/sdk/rust/macro/README.md b/sdk/rust/macro/README.md deleted file mode 100644 index c18b31fc41..0000000000 --- a/sdk/rust/macro/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# The spin-macro crate - -This crate contains procedural macros for Spin and associated WIT files. \ No newline at end of file diff --git a/sdk/rust/macro/src/lib.rs b/sdk/rust/macro/src/lib.rs deleted file mode 100644 index 957739583a..0000000000 --- a/sdk/rust/macro/src/lib.rs +++ /dev/null @@ -1,176 +0,0 @@ -use proc_macro::TokenStream; -use quote::quote; - -const WIT_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/wit"); - -/// Generates the entrypoint to a Spin Redis component written in Rust. -#[proc_macro_attribute] -pub fn redis_component(_attr: TokenStream, item: TokenStream) -> TokenStream { - let func = syn::parse_macro_input!(item as syn::ItemFn); - let func_name = &func.sig.ident; - let preamble = preamble(Export::Redis); - - quote!( - #func - mod __spin_redis { - mod preamble { - #preamble - } - impl self::preamble::exports::fermyon::spin::inbound_redis::Guest for preamble::Spin { - fn handle_message(msg: self::preamble::exports::fermyon::spin::inbound_redis::Payload) -> Result<(), self::preamble::fermyon::spin::redis_types::Error> { - match super::#func_name(msg.try_into().expect("cannot convert from Spin Redis payload")) { - Ok(()) => Ok(()), - Err(e) => { - eprintln!("{}", e); - Err(self::preamble::fermyon::spin::redis_types::Error::Error) - }, - } - } - } - } - ) - .into() -} - -/// The entrypoint to a WASI HTTP component written in Rust. -/// -/// Functions annotated with this attribute can be of two forms: -/// * Request/Response -/// * Input/Output Params -/// -/// When in doubt prefer the Request/Response variant unless streaming response bodies is something you need. -/// -/// ### Request/Response -/// -/// This form takes the form of a function with one `request` param and one `response` return value. -/// -/// Requests are anything that implements `spin_sdk::http::conversions::TryFromIncomingRequest` which includes -/// `spin_sdk::http::Request`, `spin_sdk::http::IncomingRequest`, and even hyperium's popular `http` crate's `Request` -/// type. -/// -/// Responses are anything that implements `spin_sdk::http::IntoResponse`. This includes `Result anyhow::Result { -/// // Your logic goes here -/// } -/// ``` -/// -/// ### Input/Output Params -/// -/// Input/Output functions allow for streaming HTTP bodies. This form is by its very nature harder to use than -/// the request/response form above so it should only be favored when stream response bodies is desired. -/// -/// The `request` param can be anything that implements `spin_sdk::http::TryFromIncomingRequest`. And -/// the `response_out` param must be a `spin_sdk::http::ResponseOutparam`. See the docs of `ResponseOutparam` -/// for how to use this type. -/// -/// For example: -/// -/// ```ignore -/// use spin_sdk::http_component; -/// use spin_sdk::http::{IncomingRequest, ResponseOutparam}; -/// -/// #[http_component] -/// async fn my_handler(request: IncomingRequest, response_out: ResponseOutparam) { -/// // Your logic goes here -/// } -/// ``` -#[proc_macro_attribute] -pub fn http_component(_attr: TokenStream, item: TokenStream) -> TokenStream { - let func = syn::parse_macro_input!(item as syn::ItemFn); - let func_name = &func.sig.ident; - let preamble = preamble(Export::WasiHttp); - let is_native_wasi_http_handler = func.sig.inputs.len() == 2; - let await_postfix = func.sig.asyncness.map(|_| quote!(.await)); - let handler = if is_native_wasi_http_handler { - quote! { super::#func_name(req, response_out)#await_postfix } - } else { - quote! { handle_response(response_out, super::#func_name(req)#await_postfix).await } - }; - - quote!( - #func - mod __spin_wasi_http { - mod preamble { - #preamble - } - impl self::preamble::exports::wasi::http::incoming_handler::Guest for self::preamble::Spin { - fn handle(request: self::preamble::wasi::http::types::IncomingRequest, response_out: self::preamble::wasi::http::types::ResponseOutparam) { - let request: ::spin_sdk::http::IncomingRequest = ::std::convert::Into::into(request); - let response_out: ::spin_sdk::http::ResponseOutparam = ::std::convert::Into::into(response_out); - ::spin_sdk::http::run(async move { - match ::spin_sdk::http::conversions::TryFromIncomingRequest::try_from_incoming_request(request).await { - ::std::result::Result::Ok(req) => #handler, - ::std::result::Result::Err(e) => handle_response(response_out, e).await, - } - }); - } - } - - async fn handle_response(response_out: ::spin_sdk::http::ResponseOutparam, resp: R) { - let mut response = ::spin_sdk::http::IntoResponse::into_response(resp); - let body = std::mem::take(response.body_mut()); - let response = ::std::convert::Into::into(response); - if let Err(e) = ::spin_sdk::http::ResponseOutparam::set_with_body(response_out, response, body).await { - eprintln!("Could not set `ResponseOutparam`: {e}"); - } - } - - impl From for ::spin_sdk::http::IncomingRequest { - fn from(req: self::preamble::wasi::http::types::IncomingRequest) -> Self { - unsafe { Self::from_handle(req.into_handle()) } - } - } - - impl From<::spin_sdk::http::OutgoingResponse> for self::preamble::wasi::http::types::OutgoingResponse { - fn from(resp: ::spin_sdk::http::OutgoingResponse) -> Self { - unsafe { Self::from_handle(resp.into_handle()) } - } - } - - impl From for ::spin_sdk::http::ResponseOutparam { - fn from(resp: self::preamble::wasi::http::types::ResponseOutparam) -> Self { - unsafe { Self::from_handle(resp.into_handle()) } - } - } - } - - ) - .into() -} - -#[derive(Copy, Clone)] -enum Export { - WasiHttp, - Redis, -} - -fn preamble(export: Export) -> proc_macro2::TokenStream { - let export_decl = match export { - Export::WasiHttp => quote!("wasi:http/incoming-handler": Spin), - Export::Redis => quote!("fermyon:spin/inbound-redis": Spin), - }; - let world = match export { - Export::WasiHttp => quote!("wasi-http-trigger"), - Export::Redis => quote!("redis-trigger"), - }; - quote! { - #![allow(missing_docs)] - ::spin_sdk::wit_bindgen::generate!({ - world: #world, - path: #WIT_PATH, - runtime_path: "::spin_sdk::wit_bindgen::rt", - exports: { - #export_decl - } - }); - pub struct Spin; - } -} diff --git a/sdk/rust/macro/wit/deps/http/incoming-handler.wit b/sdk/rust/macro/wit/deps/http/incoming-handler.wit deleted file mode 100644 index 70a6a043a0..0000000000 --- a/sdk/rust/macro/wit/deps/http/incoming-handler.wit +++ /dev/null @@ -1,24 +0,0 @@ -// The `wasi:http/incoming-handler` interface is meant to be exported by -// components and called by the host in response to a new incoming HTTP -// response. -// -// NOTE: in Preview3, this interface will be merged with -// `wasi:http/outgoing-handler` into a single `wasi:http/handler` interface -// that takes a `request` parameter and returns a `response` result. -// -interface incoming-handler { - use types.{incoming-request, response-outparam} - - // The `handle` function takes an outparam instead of returning its response - // so that the component may stream its response while streaming any other - // request or response bodies. The callee MUST write a response to the - // `response-outparam` and then finish the response before returning. The `handle` - // function is allowed to continue execution after finishing the response's - // output stream. While this post-response execution is taken off the - // critical path, since there is no return value, there is no way to report - // its success or failure. - handle: func( - request: incoming-request, - response-out: response-outparam - ) -} diff --git a/sdk/rust/macro/wit/deps/http/outgoing-handler.wit b/sdk/rust/macro/wit/deps/http/outgoing-handler.wit deleted file mode 100644 index 9b6a73c0cb..0000000000 --- a/sdk/rust/macro/wit/deps/http/outgoing-handler.wit +++ /dev/null @@ -1,20 +0,0 @@ -// The `wasi:http/outgoing-handler` interface is meant to be imported by -// components and implemented by the host. -// -// NOTE: in Preview3, this interface will be merged with -// `wasi:http/outgoing-handler` into a single `wasi:http/handler` interface -// that takes a `request` parameter and returns a `response` result. -// -interface outgoing-handler { - use types.{outgoing-request, request-options, future-incoming-response, error} - - // The parameter and result types of the `handle` function allow the caller - // to concurrently stream the bodies of the outgoing request and the incoming - // response. - // Consumes the outgoing-request. Gives an error if the outgoing-request - // is invalid or cannot be satisfied by this handler. - handle: func( - request: outgoing-request, - options: option - ) -> result -} diff --git a/sdk/rust/macro/wit/deps/http/types.wit b/sdk/rust/macro/wit/deps/http/types.wit deleted file mode 100644 index 9563efdfd2..0000000000 --- a/sdk/rust/macro/wit/deps/http/types.wit +++ /dev/null @@ -1,214 +0,0 @@ -// The `wasi:http/types` interface is meant to be imported by components to -// define the HTTP resource types and operations used by the component's -// imported and exported interfaces. -interface types { - use wasi:io/streams@0.2.0-rc-2023-10-18.{input-stream, output-stream} - use wasi:io/poll@0.2.0-rc-2023-10-18.{pollable} - - // This type corresponds to HTTP standard Methods. - variant method { - get, - head, - post, - put, - delete, - connect, - options, - trace, - patch, - other(string) - } - - // This type corresponds to HTTP standard Related Schemes. - variant scheme { - HTTP, - HTTPS, - other(string) - } - - // TODO: perhaps better align with HTTP semantics? - // This type enumerates the different kinds of errors that may occur when - // initially returning a response. - variant error { - invalid-url(string), - timeout-error(string), - protocol-error(string), - unexpected-error(string) - } - - // This following block defines the `fields` resource which corresponds to - // HTTP standard Fields. Soon, when resource types are added, the `type - // fields = u32` type alias can be replaced by a proper `resource fields` - // definition containing all the functions using the method syntactic sugar. - resource fields { - // Multiple values for a header are multiple entries in the list with the - // same key. - constructor(entries: list>>) - - // Values off wire are not necessarily well formed, so they are given by - // list instead of string. - get: func(name: string) -> list> - - // Values off wire are not necessarily well formed, so they are given by - // list instead of string. - set: func(name: string, value: list>) - delete: func(name: string) - append: func(name: string, value: list) - - // Values off wire are not necessarily well formed, so they are given by - // list instead of string. - entries: func() -> list>> - - // Deep copy of all contents in a fields. - clone: func() -> fields - } - - type headers = fields - type trailers = fields - - // The following block defines the `incoming-request` and `outgoing-request` - // resource types that correspond to HTTP standard Requests. Soon, when - // resource types are added, the `u32` type aliases can be replaced by - // proper `resource` type definitions containing all the functions as - // methods. Later, Preview2 will allow both types to be merged together into - // a single `request` type (that uses the single `stream` type mentioned - // above). The `consume` and `write` methods may only be called once (and - // return failure thereafter). - resource incoming-request { - method: func() -> method - - path-with-query: func() -> option - - scheme: func() -> option - - authority: func() -> option - - headers: func() -> /* child */ headers - // Will return the input-stream child at most once. If called more than - // once, subsequent calls will return error. - - consume: func() -> result - } - - resource outgoing-request { - constructor( - method: method, - path-with-query: option, - scheme: option, - authority: option, - headers: borrow - ) - - // Will return the outgoing-body child at most once. If called more than - // once, subsequent calls will return error. - write: func() -> result< /* child */ outgoing-body> - } - - // Additional optional parameters that can be set when making a request. - record request-options { - // The following timeouts are specific to the HTTP protocol and work - // independently of the overall timeouts passed to `io.poll.poll-list`. - - // The timeout for the initial connect. - connect-timeout-ms: option, - - // The timeout for receiving the first byte of the response body. - first-byte-timeout-ms: option, - - // The timeout for receiving the next chunk of bytes in the response body - // stream. - between-bytes-timeout-ms: option - } - - // The following block defines a special resource type used by the - // `wasi:http/incoming-handler` interface. When resource types are added, this - // block can be replaced by a proper `resource response-outparam { ... }` - // definition. Later, with Preview3, the need for an outparam goes away entirely - // (the `wasi:http/handler` interface used for both incoming and outgoing can - // simply return a `stream`). - resource response-outparam { - set: static func(param: response-outparam, response: result) - } - - // This type corresponds to the HTTP standard Status Code. - type status-code = u16 - - // The following block defines the `incoming-response` and `outgoing-response` - // resource types that correspond to HTTP standard Responses. Soon, when - // resource types are added, the `u32` type aliases can be replaced by proper - // `resource` type definitions containing all the functions as methods. Later, - // Preview2 will allow both types to be merged together into a single `response` - // type (that uses the single `stream` type mentioned above). The `consume` and - // `write` methods may only be called once (and return failure thereafter). - resource incoming-response { - status: func() -> status-code - - headers: func() -> /* child */ headers - - // May be called at most once. returns error if called additional times. - // TODO: make incoming-request-consume work the same way, giving a child - // incoming-body. - consume: func() -> result - } - - resource incoming-body { - // returned input-stream is a child - the implementation may trap if - // incoming-body is dropped (or consumed by call to - // incoming-body-finish) before the input-stream is dropped. - // May be called at most once. returns error if called additional times. - %stream: func() -> result - - // takes ownership of incoming-body. this will trap if the - // incoming-body-stream child is still alive! - finish: static func(this: incoming-body) -> - /* transitive child of the incoming-response of incoming-body */ future-trailers - } - - resource future-trailers { - /// Pollable that resolves when the body has been fully read, and the trailers - /// are ready to be consumed. - subscribe: func() -> /* child */ pollable - - /// Retrieve reference to trailers, if they are ready. - get: func() -> option> - } - - resource outgoing-response { - constructor(status-code: status-code, headers: borrow) - - /// Will give the child outgoing-response at most once. subsequent calls will - /// return an error. - write: func() -> result - } - - resource outgoing-body { - /// Will give the child output-stream at most once. subsequent calls will - /// return an error. - write: func() -> result - - /// Finalize an outgoing body, optionally providing trailers. This must be - /// called to signal that the response is complete. If the `outgoing-body` is - /// dropped without calling `outgoing-body-finalize`, the implementation - /// should treat the body as corrupted. - finish: static func(this: outgoing-body, trailers: option) - } - - /// The following block defines a special resource type used by the - /// `wasi:http/outgoing-handler` interface to emulate - /// `future>` in advance of Preview3. Given a - /// `future-incoming-response`, the client can call the non-blocking `get` - /// method to get the result if it is available. If the result is not available, - /// the client can call `listen` to get a `pollable` that can be passed to - /// `wasi:io/poll.poll-list`. - resource future-incoming-response { - /// option indicates readiness. - /// outer result indicates you are allowed to get the - /// incoming-response-or-error at most once. subsequent calls after ready - /// will return an error here. - /// inner result indicates whether the incoming-response was available, or an - /// error occured. - get: func() -> option>> - - subscribe: func() -> /* child */ pollable - } -} diff --git a/sdk/rust/macro/wit/deps/http/world.wit b/sdk/rust/macro/wit/deps/http/world.wit deleted file mode 100644 index 0798c84292..0000000000 --- a/sdk/rust/macro/wit/deps/http/world.wit +++ /dev/null @@ -1 +0,0 @@ -package wasi:http@0.2.0-rc-2023-10-18 diff --git a/sdk/rust/macro/wit/deps/io/poll.wit b/sdk/rust/macro/wit/deps/io/poll.wit deleted file mode 100644 index 4ff4765c99..0000000000 --- a/sdk/rust/macro/wit/deps/io/poll.wit +++ /dev/null @@ -1,32 +0,0 @@ -/// A poll API intended to let users wait for I/O events on multiple handles -/// at once. -interface poll { - /// A "pollable" handle. - resource pollable - - /// Poll for completion on a set of pollables. - /// - /// This function takes a list of pollables, which identify I/O sources of - /// interest, and waits until one or more of the events is ready for I/O. - /// - /// The result `list` contains one or more indices of handles in the - /// argument list that is ready for I/O. - /// - /// If the list contains more elements than can be indexed with a `u32` - /// value, this function traps. - /// - /// A timeout can be implemented by adding a pollable from the - /// wasi-clocks API to the list. - /// - /// This function does not return a `result`; polling in itself does not - /// do any I/O so it doesn't fail. If any of the I/O sources identified by - /// the pollables has an error, it is indicated by marking the source as - /// being reaedy for I/O. - poll-list: func(in: list>) -> list - - /// Poll for completion on a single pollable. - /// - /// This function is similar to `poll-list`, but operates on only a single - /// pollable. When it returns, the handle is ready for I/O. - poll-one: func(in: borrow) -} diff --git a/sdk/rust/macro/wit/deps/io/streams.wit b/sdk/rust/macro/wit/deps/io/streams.wit deleted file mode 100644 index d5c7835e4e..0000000000 --- a/sdk/rust/macro/wit/deps/io/streams.wit +++ /dev/null @@ -1,287 +0,0 @@ -/// WASI I/O is an I/O abstraction API which is currently focused on providing -/// stream types. -/// -/// In the future, the component model is expected to add built-in stream types; -/// when it does, they are expected to subsume this API. -interface streams { - use poll.{pollable} - - /// An error for input-stream and output-stream operations. - variant stream-error { - /// The last operation (a write or flush) failed before completion. - /// - /// More information is available in the `error` payload. - last-operation-failed(error), - /// The stream is closed: no more input will be accepted by the - /// stream. A closed output-stream will return this error on all - /// future operations. - closed - } - - /// Contextual error information about the last failure that happened on - /// a read, write, or flush from an `input-stream` or `output-stream`. - /// - /// This type is returned through the `stream-error` type whenever an - /// operation on a stream directly fails or an error is discovered - /// after-the-fact, for example when a write's failure shows up through a - /// later `flush` or `check-write`. - /// - /// Interfaces such as `wasi:filesystem/types` provide functionality to - /// further "downcast" this error into interface-specific error information. - resource error { - /// Returns a string that's suitable to assist humans in debugging this - /// error. - /// - /// The returned string will change across platforms and hosts which - /// means that parsing it, for example, would be a - /// platform-compatibility hazard. - to-debug-string: func() -> string - } - - /// An input bytestream. - /// - /// `input-stream`s are *non-blocking* to the extent practical on underlying - /// platforms. I/O operations always return promptly; if fewer bytes are - /// promptly available than requested, they return the number of bytes promptly - /// available, which could even be zero. To wait for data to be available, - /// use the `subscribe` function to obtain a `pollable` which can be polled - /// for using `wasi:io/poll`. - resource input-stream { - /// Perform a non-blocking read from the stream. - /// - /// This function returns a list of bytes containing the data that was - /// read, along with a `stream-status` which, indicates whether further - /// reads are expected to produce data. The returned list will contain up to - /// `len` bytes; it may return fewer than requested, but not more. An - /// empty list and `stream-status:open` indicates no more data is - /// available at this time, and that the pollable given by `subscribe` - /// will be ready when more data is available. - /// - /// Once a stream has reached the end, subsequent calls to `read` or - /// `skip` will always report `stream-status:ended` rather than producing more - /// data. - /// - /// When the caller gives a `len` of 0, it represents a request to read 0 - /// bytes. This read should always succeed and return an empty list and - /// the current `stream-status`. - /// - /// The `len` parameter is a `u64`, which could represent a list of u8 which - /// is not possible to allocate in wasm32, or not desirable to allocate as - /// as a return value by the callee. The callee may return a list of bytes - /// less than `len` in size while more bytes are available for reading. - read: func( - /// The maximum number of bytes to read - len: u64 - ) -> result, stream-error> - - /// Read bytes from a stream, after blocking until at least one byte can - /// be read. Except for blocking, identical to `read`. - blocking-read: func( - /// The maximum number of bytes to read - len: u64 - ) -> result, stream-error> - - /// Skip bytes from a stream. - /// - /// This is similar to the `read` function, but avoids copying the - /// bytes into the instance. - /// - /// Once a stream has reached the end, subsequent calls to read or - /// `skip` will always report end-of-stream rather than producing more - /// data. - /// - /// This function returns the number of bytes skipped, along with a - /// `stream-status` indicating whether the end of the stream was - /// reached. The returned value will be at most `len`; it may be less. - skip: func( - /// The maximum number of bytes to skip. - len: u64, - ) -> result - - /// Skip bytes from a stream, after blocking until at least one byte - /// can be skipped. Except for blocking behavior, identical to `skip`. - blocking-skip: func( - /// The maximum number of bytes to skip. - len: u64, - ) -> result - - /// Create a `pollable` which will resolve once either the specified stream - /// has bytes available to read or the other end of the stream has been - /// closed. - /// The created `pollable` is a child resource of the `input-stream`. - /// Implementations may trap if the `input-stream` is dropped before - /// all derived `pollable`s created with this function are dropped. - subscribe: func() -> pollable - } - - - /// An output bytestream. - /// - /// `output-stream`s are *non-blocking* to the extent practical on - /// underlying platforms. Except where specified otherwise, I/O operations also - /// always return promptly, after the number of bytes that can be written - /// promptly, which could even be zero. To wait for the stream to be ready to - /// accept data, the `subscribe` function to obtain a `pollable` which can be - /// polled for using `wasi:io/poll`. - resource output-stream { - /// Check readiness for writing. This function never blocks. - /// - /// Returns the number of bytes permitted for the next call to `write`, - /// or an error. Calling `write` with more bytes than this function has - /// permitted will trap. - /// - /// When this function returns 0 bytes, the `subscribe` pollable will - /// become ready when this function will report at least 1 byte, or an - /// error. - check-write: func() -> result - - /// Perform a write. This function never blocks. - /// - /// Precondition: check-write gave permit of Ok(n) and contents has a - /// length of less than or equal to n. Otherwise, this function will trap. - /// - /// returns Err(closed) without writing if the stream has closed since - /// the last call to check-write provided a permit. - write: func( - contents: list - ) -> result<_, stream-error> - - /// Perform a write of up to 4096 bytes, and then flush the stream. Block - /// until all of these operations are complete, or an error occurs. - /// - /// This is a convenience wrapper around the use of `check-write`, - /// `subscribe`, `write`, and `flush`, and is implemented with the - /// following pseudo-code: - /// - /// ```text - /// let pollable = this.subscribe(); - /// while !contents.is_empty() { - /// // Wait for the stream to become writable - /// poll-one(pollable); - /// let Ok(n) = this.check-write(); // eliding error handling - /// let len = min(n, contents.len()); - /// let (chunk, rest) = contents.split_at(len); - /// this.write(chunk ); // eliding error handling - /// contents = rest; - /// } - /// this.flush(); - /// // Wait for completion of `flush` - /// poll-one(pollable); - /// // Check for any errors that arose during `flush` - /// let _ = this.check-write(); // eliding error handling - /// ``` - blocking-write-and-flush: func( - contents: list - ) -> result<_, stream-error> - - /// Request to flush buffered output. This function never blocks. - /// - /// This tells the output-stream that the caller intends any buffered - /// output to be flushed. the output which is expected to be flushed - /// is all that has been passed to `write` prior to this call. - /// - /// Upon calling this function, the `output-stream` will not accept any - /// writes (`check-write` will return `ok(0)`) until the flush has - /// completed. The `subscribe` pollable will become ready when the - /// flush has completed and the stream can accept more writes. - flush: func() -> result<_, stream-error> - - /// Request to flush buffered output, and block until flush completes - /// and stream is ready for writing again. - blocking-flush: func() -> result<_, stream-error> - - /// Create a `pollable` which will resolve once the output-stream - /// is ready for more writing, or an error has occured. When this - /// pollable is ready, `check-write` will return `ok(n)` with n>0, or an - /// error. - /// - /// If the stream is closed, this pollable is always ready immediately. - /// - /// The created `pollable` is a child resource of the `output-stream`. - /// Implementations may trap if the `output-stream` is dropped before - /// all derived `pollable`s created with this function are dropped. - subscribe: func() -> pollable - - /// Write zeroes to a stream. - /// - /// this should be used precisely like `write` with the exact same - /// preconditions (must use check-write first), but instead of - /// passing a list of bytes, you simply pass the number of zero-bytes - /// that should be written. - write-zeroes: func( - /// The number of zero-bytes to write - len: u64 - ) -> result<_, stream-error> - - /// Perform a write of up to 4096 zeroes, and then flush the stream. - /// Block until all of these operations are complete, or an error - /// occurs. - /// - /// This is a convenience wrapper around the use of `check-write`, - /// `subscribe`, `write-zeroes`, and `flush`, and is implemented with - /// the following pseudo-code: - /// - /// ```text - /// let pollable = this.subscribe(); - /// while num_zeroes != 0 { - /// // Wait for the stream to become writable - /// poll-one(pollable); - /// let Ok(n) = this.check-write(); // eliding error handling - /// let len = min(n, num_zeroes); - /// this.write-zeroes(len); // eliding error handling - /// num_zeroes -= len; - /// } - /// this.flush(); - /// // Wait for completion of `flush` - /// poll-one(pollable); - /// // Check for any errors that arose during `flush` - /// let _ = this.check-write(); // eliding error handling - /// ``` - blocking-write-zeroes-and-flush: func( - /// The number of zero-bytes to write - len: u64 - ) -> result<_, stream-error> - - /// Read from one stream and write to another. - /// - /// This function returns the number of bytes transferred; it may be less - /// than `len`. - /// - /// Unlike other I/O functions, this function blocks until all the data - /// read from the input stream has been written to the output stream. - splice: func( - /// The stream to read from - src: input-stream, - /// The number of bytes to splice - len: u64, - ) -> result - - /// Read from one stream and write to another, with blocking. - /// - /// This is similar to `splice`, except that it blocks until at least - /// one byte can be read. - blocking-splice: func( - /// The stream to read from - src: input-stream, - /// The number of bytes to splice - len: u64, - ) -> result - - /// Forward the entire contents of an input stream to an output stream. - /// - /// This function repeatedly reads from the input stream and writes - /// the data to the output stream, until the end of the input stream - /// is reached, or an error is encountered. - /// - /// Unlike other I/O functions, this function blocks until the end - /// of the input stream is seen and all the data has been written to - /// the output stream. - /// - /// This function returns the number of bytes transferred, and the status of - /// the output stream. - forward: func( - /// The stream to read from - src: input-stream - ) -> result - } -} diff --git a/sdk/rust/macro/wit/deps/io/world.wit b/sdk/rust/macro/wit/deps/io/world.wit deleted file mode 100644 index 0fdcfcd969..0000000000 --- a/sdk/rust/macro/wit/deps/io/world.wit +++ /dev/null @@ -1 +0,0 @@ -package wasi:io@0.2.0-rc-2023-10-18 diff --git a/sdk/rust/macro/wit/inbound-redis.wit b/sdk/rust/macro/wit/inbound-redis.wit deleted file mode 100644 index 2a027c5467..0000000000 --- a/sdk/rust/macro/wit/inbound-redis.wit +++ /dev/null @@ -1,6 +0,0 @@ -interface inbound-redis { - use redis-types.{payload, error} - - // The entrypoint for a Redis handler. - handle-message: func(message: payload) -> result<_, error> -} diff --git a/sdk/rust/macro/wit/redis-types.wit b/sdk/rust/macro/wit/redis-types.wit deleted file mode 100644 index e08d593dd5..0000000000 --- a/sdk/rust/macro/wit/redis-types.wit +++ /dev/null @@ -1,24 +0,0 @@ -interface redis-types { - // General purpose error. - enum error { - success, - error, - } - - // The message payload. - type payload = list - - // A parameter type for the general-purpose `execute` function. - variant redis-parameter { - int64(s64), - binary(payload) - } - - // A return type for the general-purpose `execute` function. - variant redis-result { - nil, - status(string), - int64(s64), - binary(payload) - } -} diff --git a/sdk/rust/macro/wit/world.wit b/sdk/rust/macro/wit/world.wit deleted file mode 100644 index dc65710b11..0000000000 --- a/sdk/rust/macro/wit/world.wit +++ /dev/null @@ -1,10 +0,0 @@ -package fermyon:spin - -world redis-trigger { - export inbound-redis -} - -world wasi-http-trigger { - import wasi:http/outgoing-handler@0.2.0-rc-2023-10-18 - export wasi:http/incoming-handler@0.2.0-rc-2023-10-18 -} diff --git a/sdk/rust/src/bin/version.rs b/sdk/rust/src/bin/version.rs deleted file mode 100644 index 2837b0da34..0000000000 --- a/sdk/rust/src/bin/version.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - print!("{}", env!("SDK_VERSION")); -} diff --git a/sdk/rust/src/http.rs b/sdk/rust/src/http.rs deleted file mode 100644 index 29ce612c64..0000000000 --- a/sdk/rust/src/http.rs +++ /dev/null @@ -1,778 +0,0 @@ -/// Traits for converting between the various types -pub mod conversions; - -use std::collections::HashMap; - -#[doc(inline)] -pub use conversions::IntoResponse; -#[doc(inline)] -pub use types::{ - Error, Fields, Headers, IncomingRequest, IncomingResponse, Method, OutgoingBody, - OutgoingRequest, OutgoingResponse, Scheme, StatusCode, Trailers, -}; - -use self::conversions::{TryFromIncomingResponse, TryIntoOutgoingRequest}; -use super::wit::wasi::http0_2_0_rc_2023_10_18::types; -use crate::wit::wasi::io0_2_0_rc_2023_10_18::streams; -use futures::SinkExt; - -/// A unified request object that can represent both incoming and outgoing requests. -/// -/// This should be used in favor of `IncomingRequest` and `OutgoingRequest` when there -/// is no need for streaming bodies. -pub struct Request { - /// The method of the request - method: Method, - /// The uri for the request - /// - /// The first item is set to `None` if the supplied uri is malformed - uri: (Option, String), - /// The request headers - headers: HashMap, - /// The request body as bytes - body: Vec, -} - -impl Request { - /// Creates a new request from a method and uri - pub fn new(method: Method, uri: impl Into) -> Self { - Self { - method, - uri: Self::parse_uri(uri.into()), - headers: HashMap::new(), - body: Vec::new(), - } - } - - /// Creates a [`RequestBuilder`] - pub fn builder() -> RequestBuilder { - RequestBuilder::new(Method::Get, "/") - } - - /// Creates a [`RequestBuilder`] to GET the given `uri` - pub fn get(uri: impl Into) -> RequestBuilder { - RequestBuilder::new(Method::Get, uri) - } - - /// Creates a [`RequestBuilder`] to POST the given `body` to `uri` - pub fn post(uri: impl Into, body: impl conversions::IntoBody) -> RequestBuilder { - let mut builder = RequestBuilder::new(Method::Post, uri); - builder.body(body); - builder - } - - /// Creates a [`RequestBuilder`] to PUT the given `body` to `uri` - pub fn put(uri: impl Into, body: impl conversions::IntoBody) -> RequestBuilder { - let mut builder = RequestBuilder::new(Method::Put, uri); - builder.body(body); - builder - } - - /// Creates a [`RequestBuilder`] to PATCH the resource specified by `uri` - pub fn patch(uri: impl Into, body: impl conversions::IntoBody) -> RequestBuilder { - let mut builder = RequestBuilder::new(Method::Patch, uri); - builder.body(body); - builder - } - - /// Creates a [`RequestBuilder`] to DELETE the resource specified by `uri` - pub fn delete(uri: impl Into) -> RequestBuilder { - RequestBuilder::new(Method::Delete, uri) - } - - /// The request method - pub fn method(&self) -> &Method { - &self.method - } - - /// The request uri - pub fn uri(&self) -> &str { - &self.uri.1 - } - - /// The request uri path - pub fn path(&self) -> &str { - self.uri.0.as_ref().map(|u| u.path()).unwrap_or_default() - } - - /// The request uri query - pub fn query(&self) -> &str { - self.uri - .0 - .as_ref() - .and_then(|u| u.query()) - .unwrap_or_default() - } - - /// The request headers - pub fn headers(&self) -> impl Iterator { - self.headers.iter().map(|(k, v)| (k.as_str(), v)) - } - - /// Return a header value - /// - /// Will return `None` if the header does not exist. - pub fn header(&self, name: &str) -> Option<&HeaderValue> { - self.headers.get(&name.to_lowercase()) - } - - /// Set a header - pub fn set_header(&mut self, name: impl Into, value: impl Into) { - self.headers.insert( - name.into(), - HeaderValue { - inner: HeaderValueRep::String(value.into()), - }, - ); - } - - /// The request body - pub fn body(&self) -> &[u8] { - &self.body - } - - /// The request body - pub fn body_mut(&mut self) -> &mut Vec { - &mut self.body - } - - /// Consume this type and return its body - pub fn into_body(self) -> Vec { - self.body - } - - fn parse_uri(uri: String) -> (Option, String) { - ( - hyperium::Uri::try_from(&uri) - .or_else(|_| hyperium::Uri::try_from(&format!("http://{uri}"))) - .ok(), - uri, - ) - } - - /// Whether the request is an HTTPS request - fn is_https(&self) -> bool { - self.uri - .0 - .as_ref() - .and_then(|u| u.scheme()) - .map(|s| s == &hyperium::uri::Scheme::HTTPS) - .unwrap_or(true) - } - - /// The URI's authority - fn authority(&self) -> Option<&str> { - self.uri - .0 - .as_ref() - .and_then(|u| u.authority()) - .map(|a| a.as_str()) - } - - /// The request path and query combined - pub fn path_and_query(&self) -> Option<&str> { - self.uri - .0 - .as_ref() - .and_then(|u| u.path_and_query()) - .map(|s| s.as_str()) - } -} - -/// A request builder -pub struct RequestBuilder { - request: Request, -} - -impl RequestBuilder { - /// Create a new `RequestBuilder` - pub fn new(method: Method, uri: impl Into) -> Self { - Self { - request: Request::new(method, uri.into()), - } - } - - /// Set the method - pub fn method(&mut self, method: Method) -> &mut Self { - self.request.method = method; - self - } - - /// Set the uri - pub fn uri(&mut self, uri: impl Into) -> &mut Self { - self.request.uri = Request::parse_uri(uri.into()); - self - } - - /// Set the headers - pub fn headers(&mut self, headers: impl conversions::IntoHeaders) -> &mut Self { - self.request.headers = into_header_rep(headers); - self - } - - /// Set a header - pub fn header(&mut self, key: impl Into, value: impl Into) -> &mut Self { - self.request - .headers - .insert(key.into().to_lowercase(), HeaderValue::string(value.into())); - self - } - - /// Set the body - pub fn body(&mut self, body: impl conversions::IntoBody) -> &mut Self { - self.request.body = body.into_body(); - self - } - - /// Build the `Request` - pub fn build(&mut self) -> Request { - std::mem::replace(&mut self.request, Request::new(Method::Get, "/")) - } -} - -/// A unified response object that can represent both outgoing and incoming responses. -/// -/// This should be used in favor of `OutgoingResponse` and `IncomingResponse` when there -/// is no need for streaming bodies. -pub struct Response { - /// The status of the response - status: StatusCode, - /// The response headers - headers: HashMap, - /// The body of the response as bytes - body: Vec, -} - -impl Response { - /// Create a new response from a status and body - pub fn new(status: impl conversions::IntoStatusCode, body: impl conversions::IntoBody) -> Self { - Self { - status: status.into_status_code(), - headers: HashMap::new(), - body: body.into_body(), - } - } - - /// The response status - pub fn status(&self) -> &StatusCode { - &self.status - } - - /// The request headers - pub fn headers(&self) -> impl Iterator { - self.headers.iter().map(|(k, v)| (k.as_str(), v)) - } - - /// Return a header value - /// - /// Will return `None` if the header does not exist. - pub fn header(&self, name: &str) -> Option<&HeaderValue> { - self.headers.get(&name.to_lowercase()) - } - - /// Set a response header - pub fn set_header(&mut self, name: impl Into, value: impl Into) { - self.headers.insert( - name.into(), - HeaderValue { - inner: HeaderValueRep::String(value.into()), - }, - ); - } - - /// The response body - pub fn body(&self) -> &[u8] { - &self.body - } - - /// The response body - pub fn body_mut(&mut self) -> &mut Vec { - &mut self.body - } - - /// Consume this type and return its body - pub fn into_body(self) -> Vec { - self.body - } - - /// Converts this response into a [`ResponseBuilder`]. This can be used to - /// update a response before passing it on. - pub fn into_builder(self) -> ResponseBuilder { - ResponseBuilder { response: self } - } - - /// Creates a [`ResponseBuilder`] - pub fn builder() -> ResponseBuilder { - ResponseBuilder::new(200) - } -} - -impl std::fmt::Debug for Response { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("Response") - .field("status", &self.status) - .field("headers", &self.headers) - .field("body.len()", &self.body.len()) - .finish() - } -} - -/// A builder for `Response`` -pub struct ResponseBuilder { - response: Response, -} - -impl ResponseBuilder { - /// Create a new `ResponseBuilder` - pub fn new(status: impl conversions::IntoStatusCode) -> Self { - ResponseBuilder { - response: Response::new(status, Vec::new()), - } - } - - /// Set the status - pub fn status(&mut self, status: impl conversions::IntoStatusCode) -> &mut Self { - self.response.status = status.into_status_code(); - self - } - - /// Set the headers - pub fn headers(&mut self, headers: impl conversions::IntoHeaders) -> &mut Self { - self.response.headers = into_header_rep(headers.into_headers()); - self - } - - /// Set a header - pub fn header(&mut self, key: impl Into, value: impl Into) -> &mut Self { - self.response - .headers - .insert(key.into().to_lowercase(), HeaderValue::string(value.into())); - self - } - - /// Set the body - pub fn body(&mut self, body: impl conversions::IntoBody) -> &mut Self { - self.response.body = body.into_body(); - self - } - - /// Build the `Response` - pub fn build(&mut self) -> Response { - std::mem::replace(&mut self.response, Response::new(200, Vec::new())) - } -} - -/// A header value. -/// -/// Since header values do not have to be valid utf8, this allows for -/// both utf8 strings and bags of bytes. -#[derive(Debug, PartialEq, Eq, Clone)] -pub struct HeaderValue { - inner: HeaderValueRep, -} - -#[derive(Debug, PartialEq, Eq, Clone)] -enum HeaderValueRep { - /// Header value encoded as a utf8 string - String(String), - /// Header value as a bag of bytes - Bytes(Vec), -} - -impl HeaderValue { - /// Construct a `HeaderValue` from a string - pub fn string(str: String) -> HeaderValue { - HeaderValue { - inner: HeaderValueRep::String(str), - } - } - - /// Construct a `HeaderValue` from a bag of bytes - pub fn bytes(bytes: Vec) -> HeaderValue { - HeaderValue { - inner: String::from_utf8(bytes) - .map(HeaderValueRep::String) - .unwrap_or_else(|e| HeaderValueRep::Bytes(e.into_bytes())), - } - } - - /// Get the `HeaderValue` as a utf8 encoded string - /// - /// Returns `None` if the value is a non utf8 encoded header value - pub fn as_str(&self) -> Option<&str> { - match &self.inner { - HeaderValueRep::String(s) => Some(s), - HeaderValueRep::Bytes(b) => std::str::from_utf8(b).ok(), - } - } - - /// Get the `HeaderValue` as bytes - pub fn as_bytes(&self) -> &[u8] { - self.as_ref() - } - - /// Turn the `HeaderValue` into a String (in a lossy way if the `HeaderValue` is a bag of bytes) - pub fn into_utf8_lossy(self) -> String { - match self.inner { - HeaderValueRep::String(s) => s, - HeaderValueRep::Bytes(b) => String::from_utf8_lossy(&b).into_owned(), - } - } - - /// Turn the `HeaderValue` into bytes - pub fn into_bytes(self) -> Vec { - match self.inner { - HeaderValueRep::String(s) => s.into_bytes(), - HeaderValueRep::Bytes(b) => b, - } - } -} - -impl AsRef<[u8]> for HeaderValue { - fn as_ref(&self) -> &[u8] { - match &self.inner { - HeaderValueRep::String(s) => s.as_bytes(), - HeaderValueRep::Bytes(b) => b, - } - } -} - -fn into_header_rep(headers: impl conversions::IntoHeaders) -> HashMap { - headers - .into_headers() - .into_iter() - .map(|(k, v)| { - let v = String::from_utf8(v) - .map(HeaderValueRep::String) - .unwrap_or_else(|e| HeaderValueRep::Bytes(e.into_bytes())); - (k.to_lowercase(), HeaderValue { inner: v }) - }) - .collect() -} - -impl std::hash::Hash for Method { - fn hash(&self, state: &mut H) { - core::mem::discriminant(self).hash(state); - } -} - -impl Eq for Method {} - -impl PartialEq for Method { - fn eq(&self, other: &Self) -> bool { - match (self, other) { - (Self::Other(l), Self::Other(r)) => l == r, - _ => core::mem::discriminant(self) == core::mem::discriminant(other), - } - } -} - -impl std::fmt::Display for Method { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_str(match self { - Method::Get => "GET", - Method::Post => "POST", - Method::Put => "PUT", - Method::Delete => "DELETE", - Method::Patch => "PATCH", - Method::Head => "HEAD", - Method::Options => "OPTIONS", - Method::Connect => "CONNECT", - Method::Trace => "TRACE", - Method::Other(o) => o, - }) - } -} - -impl IncomingRequest { - /// The incoming request Uri - pub fn uri(&self) -> String { - let scheme_and_authority = - if let (Some(scheme), Some(authority)) = (self.scheme(), self.authority()) { - let scheme = match &scheme { - Scheme::Http => "http://", - Scheme::Https => "https://", - Scheme::Other(s) => s.as_str(), - }; - format!("{scheme}{authority}") - } else { - String::new() - }; - let path_and_query = self.path_with_query().unwrap_or_default(); - format!("{scheme_and_authority}{path_and_query}") - } - - /// Return a `Stream` from which the body of the specified request may be read. - /// - /// # Panics - /// - /// Panics if the body was already consumed. - pub fn into_body_stream(self) -> impl futures::Stream, streams::Error>> { - executor::incoming_body(self.consume().expect("request body was already consumed")) - } - - /// Return a `Vec` of the body or fails - pub async fn into_body(self) -> Result, streams::Error> { - use futures::TryStreamExt; - let mut stream = self.into_body_stream(); - let mut body = Vec::new(); - while let Some(chunk) = stream.try_next().await? { - body.extend(chunk); - } - Ok(body) - } -} - -impl IncomingResponse { - /// Return a `Stream` from which the body of the specified response may be read. - /// - /// # Panics - /// - /// Panics if the body was already consumed. - // TODO: This should ideally take ownership of `self` and be called `into_body_stream` (i.e. symmetric with - // `IncomingRequest::into_body_stream`). However, as of this writing, `wasmtime-wasi-http` is implemented in - // such a way that dropping an `IncomingResponse` will cause the request to be cancelled, meaning the caller - // won't necessarily have a chance to send the request body if they haven't started doing so yet (or, if they - // have started, they might not be able to finish before the connection is closed). See - // https://github.com/bytecodealliance/wasmtime/issues/7413 for details. - pub fn take_body_stream(&self) -> impl futures::Stream, streams::Error>> { - executor::incoming_body(self.consume().expect("response body was already consumed")) - } - - /// Return a `Vec` of the body or fails - /// - /// # Panics - /// - /// Panics if the body was already consumed. - pub async fn into_body(self) -> Result, streams::Error> { - use futures::TryStreamExt; - let mut stream = self.take_body_stream(); - let mut body = Vec::new(); - while let Some(chunk) = stream.try_next().await? { - body.extend(chunk); - } - Ok(body) - } -} - -impl OutgoingResponse { - /// Construct a `Sink` which writes chunks to the body of the specified response. - /// - /// # Panics - /// - /// Panics if the body was already taken. - pub fn take_body(&self) -> impl futures::Sink, Error = Error> { - executor::outgoing_body(self.write().expect("response body was already taken")) - } -} - -impl OutgoingRequest { - /// Construct a `Sink` which writes chunks to the body of the specified response. - /// - /// # Panics - /// - /// Panics if the body was already taken. - pub fn take_body(&self) -> impl futures::Sink, Error = Error> { - executor::outgoing_body(self.write().expect("request body was already taken")) - } -} - -/// The out param for setting an `OutgoingResponse` -pub struct ResponseOutparam(types::ResponseOutparam); - -impl ResponseOutparam { - #[doc(hidden)] - // This is needed for the macro so we can transfrom the macro's - // `ResponseOutparam` to this `ResponseOutparam` - pub unsafe fn from_handle(handle: u32) -> Self { - Self(types::ResponseOutparam::from_handle(handle)) - } - - /// Set the outgoing response - pub fn set(self, response: OutgoingResponse) { - types::ResponseOutparam::set(self.0, Ok(response)); - } - - /// Set with the outgoing response and the supplied buffer - /// - /// Will panic if response body has already been taken - pub async fn set_with_body( - self, - response: OutgoingResponse, - buffer: Vec, - ) -> Result<(), Error> { - let mut body = response.take_body(); - self.set(response); - body.send(buffer).await - } - - /// Return the inner, `wit-bindgen`-generated instance - pub fn into_inner(self) -> types::ResponseOutparam { - self.0 - } -} - -/// Send an outgoing request -pub async fn send(request: I) -> Result -where - I: TryIntoOutgoingRequest, - I::Error: Into> + 'static, - O: TryFromIncomingResponse, - O::Error: Into> + 'static, -{ - let (request, body_buffer) = I::try_into_outgoing_request(request) - .map_err(|e| SendError::RequestConversion(e.into()))?; - let response = if let Some(body_buffer) = body_buffer { - // It is part of the contract of the trait that implementors of `TryIntoOutgoingRequest` - // do not call `OutgoingRequest::write`` if they return a buffered body. - let mut body_sink = request.take_body(); - let response = executor::outgoing_request_send(request); - body_sink - .send(body_buffer) - .await - .map_err(|e| SendError::Http(Error::UnexpectedError(e.to_string())))?; - drop(body_sink); - response.await.map_err(SendError::Http)? - } else { - executor::outgoing_request_send(request) - .await - .map_err(SendError::Http)? - }; - - TryFromIncomingResponse::try_from_incoming_response(response) - .await - .map_err(|e: O::Error| SendError::ResponseConversion(e.into())) -} - -/// An error encountered when performing an HTTP request -#[derive(thiserror::Error, Debug)] -pub enum SendError { - /// Error converting to a request - #[error(transparent)] - RequestConversion(Box), - /// Error converting from a response - #[error(transparent)] - ResponseConversion(Box), - /// An HTTP error - #[error(transparent)] - Http(Error), -} - -#[doc(hidden)] -/// The executor for driving wasi-http futures to completion -mod executor; -#[doc(hidden)] -pub use executor::run; - -/// An error parsing a JSON body -#[cfg(feature = "json")] -#[derive(Debug)] -pub struct JsonBodyError(serde_json::Error); - -#[cfg(feature = "json")] -impl std::error::Error for JsonBodyError {} - -#[cfg(feature = "json")] -impl std::fmt::Display for JsonBodyError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_str("could not convert body to json") - } -} - -/// An error when the body is not UTF-8 -#[derive(Debug)] -pub struct NonUtf8BodyError; - -impl std::error::Error for NonUtf8BodyError {} - -impl std::fmt::Display for NonUtf8BodyError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_str("body was expected to be utf8 but was not") - } -} - -mod router; -/// Exports HTTP Router items. -pub use router::*; - -/// A Body extractor -#[derive(Debug)] -pub struct Body(pub T); - -impl std::ops::Deref for Body { - type Target = T; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -/// A Json extractor -#[derive(Debug)] -pub struct Json(pub T); - -impl std::ops::Deref for Json { - type Target = T; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -/// Helper functions for creating responses -pub mod responses { - use super::Response; - - /// Helper function to return a 404 Not Found response. - pub fn not_found() -> Response { - Response::new(404, "Not Found") - } - - /// Helper function to return a 500 Internal Server Error response. - pub fn internal_server_error() -> Response { - Response::new(500, "Internal Server Error") - } - - /// Helper function to return a 405 Method Not Allowed response. - pub fn method_not_allowed() -> Response { - Response::new(405, "Method Not Allowed") - } - - pub(crate) fn bad_request(msg: Option) -> Response { - Response::new(400, msg.map(|m| m.into_bytes())) - } -} - -impl std::fmt::Display for streams::Error { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_str(&self.to_debug_string()) - } -} - -impl std::error::Error for streams::Error {} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn request_uri_parses() { - let uri = "/hello?world=1"; - let req = Request::new(Method::Get, uri); - assert_eq!(req.uri(), uri); - assert_eq!(req.path(), "/hello"); - assert_eq!(req.query(), "world=1"); - - let uri = "http://localhost:3000/hello?world=1"; - let req = Request::new(Method::Get, uri); - assert_eq!(req.uri(), uri); - assert_eq!(req.path(), "/hello"); - assert_eq!(req.query(), "world=1"); - - let uri = "localhost:3000/hello?world=1"; - let req = Request::new(Method::Get, uri); - assert_eq!(req.uri(), uri); - assert_eq!(req.path(), "/hello"); - assert_eq!(req.query(), "world=1"); - } -} diff --git a/sdk/rust/src/http/conversions.rs b/sdk/rust/src/http/conversions.rs deleted file mode 100644 index d25c364caa..0000000000 --- a/sdk/rust/src/http/conversions.rs +++ /dev/null @@ -1,663 +0,0 @@ -use std::collections::HashMap; - -use async_trait::async_trait; - -use crate::wit::wasi::io0_2_0_rc_2023_10_18::streams; - -use super::{ - Headers, IncomingRequest, IncomingResponse, Json, JsonBodyError, OutgoingRequest, - OutgoingResponse, RequestBuilder, -}; - -use super::{responses, NonUtf8BodyError, Request, Response}; - -impl From for OutgoingResponse { - fn from(response: Response) -> Self { - let headers = response - .headers - .into_iter() - .map(|(k, v)| (k, v.into_bytes())) - .collect::>(); - OutgoingResponse::new(response.status, &Headers::new(&headers)) - } -} - -/// A trait for trying to convert from an `IncomingRequest` to the implementing type -#[async_trait] -pub trait TryFromIncomingRequest { - /// The error if conversion fails - type Error; - - /// Try to turn the `IncomingRequest` into the implementing type - async fn try_from_incoming_request(value: IncomingRequest) -> Result - where - Self: Sized; -} - -#[async_trait] -impl TryFromIncomingRequest for IncomingRequest { - type Error = std::convert::Infallible; - async fn try_from_incoming_request(request: IncomingRequest) -> Result { - Ok(request) - } -} - -#[async_trait] -impl TryFromIncomingRequest for R -where - R: TryNonRequestFromRequest, -{ - type Error = IncomingRequestError; - - async fn try_from_incoming_request(request: IncomingRequest) -> Result { - let req = Request::try_from_incoming_request(request) - .await - .map_err(convert_error)?; - R::try_from_request(req).map_err(IncomingRequestError::ConversionError) - } -} - -#[async_trait] -impl TryFromIncomingRequest for Request { - type Error = IncomingRequestError; - - async fn try_from_incoming_request(request: IncomingRequest) -> Result { - Ok(Request::builder() - .method(request.method()) - .uri(request.uri()) - .headers(request.headers()) - .body(request.into_body().await.map_err(|e| { - IncomingRequestError::BodyConversionError(anyhow::anyhow!( - "{}", - e.to_debug_string() - )) - })?) - .build()) - } -} - -#[derive(Debug, thiserror::Error)] -/// An error converting an `IncomingRequest` -pub enum IncomingRequestError { - /// There was an error converting the body to an `Option>k` - #[error(transparent)] - BodyConversionError(anyhow::Error), - /// There was an error converting the `Request` into the requested type - #[error(transparent)] - ConversionError(E), -} - -/// Helper for converting `IncomingRequestError`s that cannot fail due to conversion errors -/// into ones that can. -fn convert_error( - error: IncomingRequestError, -) -> IncomingRequestError { - match error { - IncomingRequestError::BodyConversionError(e) => { - IncomingRequestError::BodyConversionError(e) - } - IncomingRequestError::ConversionError(_) => unreachable!(), - } -} - -impl IntoResponse for IncomingRequestError { - fn into_response(self) -> Response { - match self { - IncomingRequestError::BodyConversionError(e) => e.into_response(), - IncomingRequestError::ConversionError(e) => e.into_response(), - } - } -} - -/// A trait for any type that can be constructor from a `Request` -pub trait TryFromRequest { - /// The error if the conversion fails - type Error; - /// Try to turn the request into the type - fn try_from_request(req: Request) -> Result - where - Self: Sized; -} - -impl TryFromRequest for Request { - type Error = std::convert::Infallible; - - fn try_from_request(req: Request) -> Result - where - Self: Sized, - { - Ok(req) - } -} - -impl TryFromRequest for R { - type Error = R::Error; - - fn try_from_request(req: Request) -> Result - where - Self: Sized, - { - TryNonRequestFromRequest::try_from_request(req) - } -} - -/// A hack that allows us to do blanket impls for `T where T: TryFromRequest` for all types -/// `T` *except* for `Request`. -/// -/// This is useful in `wasi_http` where we want to implement `TryFromIncomingRequest` for all types that impl -/// `TryFromRequest` with the exception of `Request` itself. This allows that implementation to first convert -/// the `IncomingRequest` to a `Request` and then using this trait convert from `Request` to the given type. -pub trait TryNonRequestFromRequest { - /// The error if the conversion fails - type Error; - /// Try to turn the request into the type - fn try_from_request(req: Request) -> Result - where - Self: Sized; -} - -impl TryNonRequestFromRequest for hyperium::Request { - type Error = B::Error; - fn try_from_request(req: Request) -> Result { - let mut builder = hyperium::Request::builder() - .uri(req.uri()) - .method(req.method); - for (n, v) in req.headers { - builder = builder.header(n, v.into_bytes()); - } - Ok(builder.body(B::try_from_body(req.body)?).unwrap()) - } -} - -impl From for hyperium::Method { - fn from(method: super::Method) -> Self { - match method { - super::Method::Get => hyperium::Method::GET, - super::Method::Post => hyperium::Method::POST, - super::Method::Put => hyperium::Method::PUT, - super::Method::Delete => hyperium::Method::DELETE, - super::Method::Patch => hyperium::Method::PATCH, - super::Method::Head => hyperium::Method::HEAD, - super::Method::Options => hyperium::Method::OPTIONS, - super::Method::Connect => hyperium::Method::CONNECT, - super::Method::Trace => hyperium::Method::TRACE, - super::Method::Other(o) => hyperium::Method::from_bytes(o.as_bytes()).expect("TODO"), - } - } -} -impl From for super::Method { - fn from(method: hyperium::Method) -> Self { - match method { - hyperium::Method::GET => super::Method::Get, - hyperium::Method::POST => super::Method::Post, - hyperium::Method::PUT => super::Method::Put, - hyperium::Method::DELETE => super::Method::Delete, - hyperium::Method::PATCH => super::Method::Patch, - hyperium::Method::HEAD => super::Method::Head, - hyperium::Method::OPTIONS => super::Method::Options, - hyperium::Method::CONNECT => super::Method::Connect, - hyperium::Method::TRACE => super::Method::Trace, - m => super::Method::Other(m.as_str().into()), - } - } -} - -/// A trait for any type that can be turned into a `Response` -pub trait IntoResponse { - /// Turn `self` into a `Response` - fn into_response(self) -> Response; -} - -impl IntoResponse for Response { - fn into_response(self) -> Response { - self - } -} - -impl IntoResponse for hyperium::Response -where - B: IntoBody, -{ - fn into_response(self) -> Response { - Response::builder() - .status(self.status().as_u16()) - .headers(self.headers()) - .body(self.into_body()) - .build() - } -} - -impl IntoResponse for std::result::Result { - fn into_response(self) -> Response { - match self { - Ok(r) => r.into_response(), - Err(e) => e.into_response(), - } - } -} - -impl IntoResponse for anyhow::Error { - fn into_response(self) -> Response { - let body = self.to_string(); - eprintln!("Handler returned an error: {}", body); - let mut source = self.source(); - while let Some(s) = source { - eprintln!(" caused by: {}", s); - source = s.source(); - } - Response { - status: 500, - headers: Default::default(), - body: body.as_bytes().to_vec(), - } - } -} - -impl IntoResponse for Box { - fn into_response(self) -> Response { - let body = self.to_string(); - eprintln!("Handler returned an error: {}", body); - let mut source = self.source(); - while let Some(s) = source { - eprintln!(" caused by: {}", s); - source = s.source(); - } - Response { - status: 500, - headers: Default::default(), - body: body.as_bytes().to_vec(), - } - } -} - -#[cfg(feature = "json")] -impl IntoResponse for super::JsonBodyError { - fn into_response(self) -> Response { - responses::bad_request(Some(format!("invalid JSON body: {}", self.0))) - } -} - -impl IntoResponse for NonUtf8BodyError { - fn into_response(self) -> Response { - responses::bad_request(Some( - "expected body to be a utf8 string but wasn't".to_owned(), - )) - } -} - -impl IntoResponse for std::convert::Infallible { - fn into_response(self) -> Response { - unreachable!() - } -} - -/// A trait for any type that can be turned into a `Response` status code -pub trait IntoStatusCode { - /// Turn `self` into a status code - fn into_status_code(self) -> u16; -} - -impl IntoStatusCode for u16 { - fn into_status_code(self) -> u16 { - self - } -} - -impl IntoStatusCode for hyperium::StatusCode { - fn into_status_code(self) -> u16 { - self.as_u16() - } -} - -/// A trait for any type that can be turned into `Response` headers -pub trait IntoHeaders { - /// Turn `self` into `Response` headers - fn into_headers(self) -> Vec<(String, Vec)>; -} - -impl IntoHeaders for Vec<(String, String)> { - fn into_headers(self) -> Vec<(String, Vec)> { - self.into_iter().map(|(k, v)| (k, v.into_bytes())).collect() - } -} - -impl IntoHeaders for Vec<(String, Vec)> { - fn into_headers(self) -> Vec<(String, Vec)> { - self - } -} - -impl IntoHeaders for HashMap> { - fn into_headers(self) -> Vec<(String, Vec)> { - self.into_iter() - .flat_map(|(k, values)| values.into_iter().map(move |v| (k.clone(), v.into_bytes()))) - .collect() - } -} - -impl IntoHeaders for HashMap { - fn into_headers(self) -> Vec<(String, Vec)> { - self.into_iter().map(|(k, v)| (k, v.into_bytes())).collect() - } -} - -impl IntoHeaders for HashMap> { - fn into_headers(self) -> Vec<(String, Vec)> { - self.into_iter().collect() - } -} - -impl IntoHeaders for &hyperium::HeaderMap { - fn into_headers(self) -> Vec<(String, Vec)> { - self.iter() - .map(|(k, v)| (k.as_str().to_owned(), v.as_bytes().to_owned())) - .collect() - } -} - -impl IntoHeaders for Headers { - fn into_headers(self) -> Vec<(String, Vec)> { - self.entries().into_headers() - } -} - -/// A trait for any type that can be turned into a `Response` body -pub trait IntoBody { - /// Turn `self` into a `Response` body - fn into_body(self) -> Vec; -} - -impl IntoBody for Option { - fn into_body(self) -> Vec { - self.map(|b| IntoBody::into_body(b)).unwrap_or_default() - } -} - -impl IntoBody for Vec { - fn into_body(self) -> Vec { - self - } -} - -impl IntoBody for bytes::Bytes { - fn into_body(self) -> Vec { - self.to_vec() - } -} - -impl IntoBody for () { - fn into_body(self) -> Vec { - Default::default() - } -} - -impl IntoBody for &str { - fn into_body(self) -> Vec { - self.to_owned().into_bytes() - } -} - -impl IntoBody for String { - fn into_body(self) -> Vec { - self.to_owned().into_bytes() - } -} - -/// A trait for converting from a body or failing -pub trait TryFromBody { - /// The error encountered if conversion fails - type Error: IntoResponse; - /// Convert from a body to `Self` or fail - fn try_from_body(body: Vec) -> Result - where - Self: Sized; -} - -impl TryFromBody for Option { - type Error = T::Error; - - fn try_from_body(body: Vec) -> Result - where - Self: Sized, - { - Ok(Some(TryFromBody::try_from_body(body)?)) - } -} - -impl TryFromBody for T { - type Error = std::convert::Infallible; - - fn try_from_body(body: Vec) -> Result - where - Self: Sized, - { - Ok(FromBody::from_body(body)) - } -} - -impl TryFromBody for String { - type Error = NonUtf8BodyError; - - fn try_from_body(body: Vec) -> Result - where - Self: Sized, - { - String::from_utf8(body).map_err(|_| NonUtf8BodyError) - } -} - -#[cfg(feature = "json")] -impl TryFromBody for Json { - type Error = JsonBodyError; - fn try_from_body(body: Vec) -> Result { - Ok(Json(serde_json::from_slice(&body).map_err(JsonBodyError)?)) - } -} - -/// A trait from converting from a body -pub trait FromBody { - /// Convert from a body into the type - fn from_body(body: Vec) -> Self; -} - -impl FromBody for Vec { - fn from_body(body: Vec) -> Self { - body - } -} - -impl FromBody for () { - fn from_body(_body: Vec) -> Self {} -} - -impl FromBody for bytes::Bytes { - fn from_body(body: Vec) -> Self { - Into::into(body) - } -} - -/// A trait for any type that can be turned into a `Response` body or fail -pub trait TryIntoBody { - /// The type of error if the conversion fails - type Error; - /// Turn `self` into an Error - fn try_into_body(self) -> Result, Self::Error>; -} - -impl TryIntoBody for B -where - B: IntoBody, -{ - type Error = std::convert::Infallible; - - fn try_into_body(self) -> Result, Self::Error> { - Ok(self.into_body()) - } -} - -#[cfg(feature = "json")] -impl TryIntoBody for Json { - type Error = JsonBodyError; - - fn try_into_body(self) -> Result, Self::Error> { - serde_json::to_vec(&self.0).map_err(JsonBodyError) - } -} - -/// A trait for converting a type into an `OutgoingRequest` -pub trait TryIntoOutgoingRequest { - /// The error if the conversion fails - type Error; - - /// Turn the type into an `OutgoingRequest` - /// - /// If the implementor can be sure that the `OutgoingRequest::write` has not been called they - /// can return a buffer as the second element of the returned tuple and `send` will send - /// that as the request body. - fn try_into_outgoing_request(self) -> Result<(OutgoingRequest, Option>), Self::Error>; -} - -impl TryIntoOutgoingRequest for OutgoingRequest { - type Error = std::convert::Infallible; - - fn try_into_outgoing_request(self) -> Result<(OutgoingRequest, Option>), Self::Error> { - Ok((self, None)) - } -} - -impl TryIntoOutgoingRequest for Request { - type Error = std::convert::Infallible; - - fn try_into_outgoing_request(self) -> Result<(OutgoingRequest, Option>), Self::Error> { - let headers = self - .headers() - .map(|(k, v)| (k.to_owned(), v.as_bytes().to_owned())) - .collect::>(); - let request = OutgoingRequest::new( - self.method(), - self.path_and_query(), - Some(if self.is_https() { - &super::Scheme::Https - } else { - &super::Scheme::Http - }), - self.authority(), - &Headers::new(&headers), - ); - Ok((request, Some(self.into_body()))) - } -} - -impl TryIntoOutgoingRequest for RequestBuilder { - type Error = std::convert::Infallible; - - fn try_into_outgoing_request( - mut self, - ) -> Result<(OutgoingRequest, Option>), Self::Error> { - self.build().try_into_outgoing_request() - } -} - -impl TryIntoOutgoingRequest for hyperium::Request -where - B: TryIntoBody, - B::Error: std::error::Error + Send + Sync + 'static, -{ - type Error = anyhow::Error; - fn try_into_outgoing_request(self) -> Result<(OutgoingRequest, Option>), Self::Error> { - let headers = self - .headers() - .into_iter() - .map(|(n, v)| (n.as_str().to_owned(), v.as_bytes().to_owned())) - .collect::>(); - let request = OutgoingRequest::new( - &self.method().clone().into(), - self.uri().path_and_query().map(|p| p.as_str()), - self.uri() - .scheme() - .map(|s| match s.as_str() { - "http" => super::Scheme::Http, - "https" => super::Scheme::Https, - s => super::Scheme::Other(s.to_owned()), - }) - .as_ref(), - self.uri().authority().map(|a| a.as_str()), - &Headers::new(&headers), - ); - let buffer = TryIntoBody::try_into_body(self.into_body())?; - Ok((request, Some(buffer))) - } -} - -/// A trait for converting from an `IncomingRequest` -#[async_trait] -pub trait TryFromIncomingResponse { - /// The error if conversion fails - type Error; - /// Turn the `IncomingResponse` into the type - async fn try_from_incoming_response(resp: IncomingResponse) -> Result - where - Self: Sized; -} - -#[async_trait] -impl TryFromIncomingResponse for IncomingResponse { - type Error = std::convert::Infallible; - async fn try_from_incoming_response(resp: IncomingResponse) -> Result { - Ok(resp) - } -} - -#[async_trait] -impl TryFromIncomingResponse for Response { - type Error = streams::Error; - async fn try_from_incoming_response(resp: IncomingResponse) -> Result { - Ok(Response::builder() - .status(resp.status()) - .headers(resp.headers()) - .body(resp.into_body().await?) - .build()) - } -} - -#[async_trait] -impl TryFromIncomingResponse for hyperium::Response { - type Error = B::Error; - async fn try_from_incoming_response(resp: IncomingResponse) -> Result { - let mut builder = hyperium::Response::builder().status(resp.status()); - for (n, v) in resp.headers().entries() { - builder = builder.header(n, v); - } - let body = resp.into_body().await.expect("TODO"); - Ok(builder.body(B::try_from_body(body)?).unwrap()) - } -} - -/// Turn a type into a `Request` -pub trait TryIntoRequest { - /// The error if the conversion fails - type Error; - - /// Turn `self` into a `Request` - fn try_into_request(self) -> Result; -} - -impl TryIntoRequest for Request { - type Error = std::convert::Infallible; - - fn try_into_request(self) -> Result { - Ok(self) - } -} - -impl TryIntoRequest for hyperium::Request { - type Error = B::Error; - fn try_into_request(self) -> Result { - Ok(Request::builder() - .method(self.method().clone().into()) - .uri(self.uri().to_string()) - .headers(self.headers()) - .body(B::try_into_body(self.into_body())?) - .build()) - } -} diff --git a/sdk/rust/src/http/executor.rs b/sdk/rust/src/http/executor.rs deleted file mode 100644 index cfe9b4d30f..0000000000 --- a/sdk/rust/src/http/executor.rs +++ /dev/null @@ -1,220 +0,0 @@ -use crate::wit::wasi::http0_2_0_rc_2023_10_18::outgoing_handler; -use crate::wit::wasi::http0_2_0_rc_2023_10_18::types::{ - self, IncomingBody, IncomingResponse, OutgoingBody, OutgoingRequest, -}; -use crate::wit::wasi::io0_2_0_rc_2023_10_18 as io; -use crate::wit::wasi::io0_2_0_rc_2023_10_18::streams::{InputStream, OutputStream, StreamError}; - -use futures::{future, sink, stream, Sink, Stream}; - -use std::cell::RefCell; -use std::future::Future; -use std::mem; -use std::rc::Rc; -use std::sync::{Arc, Mutex}; -use std::task::{Context, Poll, Wake, Waker}; - -const READ_SIZE: u64 = 16 * 1024; - -static WAKERS: Mutex> = Mutex::new(Vec::new()); - -/// Run the specified future to completion blocking until it yields a result. -/// -/// Based on an executor using `wasi::io/poll/poll-list`, -pub fn run(future: impl Future) -> T { - futures::pin_mut!(future); - struct DummyWaker; - - impl Wake for DummyWaker { - fn wake(self: Arc) {} - } - - let waker = Arc::new(DummyWaker).into(); - - loop { - match future.as_mut().poll(&mut Context::from_waker(&waker)) { - Poll::Pending => { - let mut new_wakers = Vec::new(); - - let wakers = mem::take::>(&mut WAKERS.lock().unwrap()); - - assert!(!wakers.is_empty()); - - let pollables = wakers - .iter() - .map(|(pollable, _)| pollable) - .collect::>(); - - let mut ready = vec![false; wakers.len()]; - - for index in io::poll::poll_list(&pollables) { - ready[usize::try_from(index).unwrap()] = true; - } - - for (ready, (pollable, waker)) in ready.into_iter().zip(wakers) { - if ready { - waker.wake() - } else { - new_wakers.push((pollable, waker)); - } - } - - *WAKERS.lock().unwrap() = new_wakers; - } - Poll::Ready(result) => break result, - } - } -} - -pub(crate) fn outgoing_body(body: OutgoingBody) -> impl Sink, Error = types::Error> { - struct Outgoing(Option<(OutputStream, OutgoingBody)>); - - impl Drop for Outgoing { - fn drop(&mut self) { - if let Some((stream, body)) = self.0.take() { - drop(stream); - OutgoingBody::finish(body, None); - } - } - } - - let stream = body.write().expect("response body should be writable"); - let pair = Rc::new(RefCell::new(Outgoing(Some((stream, body))))); - - sink::unfold((), { - move |(), chunk: Vec| { - future::poll_fn({ - let mut offset = 0; - let mut flushing = false; - let pair = pair.clone(); - - move |context| { - let pair = pair.borrow(); - let (stream, _) = &pair.0.as_ref().unwrap(); - loop { - match stream.check_write() { - Ok(0) => { - WAKERS - .lock() - .unwrap() - .push((stream.subscribe(), context.waker().clone())); - - break Poll::Pending; - } - Ok(count) => { - if offset == chunk.len() { - if flushing { - break Poll::Ready(Ok(())); - } else { - match stream.flush() { - Ok(()) => flushing = true, - Err(StreamError::Closed) => break Poll::Ready(Ok(())), - Err(StreamError::LastOperationFailed(e)) => { - break Poll::Ready(Err( - types::Error::ProtocolError(format!( - "I/O error: {e}" - )), - )) - } - } - } - } else { - let count = - usize::try_from(count).unwrap().min(chunk.len() - offset); - - match stream.write(&chunk[offset..][..count]) { - Ok(()) => { - offset += count; - } - Err(e) => { - break Poll::Ready(Err(types::Error::ProtocolError( - format!("I/O error: {e}"), - ))) - } - } - } - } - // If the stream is closed but the entire chunk was - // written then we've done all we could so this - // chunk is now complete. - Err(StreamError::Closed) if offset == chunk.len() => { - break Poll::Ready(Ok(())) - } - Err(e) => { - break Poll::Ready(Err(types::Error::ProtocolError(format!( - "I/O error: {e}" - )))) - } - } - } - } - }) - } - }) -} - -/// Send the specified request and return the response. -pub(crate) fn outgoing_request_send( - request: OutgoingRequest, -) -> impl Future> { - let response = outgoing_handler::handle(request, None); - future::poll_fn({ - move |context| match &response { - Ok(response) => { - if let Some(response) = response.get() { - Poll::Ready(response.unwrap()) - } else { - WAKERS - .lock() - .unwrap() - .push((response.subscribe(), context.waker().clone())); - Poll::Pending - } - } - Err(error) => Poll::Ready(Err(error.clone())), - } - }) -} - -#[doc(hidden)] -pub fn incoming_body( - body: IncomingBody, -) -> impl Stream, io::streams::Error>> { - struct Incoming(Option<(InputStream, IncomingBody)>); - - impl Drop for Incoming { - fn drop(&mut self) { - if let Some((stream, body)) = self.0.take() { - drop(stream); - IncomingBody::finish(body); - } - } - } - - stream::poll_fn({ - let stream = body.stream().expect("response body should be readable"); - let pair = Incoming(Some((stream, body))); - - move |context| { - if let Some((stream, _)) = &pair.0 { - match stream.read(READ_SIZE) { - Ok(buffer) => { - if buffer.is_empty() { - WAKERS - .lock() - .unwrap() - .push((stream.subscribe(), context.waker().clone())); - Poll::Pending - } else { - Poll::Ready(Some(Ok(buffer))) - } - } - Err(StreamError::Closed) => Poll::Ready(None), - Err(StreamError::LastOperationFailed(error)) => Poll::Ready(Some(Err(error))), - } - } else { - Poll::Ready(None) - } - } - }) -} diff --git a/sdk/rust/src/http/router.rs b/sdk/rust/src/http/router.rs deleted file mode 100644 index ca04046bad..0000000000 --- a/sdk/rust/src/http/router.rs +++ /dev/null @@ -1,585 +0,0 @@ -// This router implementation is heavily inspired by the `Endpoint` type in the https://github.com/http-rs/tide project. - -use super::conversions::{IntoResponse, TryFromRequest, TryIntoRequest}; -use super::{responses, Method, Request, Response}; -use async_trait::async_trait; -use routefinder::{Captures, Router as MethodRouter}; -use std::future::Future; -use std::{collections::HashMap, fmt::Display}; - -/// An HTTP request handler. -/// -/// This trait is automatically implemented for `Fn` types, and so is rarely implemented -/// directly by Spin users. -#[async_trait(?Send)] -pub trait Handler { - /// Invoke the handler. - async fn handle(&self, req: Request, params: Params) -> Response; -} - -#[async_trait(?Send)] -impl Handler for Box { - async fn handle(&self, req: Request, params: Params) -> Response { - self.as_ref().handle(req, params).await - } -} - -#[async_trait(?Send)] -impl Handler for F -where - F: Fn(Request, Params) -> Fut + 'static, - Fut: Future + 'static, -{ - async fn handle(&self, req: Request, params: Params) -> Response { - let fut = (self)(req, params); - fut.await - } -} - -/// Route parameters extracted from a URI that match a route pattern. -pub type Params = Captures<'static, 'static>; - -/// The Spin SDK HTTP router. -pub struct Router { - methods_map: HashMap>>, - any_methods: MethodRouter>, -} - -impl Default for Router { - fn default() -> Router { - Router::new() - } -} - -impl Display for Router { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - writeln!(f, "Registered routes:")?; - for (method, router) in &self.methods_map { - for route in router.iter() { - writeln!(f, "- {}: {}", method, route.0)?; - } - } - Ok(()) - } -} - -struct RouteMatch<'a> { - params: Captures<'static, 'static>, - handler: &'a dyn Handler, -} - -impl Router { - /// Synchronously dispatches a request to the appropriate handler along with the URI parameters. - pub fn handle(&self, request: R) -> Response - where - R: TryIntoRequest, - R::Error: IntoResponse, - { - crate::http::executor::run(self.handle_async(request)) - } - - /// Asynchronously dispatches a request to the appropriate handler along with the URI parameters. - pub async fn handle_async(&self, request: R) -> Response - where - R: TryIntoRequest, - R::Error: IntoResponse, - { - let request = match R::try_into_request(request) { - Ok(r) => r, - Err(e) => return e.into_response(), - }; - let method = request.method.clone(); - let path = &request.path(); - let RouteMatch { params, handler } = self.find(path, method); - handler.handle(request, params).await - } - - fn find(&self, path: &str, method: Method) -> RouteMatch<'_> { - let best_match = self - .methods_map - .get(&method) - .and_then(|r| r.best_match(path)); - - if let Some(m) = best_match { - let params = m.captures().into_owned(); - let handler = m.handler(); - return RouteMatch { handler, params }; - } - - let best_match = self.any_methods.best_match(path); - - match best_match { - Some(m) => { - let params = m.captures().into_owned(); - let handler = m.handler(); - RouteMatch { handler, params } - } - None if method == Method::Head => { - // If it is a HTTP HEAD request then check if there is a callback in the methods map - // if not then fallback to the behavior of HTTP GET else proceed as usual - self.find(path, Method::Get) - } - None => { - // Handle the failure case where no match could be resolved. - self.fail(path, method) - } - } - } - - // Helper function to handle the case where a best match couldn't be resolved. - fn fail(&self, path: &str, method: Method) -> RouteMatch<'_> { - // First, filter all routers to determine if the path can match but the provided method is not allowed. - let is_method_not_allowed = self - .methods_map - .iter() - .filter(|(k, _)| **k != method) - .any(|(_, r)| r.best_match(path).is_some()); - - if is_method_not_allowed { - // If this `path` can be handled by a callback registered with a different HTTP method - // should return 405 Method Not Allowed - RouteMatch { - handler: &method_not_allowed, - params: Captures::default(), - } - } else { - // ... Otherwise, nothing matched so 404. - RouteMatch { - handler: ¬_found, - params: Captures::default(), - } - } - } - - /// Register a handler at the path for all methods. - pub fn any(&mut self, path: &str, handler: F) - where - F: Fn(Req, Params) -> Resp + 'static, - Req: TryFromRequest + 'static, - Req::Error: IntoResponse + 'static, - Resp: IntoResponse + 'static, - { - let handler = move |req, params| { - let res = TryFromRequest::try_from_request(req).map(|r| handler(r, params)); - async move { - match res { - Ok(res) => res.into_response(), - Err(e) => e.into_response(), - } - } - }; - - self.any_async(path, handler) - } - - /// Register an async handler at the path for all methods. - pub fn any_async(&mut self, path: &str, handler: F) - where - F: Fn(I, Params) -> Fut + 'static, - Fut: Future + 'static, - I: TryFromRequest + 'static, - I::Error: IntoResponse + 'static, - O: IntoResponse + 'static, - { - let handler = move |req, params| { - let res = TryFromRequest::try_from_request(req).map(|r| handler(r, params)); - async move { - match res { - Ok(f) => f.await.into_response(), - Err(e) => e.into_response(), - } - } - }; - - self.any_methods.add(path, Box::new(handler)).unwrap(); - } - - /// Register a handler at the path for the specified HTTP method. - pub fn add(&mut self, path: &str, method: Method, handler: F) - where - F: Fn(Req, Params) -> Resp + 'static, - Req: TryFromRequest + 'static, - Req::Error: IntoResponse + 'static, - Resp: IntoResponse + 'static, - { - let handler = move |req, params| { - let res = TryFromRequest::try_from_request(req).map(|r| handler(r, params)); - async move { - match res { - Ok(res) => res.into_response(), - Err(e) => e.into_response(), - } - } - }; - - self.add_async(path, method, handler) - } - - /// Register an async handler at the path for the specified HTTP method. - pub fn add_async(&mut self, path: &str, method: Method, handler: F) - where - F: Fn(I, Params) -> Fut + 'static, - Fut: Future + 'static, - I: TryFromRequest + 'static, - I::Error: IntoResponse + 'static, - O: IntoResponse + 'static, - { - let handler = move |req, params| { - let res = TryFromRequest::try_from_request(req).map(|r| handler(r, params)); - async move { - match res { - Ok(f) => f.await.into_response(), - Err(e) => e.into_response(), - } - } - }; - - self.methods_map - .entry(method) - .or_default() - .add(path, Box::new(handler)) - .unwrap(); - } - - /// Register a handler at the path for the HTTP GET method. - pub fn get(&mut self, path: &str, handler: F) - where - F: Fn(Req, Params) -> Resp + 'static, - Req: TryFromRequest + 'static, - Req::Error: IntoResponse + 'static, - Resp: IntoResponse + 'static, - { - self.add(path, Method::Get, handler) - } - - /// Register an async handler at the path for the HTTP GET method. - pub fn get_async(&mut self, path: &str, handler: F) - where - F: Fn(Req, Params) -> Fut + 'static, - Fut: Future + 'static, - Req: TryFromRequest + 'static, - Req::Error: IntoResponse + 'static, - Resp: IntoResponse + 'static, - { - self.add_async(path, Method::Get, handler) - } - - /// Register a handler at the path for the HTTP HEAD method. - pub fn head(&mut self, path: &str, handler: F) - where - F: Fn(Req, Params) -> Resp + 'static, - Req: TryFromRequest + 'static, - Req::Error: IntoResponse + 'static, - Resp: IntoResponse + 'static, - { - self.add(path, Method::Head, handler) - } - - /// Register an async handler at the path for the HTTP HEAD method. - pub fn head_async(&mut self, path: &str, handler: F) - where - F: Fn(Req, Params) -> Fut + 'static, - Fut: Future + 'static, - Req: TryFromRequest + 'static, - Req::Error: IntoResponse + 'static, - Resp: IntoResponse + 'static, - { - self.add_async(path, Method::Head, handler) - } - - /// Register a handler at the path for the HTTP POST method. - pub fn post(&mut self, path: &str, handler: F) - where - F: Fn(Req, Params) -> Resp + 'static, - Req: TryFromRequest + 'static, - Req::Error: IntoResponse + 'static, - Resp: IntoResponse + 'static, - { - self.add(path, Method::Post, handler) - } - - /// Register an async handler at the path for the HTTP POST method. - pub fn post_async(&mut self, path: &str, handler: F) - where - F: Fn(Req, Params) -> Fut + 'static, - Fut: Future + 'static, - Req: TryFromRequest + 'static, - Req::Error: IntoResponse + 'static, - Resp: IntoResponse + 'static, - { - self.add_async(path, Method::Post, handler) - } - - /// Register a handler at the path for the HTTP DELETE method. - pub fn delete(&mut self, path: &str, handler: F) - where - F: Fn(Req, Params) -> Resp + 'static, - Req: TryFromRequest + 'static, - Req::Error: IntoResponse + 'static, - Resp: IntoResponse + 'static, - { - self.add(path, Method::Delete, handler) - } - - /// Register an async handler at the path for the HTTP DELETE method. - pub fn delete_async(&mut self, path: &str, handler: F) - where - F: Fn(Req, Params) -> Fut + 'static, - Fut: Future + 'static, - Req: TryFromRequest + 'static, - Req::Error: IntoResponse + 'static, - Resp: IntoResponse + 'static, - { - self.add_async(path, Method::Delete, handler) - } - - /// Register a handler at the path for the HTTP PUT method. - pub fn put(&mut self, path: &str, handler: F) - where - F: Fn(Req, Params) -> Resp + 'static, - Req: TryFromRequest + 'static, - Req::Error: IntoResponse + 'static, - Resp: IntoResponse + 'static, - { - self.add(path, Method::Put, handler) - } - - /// Register an async handler at the path for the HTTP PUT method. - pub fn put_async(&mut self, path: &str, handler: F) - where - F: Fn(Req, Params) -> Fut + 'static, - Fut: Future + 'static, - Req: TryFromRequest + 'static, - Req::Error: IntoResponse + 'static, - Resp: IntoResponse + 'static, - { - self.add_async(path, Method::Put, handler) - } - - /// Register a handler at the path for the HTTP PATCH method. - pub fn patch(&mut self, path: &str, handler: F) - where - F: Fn(Req, Params) -> Resp + 'static, - Req: TryFromRequest + 'static, - Req::Error: IntoResponse + 'static, - Resp: IntoResponse + 'static, - { - self.add(path, Method::Patch, handler) - } - - /// Register an async handler at the path for the HTTP PATCH method. - pub fn patch_async(&mut self, path: &str, handler: F) - where - F: Fn(Req, Params) -> Fut + 'static, - Fut: Future + 'static, - Req: TryFromRequest + 'static, - Req::Error: IntoResponse + 'static, - Resp: IntoResponse + 'static, - { - self.add_async(path, Method::Patch, handler) - } - - /// Register a handler at the path for the HTTP OPTIONS method. - pub fn options(&mut self, path: &str, handler: F) - where - F: Fn(Req, Params) -> Resp + 'static, - Req: TryFromRequest + 'static, - Req::Error: IntoResponse + 'static, - Resp: IntoResponse + 'static, - { - self.add(path, Method::Options, handler) - } - - /// Register an async handler at the path for the HTTP OPTIONS method. - pub fn options_async(&mut self, path: &str, handler: F) - where - F: Fn(Req, Params) -> Fut + 'static, - Fut: Future + 'static, - Req: TryFromRequest + 'static, - Req::Error: IntoResponse + 'static, - Resp: IntoResponse + 'static, - { - self.add_async(path, Method::Options, handler) - } - - /// Construct a new Router. - pub fn new() -> Self { - Router { - methods_map: HashMap::default(), - any_methods: MethodRouter::new(), - } - } -} - -async fn not_found(_req: Request, _params: Params) -> Response { - responses::not_found() -} - -async fn method_not_allowed(_req: Request, _params: Params) -> Response { - responses::method_not_allowed() -} - -/// A macro to help with constructing a Router from a stream of tokens. -#[macro_export] -macro_rules! http_router { - ($($method:tt $path:literal => $h:expr),*) => { - { - let mut router = $crate::http::Router::new(); - $( - $crate::http_router!(@build router $method $path => $h); - )* - router - } - }; - (@build $r:ident HEAD $path:literal => $h:expr) => { - $r.head($path, $h); - }; - (@build $r:ident GET $path:literal => $h:expr) => { - $r.get($path, $h); - }; - (@build $r:ident PUT $path:literal => $h:expr) => { - $r.put($path, $h); - }; - (@build $r:ident POST $path:literal => $h:expr) => { - $r.post($path, $h); - }; - (@build $r:ident PATCH $path:literal => $h:expr) => { - $r.patch($path, $h); - }; - (@build $r:ident DELETE $path:literal => $h:expr) => { - $r.delete($path, $h); - }; - (@build $r:ident OPTIONS $path:literal => $h:expr) => { - $r.options($path, $h); - }; - (@build $r:ident _ $path:literal => $h:expr) => { - $r.any($path, $h); - }; -} - -#[cfg(test)] -mod tests { - use super::*; - - fn make_request(method: Method, path: &str) -> Request { - Request::new(method, path) - } - - fn echo_param(_req: Request, params: Params) -> Response { - match params.get("x") { - Some(path) => Response::new(200, path), - None => responses::not_found(), - } - } - - #[test] - fn test_method_not_allowed() { - let mut router = Router::default(); - router.get("/:x", echo_param); - - let req = make_request(Method::Post, "/foobar"); - let res = router.handle(req); - assert_eq!(res.status, hyperium::StatusCode::METHOD_NOT_ALLOWED); - } - - #[test] - fn test_not_found() { - fn h1(_req: Request, _params: Params) -> anyhow::Result { - Ok(Response::new(200, ())) - } - - let mut router = Router::default(); - router.get("/h1/:param", h1); - - let req = make_request(Method::Get, "/h1/"); - let res = router.handle(req); - assert_eq!(res.status, hyperium::StatusCode::NOT_FOUND); - } - - #[test] - fn test_multi_param() { - fn multiply(_req: Request, params: Params) -> anyhow::Result { - let x: i64 = params.get("x").unwrap().parse()?; - let y: i64 = params.get("y").unwrap().parse()?; - Ok(Response::new(200, format!("{result}", result = x * y))) - } - - let mut router = Router::default(); - router.get("/multiply/:x/:y", multiply); - - let req = make_request(Method::Get, "/multiply/2/4"); - let res = router.handle(req); - - assert_eq!(res.body, "8".to_owned().into_bytes()); - } - - #[test] - fn test_param() { - let mut router = Router::default(); - router.get("/:x", echo_param); - - let req = make_request(Method::Get, "/y"); - let res = router.handle(req); - - assert_eq!(res.body, "y".to_owned().into_bytes()); - } - - #[test] - fn test_wildcard() { - fn echo_wildcard(_req: Request, params: Params) -> Response { - match params.wildcard() { - Some(path) => Response::new(200, path), - None => responses::not_found(), - } - } - - let mut router = Router::default(); - router.get("/*", echo_wildcard); - - let req = make_request(Method::Get, "/foo/bar"); - let res = router.handle(req); - assert_eq!(res.status, hyperium::StatusCode::OK); - assert_eq!(res.body, "foo/bar".to_owned().into_bytes()); - } - - #[test] - fn test_wildcard_last_segment() { - let mut router = Router::default(); - router.get("/:x/*", echo_param); - - let req = make_request(Method::Get, "/foo/bar"); - let res = router.handle(req); - assert_eq!(res.body, "foo".to_owned().into_bytes()); - } - - #[test] - fn test_router_display() { - let mut router = Router::default(); - router.get("/:x", echo_param); - - let expected = "Registered routes:\n- GET: /:x\n"; - let actual = format!("{}", router); - - assert_eq!(actual.as_str(), expected); - } - - #[test] - fn test_ambiguous_wildcard_vs_star() { - fn h1(_req: Request, _params: Params) -> anyhow::Result { - Ok(Response::new(200, "one/two")) - } - - fn h2(_req: Request, _params: Params) -> anyhow::Result { - Ok(Response::new(200, "posts/*")) - } - - let mut router = Router::default(); - router.get("/:one/:two", h1); - router.get("/posts/*", h2); - - let req = make_request(Method::Get, "/posts/2"); - let res = router.handle(req); - - assert_eq!(res.body, "posts/*".to_owned().into_bytes()); - } -} diff --git a/sdk/rust/src/key_value.rs b/sdk/rust/src/key_value.rs deleted file mode 100644 index 7a62a8f4f9..0000000000 --- a/sdk/rust/src/key_value.rs +++ /dev/null @@ -1,46 +0,0 @@ -//! Spin key-value persistent storage -//! -//! This module provides a generic interface for key-value storage, which may be implemented by the host various -//! ways (e.g. via an in-memory table, a local file, or a remote database). Details such as consistency model and -//! durability will depend on the implementation and may vary from one to store to the next. - -use super::wit::v2::key_value; - -#[cfg(feature = "json")] -use serde::{de::DeserializeOwned, Serialize}; - -#[doc(inline)] -pub use key_value::{Error, Store}; - -impl Store { - /// Open the default store. - /// - /// This is equivalent to `Store::open("default")`. - pub fn open_default() -> Result { - Self::open("default") - } -} - -impl Store { - #[cfg(feature = "json")] - /// Serialize the given data to JSON, then set it as the value for the specified `key`. - pub fn set_json( - &self, - key: impl AsRef, - value: &T, - ) -> Result<(), anyhow::Error> { - Ok(self.set(key.as_ref(), &serde_json::to_vec(value)?)?) - } - - #[cfg(feature = "json")] - /// Deserialize an instance of type `T` from the value of `key`. - pub fn get_json( - &self, - key: impl AsRef, - ) -> Result, anyhow::Error> { - let Some(value) = self.get(key.as_ref())? else { - return Ok(None); - }; - Ok(serde_json::from_slice(&value)?) - } -} diff --git a/sdk/rust/src/lib.rs b/sdk/rust/src/lib.rs deleted file mode 100644 index 2b9149abb3..0000000000 --- a/sdk/rust/src/lib.rs +++ /dev/null @@ -1,97 +0,0 @@ -//! The Rust Spin SDK. - -#![deny(missing_docs)] - -/// Key/Value storage. -pub mod key_value; - -/// SQLite storage. -pub mod sqlite; - -/// Large Language Model APIs -pub mod llm; - -/// Exports the procedural macros for writing handlers for Spin components. -pub use spin_macro::*; - -#[doc(hidden)] -/// Module containing wit bindgen generated code. -/// -/// This is only meant for internal consumption. -pub mod wit { - #![allow(missing_docs)] - - wit_bindgen::generate!({ - world: "platform-rc20231018", - path: "./wit", - }); - pub use fermyon::spin2_0_0 as v2; -} - -/// Needed by the export macro -/// -/// See [this commit](https://github.com/bytecodealliance/wit-bindgen/pull/394/commits/9d2ea88f986f4a883ba243449e3a070cac18958e) for more info. -#[cfg(target_arch = "wasm32")] -#[doc(hidden)] -pub use wit::__link_section; - -#[export_name = concat!("spin-sdk-version-", env!("SDK_VERSION"))] -extern "C" fn __spin_sdk_version() {} - -#[cfg(feature = "export-sdk-language")] -#[export_name = "spin-sdk-language-rust"] -extern "C" fn __spin_sdk_language() {} - -#[export_name = concat!("spin-sdk-commit-", env!("SDK_COMMIT"))] -extern "C" fn __spin_sdk_hash() {} - -/// Helpers for building Spin `wasi-http` components. -pub mod http; - -/// Implementation of the spin redis interface. -#[allow(missing_docs)] -pub mod redis { - use std::hash::{Hash, Hasher}; - - pub use super::wit::v2::redis::{Connection, Error, Payload, RedisParameter, RedisResult}; - - impl PartialEq for RedisResult { - fn eq(&self, other: &Self) -> bool { - use RedisResult::*; - match (self, other) { - (Nil, Nil) => true, - (Status(a), Status(b)) => a == b, - (Int64(a), Int64(b)) => a == b, - (Binary(a), Binary(b)) => a == b, - _ => false, - } - } - } - - impl Eq for RedisResult {} - - impl Hash for RedisResult { - fn hash(&self, state: &mut H) { - use RedisResult::*; - - match self { - Nil => (), - Status(s) => s.hash(state), - Int64(v) => v.hash(state), - Binary(v) => v.hash(state), - } - } - } -} - -/// Implementation of the spin postgres db interface. -pub mod pg; - -/// Implementation of the Spin MySQL database interface. -pub mod mysql; - -#[doc(inline)] -pub use wit::v2::variables; - -#[doc(hidden)] -pub use wit_bindgen; diff --git a/sdk/rust/src/llm.rs b/sdk/rust/src/llm.rs deleted file mode 100644 index adad39ae0e..0000000000 --- a/sdk/rust/src/llm.rs +++ /dev/null @@ -1,77 +0,0 @@ -pub use crate::wit::v2::llm::{ - self, EmbeddingsResult, EmbeddingsUsage, Error, InferencingParams, InferencingResult, - InferencingUsage, -}; - -/// The model use for inferencing -#[allow(missing_docs)] -#[derive(Debug, Clone, Copy)] -pub enum InferencingModel<'a> { - Llama2Chat, - CodellamaInstruct, - Other(&'a str), -} - -impl<'a> std::fmt::Display for InferencingModel<'a> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let str = match self { - InferencingModel::Llama2Chat => "llama2-chat", - InferencingModel::CodellamaInstruct => "codellama-instruct", - InferencingModel::Other(s) => s, - }; - f.write_str(str) - } -} - -impl Default for InferencingParams { - fn default() -> Self { - Self { - max_tokens: 100, - repeat_penalty: 1.1, - repeat_penalty_last_n_token_count: 64, - temperature: 0.8, - top_k: 40, - top_p: 0.9, - } - } -} - -/// Perform inferencing using the provided model and prompt -pub fn infer(model: InferencingModel, prompt: &str) -> Result { - llm::infer(&model.to_string(), prompt, None) -} - -/// Perform inferencing using the provided model, prompt, and options -pub fn infer_with_options( - model: InferencingModel, - prompt: &str, - options: InferencingParams, -) -> Result { - llm::infer(&model.to_string(), prompt, Some(options)) -} - -/// Model used for generating embeddings -#[allow(missing_docs)] -#[derive(Debug, Clone, Copy)] -pub enum EmbeddingModel<'a> { - AllMiniLmL6V2, - Other(&'a str), -} - -impl<'a> std::fmt::Display for EmbeddingModel<'a> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let str = match self { - EmbeddingModel::AllMiniLmL6V2 => "all-minilm-l6-v2", - EmbeddingModel::Other(s) => s, - }; - f.write_str(str) - } -} - -/// Generate embeddings using the provided model and collection of text -pub fn generate_embeddings( - model: EmbeddingModel, - text: &[String], -) -> Result { - llm::generate_embeddings(&model.to_string(), text) -} diff --git a/sdk/rust/src/mysql.rs b/sdk/rust/src/mysql.rs deleted file mode 100644 index 104ded4a12..0000000000 --- a/sdk/rust/src/mysql.rs +++ /dev/null @@ -1,280 +0,0 @@ -//! Conversions between Rust, WIT and **MySQL** types. -//! -//! # Types -//! -//! | Rust type | WIT (db-value) | MySQL type(s) | -//! |-----------|---------------------|-------------------------| -//! | `bool` | int8(s8) | TINYINT(1), BOOLEAN | -//! | `i8` | int8(s8) | TINYINT | -//! | `i16` | int16(s16) | SMALLINT | -//! | `i32` | int32(s32) | MEDIUM, INT | -//! | `i64` | int64(s64) | BIGINT | -//! | `u8` | uint8(u8) | TINYINT UNSIGNED | -//! | `u16` | uint16(u16) | SMALLINT UNSIGNED | -//! | `u32` | uint32(u32) | INT UNSIGNED | -//! | `u64` | uint64(u64) | BIGINT UNSIGNED | -//! | `f32` | floating32(float32) | FLOAT | -//! | `f64` | floating64(float64) | DOUBLE | -//! | `String` | str(string) | VARCHAR, CHAR, TEXT | -//! | `Vec` | binary(list\) | VARBINARY, BINARY, BLOB | - -#[doc(inline)] -pub use super::wit::v2::mysql::{Connection, Error as MysqlError}; -#[doc(inline)] -pub use super::wit::v2::rdbms_types::*; - -/// A MySQL error -#[derive(Debug, thiserror::Error)] -pub enum Error { - /// Failed to deserialize [`DbValue`] - #[error("error value decoding: {0}")] - Decode(String), - /// MySQL query failed with an error - #[error(transparent)] - MysqlError(#[from] MysqlError), -} - -/// A type that can be decoded from the database. -pub trait Decode: Sized { - /// Decode a new value of this type using a [`DbValue`]. - fn decode(value: &DbValue) -> Result; -} - -impl Decode for Option -where - T: Decode, -{ - fn decode(value: &DbValue) -> Result { - match value { - DbValue::DbNull => Ok(None), - v => Ok(Some(T::decode(v)?)), - } - } -} - -impl Decode for bool { - fn decode(value: &DbValue) -> Result { - match value { - DbValue::Int8(0) => Ok(false), - DbValue::Int8(1) => Ok(true), - _ => Err(Error::Decode(format_decode_err( - "TINYINT(1), BOOLEAN", - value, - ))), - } - } -} - -impl Decode for i8 { - fn decode(value: &DbValue) -> Result { - match value { - DbValue::Int8(n) => Ok(*n), - _ => Err(Error::Decode(format_decode_err("TINYINT", value))), - } - } -} - -impl Decode for i16 { - fn decode(value: &DbValue) -> Result { - match value { - DbValue::Int16(n) => Ok(*n), - _ => Err(Error::Decode(format_decode_err("SMALLINT", value))), - } - } -} - -impl Decode for i32 { - fn decode(value: &DbValue) -> Result { - match value { - DbValue::Int32(n) => Ok(*n), - _ => Err(Error::Decode(format_decode_err("INT", value))), - } - } -} - -impl Decode for i64 { - fn decode(value: &DbValue) -> Result { - match value { - DbValue::Int64(n) => Ok(*n), - _ => Err(Error::Decode(format_decode_err("BIGINT", value))), - } - } -} - -impl Decode for u8 { - fn decode(value: &DbValue) -> Result { - match value { - DbValue::Uint8(n) => Ok(*n), - _ => Err(Error::Decode(format_decode_err("UNSIGNED TINYINT", value))), - } - } -} - -impl Decode for u16 { - fn decode(value: &DbValue) -> Result { - match value { - DbValue::Uint16(n) => Ok(*n), - _ => Err(Error::Decode(format_decode_err("UNSIGNED SMALLINT", value))), - } - } -} - -impl Decode for u32 { - fn decode(value: &DbValue) -> Result { - match value { - DbValue::Uint32(n) => Ok(*n), - _ => Err(Error::Decode(format_decode_err( - "UNISIGNED MEDIUMINT, UNSIGNED INT", - value, - ))), - } - } -} - -impl Decode for u64 { - fn decode(value: &DbValue) -> Result { - match value { - DbValue::Uint64(n) => Ok(*n), - _ => Err(Error::Decode(format_decode_err("UNSIGNED BIGINT", value))), - } - } -} - -impl Decode for f32 { - fn decode(value: &DbValue) -> Result { - match value { - DbValue::Floating32(n) => Ok(*n), - _ => Err(Error::Decode(format_decode_err("FLOAT", value))), - } - } -} - -impl Decode for f64 { - fn decode(value: &DbValue) -> Result { - match value { - DbValue::Floating64(n) => Ok(*n), - _ => Err(Error::Decode(format_decode_err("DOUBLE", value))), - } - } -} - -impl Decode for Vec { - fn decode(value: &DbValue) -> Result { - match value { - DbValue::Binary(n) => Ok(n.to_owned()), - _ => Err(Error::Decode(format_decode_err("BINARY, VARBINARY", value))), - } - } -} - -impl Decode for String { - fn decode(value: &DbValue) -> Result { - match value { - DbValue::Str(s) => Ok(s.to_owned()), - _ => Err(Error::Decode(format_decode_err( - "CHAR, VARCHAR, TEXT", - value, - ))), - } - } -} - -fn format_decode_err(types: &str, value: &DbValue) -> String { - format!("Expected {} from the DB but got {:?}", types, value) -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn boolean() { - assert!(bool::decode(&DbValue::Int8(1)).unwrap()); - assert!(bool::decode(&DbValue::Int8(3)).is_err()); - assert!(bool::decode(&DbValue::Int32(0)).is_err()); - assert!(Option::::decode(&DbValue::DbNull).unwrap().is_none()); - } - - #[test] - fn int8() { - assert_eq!(i8::decode(&DbValue::Int8(0)).unwrap(), 0); - assert!(i8::decode(&DbValue::Int32(0)).is_err()); - assert!(Option::::decode(&DbValue::DbNull).unwrap().is_none()); - } - - #[test] - fn int16() { - assert_eq!(i16::decode(&DbValue::Int16(0)).unwrap(), 0); - assert!(i16::decode(&DbValue::Int32(0)).is_err()); - assert!(Option::::decode(&DbValue::DbNull).unwrap().is_none()); - } - - #[test] - fn int32() { - assert_eq!(i32::decode(&DbValue::Int32(0)).unwrap(), 0); - assert!(i32::decode(&DbValue::Boolean(false)).is_err()); - assert!(Option::::decode(&DbValue::DbNull).unwrap().is_none()); - } - - #[test] - fn int64() { - assert_eq!(i64::decode(&DbValue::Int64(0)).unwrap(), 0); - assert!(i64::decode(&DbValue::Boolean(false)).is_err()); - assert!(Option::::decode(&DbValue::DbNull).unwrap().is_none()); - } - - #[test] - fn uint8() { - assert_eq!(u8::decode(&DbValue::Uint8(0)).unwrap(), 0); - assert!(u8::decode(&DbValue::Uint32(0)).is_err()); - assert!(Option::::decode(&DbValue::DbNull).unwrap().is_none()); - } - - #[test] - fn uint16() { - assert_eq!(u16::decode(&DbValue::Uint16(0)).unwrap(), 0); - assert!(u16::decode(&DbValue::Uint32(0)).is_err()); - assert!(Option::::decode(&DbValue::DbNull).unwrap().is_none()); - } - - #[test] - fn uint32() { - assert_eq!(u32::decode(&DbValue::Uint32(0)).unwrap(), 0); - assert!(u32::decode(&DbValue::Boolean(false)).is_err()); - assert!(Option::::decode(&DbValue::DbNull).unwrap().is_none()); - } - - #[test] - fn uint64() { - assert_eq!(u64::decode(&DbValue::Uint64(0)).unwrap(), 0); - assert!(u64::decode(&DbValue::Boolean(false)).is_err()); - assert!(Option::::decode(&DbValue::DbNull).unwrap().is_none()); - } - - #[test] - fn floating32() { - assert!(f32::decode(&DbValue::Floating32(0.0)).is_ok()); - assert!(f32::decode(&DbValue::Boolean(false)).is_err()); - assert!(Option::::decode(&DbValue::DbNull).unwrap().is_none()); - } - - #[test] - fn floating64() { - assert!(f64::decode(&DbValue::Floating64(0.0)).is_ok()); - assert!(f64::decode(&DbValue::Boolean(false)).is_err()); - assert!(Option::::decode(&DbValue::DbNull).unwrap().is_none()); - } - - #[test] - fn str() { - assert_eq!( - String::decode(&DbValue::Str(String::from("foo"))).unwrap(), - String::from("foo") - ); - - assert!(String::decode(&DbValue::Int32(0)).is_err()); - assert!(Option::::decode(&DbValue::DbNull) - .unwrap() - .is_none()); - } -} diff --git a/sdk/rust/src/pg.rs b/sdk/rust/src/pg.rs deleted file mode 100644 index 07e120f9da..0000000000 --- a/sdk/rust/src/pg.rs +++ /dev/null @@ -1,196 +0,0 @@ -//! Conversions between Rust, WIT and **Postgres** types. -//! -//! # Types -//! -//! | Rust type | WIT (db-value) | Postgres type(s) | -//! |------------|---------------------|----------------------------- | -//! | `bool` | boolean(bool) | BOOL | -//! | `i16` | int16(s16) | SMALLINT, SMALLSERIAL, INT2 | -//! | `i32` | int32(s32) | INT, SERIAL, INT4 | -//! | `i64` | int64(s64) | BIGINT, BIGSERIAL, INT8 | -//! | `f32` | floating32(float32) | REAL, FLOAT4 | -//! | `f64` | floating64(float64) | DOUBLE PRECISION, FLOAT8 | -//! | `String` | str(string) | VARCHAR, CHAR(N), TEXT | -//! | `Vec` | binary(list\) | BYTEA | - -#[doc(inline)] -pub use super::wit::v2::postgres::{Connection, Error as PgError}; -#[doc(inline)] -pub use super::wit::v2::rdbms_types::*; - -/// A pg error -#[derive(Debug, thiserror::Error)] -pub enum Error { - /// Failed to deserialize [`DbValue`] - #[error("error value decoding: {0}")] - Decode(String), - /// Pg query failed with an error - #[error(transparent)] - PgError(#[from] PgError), -} - -/// A type that can be decoded from the database. -pub trait Decode: Sized { - /// Decode a new value of this type using a [`DbValue`]. - fn decode(value: &DbValue) -> Result; -} - -impl Decode for Option -where - T: Decode, -{ - fn decode(value: &DbValue) -> Result { - match value { - DbValue::DbNull => Ok(None), - v => Ok(Some(T::decode(v)?)), - } - } -} - -impl Decode for bool { - fn decode(value: &DbValue) -> Result { - match value { - DbValue::Boolean(boolean) => Ok(*boolean), - _ => Err(Error::Decode(format_decode_err("BOOL", value))), - } - } -} - -impl Decode for i16 { - fn decode(value: &DbValue) -> Result { - match value { - DbValue::Int16(n) => Ok(*n), - _ => Err(Error::Decode(format_decode_err("SMALLINT", value))), - } - } -} - -impl Decode for i32 { - fn decode(value: &DbValue) -> Result { - match value { - DbValue::Int32(n) => Ok(*n), - _ => Err(Error::Decode(format_decode_err("INT", value))), - } - } -} - -impl Decode for i64 { - fn decode(value: &DbValue) -> Result { - match value { - DbValue::Int64(n) => Ok(*n), - _ => Err(Error::Decode(format_decode_err("BIGINT", value))), - } - } -} - -impl Decode for f32 { - fn decode(value: &DbValue) -> Result { - match value { - DbValue::Floating32(n) => Ok(*n), - _ => Err(Error::Decode(format_decode_err("REAL", value))), - } - } -} - -impl Decode for f64 { - fn decode(value: &DbValue) -> Result { - match value { - DbValue::Floating64(n) => Ok(*n), - _ => Err(Error::Decode(format_decode_err("DOUBLE PRECISION", value))), - } - } -} - -impl Decode for Vec { - fn decode(value: &DbValue) -> Result { - match value { - DbValue::Binary(n) => Ok(n.to_owned()), - _ => Err(Error::Decode(format_decode_err("BYTEA", value))), - } - } -} - -impl Decode for String { - fn decode(value: &DbValue) -> Result { - match value { - DbValue::Str(s) => Ok(s.to_owned()), - _ => Err(Error::Decode(format_decode_err( - "CHAR, VARCHAR, TEXT", - value, - ))), - } - } -} - -fn format_decode_err(types: &str, value: &DbValue) -> String { - format!("Expected {} from the DB but got {:?}", types, value) -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn boolean() { - assert!(bool::decode(&DbValue::Boolean(true)).unwrap()); - assert!(bool::decode(&DbValue::Int32(0)).is_err()); - assert!(Option::::decode(&DbValue::DbNull).unwrap().is_none()); - } - - #[test] - fn int16() { - assert_eq!(i16::decode(&DbValue::Int16(0)).unwrap(), 0); - assert!(i16::decode(&DbValue::Int32(0)).is_err()); - assert!(Option::::decode(&DbValue::DbNull).unwrap().is_none()); - } - - #[test] - fn int32() { - assert_eq!(i32::decode(&DbValue::Int32(0)).unwrap(), 0); - assert!(i32::decode(&DbValue::Boolean(false)).is_err()); - assert!(Option::::decode(&DbValue::DbNull).unwrap().is_none()); - } - - #[test] - fn int64() { - assert_eq!(i64::decode(&DbValue::Int64(0)).unwrap(), 0); - assert!(i64::decode(&DbValue::Boolean(false)).is_err()); - assert!(Option::::decode(&DbValue::DbNull).unwrap().is_none()); - } - - #[test] - fn floating32() { - assert!(f32::decode(&DbValue::Floating32(0.0)).is_ok()); - assert!(f32::decode(&DbValue::Boolean(false)).is_err()); - assert!(Option::::decode(&DbValue::DbNull).unwrap().is_none()); - } - - #[test] - fn floating64() { - assert!(f64::decode(&DbValue::Floating64(0.0)).is_ok()); - assert!(f64::decode(&DbValue::Boolean(false)).is_err()); - assert!(Option::::decode(&DbValue::DbNull).unwrap().is_none()); - } - - #[test] - fn str() { - assert_eq!( - String::decode(&DbValue::Str(String::from("foo"))).unwrap(), - String::from("foo") - ); - - assert!(String::decode(&DbValue::Int32(0)).is_err()); - assert!(Option::::decode(&DbValue::DbNull) - .unwrap() - .is_none()); - } - - #[test] - fn binary() { - assert!(Vec::::decode(&DbValue::Binary(vec![0, 0])).is_ok()); - assert!(Vec::::decode(&DbValue::Boolean(false)).is_err()); - assert!(Option::>::decode(&DbValue::DbNull) - .unwrap() - .is_none()); - } -} diff --git a/sdk/rust/src/sqlite.rs b/sdk/rust/src/sqlite.rs deleted file mode 100644 index be7021a35b..0000000000 --- a/sdk/rust/src/sqlite.rs +++ /dev/null @@ -1,105 +0,0 @@ -use super::wit::v2::sqlite; - -#[doc(inline)] -pub use sqlite::{Connection, Error, QueryResult, RowResult, Value}; - -impl sqlite::Connection { - /// Open a connection to the default database - pub fn open_default() -> Result { - Self::open("default") - } -} - -impl sqlite::QueryResult { - /// Get all the rows for this query result - pub fn rows(&self) -> impl Iterator> { - self.rows.iter().map(|r| Row { - columns: self.columns.as_slice(), - result: r, - }) - } -} - -/// A database row result -pub struct Row<'a> { - columns: &'a [String], - result: &'a sqlite::RowResult, -} - -impl<'a> Row<'a> { - /// Get a value by its column name - pub fn get>(&self, column: &str) -> Option { - let i = self.columns.iter().position(|c| c == column)?; - self.result.get(i) - } -} - -impl sqlite::RowResult { - /// Get a value by its index - pub fn get<'a, T: TryFrom<&'a Value>>(&'a self, index: usize) -> Option { - self.values.get(index).and_then(|c| c.try_into().ok()) - } -} - -impl<'a> TryFrom<&'a Value> for bool { - type Error = (); - - fn try_from(value: &'a Value) -> Result { - match value { - Value::Integer(i) => Ok(*i != 0), - _ => Err(()), - } - } -} - -macro_rules! int_conversions { - ($($t:ty),*) => { - $(impl<'a> TryFrom<&'a Value> for $t { - type Error = (); - - fn try_from(value: &'a Value) -> Result { - match value { - Value::Integer(i) => (*i).try_into().map_err(|_| ()), - _ => Err(()), - } - } - })* - }; -} - -int_conversions!(u8, u16, u32, u64, i8, i16, i32, i64, usize, isize); - -impl<'a> TryFrom<&'a Value> for f64 { - type Error = (); - - fn try_from(value: &'a Value) -> Result { - match value { - Value::Real(f) => Ok(*f), - _ => Err(()), - } - } -} - -impl<'a> TryFrom<&'a Value> for &'a str { - type Error = (); - - fn try_from(value: &'a Value) -> Result { - match value { - Value::Text(s) => Ok(s.as_str()), - Value::Blob(b) => std::str::from_utf8(b).map_err(|_| ()), - _ => Err(()), - } - } -} - -impl<'a> TryFrom<&'a Value> for &'a [u8] { - type Error = (); - - fn try_from(value: &'a Value) -> Result { - match value { - Value::Blob(b) => Ok(b.as_slice()), - Value::Text(s) => Ok(s.as_bytes()), - _ => Err(()), - } - } -} diff --git a/sdk/rust/wit b/sdk/rust/wit deleted file mode 120000 index 902b54888f..0000000000 --- a/sdk/rust/wit +++ /dev/null @@ -1 +0,0 @@ -../../wit \ No newline at end of file diff --git a/templates/http-rust/content/Cargo.toml b/templates/http-rust/content/Cargo.toml index ecb795c18e..f385a760b7 100644 --- a/templates/http-rust/content/Cargo.toml +++ b/templates/http-rust/content/Cargo.toml @@ -10,6 +10,6 @@ crate-type = ["cdylib"] [dependencies] anyhow = "1" -spin-sdk = { git = "https://github.com/fermyon/spin", branch = "main" } +spin-sdk = "2.2.0" [workspace] diff --git a/templates/redis-rust/content/Cargo.toml b/templates/redis-rust/content/Cargo.toml index b69efc503b..8338754c03 100644 --- a/templates/redis-rust/content/Cargo.toml +++ b/templates/redis-rust/content/Cargo.toml @@ -14,6 +14,6 @@ anyhow = "1" # Crate to simplify working with bytes. bytes = "1" # The Spin SDK. -spin-sdk = { git = "https://github.com/fermyon/spin", branch = "main" } +spin-sdk = "2.2.0" [workspace] diff --git a/tests/test-components/components/Cargo.lock b/tests/test-components/components/Cargo.lock index e3dcf6ae2f..3a4702630a 100644 --- a/tests/test-components/components/Cargo.lock +++ b/tests/test-components/components/Cargo.lock @@ -604,7 +604,9 @@ dependencies = [ [[package]] name = "spin-macro" -version = "2.3.0-pre0" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13524474ab9f876586e29f954377a66ed14fcb646fc9893e6f0e762213ddbd86" dependencies = [ "anyhow", "bytes", @@ -628,7 +630,9 @@ dependencies = [ [[package]] name = "spin-sdk" -version = "2.3.0-pre0" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f05d0c09c0935fbb586d0a76e0f14b26b23f421c5e11b81d7200d22c4ead1211" dependencies = [ "anyhow", "async-trait", diff --git a/tests/test-components/components/headers-dynamic-env/Cargo.toml b/tests/test-components/components/headers-dynamic-env/Cargo.toml index cf6d87bbd6..6a481d5437 100644 --- a/tests/test-components/components/headers-dynamic-env/Cargo.toml +++ b/tests/test-components/components/headers-dynamic-env/Cargo.toml @@ -9,4 +9,4 @@ crate-type = ["cdylib"] [dependencies] anyhow = "1" http = "0.2" -spin-sdk = { path = "../../../../sdk/rust" } +spin-sdk = "2.2.0" diff --git a/tests/test-components/components/hello-world/Cargo.toml b/tests/test-components/components/hello-world/Cargo.toml index 4d439678a3..94632246bb 100644 --- a/tests/test-components/components/hello-world/Cargo.toml +++ b/tests/test-components/components/hello-world/Cargo.toml @@ -9,4 +9,4 @@ crate-type = ["cdylib"] [dependencies] anyhow = "1" http = "0.2" -spin-sdk = { path = "../../../../sdk/rust" } +spin-sdk = "2.2.0" diff --git a/tests/test-components/components/integration-http-outbound-post/Cargo.toml b/tests/test-components/components/integration-http-outbound-post/Cargo.toml index 0572d2d3ab..1f28a523f1 100644 --- a/tests/test-components/components/integration-http-outbound-post/Cargo.toml +++ b/tests/test-components/components/integration-http-outbound-post/Cargo.toml @@ -12,4 +12,4 @@ futures = "0.3.28" hex = "0.4.3" sha2 = "0.10.6" url = "2.4.0" -spin-sdk = { path = "../../../../sdk/rust" } +spin-sdk = "2.2.0" diff --git a/tests/test-components/components/integration-simple/Cargo.toml b/tests/test-components/components/integration-simple/Cargo.toml index fd049e62b8..a770c3f366 100644 --- a/tests/test-components/components/integration-simple/Cargo.toml +++ b/tests/test-components/components/integration-simple/Cargo.toml @@ -9,4 +9,4 @@ crate-type = ["cdylib"] [dependencies] anyhow = "1" http = "0.2" -spin-sdk = { path = "../../../../sdk/rust" } +spin-sdk = "2.2.0" diff --git a/tests/test-components/components/integration-variables/Cargo.toml b/tests/test-components/components/integration-variables/Cargo.toml index 14a7424561..7ba7dbc751 100644 --- a/tests/test-components/components/integration-variables/Cargo.toml +++ b/tests/test-components/components/integration-variables/Cargo.toml @@ -9,4 +9,4 @@ crate-type = ["cdylib"] [dependencies] anyhow = "1" http = "0.2" -spin-sdk = { path = "../../../../sdk/rust" } +spin-sdk = "2.2.0" diff --git a/tests/test-components/components/integration-wasi-http-streaming/Cargo.toml b/tests/test-components/components/integration-wasi-http-streaming/Cargo.toml index 432f40ffe8..f0fe4b05b6 100644 --- a/tests/test-components/components/integration-wasi-http-streaming/Cargo.toml +++ b/tests/test-components/components/integration-wasi-http-streaming/Cargo.toml @@ -12,4 +12,4 @@ futures = "0.3.28" hex = "0.4.3" sha2 = "0.10.6" url = "2.4.0" -spin-sdk = { path = "../../../../sdk/rust" } +spin-sdk = "2.2.0" diff --git a/tests/test-components/components/key-value-simple/Cargo.toml b/tests/test-components/components/key-value-simple/Cargo.toml index ead21d8778..2063aa7be9 100644 --- a/tests/test-components/components/key-value-simple/Cargo.toml +++ b/tests/test-components/components/key-value-simple/Cargo.toml @@ -9,4 +9,4 @@ crate-type = ["cdylib"] [dependencies] anyhow = "1.0" serde_qs = "0.12.0" -spin-sdk = { path = "../../../../sdk/rust" } +spin-sdk = "2.2.0" diff --git a/tests/test-components/components/outbound-http/Cargo.toml b/tests/test-components/components/outbound-http/Cargo.toml index 8b2a49e5ff..5fb341023c 100644 --- a/tests/test-components/components/outbound-http/Cargo.toml +++ b/tests/test-components/components/outbound-http/Cargo.toml @@ -9,4 +9,4 @@ crate-type = ["cdylib"] [dependencies] anyhow = "1" http = "0.2" -spin-sdk = { path = "../../../../sdk/rust" } +spin-sdk = "2.2.0" diff --git a/tests/test-components/components/redis-smoke-test/Cargo.toml b/tests/test-components/components/redis-smoke-test/Cargo.toml index 6d16c22b74..33b487446f 100644 --- a/tests/test-components/components/redis-smoke-test/Cargo.toml +++ b/tests/test-components/components/redis-smoke-test/Cargo.toml @@ -9,4 +9,4 @@ crate-type = ["cdylib"] [dependencies] anyhow = "1" bytes = "1" -spin-sdk = { path = "../../../../sdk/rust" } +spin-sdk = "2.2.0"