sunfishcode / hello-wasi-http

57 stars 17 forks source link

Use `cargo component serve`? #14

Closed sunfishcode closed 3 months ago

sunfishcode commented 4 months ago

https://github.com/bytecodealliance/cargo-component/pull/305 adds a cargo component serve command. Should use use that here?

yoshuawuyts commented 4 months ago

I think we should! - Though I don't know how to use it. It assumes a binary target is available (main.rs) but I don't know what the signature of the main function should be? If you write:

pub use wasi::http::types::{IncomingRequest, ResponseOutparam};

fn main(request: IncomingRequest, outparam: ResponseOutparam) { ... }

The program does nothing and you get the following warning:

warning: function `main` is never used
 --> src/lib.rs:5:4
  |
5 | fn main(request: IncomingRequest, outparam: ResponseOutparam) {
  |    ^^^^
  |
  = note: `#[warn(dead_code)]` on by default

I think this might point at a bug in cargo-component ?

calvinrp commented 4 months ago

@yoshuawuyts I'm struggling to reproduce. I cloned the repo and ran cargo component serve without issues. What version of cargo-component are you running? It shouldn't be using a fn main, as it builds with --lib.

sunfishcode commented 3 months ago

This is now done in #15!