Merge pull request #2169 from bytecodealliance/pch/fix_wasmtime_wiggle
wiggle-wasmtime: witx paths should be relative to CARGO_MANIFEST_DIR,…
This commit is contained in:
10
Cargo.lock
generated
10
Cargo.lock
generated
@@ -1905,6 +1905,15 @@ dependencies = [
|
|||||||
"lazy_static",
|
"lazy_static",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "shellexpand"
|
||||||
|
version = "2.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9a2b22262a9aaf9464d356f656fea420634f78c881c5eebd5ef5e66d8b9bc603"
|
||||||
|
dependencies = [
|
||||||
|
"dirs",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "smallvec"
|
name = "smallvec"
|
||||||
version = "1.4.1"
|
version = "1.4.1"
|
||||||
@@ -2700,6 +2709,7 @@ dependencies = [
|
|||||||
"heck",
|
"heck",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
"shellexpand",
|
||||||
"syn",
|
"syn",
|
||||||
"witx",
|
"witx",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
use crate::WasiCtx;
|
use crate::WasiCtx;
|
||||||
|
|
||||||
wiggle::from_witx!({
|
wiggle::from_witx!({
|
||||||
witx: ["WASI/phases/snapshot/witx/wasi_snapshot_preview1.witx"],
|
witx: ["$WASI_ROOT/phases/snapshot/witx/wasi_snapshot_preview1.witx"],
|
||||||
ctx: WasiCtx,
|
ctx: WasiCtx,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,9 @@ pub use wasi_common::{WasiCtx, WasiCtxBuilder};
|
|||||||
wasmtime_wiggle::wasmtime_integration!({
|
wasmtime_wiggle::wasmtime_integration!({
|
||||||
// The wiggle code to integrate with lives here:
|
// The wiggle code to integrate with lives here:
|
||||||
target: wasi_common::wasi,
|
target: wasi_common::wasi,
|
||||||
// This must be the same witx document as used above:
|
// This must be the same witx document as used above. This should be ensured by
|
||||||
witx: ["phases/snapshot/witx/wasi_snapshot_preview1.witx"],
|
// the `WASI_ROOT` env variable, which is set in wasi-common's `build.rs`.
|
||||||
|
witx: ["$WASI_ROOT/phases/snapshot/witx/wasi_snapshot_preview1.witx"],
|
||||||
// This must be the same ctx type as used for the target:
|
// This must be the same ctx type as used for the target:
|
||||||
ctx: WasiCtx,
|
ctx: WasiCtx,
|
||||||
// This macro will emit a struct to represent the instance,
|
// This macro will emit a struct to represent the instance,
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ proc-macro2 = "1.0"
|
|||||||
heck = "0.3"
|
heck = "0.3"
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
syn = { version = "1.0", features = ["full"] }
|
syn = { version = "1.0", features = ["full"] }
|
||||||
|
shellexpand = "2.0"
|
||||||
|
|
||||||
[badges]
|
[badges]
|
||||||
maintenance = { status = "actively-developed" }
|
maintenance = { status = "actively-developed" }
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
use {
|
use {
|
||||||
proc_macro2::Span,
|
proc_macro2::Span,
|
||||||
std::{
|
std::{collections::HashMap, iter::FromIterator, path::PathBuf},
|
||||||
collections::HashMap,
|
|
||||||
iter::FromIterator,
|
|
||||||
path::{Path, PathBuf},
|
|
||||||
},
|
|
||||||
syn::{
|
syn::{
|
||||||
braced, bracketed,
|
braced, bracketed,
|
||||||
parse::{Parse, ParseStream},
|
parse::{Parse, ParseStream},
|
||||||
@@ -143,19 +139,6 @@ impl WitxConf {
|
|||||||
Self::Literal(doc) => witx::parse(doc.as_ref()).expect("parsing witx"),
|
Self::Literal(doc) => witx::parse(doc.as_ref()).expect("parsing witx"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// If using the [`Paths`][paths] syntax, make all paths relative to a root directory.
|
|
||||||
///
|
|
||||||
/// [paths]: enum.WitxConf.html#variant.Paths
|
|
||||||
pub fn make_paths_relative_to<P: AsRef<Path>>(&mut self, root: P) {
|
|
||||||
if let Self::Paths(paths) = self {
|
|
||||||
paths.as_mut().iter_mut().for_each(|p| {
|
|
||||||
if !p.is_absolute() {
|
|
||||||
*p = PathBuf::from(root.as_ref()).join(p.clone());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A collection of paths, pointing to witx documents.
|
/// A collection of paths, pointing to witx documents.
|
||||||
@@ -201,10 +184,19 @@ impl Parse for Paths {
|
|||||||
let content;
|
let content;
|
||||||
let _ = bracketed!(content in input);
|
let _ = bracketed!(content in input);
|
||||||
let path_lits: Punctuated<LitStr, Token![,]> = content.parse_terminated(Parse::parse)?;
|
let path_lits: Punctuated<LitStr, Token![,]> = content.parse_terminated(Parse::parse)?;
|
||||||
Ok(path_lits
|
|
||||||
|
let expanded_paths = path_lits
|
||||||
.iter()
|
.iter()
|
||||||
.map(|lit| PathBuf::from(lit.value()))
|
.map(|lit| {
|
||||||
.collect())
|
PathBuf::from(
|
||||||
|
shellexpand::env(&lit.value())
|
||||||
|
.expect("shell expansion")
|
||||||
|
.as_ref(),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect::<Vec<PathBuf>>();
|
||||||
|
|
||||||
|
Ok(Paths(expanded_paths))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -90,10 +90,7 @@ use syn::parse_macro_input;
|
|||||||
/// ```
|
/// ```
|
||||||
#[proc_macro]
|
#[proc_macro]
|
||||||
pub fn from_witx(args: TokenStream) -> TokenStream {
|
pub fn from_witx(args: TokenStream) -> TokenStream {
|
||||||
let mut config = parse_macro_input!(args as wiggle_generate::Config);
|
let config = parse_macro_input!(args as wiggle_generate::Config);
|
||||||
config.witx.make_paths_relative_to(
|
|
||||||
std::env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR env var"),
|
|
||||||
);
|
|
||||||
|
|
||||||
let doc = config.load_document();
|
let doc = config.load_document();
|
||||||
let names = wiggle_generate::Names::new(&config.ctx.name, quote!(wiggle));
|
let names = wiggle_generate::Names::new(&config.ctx.name, quote!(wiggle));
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use wiggle::{GuestMemory, GuestPtr};
|
|||||||
use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx};
|
use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx};
|
||||||
|
|
||||||
wiggle::from_witx!({
|
wiggle::from_witx!({
|
||||||
witx: ["tests/arrays.witx"],
|
witx: ["$CARGO_MANIFEST_DIR/tests/arrays.witx"],
|
||||||
ctx: WasiCtx,
|
ctx: WasiCtx,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use wiggle::GuestMemory;
|
|||||||
use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx};
|
use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx};
|
||||||
|
|
||||||
wiggle::from_witx!({
|
wiggle::from_witx!({
|
||||||
witx: ["tests/atoms.witx"],
|
witx: ["$CARGO_MANIFEST_DIR/tests/atoms.witx"],
|
||||||
ctx: WasiCtx,
|
ctx: WasiCtx,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use wiggle::{GuestMemory, GuestPtr};
|
|||||||
use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx};
|
use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx};
|
||||||
|
|
||||||
wiggle::from_witx!({
|
wiggle::from_witx!({
|
||||||
witx: ["tests/flags.witx"],
|
witx: ["$CARGO_MANIFEST_DIR/tests/flags.witx"],
|
||||||
ctx: WasiCtx,
|
ctx: WasiCtx,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx};
|
|||||||
const FD_VAL: u32 = 123;
|
const FD_VAL: u32 = 123;
|
||||||
|
|
||||||
wiggle::from_witx!({
|
wiggle::from_witx!({
|
||||||
witx: ["tests/handles.witx"],
|
witx: ["$CARGO_MANIFEST_DIR/tests/handles.witx"],
|
||||||
ctx: WasiCtx,
|
ctx: WasiCtx,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use wiggle::GuestMemory;
|
|||||||
use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx};
|
use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx};
|
||||||
|
|
||||||
wiggle::from_witx!({
|
wiggle::from_witx!({
|
||||||
witx: ["tests/ints.witx"],
|
witx: ["$CARGO_MANIFEST_DIR/tests/ints.witx"],
|
||||||
ctx: WasiCtx,
|
ctx: WasiCtx,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ mod struct_test {
|
|||||||
/// Test that a union variant that conflicts with a Rust keyword can be compiled properly.
|
/// Test that a union variant that conflicts with a Rust keyword can be compiled properly.
|
||||||
mod union_test {
|
mod union_test {
|
||||||
wiggle::from_witx!({
|
wiggle::from_witx!({
|
||||||
witx: ["tests/keywords_union.witx"],
|
witx: ["$CARGO_MANIFEST_DIR/tests/keywords_union.witx"],
|
||||||
ctx: DummyCtx,
|
ctx: DummyCtx,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use wiggle::{GuestMemory, GuestPtr};
|
|||||||
use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx};
|
use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx};
|
||||||
|
|
||||||
wiggle::from_witx!({
|
wiggle::from_witx!({
|
||||||
witx: ["tests/pointers.witx"],
|
witx: ["$CARGO_MANIFEST_DIR/tests/pointers.witx"],
|
||||||
ctx: WasiCtx,
|
ctx: WasiCtx,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use wiggle::{GuestMemory, GuestPtr};
|
|||||||
use wiggle_test::{impl_errno, HostMemory, MemArea, MemAreas, WasiCtx};
|
use wiggle_test::{impl_errno, HostMemory, MemArea, MemAreas, WasiCtx};
|
||||||
|
|
||||||
wiggle::from_witx!({
|
wiggle::from_witx!({
|
||||||
witx: ["tests/strings.witx"],
|
witx: ["$CARGO_MANIFEST_DIR/tests/strings.witx"],
|
||||||
ctx: WasiCtx,
|
ctx: WasiCtx,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use wiggle::{GuestMemory, GuestPtr};
|
|||||||
use wiggle_test::{impl_errno, HostMemory, MemArea, MemAreas, WasiCtx};
|
use wiggle_test::{impl_errno, HostMemory, MemArea, MemAreas, WasiCtx};
|
||||||
|
|
||||||
wiggle::from_witx!({
|
wiggle::from_witx!({
|
||||||
witx: ["tests/structs.witx"],
|
witx: ["$CARGO_MANIFEST_DIR/tests/structs.witx"],
|
||||||
ctx: WasiCtx,
|
ctx: WasiCtx,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use wiggle::{GuestMemory, GuestType};
|
|||||||
use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx};
|
use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx};
|
||||||
|
|
||||||
wiggle::from_witx!({
|
wiggle::from_witx!({
|
||||||
witx: ["tests/union.witx"],
|
witx: ["$CARGO_MANIFEST_DIR/tests/union.witx"],
|
||||||
ctx: WasiCtx,
|
ctx: WasiCtx,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use wiggle_test::WasiCtx;
|
|||||||
// witx is exposed with the type signatures that we expect.
|
// witx is exposed with the type signatures that we expect.
|
||||||
|
|
||||||
wiggle::from_witx!({
|
wiggle::from_witx!({
|
||||||
witx: ["tests/wasi.witx"],
|
witx: ["$CARGO_MANIFEST_DIR/tests/wasi.witx"],
|
||||||
ctx: WasiCtx,
|
ctx: WasiCtx,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -16,7 +16,10 @@ wiggle::from_witx!({
|
|||||||
#[test]
|
#[test]
|
||||||
fn document_equivalent() {
|
fn document_equivalent() {
|
||||||
let macro_doc = metadata::document();
|
let macro_doc = metadata::document();
|
||||||
let disk_doc = witx::load(&["tests/wasi.witx"]).expect("load wasi.witx from disk");
|
let mut path = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||||
|
path.push("tests");
|
||||||
|
path.push("wasi.witx");
|
||||||
|
let disk_doc = witx::load(&[path]).expect("load wasi.witx from disk");
|
||||||
|
|
||||||
assert_eq!(macro_doc, disk_doc);
|
assert_eq!(macro_doc, disk_doc);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,10 +47,7 @@ use config::{MissingMemoryConf, ModuleConf, TargetConf};
|
|||||||
///
|
///
|
||||||
#[proc_macro]
|
#[proc_macro]
|
||||||
pub fn wasmtime_integration(args: TokenStream) -> TokenStream {
|
pub fn wasmtime_integration(args: TokenStream) -> TokenStream {
|
||||||
let mut config = parse_macro_input!(args as config::Config);
|
let config = parse_macro_input!(args as config::Config);
|
||||||
config
|
|
||||||
.witx
|
|
||||||
.make_paths_relative_to(std::env::var("WASI_ROOT").expect("WASI_ROOT env var"));
|
|
||||||
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));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user