summaryrefslogtreecommitdiffstats
path: root/tools/wasi-headers/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tools/wasi-headers/src/lib.rs')
-rw-r--r--tools/wasi-headers/src/lib.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/tools/wasi-headers/src/lib.rs b/tools/wasi-headers/src/lib.rs
new file mode 100644
index 0000000..8844c49
--- /dev/null
+++ b/tools/wasi-headers/src/lib.rs
@@ -0,0 +1,39 @@
+mod c_header;
+
+use anyhow::Result;
+pub use c_header::{to_c, Generated};
+use std::path::{Path, PathBuf};
+use witx::load;
+
+pub fn generate<P: AsRef<Path>>(inputs: &[P]) -> Result<Generated> {
+ let doc = load(&inputs)?;
+
+ let inputs_str = &inputs
+ .iter()
+ .map(|p| {
+ p.as_ref()
+ .file_name()
+ .unwrap()
+ .to_str()
+ .unwrap()
+ .to_string()
+ })
+ .collect::<Vec<_>>()
+ .join(", ");
+
+ Ok(to_c(&doc, &inputs_str))
+}
+
+pub fn snapshot_witx_files() -> Result<Vec<PathBuf>> {
+ witx::phases::snapshot()
+}
+
+pub fn libc_wasi_api_header() -> PathBuf {
+ PathBuf::from(env!("CARGO_MANIFEST_DIR"))
+ .join("../../libc-bottom-half/headers/public/wasi/api.h")
+}
+
+pub fn libc_wasi_api_source() -> PathBuf {
+ PathBuf::from(env!("CARGO_MANIFEST_DIR"))
+ .join("../../libc-bottom-half/sources/__wasilibc_real.c")
+}