Skip to content

Commit

Permalink
Made lints happy and got tests working again
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-F-Bryan committed Feb 22, 2023
1 parent 95a3a2d commit eb7ba21
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 125 deletions.
34 changes: 4 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 13 additions & 20 deletions lib/wcgi-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,30 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = { version = "1", features = ["backtrace"] }
async-trait = "0.1.64"
bytes = "1.4.0"
clap = { version = "4", features = ["derive", "env"] }
futures = "0.3.25"
http = "0.2.8"
hyper = { version = "0.14.23", features = ["server", "stream"] }
md5 = "0.7.0"
serde = { version = "1.0.152", features = ["derive"] }
serde_cbor = "0.11.2"
thiserror = "1.0.38"
tiny_http = "0.12.0"
hyper = { version = "0.14", features = ["server", "stream"] }
serde = { version = "1.0", features = ["derive"] }
serde_cbor = "0.11"
thiserror = "1.0"
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
tower-service = "0.3"
tracing = "0.1.37"
tracing-subscriber = { version = "0.3.16", features = ["fmt", "env-filter"] }
wasmer = { version = "3.2.0-alpha.1", path = "../api", default-features = false, features = [
"sys",
"cranelift",
"singlepass",
] }
wasmer-wasi = { version = "3.2.0-alpha.1", path = "../wasi", features = [
"sys-default",
], default-features = false }
wasmer = { version = "3.2.0-alpha.1", path = "../api", default-features = false }
wasmer-vfs = { version = "3.2.0-alpha.1", path = "../vfs", default-features = false }
wasmer-wasi = { version = "3.2.0-alpha.1", path = "../wasi", default-features = false, features = ["sys-default"] }
wcgi = { version = "0.1.1" }
wcgi-host = { version = "0.1.0" }
webc = { version = "5.0.0-rc.1", default-features = false }

[dev-dependencies]
reqwest = { version = "0.11.0", default-features = false, features = [
"rustls-tls",
] }
anyhow = { version = "1", features = ["backtrace"] }
clap = { version = "4", features = ["derive", "env"] }
tempfile = "3.3.0"
tracing-subscriber = { version = "0.3.16", features = ["fmt", "env-filter"] }
ureq = "2.6.2"

[features]
default = ["wasmer/sys", "wasmer/singlepass"]
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/wcgi-runner/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::{
/// ```rust,no_run
/// use wcgi_runner::Runner;
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::io::Error>> {
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let webc = std::fs::read("path/to/server.webc")?;
/// let runner = Runner::builder().build_webc(webc)?;
/// # Ok(())
Expand Down
2 changes: 2 additions & 0 deletions lib/wcgi-runner/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Rust 1.64 doesn't understand tool-specific lints
#![warn(unknown_lints)]
// For now, let's ignore the fact that some of our Error variants are really big
#![allow(clippy::result_large_err)]

Expand Down
2 changes: 1 addition & 1 deletion lib/wcgi-runner/src/module_loader/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
Error,
};

#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct WasmLoader {
program: String,
wasm: Bytes,
Expand Down
6 changes: 4 additions & 2 deletions lib/wcgi-runner/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ use crate::{context::Context, Builder, Error};
/// so it can be easily integrated with a Hyper server and the Tower ecosystem.
///
/// ```rust,no_run
/// # use std::net::SocketAddr;
/// use std::net::SocketAddr;
/// use wcgi_runner::Runner;
///
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let webc = b"...";
/// let webc: &[u8] = b"...";
/// let address: SocketAddr = ([127, 0, 0, 1], 3000).into();
/// let runner = Runner::builder().build_webc(webc)?;
///
Expand Down
84 changes: 13 additions & 71 deletions lib/wcgi-runner/tests/integration.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use std::{
path::{Path, PathBuf},
process::{Command, Output, Stdio},
};
use std::path::Path;

use bytes::Bytes;
use http::{Request, StatusCode};
use hyper::{body::HttpBody, Body};
use tempfile::TempDir;
use wcgi_host::CgiDialect;
use wcgi_runner::Builder;

const FERRIS_SAYS: &str = "https://registry-cdn.wapm.dev/packages/wasmer-examples/ferris-says/ferris-says-0.2.0-2f5dfb76-77a9-11ed-a646-d2c429a5b858.webc";
const STATICSERVER: &str =
"https://registry-cdn.wapm.dev/contents/syrusakbary/staticserver/1.0.2/serve.wasm";

#[tokio::test]
async fn execute_a_webc_server() {
Expand All @@ -35,22 +35,19 @@ async fn execute_a_webc_server() {

#[tokio::test]
async fn execute_a_webassembly_server_with_mounted_directories() {
let static_server = build_wasi("staticserver").join("serve.wasm");
let wasm = std::fs::read(&static_server).unwrap();
let wasm = cached(STATICSERVER);
let temp = TempDir::new().unwrap();
let example = temp.path().join("example");
std::fs::create_dir_all(&example).unwrap();
std::fs::write(example.join("file.txt"), b"Hello, World!").unwrap();

let runner = Builder::default()
.program(static_server.display().to_string())
.map_dir(
"example",
project_root()
.join("examples")
.join("staticserver")
.join("example"),
)
.program("staticserver")
.map_dir("example", example)
.build_wasm(wasm)
.unwrap();
let req = Request::builder()
.uri("/example/index.html")
.uri("/example/file.txt")
.body(Body::default())
.unwrap();
let response = runner.handle(req).await.unwrap();
Expand All @@ -63,7 +60,7 @@ async fn execute_a_webassembly_server_with_mounted_directories() {
buffer.extend(chunk);
}
let body = String::from_utf8(buffer).unwrap();
assert!(body.contains("<h1>Welcome to WebC</h1>"));
assert!(body.contains("Hello, World!"));
}

/// Download a file, caching it in $CARGO_TARGET_TMPDIR to avoid unnecessary
Expand Down Expand Up @@ -96,58 +93,3 @@ fn cached(url: &str) -> Bytes {

body.into()
}

/// Compile a package in this workspace to `wasm32-wasi` and get the directory
/// the final binary was saved to.
fn build_wasi(name: &str) -> PathBuf {
let cargo = std::env::var("CARGO").unwrap_or_else(|_| "cargo".to_string());

let mut cmd = Command::new(cargo);
cmd.arg("build")
.arg("--target=wasm32-wasi")
.args(["--package", name])
.stdin(Stdio::null())
.stdout(Stdio::piped())
.stderr(Stdio::piped());

// Note: We were seeing build failures in CI because "cargo llvm-cov"
// automatically sets $RUSTFLAGS to include "-Zinstrument-coverage" and
// "profielr_builtins" isn't available for WebAssembly.
// See https://github.com/taiki-e/cargo-llvm-cov/issues/221
cmd.env("RUSTFLAGS", "");

let Output {
status,
stdout,
stderr,
} = cmd.output().expect("Unable to invoke cargo");

if !status.success() {
if !stdout.is_empty() {
eprintln!("---- STDOUT ----");
eprintln!("{}", String::from_utf8_lossy(&stdout));
}
if !stderr.is_empty() {
eprintln!("---- STDERR ----");
eprintln!("{}", String::from_utf8_lossy(&stderr));
}
panic!("{cmd:?} failed with {status}");
}

let target_dir = match std::env::var("CARGO_TARGET_DIR") {
Ok(s) => PathBuf::from(s),
Err(_) => project_root().join("target"),
};
target_dir.join("wasm32-wasi").join("debug")
}

fn project_root() -> &'static Path {
let path = Path::new(env!("CARGO_MANIFEST_DIR"))
.ancestors()
.nth(2)
.unwrap();

assert!(path.join(".git").exists());

path
}

0 comments on commit eb7ba21

Please sign in to comment.