-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to run in WasmCloud? #12
Comments
I have read the introduction of the
|
Hello! The component you obtain from using the template there: https://github.com/leptos-rs/start-wasi is using native WASI interfaces so you shouldn't have any trouble running it in a wasmCloud environment. Sadly, the only way I have found to let users pass the WASI types in the I am not aware of a way to ease the process, I know you can use a custom WIT cc @brooksmtownsend, do you have any insights? 🙏 |
I've tried and the backend works fine. However, it seems that the existing approach doesn't allow the front-end static resources to be used directly. After reading the |
The |
I think we should have another crate specifically for wasmCloud anyway. This is what folks with Spin do. They integrate |
Isn't that what this is? https://github.com/raskyld/leptos-wasmcloud
…On Wed, Dec 11, 2024, at 4:08 AM, Enzo Nocera wrote:
I think we should have another crate specifically for wasmCloud anyway.
This is what folks with Spin do. They integrate `leptos_wasi` in their `spin` integration crate to have a DX really tailored for Spin users.
—
Reply to this email directly, view it on GitHub <#12 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ABVBTCP2SFEU5CVUICBSH7D2FATKPAVCNFSM6AAAAABS3IBDC6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMZVHAYTINBXGE>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Nope, actually this repo has wasmCloud in its name because I initially intended to work on wasmCloud integration but I ended-up focusing on a pure-WASI first to have a reusable piece for the broader eco-system! |
I have already tried and succeeded with this issue. I feel that a new repo similar to start-wasmcloud based on this repo can be quickly used.
mod bindings {
wit_bindgen::generate!({ generate_all });
}
use bindings::wasi::blobstore::{blobstore::{container_exists, create_container, get_container}, types::IncomingValue};
use bindings::wasi::logging::logging::{log, Level};
const CONTAINER_NAME: &str = "pkg";
fn serve_static_files(path: String)
-> Option<Body>
{
log(Level::Info, "", &format!("access file path:{}", path));
let container = if container_exists(&CONTAINER_NAME.to_string()).unwrap() {
log(Level::Debug, "", "Container already exists, fetching ...");
get_container(&CONTAINER_NAME.to_string()).expect("container to exist")
} else {
log(Level::Error, "", "Container already exists, fetching ...");
create_container(&CONTAINER_NAME.to_string()).expect("to be able to create container")
};
let object_name = path.strip_prefix("/").unwrap_or(&path).to_string();
if let Ok(result) = container.has_object(&object_name) {
if result {
let metadata = container.object_info(&object_name).unwrap();
let object = container.get_data(&object_name, 0, metadata.size).unwrap();
if let Ok(body) = IncomingValue::incoming_value_consume_async(object) {
let mut read_bytes: u64 = 0;
Some(
Body::Async(
Box::pin(stream::poll_fn(move |_| -> Poll<Option<Result<Bytes, Error>>> {
if read_bytes >= metadata.size {
return Poll::Ready(None)
}
match body.blocking_read(256) {
Err(err) => Poll::Ready(Some(Err(err.into()))),
Ok(data) => {
read_bytes += data.len() as u64;
Poll::Ready(Some(Ok(Bytes::from(data))))
}
}
}))
)
)
} else {
log(Level::Error, "", "Failed to convert object to bytes");
None
}
} else {
log(Level::Error, "", "Failed to find object");
None
}
} else {
log(Level::Error, "", "Failed to check if object exists");
None
}
} I can create this |
I created this template project.https://github.com/tqq1994516/start-wasmcloud |
First of all, my apologies for missing the mentions in this issue (grumble grumble GitHub inbox) Well done with the template project! I'm a big fan of the layout, and I think we could continue to improve it with a hot reload experience (wasmcloud or leptos) since our |
@brooksmtownsend Thank you for your attention. Currently, I've indeed come across two problems and I don't know how to solve them. I'm wondering if you know about them. Hot - reloading in Leptos can be done with |
I have looked at the examples of WasmCloud. They used the
wasmcloud-component
andwit-bindgen
crate instead ofwasi
. I'm not sure if it will have any impact.The text was updated successfully, but these errors were encountered: