Skip to content
Draft
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ serde_json = { workspace = true, optional = true }
wasip2.workspace = true

[target.'cfg(all(target_os = "wasi", target_env = "p3"))'.dependencies]
wasip3 = { workspace = true, features = ["async-spawn"] }
wasip3 = { workspace = true, features = ["async-spawn", "http-compat"] }

[dev-dependencies]
anyhow.workspace = true
Expand Down
3 changes: 0 additions & 3 deletions axum/examples/hello_world.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#![cfg_attr(not(all(target_os = "wasi", target_env = "p2")), no_main)]
#![cfg(all(target_os = "wasi", target_env = "p2"))]

//! Run with
//!
//! ```sh
Expand Down
3 changes: 0 additions & 3 deletions axum/examples/hello_world_nomacro.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#![cfg_attr(not(all(target_os = "wasi", target_env = "p2")), no_main)]
#![cfg(all(target_os = "wasi", target_env = "p2"))]

//! Run with
//!
//! ```sh
Expand Down
3 changes: 0 additions & 3 deletions axum/examples/weather.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#![cfg_attr(not(all(target_os = "wasi", target_env = "p2")), no_main)]
#![cfg(all(target_os = "wasi", target_env = "p2"))]

//! This demo app shows a Axum based wasi-http server making an arbitrary
//! number of http requests as part of serving a single response.
//!
Expand Down
1 change: 0 additions & 1 deletion axum/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![cfg(all(target_os = "wasi", target_env = "p2"))]
//! Support for the [`axum`] web server framework in wasi-http components, via
//! [`wstd`].
//!
Expand Down
3 changes: 0 additions & 3 deletions examples/complex_http_client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#![cfg_attr(not(all(target_os = "wasi", target_env = "p2")), no_main)]
#![cfg(all(target_os = "wasi", target_env = "p2"))]

use anyhow::{Result, anyhow};
use clap::{ArgAction, Parser};
use std::str::FromStr;
Expand Down
3 changes: 0 additions & 3 deletions examples/http_client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#![cfg_attr(not(all(target_os = "wasi", target_env = "p2")), no_main)]
#![cfg(all(target_os = "wasi", target_env = "p2"))]

use anyhow::{Result, anyhow};
use clap::{ArgAction, Parser};
use wstd::http::{Body, BodyExt, Client, Method, Request, Uri};
Expand Down
3 changes: 0 additions & 3 deletions examples/http_server.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#![cfg_attr(not(all(target_os = "wasi", target_env = "p2")), no_main)]
#![cfg(all(target_os = "wasi", target_env = "p2"))]

use anyhow::{Context, Result};
use futures_lite::stream::{once_future, unfold};
use http_body_util::{BodyExt, StreamBody};
Expand Down
3 changes: 0 additions & 3 deletions examples/http_server_proxy.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#![cfg_attr(not(all(target_os = "wasi", target_env = "p2")), no_main)]
#![cfg(all(target_os = "wasi", target_env = "p2"))]

//! Run the example with:
//! ```sh
//! cargo build --example http_server_proxy --target=wasm32-wasip2
Expand Down
33 changes: 33 additions & 0 deletions macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,10 @@ pub fn attr_macro_http_server(_attr: TokenStream, item: TokenStream) -> TokenStr
}

quote! {
#[cfg(target_env = "p2")]
struct TheServer;

#[cfg(target_env = "p2")]
impl ::wstd::__internal::wasip2::exports::http::incoming_handler::Guest for TheServer {
fn handle(
request: ::wstd::__internal::wasip2::http::types::IncomingRequest,
Expand All @@ -146,8 +148,39 @@ pub fn attr_macro_http_server(_attr: TokenStream, item: TokenStream) -> TokenStr
}
}

#[cfg(target_env = "p2")]
::wstd::__internal::wasip2::http::proxy::export!(TheServer with_types_in ::wstd::__internal::wasip2);

#[cfg(target_env = "p3")]
struct TheServer;

#[cfg(target_env = "p3")]
impl ::wstd::__internal::wasip3::exports::http::handler::Guest for TheServer {
async fn handle(
request: ::wstd::__internal::wasip3::http::types::Request,
) -> ::core::result::Result<
::wstd::__internal::wasip3::http::types::Response,
::wstd::__internal::wasip3::http::types::ErrorCode,
> {
#(#attrs)*
#vis #run_async fn __run(#inputs) #output {
#body
}

let request = ::wstd::http::request::try_from_incoming(request)
.map_err(::wstd::http::response::error_code)?;
let response = __run(request) #run_await
.map_err(::wstd::http::response::error_code)?;
::wstd::http::response::try_into_outgoing(response)
.map_err(::wstd::http::response::error_code)
}
}

#[cfg(target_env = "p3")]
::wstd::__internal::wasip3::http::service::export!(
TheServer with_types_in ::wstd::__internal::wasip3
);

// Provide an actual function named `main`.
//
// WASI HTTP server components don't use a traditional `main` function.
Expand Down
File renamed without changes.
Loading
Loading