feat: add a histrical wit-bindgen
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
[package]
|
||||
name = "wit-bindgen-gen-c"
|
||||
version = "0.1.0"
|
||||
authors = ["Alex Crichton <alex@alexcrichton.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[lib]
|
||||
doctest = false
|
||||
test = false
|
||||
|
||||
[dependencies]
|
||||
wit-bindgen-gen-core = { path = '../gen-core', version = '0.1.0' }
|
||||
heck = "0.3"
|
||||
structopt = { version = "0.3", default-features = false, optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
test-helpers = { path = '../test-helpers', features = ['wit-bindgen-gen-c'] }
|
||||
@@ -0,0 +1,4 @@
|
||||
fn main() {
|
||||
println!("cargo:rerun-if-changed=build.rs");
|
||||
// this build script is currently only here so OUT_DIR is set for testing.
|
||||
}
|
||||
2260
__wasm/wit-bindgen-sample/wit-bindgen/crates/gen-c/src/lib.rs
Normal file
2260
__wasm/wit-bindgen-sample/wit-bindgen/crates/gen-c/src/lib.rs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,58 @@
|
||||
use std::env;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
|
||||
mod imports {
|
||||
test_helpers::codegen_c_import!(
|
||||
// ...
|
||||
"*.wit"
|
||||
|
||||
// TODO: implement async support
|
||||
"!async-functions.wit"
|
||||
);
|
||||
}
|
||||
|
||||
mod exports {
|
||||
test_helpers::codegen_c_export!(
|
||||
"*.wit"
|
||||
|
||||
// TODO: implement async support
|
||||
"!async-functions.wit"
|
||||
|
||||
// TODO: these use push/pull buffer in exports which isn't implemented
|
||||
// yet
|
||||
"!wasi-next.wit"
|
||||
"!host.wit"
|
||||
);
|
||||
}
|
||||
|
||||
fn verify(dir: &str, name: &str) {
|
||||
let dir = Path::new(dir);
|
||||
let path = PathBuf::from(env::var_os("WASI_SDK_PATH").unwrap());
|
||||
let mut cmd = Command::new(path.join("bin/clang"));
|
||||
cmd.arg("--sysroot").arg(path.join("share/wasi-sysroot"));
|
||||
cmd.arg(dir.join(format!("{}.c", name)));
|
||||
cmd.arg("-I").arg(dir);
|
||||
cmd.arg("-Wall")
|
||||
.arg("-Wextra")
|
||||
.arg("-Werror")
|
||||
.arg("-Wno-unused-parameter");
|
||||
cmd.arg("-c");
|
||||
cmd.arg("-o").arg(dir.join("obj.o"));
|
||||
|
||||
println!("{:?}", cmd);
|
||||
let output = match cmd.output() {
|
||||
Ok(output) => output,
|
||||
Err(e) => panic!("failed to spawn compiler: {}", e),
|
||||
};
|
||||
|
||||
if output.status.success() {
|
||||
return;
|
||||
}
|
||||
println!("status: {}", output.status);
|
||||
println!("stdout: ------------------------------------------");
|
||||
println!("{}", String::from_utf8_lossy(&output.stdout));
|
||||
println!("stderr: ------------------------------------------");
|
||||
println!("{}", String::from_utf8_lossy(&output.stderr));
|
||||
panic!("failed to compile");
|
||||
}
|
||||
Reference in New Issue
Block a user