Skip to content

Commit 20ada4b

Browse files
alexcrichtonac000
authored andcommitted
Wasm-wc: Core of initial Wasm component model language module support
This is the work of Alex Crichton. This is written in Rust. The problem is that there is currently no support on the C side of things for the component model, which is the point of this module. It talks to Unit via automatically generated bindings. I've (Andrew) just made some minor tweaks to src/lib.rs, build.rs & Cargo.toml to adjust some paths, adjust where we get the language module config from and the module name and where it's located in the source tree, I also removed and disabled the tracking of the Cargo.lock file, this is constantly changing and not tracking it seems right for 'libraries' and dropped the README's... Other than that I have tried to leave his work intact, subsequent commits will make some larger changes, but I didn't want to intermix them with Alex's work. One such commit will update the module to use wasmtime 17 which brings WASI 0.2.0 support. Signed-off-by: Andrew Clayton <[email protected]>
1 parent f078272 commit 20ada4b

File tree

5 files changed

+620
-0
lines changed

5 files changed

+620
-0
lines changed

src/wasm-wasi-component/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Cargo.lock
2+
3+
target

src/wasm-wasi-component/Cargo.toml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[package]
2+
name = "wasm-wasi-component"
3+
version = "0.1.0"
4+
edition = "2021"
5+
publish = false
6+
7+
[lib]
8+
crate-type = ["cdylib"]
9+
10+
[dependencies]
11+
anyhow = "1.0.75"
12+
bytes = "1.5.0"
13+
futures-util = { version = "0.3.29", default-features = false }
14+
http = "0.2.9"
15+
http-body = { version = "1.0.0-rc.2", default-features = false }
16+
http-body-util = "0.1.0-rc.2"
17+
tokio = { version = "1.33.0", default-features = false }
18+
wasmtime = "14.0.2"
19+
wasmtime-wasi = "14.0.2"
20+
wasmtime-wasi-http = "14.0.2"
21+
22+
[build-dependencies]
23+
bindgen = "0.68.1"
24+
cc = "1.0.83"
25+
26+
[profile.dev]
27+
panic = 'abort'
28+
29+
[profile.release]
30+
panic = 'abort'

src/wasm-wasi-component/build.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use std::env;
2+
use std::path::PathBuf;
3+
4+
fn main() {
5+
// Tell cargo to invalidate the built crate whenever the wrapper changes
6+
println!("cargo:rerun-if-changed=wrapper.h");
7+
8+
let bindings = bindgen::Builder::default()
9+
.clang_args(["-I", "../"])
10+
.clang_args(["-I", "../../build/include"])
11+
.header("./wrapper.h")
12+
// only generate bindings for `nxt_*` header files
13+
.allowlist_file(".*nxt_.*.h")
14+
// generates an "improper_ctypes" warning and we don't need it anyway
15+
.blocklist_function("nxt_vsprintf")
16+
// Tell cargo to invalidate the built crate whenever any of the
17+
// included header files changed.
18+
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
19+
// disable some features which aren't necessary
20+
.layout_tests(false)
21+
.derive_debug(false)
22+
.generate()
23+
.expect("Unable to generate bindings");
24+
25+
cc::Build::new()
26+
.object("../../build/src/nxt_unit.o")
27+
.compile("nxt-unit");
28+
29+
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
30+
bindings
31+
.write_to_file(out_path.join("bindings.rs"))
32+
.expect("Couldn't write bindings!");
33+
}

0 commit comments

Comments
 (0)