Move back to only one WASI submodule (#1434)
* Move back to only one WASI submodule This commit fixes the issue where we have two WASI submodules for build reasons in this repository. The fix was to place the submodule in the `wasi-common` crate, and then anyone using the `wig` crate has to be sure to define a `WASI_ROOT` env var in a build script to be able to parse witx files. With all that in place `wasi-common` becomes the source of truth for the witx files we're parsing, and crates like `wasmtime-wasi` use build-scripts shenanigans to read the same witx files. This should hopefully get us so we're compatible with publishing and still only have one submodule! * rustfmt
This commit is contained in:
@@ -11,6 +11,11 @@ readme = "README.md"
|
||||
edition = "2018"
|
||||
include = ["src/**/*", "LICENSE", "WASI/phases"]
|
||||
|
||||
# This doesn't actually link to a native library, but it allows us to set env
|
||||
# vars like `DEP_WASI_COMMON_14_*` for crates that have build scripts and depend
|
||||
# on this crate, allowing other crates to use the same witx files.
|
||||
links = "wasi-common-14"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0"
|
||||
thiserror = "1.0"
|
||||
|
||||
8
crates/wasi-common/build.rs
Normal file
8
crates/wasi-common/build.rs
Normal file
@@ -0,0 +1,8 @@
|
||||
// Tell any dependencies, if necessary, where our WASI submodule is so they can
|
||||
// use the same witx files if they want.
|
||||
fn main() {
|
||||
let cwd = std::env::current_dir().unwrap();
|
||||
let wasi = cwd.join("WASI");
|
||||
println!("cargo:wasi={}", wasi.display());
|
||||
println!("cargo:rustc-env=WASI_ROOT={}", wasi.display());
|
||||
}
|
||||
@@ -8,7 +8,7 @@ use crate::old::snapshot_0::wasi::*;
|
||||
use std::{convert::TryInto, io, mem, slice};
|
||||
use wig::witx_host_types;
|
||||
|
||||
witx_host_types!("old/snapshot_0" "wasi_unstable");
|
||||
witx_host_types!("phases/old/snapshot_0/witx/wasi_unstable.witx");
|
||||
|
||||
pub(crate) unsafe fn ciovec_to_host(ciovec: &__wasi_ciovec_t) -> io::IoSlice {
|
||||
let slice = slice::from_raw_parts(ciovec.buf as *const u8, ciovec.buf_len);
|
||||
|
||||
@@ -9,7 +9,7 @@ pub mod wasi;
|
||||
pub mod wasi32;
|
||||
|
||||
pub mod hostcalls {
|
||||
wig::define_hostcalls!("old/snapshot_0" "wasi_unstable");
|
||||
wig::define_hostcalls!("phases/old/snapshot_0/witx/wasi_unstable.witx");
|
||||
}
|
||||
|
||||
pub use ctx::{WasiCtx, WasiCtxBuilder};
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
use wig::witx_wasi_types;
|
||||
|
||||
witx_wasi_types!("old/snapshot_0" "wasi_unstable");
|
||||
witx_wasi_types!("phases/old/snapshot_0/witx/wasi_unstable.witx");
|
||||
|
||||
pub type WasiResult<T> = Result<T, WasiError>;
|
||||
|
||||
|
||||
@@ -12,4 +12,4 @@ use wig::witx_wasi32_types;
|
||||
pub type uintptr_t = u32;
|
||||
pub type size_t = u32;
|
||||
|
||||
witx_wasi32_types!("old/snapshot_0" "wasi_unstable");
|
||||
witx_wasi32_types!("phases/old/snapshot_0/witx/wasi_unstable.witx");
|
||||
|
||||
@@ -17,7 +17,7 @@ proc-macro = true
|
||||
quote = "1.0.2"
|
||||
proc-macro2 = "1.0.6"
|
||||
heck = "0.3.1"
|
||||
witx = { path = "WASI/tools/witx", version = "0.8.4" }
|
||||
witx = { path = "../WASI/tools/witx", version = "0.8.4" }
|
||||
|
||||
[badges]
|
||||
maintenance = { status = "actively-developed" }
|
||||
|
||||
Submodule crates/wasi-common/wig/WASI deleted from 068b282abf
@@ -3,21 +3,17 @@ use proc_macro2::TokenStream;
|
||||
use quote::{format_ident, quote};
|
||||
|
||||
pub fn define(args: TokenStream) -> TokenStream {
|
||||
let (path, phase) = utils::witx_path_from_args(args);
|
||||
let path = utils::witx_path_from_args(args);
|
||||
let doc = match witx::load(&[&path]) {
|
||||
Ok(doc) => doc,
|
||||
Err(e) => {
|
||||
panic!("error opening file {}: {}", path, e);
|
||||
panic!("error opening file {}: {}", path.display(), e);
|
||||
}
|
||||
};
|
||||
|
||||
let mut ret = TokenStream::new();
|
||||
|
||||
let old = match phase.as_str() {
|
||||
"snapshot" => false,
|
||||
"old/snapshot_0" => true,
|
||||
s => panic!("unsupported phase: {}", s),
|
||||
};
|
||||
let old = true;
|
||||
|
||||
for module in doc.modules() {
|
||||
for func in module.funcs() {
|
||||
|
||||
@@ -25,11 +25,11 @@ impl Mode {
|
||||
pub fn gen(args: TokenStream, mode: Mode) -> TokenStream {
|
||||
let mut output = TokenStream::new();
|
||||
|
||||
let (path, _phase) = utils::witx_path_from_args(args);
|
||||
let path = utils::witx_path_from_args(args);
|
||||
let doc = match witx::load(&[&path]) {
|
||||
Ok(doc) => doc,
|
||||
Err(e) => {
|
||||
panic!("error opening file {}: {}", path, e);
|
||||
panic!("error opening file {}: {}", path.display(), e);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
use proc_macro2::{Ident, Literal, TokenStream, TokenTree};
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// Given the input tokens to a macro invocation, return the path to the
|
||||
/// witx file to process.
|
||||
pub(crate) fn witx_path_from_args(args: TokenStream) -> (String, String) {
|
||||
pub(crate) fn witx_path_from_args(args: TokenStream) -> PathBuf {
|
||||
let mut strings = Vec::new();
|
||||
|
||||
for arg in args {
|
||||
@@ -15,20 +16,11 @@ pub(crate) fn witx_path_from_args(args: TokenStream) -> (String, String) {
|
||||
}
|
||||
}
|
||||
|
||||
if strings.len() != 2 {
|
||||
panic!("expected two string literals");
|
||||
if strings.len() != 1 {
|
||||
panic!("expected one string literals");
|
||||
}
|
||||
|
||||
let phase = &strings[0];
|
||||
let id = &strings[1];
|
||||
let path = witx_path(phase, id);
|
||||
|
||||
(path, phase.clone())
|
||||
}
|
||||
|
||||
fn witx_path(phase: &str, id: &str) -> String {
|
||||
let root = env!("CARGO_MANIFEST_DIR");
|
||||
format!("{}/WASI/phases/{}/witx/{}.witx", root, phase, id)
|
||||
let root = PathBuf::from(std::env::var("WASI_ROOT").unwrap());
|
||||
return root.join(&strings[0]);
|
||||
}
|
||||
|
||||
// Convert a `Literal` holding a string literal into the `String`.
|
||||
|
||||
@@ -21,11 +21,11 @@ enum Abi {
|
||||
/// I'd recommend using `cargo +nightly expand` to explore the output of this
|
||||
/// macro some more.
|
||||
pub fn define_struct(args: TokenStream) -> TokenStream {
|
||||
let (path, _phase) = utils::witx_path_from_args(args);
|
||||
let path = utils::witx_path_from_args(args);
|
||||
let doc = match witx::load(&[&path]) {
|
||||
Ok(doc) => doc,
|
||||
Err(e) => {
|
||||
panic!("error opening file {}: {}", path, e);
|
||||
panic!("error opening file {}: {}", path.display(), e);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -265,11 +265,11 @@ pub fn define_struct(args: TokenStream) -> TokenStream {
|
||||
}
|
||||
|
||||
pub fn define_struct_for_wiggle(args: TokenStream) -> TokenStream {
|
||||
let (path, _phase) = utils::witx_path_from_args(args);
|
||||
let path = utils::witx_path_from_args(args);
|
||||
let doc = match witx::load(&[&path]) {
|
||||
Ok(doc) => doc,
|
||||
Err(e) => {
|
||||
panic!("error opening file {}: {}", path, e);
|
||||
panic!("error opening file {}: {}", path.display(), e);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user