Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 137 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions crates/wasi-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ maintenance = { status = "actively-developed" }

[features]
default = ["trace_log"]
# This feature enables `log::trace` calls in syscalls shims, in effect
# emulating something like `strace`. This feature is an opt-out and hence
# enabled by default.
trace_log = []
# This feature enables the `tracing` logs in the calls to target the `log`
# ecosystem of backends (e.g. `env_logger`. Disable this if you want to use
# `tracing-subscriber`.
trace_log = [ "wiggle/tracing_log" ]
# Need to make the wiggle_metadata feature available to consumers of this
# crate if they want the snapshots to have metadata available.
wiggle_metadata = ["wiggle/wiggle_metadata"]
14 changes: 9 additions & 5 deletions crates/wiggle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ include = ["src/**/*", "LICENSE"]
thiserror = "1"
witx = { path = "../wasi-common/WASI/tools/witx", version = "0.8.5", optional = true }
wiggle-macro = { path = "macro", version = "0.17.0" }
tracing = "0.1.15"

[badges]
maintenance = { status = "actively-developed" }
Expand All @@ -23,13 +24,16 @@ wiggle-test = { path = "test-helpers" }
proptest = "0.9"

[features]
# These features have no effect on the users of this crate. They are only
# necessary for testing.
# The wiggle proc-macro emits some code (inside `pub mod metadata`) guarded
# by the `wiggle_metadata` feature flag. We use this feature flag so that
# users of wiggle are not forced to take a direct dependency on the `witx`
# crate unless they want it.
wiggle_metadata = ['witx', "wiggle-macro/wiggle_metadata"]
# In order to test that the contents of this metadata module meet
# expectations, we must have this feature enabled for the crate by default.
default = ["wiggle_metadata"]

# The `tracing` crate can use the `log` ecosystem of backends with this
# non-default feature. We don't need to provide this by default, but its
# useful for users that don't want to use `tracing-subscriber` to get
# the logs out of wiggle-generated libraries.
tracing_log = [ "tracing/log" ]

default = ["wiggle_metadata" ]
38 changes: 25 additions & 13 deletions crates/wiggle/generate/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,35 @@ pub enum ConfigField {
Error(ErrorConf),
}

impl ConfigField {
pub fn parse_pair(ident: &str, value: ParseStream, err_loc: Span) -> Result<Self> {
match ident {
"witx" => Ok(ConfigField::Witx(WitxConf::Paths(value.parse()?))),
"witx_literal" => Ok(ConfigField::Witx(WitxConf::Literal(value.parse()?))),
"ctx" => Ok(ConfigField::Ctx(value.parse()?)),
"errors" => Ok(ConfigField::Error(value.parse()?)),
_ => Err(Error::new(err_loc, "expected `witx`, `ctx`, or `errors`")),
}
}
mod kw {
syn::custom_keyword!(witx);
syn::custom_keyword!(witx_literal);
syn::custom_keyword!(ctx);
syn::custom_keyword!(errors);
}

impl Parse for ConfigField {
fn parse(input: ParseStream) -> Result<Self> {
let id: Ident = input.parse()?;
let _colon: Token![:] = input.parse()?;
Self::parse_pair(id.to_string().as_ref(), input, id.span())
let lookahead = input.lookahead1();
if lookahead.peek(kw::witx) {
input.parse::<kw::witx>()?;
input.parse::<Token![:]>()?;
Ok(ConfigField::Witx(WitxConf::Paths(input.parse()?)))
} else if lookahead.peek(kw::witx_literal) {
input.parse::<kw::witx_literal>()?;
input.parse::<Token![:]>()?;
Ok(ConfigField::Witx(WitxConf::Literal(input.parse()?)))
} else if lookahead.peek(kw::ctx) {
input.parse::<kw::ctx>()?;
input.parse::<Token![:]>()?;
Ok(ConfigField::Ctx(input.parse()?))
} else if lookahead.peek(kw::errors) {
input.parse::<kw::errors>()?;
input.parse::<Token![:]>()?;
Ok(ConfigField::Error(input.parse()?))
} else {
Err(lookahead.error())
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions crates/wiggle/generate/src/error_transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ pub struct ErrorTransform {
}

impl ErrorTransform {
pub fn empty() -> Self {
Self { m: Vec::new() }
}
pub fn new(conf: &ErrorConf, doc: &Document) -> Result<Self, Error> {
let mut richtype_identifiers = HashMap::new();
let m = conf.iter().map(|(ident, field)|
Expand Down
Loading