Skip to content
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

Upgrade to Hyper 1.x #4927

Merged
merged 4 commits into from
Jul 16, 2024
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
372 changes: 189 additions & 183 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ edge-schema = { version = "=0.1.0" }
shared-buffer = "0.1.4"

# Third-party crates
http = "1.0.0"
hyper = "1"
reqwest = { version = "0.12.0", default-features = false }
enumset = "1.1.0"
memoffset = "0.9.0"
wasmparser = { version = "0.121.0", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions lib/api/src/sys/tunables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ mod tests {
impl VMTinyMemory {
pub fn new() -> Result<Self, MemoryError> {
let sz = 18 * WASM_PAGE_SIZE;
let mut memory = Vec::new();
memory.resize(sz, 0);
let memory = vec![0; sz];
let mut ret = Self {
mem: memory,
memory_definition: None,
Expand Down Expand Up @@ -304,6 +303,7 @@ mod tests {
all(target_os = "macos", target_arch = "aarch64")
))
))]
#[allow(clippy::print_stdout)]
fn check_small_stack() -> Result<(), Box<dyn std::error::Error>> {
use crate::{imports, wat2wasm, Engine, Instance, Module, Store};
use wasmer_compiler_singlepass::Singlepass;
Expand Down
4 changes: 2 additions & 2 deletions lib/backend-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ serde_json = "1"
url = "2"
futures = "0.3"
tracing = "0.1"
cynic = { version = "=3.4.3", features = ["http-reqwest"] }
cynic = { version = "3.7.2", features = ["http-reqwest"] }
pin-project-lite = "0.2.10"
serde_path_to_error = "0.1.14"
harsh = "0.2.2"
reqwest = { version = "0.11.13", default-features = false, features = ["json"] }
reqwest = { workspace = true, default-features = false, features = ["json"] }
merge-streams = "0.1.2"

[target.'cfg(target_family = "wasm")'.dependencies.getrandom]
Expand Down
48 changes: 24 additions & 24 deletions lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,30 +375,30 @@ fn test_run() {
}
}

#[cfg(test)]
fn print_wasmer_root_to_stdout(config: &Config) {
println!("print_wasmer_root_to_stdout");

use walkdir::WalkDir;

for entry in WalkDir::new(&config.wasmer_dir)
.into_iter()
.filter_map(Result::ok)
{
let f_name = String::from(entry.path().canonicalize().unwrap().to_string_lossy());
println!("{f_name}");
}

for entry in WalkDir::new(&config.root_dir)
.into_iter()
.filter_map(Result::ok)
{
let f_name = String::from(entry.path().canonicalize().unwrap().to_string_lossy());
println!("{f_name}");
}

println!("printed");
}
// #[cfg(test)]
// fn print_wasmer_root_to_stdout(config: &Config) {
// println!("print_wasmer_root_to_stdout");

// use walkdir::WalkDir;

// for entry in WalkDir::new(&config.wasmer_dir)
// .into_iter()
// .filter_map(Result::ok)
// {
// let f_name = String::from(entry.path().canonicalize().unwrap().to_string_lossy());
// println!("{f_name}");
// }

// for entry in WalkDir::new(&config.root_dir)
// .into_iter()
// .filter_map(Result::ok)
// {
// let f_name = String::from(entry.path().canonicalize().unwrap().to_string_lossy());
// println!("{f_name}");
// }

// println!("printed");
// }

#[cfg(test)]
fn fixup_symlinks(
Expand Down
80 changes: 40 additions & 40 deletions lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,46 +316,46 @@ fn test_ok() {
}
}

#[cfg(test)]
Arshia001 marked this conversation as resolved.
Show resolved Hide resolved
fn print_wasmer_root_to_stdout(config: &Config) {
println!("print_wasmer_root_to_stdout");

use walkdir::WalkDir;

println!(
"wasmer dir: {}",
std::path::Path::new(&config.wasmer_dir)
.canonicalize()
.unwrap()
.display()
);

for entry in WalkDir::new(&config.wasmer_dir)
.into_iter()
.filter_map(Result::ok)
{
let f_name = String::from(entry.path().canonicalize().unwrap().to_string_lossy());
println!("{f_name}");
}

println!(
"root dir: {}",
std::path::Path::new(&config.root_dir)
.canonicalize()
.unwrap()
.display()
);

for entry in WalkDir::new(&config.root_dir)
.into_iter()
.filter_map(Result::ok)
{
let f_name = String::from(entry.path().canonicalize().unwrap().to_string_lossy());
println!("{f_name}");
}

println!("printed");
}
// #[cfg(test)]
// fn print_wasmer_root_to_stdout(config: &Config) {
// println!("print_wasmer_root_to_stdout");

// use walkdir::WalkDir;

// println!(
// "wasmer dir: {}",
// std::path::Path::new(&config.wasmer_dir)
// .canonicalize()
// .unwrap()
// .display()
// );

// for entry in WalkDir::new(&config.wasmer_dir)
// .into_iter()
// .filter_map(Result::ok)
// {
// let f_name = String::from(entry.path().canonicalize().unwrap().to_string_lossy());
// println!("{f_name}");
// }

// println!(
// "root dir: {}",
// std::path::Path::new(&config.root_dir)
// .canonicalize()
// .unwrap()
// .display()
// );

// for entry in WalkDir::new(&config.root_dir)
// .into_iter()
// .filter_map(Result::ok)
// {
// let f_name = String::from(entry.path().canonicalize().unwrap().to_string_lossy());
// println!("{f_name}");
// }

// println!("printed");
// }

#[cfg(test)]
fn fixup_symlinks(
Expand Down
13 changes: 8 additions & 5 deletions lib/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ time01 = { package = "time", version = "0.1.45", optional = true }

# Third-party dependencies.

http.workspace = true
is-terminal = "0.4.7"
colored = "2.0"
anyhow = "1.0"
Expand Down Expand Up @@ -206,8 +207,9 @@ once_cell = "1.17.1"
indicatif = "0.17.5"
opener = "0.6.1"
normpath = "=1.1.1"
hyper = { version = "0.14.27", features = ["server"] }
http = "0.2.9"
hyper = { workspace = true, features = ["server"] }
hyper-util = { version = "0.1.5", features = ["tokio"] }
http-body-util = "0.1.1"
futures = "0.3.29"
humantime = "2.1.0"
interfaces = { version = "0.0.9", optional = true }
Expand All @@ -221,8 +223,9 @@ comfy-table = "7.0.1"
# Used by tuntap and connect
futures-util = "0.3"
mio = { version = "0.8", optional = true }
tokio-tungstenite = { version = "0.20.1", features = [
tokio-tungstenite = { version = "0.21.0", features = [
"rustls-tls-webpki-roots",
"stream",
], optional = true }
mac_address = { version = "1.1.5", optional = true }
tun-tap = { version = "0.1.3", features = ["tokio"], optional = true }
Expand All @@ -248,15 +251,15 @@ clap = { version = "4.3.4", default-features = false, features = [
] }

[target.'cfg(not(target_arch = "riscv64"))'.dependencies]
reqwest = { version = "^0.11", default-features = false, features = [
reqwest = { workspace = true, default-features = false, features = [
"rustls-tls",
"json",
"multipart",
"gzip",
] }

[target.'cfg(target_arch = "riscv64")'.dependencies]
reqwest = { version = "^0.11", default-features = false, features = [
reqwest = { workspace = true, default-features = false, features = [
"native-tls",
"json",
"multipart",
Expand Down
7 changes: 6 additions & 1 deletion lib/cli/src/commands/app/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ use wasmer_config::{
package::{PackageIdent, PackageSource},
};

// TODO: apparently edge-util uses a different version of the http crate, which makes the
// HEADER_APP_VERSION_ID field incompatible with our use here, so it needs to be redeclared.
static EDGE_HEADER_APP_VERSION_ID: http::HeaderName =
http::HeaderName::from_static("x-edge-app-version-id");

/// Deploy an app to Wasmer Edge.
#[derive(clap::Parser, Debug)]
pub struct CmdAppDeploy {
Expand Down Expand Up @@ -669,7 +674,7 @@ pub async fn wait_app(
Ok(res) => {
let header = res
.headers()
.get(edge_util::headers::HEADER_APP_VERSION_ID)
.get(&EDGE_HEADER_APP_VERSION_ID)
.and_then(|x| x.to_str().ok())
.unwrap_or_default();

Expand Down
65 changes: 39 additions & 26 deletions lib/cli/src/commands/login.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use std::{net::TcpListener, path::PathBuf, str::FromStr, time::Duration};
use std::{path::PathBuf, str::FromStr, time::Duration};

use anyhow::Ok;
use clap::Parser;
use colored::Colorize;
#[cfg(not(test))]
use dialoguer::{console::style, Input};
use hyper::{
service::{make_service_fn, service_fn},
Body, Request, Response, Server, StatusCode,
};
use reqwest::Method;
use futures::{stream::FuturesUnordered, StreamExt};
use http_body_util::BodyExt;
use hyper::{body::Incoming, service::service_fn, Request, Response, StatusCode};
use reqwest::{Body, Method};
use serde::Deserialize;
use tokio::net::TcpListener;
use wasmer_registry::{
types::NewNonceOutput,
wasmer_env::{Registry, WasmerEnv, WASMER_DIR},
Expand Down Expand Up @@ -177,26 +177,40 @@ impl Login {
);
});

// Create a new server
let make_svc = make_service_fn(move |_| {
let context = app_context.clone();
// Jump through hyper 1.0's hoops...
let graceful = hyper_util::server::graceful::GracefulShutdown::new();

// Create a `Service` for responding to the request.
let service = service_fn(move |req| service_router(context.clone(), req));
let http = hyper::server::conn::http1::Builder::new();

// Return the service to hyper.
async move { Ok(service) }
});
let mut futs = FuturesUnordered::new();

let service = service_fn(move |req| service_router(app_context.clone(), req));

print!("Waiting for session... ");

// start the server
Server::from_tcp(listener)?
.serve(make_svc)
.with_graceful_shutdown(async {
server_shutdown_rx.recv().await;
})
.await?;
loop {
tokio::select! {
Result::Ok((stream, _addr)) = listener.accept() => {
let io = hyper_util::rt::tokio::TokioIo::new(stream);
let conn = http.serve_connection(io, service.clone());
// watch this connection
let fut = graceful.watch(conn);
futs.push(async move {
if let Err(e) = fut.await {
eprintln!("Error serving connection: {:?}", e);
}
});
},

_ = futs.next() => {}

_ = server_shutdown_rx.recv() => {
// stop the accept loop
break;
}
}
}

// receive the token from the server
let token = token_rx
Expand All @@ -217,7 +231,7 @@ impl Login {
}

async fn setup_listener() -> Result<(TcpListener, String), anyhow::Error> {
let listener = TcpListener::bind("127.0.0.1:0")?;
let listener = TcpListener::bind("127.0.0.1:0").await?;
let addr = listener.local_addr()?;
let port = addr.port();

Expand Down Expand Up @@ -331,8 +345,7 @@ impl Login {
}
}

async fn preflight(req: Request<Body>) -> Result<Response<Body>, anyhow::Error> {
let _whole_body = hyper::body::aggregate(req).await?;
async fn preflight(_: Request<Incoming>) -> Result<Response<Body>, anyhow::Error> {
let response = Response::builder()
.status(StatusCode::OK)
.header("Access-Control-Allow-Origin", "*") // FIXME: this is not secure, Don't allow all origins. @syrusakbary
Expand All @@ -344,14 +357,14 @@ async fn preflight(req: Request<Body>) -> Result<Response<Body>, anyhow::Error>

async fn handle_post_save_token(
context: AppContext,
req: Request<Body>,
req: Request<Incoming>,
) -> Result<Response<Body>, anyhow::Error> {
let AppContext {
server_shutdown_tx,
token_tx,
} = context;
let (.., body) = req.into_parts();
let body = hyper::body::to_bytes(body).await?;
let body = body.collect().await?.to_bytes();

let ValidatedNonceOutput {
token,
Expand Down Expand Up @@ -425,7 +438,7 @@ async fn handle_unknown_method(context: AppContext) -> Result<Response<Body>, an
/// Then proceed to handle the actual request - POST request
async fn service_router(
context: AppContext,
req: Request<Body>,
req: Request<Incoming>,
) -> Result<Response<Body>, anyhow::Error> {
match *req.method() {
Method::OPTIONS => preflight(req).await,
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/src/commands/package/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::{
};
use colored::Colorize;
use dialoguer::Confirm;
use hyper::Body;
use indicatif::{ProgressBar, ProgressStyle};
use reqwest::Body;
use std::{
collections::BTreeMap,
path::{Path, PathBuf},
Expand Down
Loading
Loading