add target to config
This commit is contained in:
@@ -7,6 +7,7 @@ pub use wasi_common::{WasiCtx, WasiCtxBuilder};
|
|||||||
// Defines a `struct Wasi` with member fields and appropriate APIs for dealing
|
// Defines a `struct Wasi` with member fields and appropriate APIs for dealing
|
||||||
// with all the various WASI exports.
|
// with all the various WASI exports.
|
||||||
wasmtime_wiggle::define_struct_for_wiggle!({
|
wasmtime_wiggle::define_struct_for_wiggle!({
|
||||||
|
target: wasi_common::wasi,
|
||||||
witx: ["../wasi-common/WASI/phases/snapshot/witx/wasi_snapshot_preview1.witx"],
|
witx: ["../wasi-common/WASI/phases/snapshot/witx/wasi_snapshot_preview1.witx"],
|
||||||
ctx: WasiCtx,
|
ctx: WasiCtx,
|
||||||
instance: {
|
instance: {
|
||||||
|
|||||||
@@ -4,13 +4,14 @@ use {
|
|||||||
braced,
|
braced,
|
||||||
parse::{Parse, ParseStream},
|
parse::{Parse, ParseStream},
|
||||||
punctuated::Punctuated,
|
punctuated::Punctuated,
|
||||||
Error, Ident, Result, Token,
|
Error, Ident, Path, Result, Token,
|
||||||
},
|
},
|
||||||
wiggle_generate::config::{CtxConf, WitxConf},
|
wiggle_generate::config::{CtxConf, WitxConf},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
|
pub target: TargetConf,
|
||||||
pub witx: WitxConf,
|
pub witx: WitxConf,
|
||||||
pub ctx: CtxConf,
|
pub ctx: CtxConf,
|
||||||
pub instance: InstanceConf,
|
pub instance: InstanceConf,
|
||||||
@@ -18,12 +19,14 @@ pub struct Config {
|
|||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum ConfigField {
|
pub enum ConfigField {
|
||||||
|
Target(TargetConf),
|
||||||
Witx(WitxConf),
|
Witx(WitxConf),
|
||||||
Ctx(CtxConf),
|
Ctx(CtxConf),
|
||||||
Instance(InstanceConf),
|
Instance(InstanceConf),
|
||||||
}
|
}
|
||||||
|
|
||||||
mod kw {
|
mod kw {
|
||||||
|
syn::custom_keyword!(target);
|
||||||
syn::custom_keyword!(witx);
|
syn::custom_keyword!(witx);
|
||||||
syn::custom_keyword!(witx_literal);
|
syn::custom_keyword!(witx_literal);
|
||||||
syn::custom_keyword!(ctx);
|
syn::custom_keyword!(ctx);
|
||||||
@@ -35,7 +38,11 @@ mod kw {
|
|||||||
impl Parse for ConfigField {
|
impl Parse for ConfigField {
|
||||||
fn parse(input: ParseStream) -> Result<Self> {
|
fn parse(input: ParseStream) -> Result<Self> {
|
||||||
let lookahead = input.lookahead1();
|
let lookahead = input.lookahead1();
|
||||||
if lookahead.peek(kw::witx) {
|
if lookahead.peek(kw::target) {
|
||||||
|
input.parse::<kw::target>()?;
|
||||||
|
input.parse::<Token![:]>()?;
|
||||||
|
Ok(ConfigField::Target(input.parse()?))
|
||||||
|
} else if lookahead.peek(kw::witx) {
|
||||||
input.parse::<kw::witx>()?;
|
input.parse::<kw::witx>()?;
|
||||||
input.parse::<Token![:]>()?;
|
input.parse::<Token![:]>()?;
|
||||||
Ok(ConfigField::Witx(WitxConf::Paths(input.parse()?)))
|
Ok(ConfigField::Witx(WitxConf::Paths(input.parse()?)))
|
||||||
@@ -59,11 +66,18 @@ impl Parse for ConfigField {
|
|||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
pub fn build(fields: impl Iterator<Item = ConfigField>, err_loc: Span) -> Result<Self> {
|
pub fn build(fields: impl Iterator<Item = ConfigField>, err_loc: Span) -> Result<Self> {
|
||||||
|
let mut target = None;
|
||||||
let mut witx = None;
|
let mut witx = None;
|
||||||
let mut ctx = None;
|
let mut ctx = None;
|
||||||
let mut instance = None;
|
let mut instance = None;
|
||||||
for f in fields {
|
for f in fields {
|
||||||
match f {
|
match f {
|
||||||
|
ConfigField::Target(c) => {
|
||||||
|
if target.is_some() {
|
||||||
|
return Err(Error::new(err_loc, "duplicate `target` field"));
|
||||||
|
}
|
||||||
|
target = Some(c);
|
||||||
|
}
|
||||||
ConfigField::Witx(c) => {
|
ConfigField::Witx(c) => {
|
||||||
if witx.is_some() {
|
if witx.is_some() {
|
||||||
return Err(Error::new(err_loc, "duplicate `witx` field"));
|
return Err(Error::new(err_loc, "duplicate `witx` field"));
|
||||||
@@ -85,6 +99,9 @@ impl Config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(Config {
|
Ok(Config {
|
||||||
|
target: target
|
||||||
|
.take()
|
||||||
|
.ok_or_else(|| Error::new(err_loc, "`target` field required"))?,
|
||||||
witx: witx
|
witx: witx
|
||||||
.take()
|
.take()
|
||||||
.ok_or_else(|| Error::new(err_loc, "`witx` field required"))?,
|
.ok_or_else(|| Error::new(err_loc, "`witx` field required"))?,
|
||||||
@@ -117,6 +134,19 @@ impl Parse for Config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct TargetConf {
|
||||||
|
pub path: Path,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Parse for TargetConf {
|
||||||
|
fn parse(input: ParseStream) -> Result<Self> {
|
||||||
|
Ok(TargetConf {
|
||||||
|
path: input.parse()?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
enum InstanceConfField {
|
enum InstanceConfField {
|
||||||
Name(Ident),
|
Name(Ident),
|
||||||
Docs(String),
|
Docs(String),
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use wiggle_generate::Names;
|
|||||||
|
|
||||||
mod config;
|
mod config;
|
||||||
|
|
||||||
use config::InstanceConf;
|
use config::{InstanceConf, TargetConf};
|
||||||
|
|
||||||
#[proc_macro]
|
#[proc_macro]
|
||||||
pub fn define_struct_for_wiggle(args: TokenStream) -> TokenStream {
|
pub fn define_struct_for_wiggle(args: TokenStream) -> TokenStream {
|
||||||
@@ -17,7 +17,7 @@ pub fn define_struct_for_wiggle(args: TokenStream) -> TokenStream {
|
|||||||
let doc = config.load_document();
|
let doc = config.load_document();
|
||||||
let names = Names::new(&config.ctx.name, quote!(wasmtime_wiggle));
|
let names = Names::new(&config.ctx.name, quote!(wasmtime_wiggle));
|
||||||
|
|
||||||
generate(&doc, &names, &config.instance).into()
|
generate(&doc, &names, &config.target, &config.instance).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Abi {
|
enum Abi {
|
||||||
@@ -27,7 +27,12 @@ enum Abi {
|
|||||||
F64,
|
F64,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate(doc: &witx::Document, names: &Names, instance_conf: &InstanceConf) -> TokenStream2 {
|
fn generate(
|
||||||
|
doc: &witx::Document,
|
||||||
|
names: &Names,
|
||||||
|
target_conf: &TargetConf,
|
||||||
|
instance_conf: &InstanceConf,
|
||||||
|
) -> TokenStream2 {
|
||||||
let mut fields = Vec::new();
|
let mut fields = Vec::new();
|
||||||
let mut get_exports = Vec::new();
|
let mut get_exports = Vec::new();
|
||||||
let mut ctor_externs = Vec::new();
|
let mut ctor_externs = Vec::new();
|
||||||
@@ -35,6 +40,7 @@ fn generate(doc: &witx::Document, names: &Names, instance_conf: &InstanceConf) -
|
|||||||
let mut linker_add = Vec::new();
|
let mut linker_add = Vec::new();
|
||||||
|
|
||||||
let runtime = names.runtime_mod();
|
let runtime = names.runtime_mod();
|
||||||
|
let target_path = &target_conf.path;
|
||||||
|
|
||||||
for module in doc.modules() {
|
for module in doc.modules() {
|
||||||
let module_name = module.name.as_str();
|
let module_name = module.name.as_str();
|
||||||
@@ -223,7 +229,7 @@ fn generate(doc: &witx::Document, names: &Names, instance_conf: &InstanceConf) -
|
|||||||
// root of each function invocation is correct.
|
// root of each function invocation is correct.
|
||||||
let bc = #runtime::BorrowChecker::new();
|
let bc = #runtime::BorrowChecker::new();
|
||||||
let mem = #runtime::WasmtimeGuestMemory::new( mem, bc );
|
let mem = #runtime::WasmtimeGuestMemory::new( mem, bc );
|
||||||
wasi_common::wasi::#module_id::#name_ident(
|
#target_path::#module_id::#name_ident(
|
||||||
&mut my_cx.borrow_mut(),
|
&mut my_cx.borrow_mut(),
|
||||||
&mem,
|
&mem,
|
||||||
#(#hostcall_args),*
|
#(#hostcall_args),*
|
||||||
|
|||||||
Reference in New Issue
Block a user