From 34a9ad98264a351ae72928c1fb77d85c1c750d12 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 31 May 2024 10:27:40 -0500 Subject: [PATCH] Update `wit-bindgen`, add `features` to `bindgen!` (#8720) This commit updates the wit-bindgen family of crates and additionally adds a `features` key to the `bindgen!` macro. This brings it in line with `wit-bindgen`'s support which enables usage of the new `@since` and `@unstable` features of WIT. --- Cargo.lock | 165 +++++-------------- Cargo.toml | 4 +- crates/component-macro/src/bindgen.rs | 17 +- crates/wasmtime/src/runtime/component/mod.rs | 9 +- supply-chain/imports.lock | 30 ++++ 5 files changed, 101 insertions(+), 124 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9d23f7c158..8041eb4e6d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -853,7 +853,7 @@ dependencies = [ "serde_derive", "smallvec", "target-lexicon", - "wasmparser 0.209.1", + "wasmparser", "wasmtime-types", "wat", ] @@ -2763,7 +2763,7 @@ dependencies = [ "cargo_metadata", "heck 0.4.0", "wasmtime", - "wit-component 0.209.1", + "wit-component", ] [[package]] @@ -3093,7 +3093,7 @@ name = "verify-component-adapter" version = "22.0.0" dependencies = [ "anyhow", - "wasmparser 0.209.1", + "wasmparser", "wat", ] @@ -3186,7 +3186,7 @@ dependencies = [ "byte-array-literals", "object 0.33.0", "wasi", - "wasm-encoder 0.209.1", + "wasm-encoder", "wit-bindgen-rust-macro", ] @@ -3244,15 +3244,6 @@ version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" -[[package]] -name = "wasm-encoder" -version = "0.208.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6425e84e42f7f558478e40ecc2287912cb319f2ca68e5c0bb93c61d4fc63fa17" -dependencies = [ - "leb128", -] - [[package]] name = "wasm-encoder" version = "0.209.1" @@ -3262,22 +3253,6 @@ dependencies = [ "leb128", ] -[[package]] -name = "wasm-metadata" -version = "0.208.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42a2c4280ad374a6db3d76d4bb61e2ec4b3b9ce5469cc4f2bbc5708047a2bbff" -dependencies = [ - "anyhow", - "indexmap 2.2.6", - "serde", - "serde_derive", - "serde_json", - "spdx", - "wasm-encoder 0.208.1", - "wasmparser 0.208.1", -] - [[package]] name = "wasm-metadata" version = "0.209.1" @@ -3290,8 +3265,8 @@ dependencies = [ "serde_derive", "serde_json", "spdx", - "wasm-encoder 0.209.1", - "wasmparser 0.209.1", + "wasm-encoder", + "wasmparser", ] [[package]] @@ -3304,8 +3279,8 @@ dependencies = [ "log", "rand", "thiserror", - "wasm-encoder 0.209.1", - "wasmparser 0.209.1", + "wasm-encoder", + "wasmparser", ] [[package]] @@ -3319,7 +3294,7 @@ dependencies = [ "flagset", "indexmap 2.2.6", "leb128", - "wasm-encoder 0.209.1", + "wasm-encoder", ] [[package]] @@ -3362,19 +3337,6 @@ dependencies = [ "paste", ] -[[package]] -name = "wasmparser" -version = "0.208.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd921789c9dcc495f589cb37d200155dee65b4a4beeb853323b5e24e0a5f9c58" -dependencies = [ - "ahash", - "bitflags 2.4.1", - "hashbrown 0.14.3", - "indexmap 2.2.6", - "semver", -] - [[package]] name = "wasmparser" version = "0.209.1" @@ -3405,7 +3367,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ceca8ae6eaa8c7c87b33c25c53bdf299f8c2a764aee1179402ff7652ef3a6859" dependencies = [ "anyhow", - "wasmparser 0.209.1", + "wasmparser", ] [[package]] @@ -3448,8 +3410,8 @@ dependencies = [ "target-lexicon", "tempfile", "wasi-common", - "wasm-encoder 0.209.1", - "wasmparser 0.209.1", + "wasm-encoder", + "wasmparser", "wasmtime-asm-macros", "wasmtime-cache", "wasmtime-component-macro", @@ -3591,7 +3553,7 @@ dependencies = [ "tracing", "walkdir", "wasi-common", - "wasmparser 0.209.1", + "wasmparser", "wasmtime", "wasmtime-cache", "wasmtime-cli-flags", @@ -3608,7 +3570,7 @@ dependencies = [ "wast 209.0.1", "wat", "windows-sys 0.52.0", - "wit-component 0.209.1", + "wit-component", ] [[package]] @@ -3641,7 +3603,7 @@ dependencies = [ "wasmtime", "wasmtime-component-util", "wasmtime-wit-bindgen", - "wit-parser 0.209.1", + "wit-parser", ] [[package]] @@ -3665,7 +3627,7 @@ dependencies = [ "object 0.33.0", "target-lexicon", "thiserror", - "wasmparser 0.209.1", + "wasmparser", "wasmtime-environ", "wasmtime-versioned-export-macros", ] @@ -3688,8 +3650,8 @@ dependencies = [ "serde", "serde_derive", "target-lexicon", - "wasm-encoder 0.209.1", - "wasmparser 0.209.1", + "wasm-encoder", + "wasmparser", "wasmprinter", "wasmtime-component-util", "wasmtime-types", @@ -3704,7 +3666,7 @@ dependencies = [ "component-fuzz-util", "env_logger", "libfuzzer-sys", - "wasmparser 0.209.1", + "wasmparser", "wasmprinter", "wasmtime-environ", "wat", @@ -3762,7 +3724,7 @@ dependencies = [ "rand", "smallvec", "target-lexicon", - "wasmparser 0.209.1", + "wasmparser", "wasmtime", "wasmtime-fuzzing", ] @@ -3783,12 +3745,12 @@ dependencies = [ "target-lexicon", "tempfile", "v8", - "wasm-encoder 0.209.1", + "wasm-encoder", "wasm-mutate", "wasm-smith", "wasm-spec-interpreter", "wasmi", - "wasmparser 0.209.1", + "wasmparser", "wasmprinter", "wasmtime", "wasmtime-wast", @@ -3837,7 +3799,7 @@ dependencies = [ "serde", "serde_derive", "smallvec", - "wasmparser 0.209.1", + "wasmparser", ] [[package]] @@ -3956,7 +3918,7 @@ dependencies = [ "gimli", "object 0.33.0", "target-lexicon", - "wasmparser 0.209.1", + "wasmparser", "wasmtime-cranelift", "wasmtime-environ", "winch-codegen", @@ -3969,7 +3931,7 @@ dependencies = [ "anyhow", "heck 0.4.0", "indexmap 2.2.6", - "wit-parser 0.209.1", + "wit-parser", ] [[package]] @@ -3995,7 +3957,7 @@ dependencies = [ "leb128", "memchr", "unicode-width", - "wasm-encoder 0.209.1", + "wasm-encoder", ] [[package]] @@ -4124,7 +4086,7 @@ dependencies = [ "regalloc2", "smallvec", "target-lexicon", - "wasmparser 0.209.1", + "wasmparser", "wasmtime-cranelift", "wasmtime-environ", ] @@ -4301,9 +4263,9 @@ dependencies = [ [[package]] name = "wit-bindgen" -version = "0.25.0" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f497a5ce965e6cb9929079bb4af633bd88dfb19d0dfc5341580e354947f00b2" +checksum = "a84376ff4f74ed07674a1157c0bd19e6627ab01fc90952a27ccefb52a24530f0" dependencies = [ "wit-bindgen-rt", "wit-bindgen-rust-macro", @@ -4311,43 +4273,43 @@ dependencies = [ [[package]] name = "wit-bindgen-core" -version = "0.25.0" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7076a12e69af6e1f6093bd16657d7ae61c30cfd3c5f62321046eb863b17ab1e2" +checksum = "36d4706efb67fadfbbde77955b299b111dd096e6776d8c6561d92f6147941880" dependencies = [ "anyhow", "heck 0.5.0", - "wit-parser 0.208.1", + "wit-parser", ] [[package]] name = "wit-bindgen-rt" -version = "0.25.0" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef83e2f948056d4195b4c2a236a10378b70c8fd7501039c5a106c1a756fa7da6" +checksum = "29c7526379ace8709ee9ab9f2bb50f112d95581063a59ef3097d9c10153886c9" dependencies = [ "bitflags 2.4.1", ] [[package]] name = "wit-bindgen-rust" -version = "0.25.0" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f8ca0dd2aa75452450da1906391aba9d3a43d95fa920e872361ea00acc452a5" +checksum = "514295193d1a2f42e6a948cd7d9fd81e2b8fadc319667dcf19fd7aceaf2113a2" dependencies = [ "anyhow", "heck 0.5.0", "indexmap 2.2.6", - "wasm-metadata 0.208.1", + "wasm-metadata", "wit-bindgen-core", - "wit-component 0.208.1", + "wit-component", ] [[package]] name = "wit-bindgen-rust-macro" -version = "0.25.0" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d734e18bdf439ed86afe9d85fc5bfa38db4b676fc0e0a0dae95bd8f14de039" +checksum = "f0409a3356ca02599aff78f717968fd7f12df4bf879f325e2a97b45c84c90fff" dependencies = [ "anyhow", "proc-macro2", @@ -4357,25 +4319,6 @@ dependencies = [ "wit-bindgen-rust", ] -[[package]] -name = "wit-component" -version = "0.208.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fef7dd0e47f5135dd8739ccc5b188ab8b7e27e1d64df668aa36680f0b8646db8" -dependencies = [ - "anyhow", - "bitflags 2.4.1", - "indexmap 2.2.6", - "log", - "serde", - "serde_derive", - "serde_json", - "wasm-encoder 0.208.1", - "wasm-metadata 0.208.1", - "wasmparser 0.208.1", - "wit-parser 0.208.1", -] - [[package]] name = "wit-component" version = "0.209.1" @@ -4389,28 +4332,10 @@ dependencies = [ "serde", "serde_derive", "serde_json", - "wasm-encoder 0.209.1", - "wasm-metadata 0.209.1", - "wasmparser 0.209.1", - "wit-parser 0.209.1", -] - -[[package]] -name = "wit-parser" -version = "0.208.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "516417a730725fe3e6c9e2efc8d86697480f80496d32b24e62736950704c047c" -dependencies = [ - "anyhow", - "id-arena", - "indexmap 2.2.6", - "log", - "semver", - "serde", - "serde_derive", - "serde_json", - "unicode-xid", - "wasmparser 0.208.1", + "wasm-encoder", + "wasm-metadata", + "wasmparser", + "wit-parser", ] [[package]] @@ -4428,7 +4353,7 @@ dependencies = [ "serde_derive", "serde_json", "unicode-xid", - "wasmparser 0.209.1", + "wasmparser", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index ef48f5fc0a..be1e8c0678 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -248,8 +248,8 @@ io-lifetimes = { version = "2.0.3", default-features = false } io-extras = "0.18.1" rustix = "0.38.31" # wit-bindgen: -wit-bindgen = { version = "0.25.0", default-features = false } -wit-bindgen-rust-macro = { version = "0.25.0", default-features = false } +wit-bindgen = { version = "0.26.0", default-features = false } +wit-bindgen-rust-macro = { version = "0.26.0", default-features = false } # wasm-tools family: wasmparser = { version = "0.209.1", default-features = false } diff --git a/crates/component-macro/src/bindgen.rs b/crates/component-macro/src/bindgen.rs index e35b20af65..eb05d4ad81 100644 --- a/crates/component-macro/src/bindgen.rs +++ b/crates/component-macro/src/bindgen.rs @@ -80,6 +80,7 @@ impl Parse for Config { let mut inline = None; let mut path = None; let mut async_configured = false; + let mut features = Vec::new(); if input.peek(token::Brace) { let content; @@ -150,6 +151,9 @@ impl Parse for Config { } Opt::Stringify(val) => opts.stringify = val, Opt::SkipMutForwardingImpls(val) => opts.skip_mut_forwarding_impls = val, + Opt::Features(f) => { + features.extend(f.into_iter().map(|f| f.value())); + } } } } else { @@ -158,7 +162,7 @@ impl Parse for Config { path = Some(input.parse::()?.value()); } } - let (resolve, pkg, files) = parse_source(&path, &inline) + let (resolve, pkg, files) = parse_source(&path, &inline, &features) .map_err(|err| Error::new(call_site, format!("{err:?}")))?; let world = resolve @@ -176,8 +180,10 @@ impl Parse for Config { fn parse_source( path: &Option, inline: &Option, + features: &[String], ) -> anyhow::Result<(Resolve, PackageId, Vec)> { let mut resolve = Resolve::default(); + resolve.features.extend(features.iter().cloned()); let mut files = Vec::new(); let root = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()); @@ -221,6 +227,7 @@ mod kw { syn::custom_keyword!(additional_derives); syn::custom_keyword!(stringify); syn::custom_keyword!(skip_mut_forwarding_impls); + syn::custom_keyword!(features); } enum Opt { @@ -237,6 +244,7 @@ enum Opt { AdditionalDerives(Vec), Stringify(bool), SkipMutForwardingImpls(bool), + Features(Vec), } impl Parse for Opt { @@ -387,6 +395,13 @@ impl Parse for Opt { Ok(Opt::SkipMutForwardingImpls( input.parse::()?.value, )) + } else if l.peek(kw::features) { + input.parse::()?; + input.parse::()?; + let contents; + syn::bracketed!(contents in input); + let list = Punctuated::<_, Token![,]>::parse_terminated(&contents)?; + Ok(Opt::Features(list.into_iter().collect())) } else { Err(l.error()) } diff --git a/crates/wasmtime/src/runtime/component/mod.rs b/crates/wasmtime/src/runtime/component/mod.rs index 28f2653044..d7fd4e1037 100644 --- a/crates/wasmtime/src/runtime/component/mod.rs +++ b/crates/wasmtime/src/runtime/component/mod.rs @@ -521,7 +521,14 @@ pub(crate) use self::store::ComponentStoreData; /// Hash, /// serde::Deserialize, /// serde::Serialize, -/// ] +/// ], +/// +/// // A list of WIT "features" to enable when parsing the WIT document that +/// // this bindgen macro matches. WIT features are all disabled by default +/// // and must be opted-in-to if source level features are used. +/// // +/// // This option defaults to an empty array. +/// features: ["foo", "bar", "baz"], /// }); /// ``` pub use wasmtime_component_macro::bindgen; diff --git a/supply-chain/imports.lock b/supply-chain/imports.lock index 15c1483f48..ad0f41ae21 100644 --- a/supply-chain/imports.lock +++ b/supply-chain/imports.lock @@ -2557,6 +2557,12 @@ when = "2024-05-20" user-id = 73222 user-login = "wasmtime-publish" +[[publisher.wit-bindgen]] +version = "0.26.0" +when = "2024-05-30" +user-id = 73222 +user-login = "wasmtime-publish" + [[publisher.wit-bindgen-core]] version = "0.20.0" when = "2024-02-29" @@ -2575,6 +2581,12 @@ when = "2024-05-20" user-id = 73222 user-login = "wasmtime-publish" +[[publisher.wit-bindgen-core]] +version = "0.26.0" +when = "2024-05-30" +user-id = 73222 +user-login = "wasmtime-publish" + [[publisher.wit-bindgen-rt]] version = "0.22.0" when = "2024-03-11" @@ -2587,6 +2599,12 @@ when = "2024-05-20" user-id = 73222 user-login = "wasmtime-publish" +[[publisher.wit-bindgen-rt]] +version = "0.26.0" +when = "2024-05-30" +user-id = 73222 +user-login = "wasmtime-publish" + [[publisher.wit-bindgen-rust]] version = "0.20.0" when = "2024-02-29" @@ -2605,6 +2623,12 @@ when = "2024-05-20" user-id = 73222 user-login = "wasmtime-publish" +[[publisher.wit-bindgen-rust]] +version = "0.26.0" +when = "2024-05-30" +user-id = 73222 +user-login = "wasmtime-publish" + [[publisher.wit-bindgen-rust-macro]] version = "0.20.0" when = "2024-02-29" @@ -2623,6 +2647,12 @@ when = "2024-05-20" user-id = 73222 user-login = "wasmtime-publish" +[[publisher.wit-bindgen-rust-macro]] +version = "0.26.0" +when = "2024-05-30" +user-id = 73222 +user-login = "wasmtime-publish" + [[publisher.wit-component]] version = "0.201.0" when = "2024-02-27"