Skip to content

Commit 9bff9ee

Browse files
committed
feat: cargo init and configuration of the build targets
Signed-off-by: Enzo "raskyld" Nocera <[email protected]>
1 parent 66d8327 commit 9bff9ee

File tree

5 files changed

+80
-2
lines changed

5 files changed

+80
-2
lines changed

.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,8 @@ Cargo.lock
1818
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
1919
# and can be added to the global gitignore or merged into this file. For a more nuclear
2020
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
21-
#.idea/
21+
#.idea/
22+
23+
# Added by cargo
24+
25+
/target

Cargo.toml

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
[package]
2+
name = "leptos-wasmcloud"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[lib]
7+
crate-type = ["cdylib"]
8+
9+
[dependencies]
10+
leptos = "0.6.6"
11+
leptos_integration_utils = { version = "0.6.6", optional = true }
12+
leptos_meta = "0.6.6"
13+
leptos_router = "0.6.6"
14+
wasm-bindgen = { version = "0.2", optional = true }
15+
wit-bindgen = { version = "0.32.0", optional = true }
16+
17+
[features]
18+
hydrate = [
19+
"leptos/hydrate",
20+
"leptos_meta/hydrate",
21+
"leptos_router/hydrate",
22+
"dep:wasm-bindgen",
23+
]
24+
ssr = [
25+
"leptos/ssr",
26+
"leptos_meta/ssr",
27+
"leptos_router/ssr",
28+
"dep:wit-bindgen",
29+
]
30+
31+
[profile.wasm-release]
32+
inherits = "release"
33+
opt-level = 'z'
34+
lto = true
35+
codegen-units = 1
36+
panic = "abort"
37+
38+
[package.metadata.leptos]
39+
# == Hydrate (client)
40+
lib-profile-release = "wasm-release"
41+
lib-features = ["hydrate"]
42+
lib-cargo-args = [
43+
"-Zbuild-std=std,panic_abort,core,alloc",
44+
"-Zbuild-std-features=panic_immediate_abort,wasi_ext",
45+
]
46+
47+
# == SSR
48+
bin-profile-release = "wasm-release"
49+
# TODO: port to wasip2 as soon as cargo-component supports it
50+
bin-target-triple = "wasm32-wasip1"
51+
bin-features = ["ssr"]
52+
bin-cargo-args = [
53+
"-Zbuild-std=std,panic_abort,core,alloc",
54+
"-Zbuild-std-features=panic_immediate_abort,wasi_ext",
55+
]

README.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,21 @@ when building your *full-stack* :tm: app with wasmCloud :sunglasses:
6666
[wasi-http-handler]: https://github.com/WebAssembly/wasi-http/blob/main/wit/handler.wit#L4
6767
[leptos-integrations]: https://github.com/leptos-rs/leptos/tree/main/integrations
6868

69+
### Is Nightly Rust needed?
70+
71+
As of Rust 1.82.0, IIUC, the two unstable features we may be interested in are:
72+
* `wasi_ext`: Some extensions to `std::fs` and `std::net`, but seems to be only
73+
*nice-to-have*.
74+
* the cargo feature [`build-std`](https://github.com/rust-lang/cargo/blob/rust-1.82.0/src/cargo/core/features.rs#L1253),
75+
to rebuild the stdlib with optimisation of the WebAssembly target. While it's more
76+
of a *nice-to-have* for the `ssr`, it's kind of important for production build
77+
of the `csr` as explained in [Leptos Docs][leptos-wasm-size].
78+
79+
[leptos-wasm-size]: https://book.leptos.dev/deployment/binary_size.html
80+
6981
## Roadmap
7082

7183
* [x] Start thinking about the overall architecture.
7284
* [ ] Get in touch with Leptos maintainers on their Discord to get tips.
7385
* [ ] Decide whether it should be in-tree Leptos code or a dedicated repo.
74-
* [ ] Start building (indeed)
86+
* [x] Start building (indeed)

rust-toolchain.toml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[toolchain]
2+
chanel = ["nightly"]
3+
# TODO: port to wasip2 as soon as cargo-component supports it
4+
targets = [ "wasm32-unknown-unknown", "wasm32-wasip1" ]

src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("Hello, world!");
3+
}

0 commit comments

Comments
 (0)