diff --git a/Cargo.toml b/Cargo.toml index 8169fde726..6ebec5be56 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ edition = "2018" license = "Apache-2.0 WITH LLVM-exception" [dependencies] +wasi-common-cbindgen = { path = "wasi-common-cbindgen" } cast = "0.2" failure = "0.1" libc = "0.2" @@ -19,3 +20,5 @@ rand = "0.6" [lib] name = "wasi_common" crate-type = ["rlib", "staticlib", "cdylib"] + +[workspace] \ No newline at end of file diff --git a/src/hostcalls.rs b/src/hostcalls.rs index d377dbf90a..1307ea4d34 100644 --- a/src/hostcalls.rs +++ b/src/hostcalls.rs @@ -24,13 +24,16 @@ use std::ffi::{OsStr, OsString}; use std::os::unix::prelude::{FromRawFd, OsStrExt, OsStringExt, RawFd}; use std::time::SystemTime; use std::{cmp, slice}; +use wasi_common_cbindgen::wasi_common_cbindgen; +#[wasi_common_cbindgen] pub fn proc_exit(rval: wasm32::__wasi_exitcode_t) -> () { // TODO: Rather than call std::process::exit here, we should trigger a // stack unwind similar to a trap. std::process::exit(dec_exitcode(rval) as i32); } +#[wasi_common_cbindgen] pub fn args_get( wasi_ctx: &WasiCtx, memory: &mut [u8], diff --git a/wasi-common-cbindgen/Cargo.toml b/wasi-common-cbindgen/Cargo.toml new file mode 100644 index 0000000000..ddb546170b --- /dev/null +++ b/wasi-common-cbindgen/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "wasi-common-cbindgen" +version = "0.1.0" +authors = ["Jakub Konka "] +edition = "2018" + +[lib] +proc-macro = true + +[dependencies] +syn = { version = "0.15.34", features = ["full"] } +quote = "0.6.12" +proc-macro2 = "0.4.30" diff --git a/wasi-common-cbindgen/src/lib.rs b/wasi-common-cbindgen/src/lib.rs new file mode 100644 index 0000000000..2fa082a3e0 --- /dev/null +++ b/wasi-common-cbindgen/src/lib.rs @@ -0,0 +1,18 @@ +extern crate proc_macro; + +use proc_macro::TokenStream; +use quote::quote; +use syn::{FnArg, ArgCaptured, Pat, PatIdent}; +use std::collections::HashMap; + +#[proc_macro_attribute] +pub fn wasi_common_cbindgen(attr: TokenStream, function: TokenStream) -> TokenStream { + assert!(attr.is_empty()); + + let function = syn::parse_macro_input!(function as syn::ItemFn); + let result = quote! { + #function + }; + + result.into() +}