Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions examples/leptos_ssr_axum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,28 @@ name = "leptos_ssr_axum"
authors = ["codeitlikemiley <codeitlikemiley@gmail.com>"]
description = "Antigravity SDK Chat Interface — Leptos + Spin WASI Example"
version = "0.1.0"
edition = "2021"
edition = "2024"
rust-version = "1.93.0"
build = "build.rs"

[lib]
crate-type = [ "cdylib" ]

[dependencies]
any_spawner = { version = "0.3.0", features = ["futures-executor"] }
bytes = "1.7.2"
console_error_panic_hook = "0.1"
futures = "0.3.30"
hydration_context = { version = "0.3.0" }
leptos = { version = "0.8.9" }
leptos_meta = { version = "0.8.5" }
leptos_router = { version = "0.8.7" }
leptos_wasi = { git = "https://github.com/codeitlikemiley/leptos_wasi", optional = true }
spin-sdk = { version = "5", optional = true }
wasi = { version = "=0.13.1", optional = true }
leptos_wasi = { git = "https://github.com/leptos-rs/leptos_wasi", rev = "216acc484b0d6fe4b18876f1c96b68272498592b", default-features = false, features = ["wasip3"], optional = true }
server_fn = { version = "0.8.7", features = ["axum-no-default"] }
spin-sdk = { version = "6.0.0", features = ["json"], optional = true }
wasip3 = { version = "0.6.0", features = ["http-compat"], optional = true }
http = { version = "1.1.0", optional = true }
http-body = { version = "1.0.0", optional = true }
wasm-bindgen = { version = "=0.2.103", optional = true }
wasm-bindgen-futures = { version = "0.4", optional = true }
web-sys = { version = "0.3", features = ["Storage", "Window", "EventSource", "MessageEvent", "ErrorEvent", "Document", "Element", "HtmlMetaElement"], optional = true }
Expand All @@ -38,13 +46,21 @@ ssr = [
"leptos/ssr",
"leptos_meta/ssr",
"leptos_router/ssr",
"leptos/spin",
"dep:spin-sdk",
"dep:leptos_wasi",
"dep:wasi",
"dep:wasip3",
"dep:antigravity-sdk-rust",
"dep:http",
"dep:http-body",
]

[profile.wasm-release]
inherits = "release"
opt-level = 'z'
lto = true
codegen-units = 1
panic = "abort"

[package.metadata.leptos]
output-name = "leptos_ssr_axum"
tailwind-input-file = "input.css"
Expand All @@ -53,3 +69,8 @@ bin-features = ["ssr"]
bin-default-features = false
lib-features = ["hydrate"]
lib-default-features = false
lib-profile-release = "wasm-release"
bin-profile-release = "wasm-release"
bin-target-triple = "wasm32-wasip2"
bin-target-dir = "target/server"

4 changes: 2 additions & 2 deletions examples/leptos_ssr_axum/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Browser ──[HTTP/SSE]──→ Spin Component (WASI Guest)
## Prerequisites

Ensure you have the following installed on your system:
- **Rust** (with `wasm32-wasip1` and `wasm32-unknown-unknown` targets added).
- **Rust** (with `wasm32-wasip2` and `wasm32-unknown-unknown` targets added).
- **Spin CLI**: Install Spin by following the [Spin Installation Guide](https://developer.fermyon.com/spin/v2/install).
- **cargo-leptos**: Install cargo-leptos using cargo:
```sh
Expand Down Expand Up @@ -73,7 +73,7 @@ spin build --up

This will:
1. Run `cargo leptos build --release` to compile client-side hydrate WASM assets and output-style CSS.
2. Compile the server-side logic to the `wasm32-wasip1` target.
2. Compile the server-side logic to the `wasm32-wasip2` target.
3. Start the Spin local web server.

Open `http://localhost:3000` (or the port outputted by Spin) in your web browser.
Expand Down
21 changes: 21 additions & 0 deletions examples/leptos_ssr_axum/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use std::env;
fn main() {
println!("cargo::rustc-check-cfg=cfg(runtime_spin)");
println!("cargo::rustc-check-cfg=cfg(runtime_wasmtime)");
let runtime = env::var("WASI_RUNTIME").unwrap_or_else(|_| "wasmtime".to_string());
println!("cargo:rustc-env=WASI_RUNTIME={}", runtime);
match runtime.as_str() {
"spin" => {
println!("cargo:rustc-cfg=runtime_spin");
}
"wasmtime" => {
println!("cargo:rustc-cfg=runtime_wasmtime");
}
_ => {
println!("cargo:rustc-cfg=runtime_wasmtime");
}
}
if env::var("SPIN_BUILD").is_ok() {
println!("cargo:rustc-cfg=runtime_spin");
}
}
5 changes: 3 additions & 2 deletions examples/leptos_ssr_axum/spin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ agent_server_url = { required = false, default = "http://127.0.0.1:8080" }
[[trigger.http]]
route = "/..."
component = "leptos-ssr-axum"
executor = { type = "http" }

[component.leptos-ssr-axum]
source = "target/wasm32-wasip1/release/leptos_ssr_axum.wasm"
source = "target/wasm32-wasip2/release/leptos_ssr_axum.wasm"
allowed_outbound_hosts = ["https://generativelanguage.googleapis.com", "http://127.0.0.1:8080"]
key_value_stores = ["default"]
[component.leptos-ssr-axum.variables]
gemini_api_key = "{{ gemini_api_key }}"
agent_server_url = "{{ agent_server_url }}"
[component.leptos-ssr-axum.build]
command = "cargo leptos build --release && LEPTOS_OUTPUT_NAME=leptos_ssr_axum cargo build --lib --target wasm32-wasip1 --release --no-default-features --features ssr"
command = "WASI_RUNTIME=spin cargo leptos build --release && WASI_RUNTIME=spin LEPTOS_OUTPUT_NAME=leptos_ssr_axum cargo build --lib --target wasm32-wasip2 --release --no-default-features --features ssr"
watch = ["src/**/*.rs", "Cargo.toml"]

[[trigger.http]]
Expand Down
Loading
Loading