Add placeholder for cbindgen proc_macro_attribute
This commit is contained in:
@@ -10,6 +10,7 @@ edition = "2018"
|
|||||||
license = "Apache-2.0 WITH LLVM-exception"
|
license = "Apache-2.0 WITH LLVM-exception"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
wasi-common-cbindgen = { path = "wasi-common-cbindgen" }
|
||||||
cast = "0.2"
|
cast = "0.2"
|
||||||
failure = "0.1"
|
failure = "0.1"
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
@@ -19,3 +20,5 @@ rand = "0.6"
|
|||||||
[lib]
|
[lib]
|
||||||
name = "wasi_common"
|
name = "wasi_common"
|
||||||
crate-type = ["rlib", "staticlib", "cdylib"]
|
crate-type = ["rlib", "staticlib", "cdylib"]
|
||||||
|
|
||||||
|
[workspace]
|
||||||
@@ -24,13 +24,16 @@ use std::ffi::{OsStr, OsString};
|
|||||||
use std::os::unix::prelude::{FromRawFd, OsStrExt, OsStringExt, RawFd};
|
use std::os::unix::prelude::{FromRawFd, OsStrExt, OsStringExt, RawFd};
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
use std::{cmp, slice};
|
use std::{cmp, slice};
|
||||||
|
use wasi_common_cbindgen::wasi_common_cbindgen;
|
||||||
|
|
||||||
|
#[wasi_common_cbindgen]
|
||||||
pub fn proc_exit(rval: wasm32::__wasi_exitcode_t) -> () {
|
pub fn proc_exit(rval: wasm32::__wasi_exitcode_t) -> () {
|
||||||
// TODO: Rather than call std::process::exit here, we should trigger a
|
// TODO: Rather than call std::process::exit here, we should trigger a
|
||||||
// stack unwind similar to a trap.
|
// stack unwind similar to a trap.
|
||||||
std::process::exit(dec_exitcode(rval) as i32);
|
std::process::exit(dec_exitcode(rval) as i32);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[wasi_common_cbindgen]
|
||||||
pub fn args_get(
|
pub fn args_get(
|
||||||
wasi_ctx: &WasiCtx,
|
wasi_ctx: &WasiCtx,
|
||||||
memory: &mut [u8],
|
memory: &mut [u8],
|
||||||
|
|||||||
13
wasi-common-cbindgen/Cargo.toml
Normal file
13
wasi-common-cbindgen/Cargo.toml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
[package]
|
||||||
|
name = "wasi-common-cbindgen"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Jakub Konka <kubkon@jakubkonka.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
proc-macro = true
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
syn = { version = "0.15.34", features = ["full"] }
|
||||||
|
quote = "0.6.12"
|
||||||
|
proc-macro2 = "0.4.30"
|
||||||
18
wasi-common-cbindgen/src/lib.rs
Normal file
18
wasi-common-cbindgen/src/lib.rs
Normal file
@@ -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()
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user