diff --git a/Cargo.lock b/Cargo.lock index 514c5d182..79331e436 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -203,9 +203,9 @@ dependencies = [ "heck", "indexmap", "wasmtime-environ", - "wit-bindgen-guest-rust", - "wit-component 0.7.0", - "wit-parser 0.6.1", + "wit-bindgen", + "wit-component", + "wit-parser", ] [[package]] @@ -219,9 +219,9 @@ dependencies = [ "indexmap", "js-component-bindgen", "wasmtime-environ", - "wit-bindgen-guest-rust", - "wit-component 0.7.0", - "wit-parser 0.6.1", + "wit-bindgen", + "wit-component", + "wit-parser", ] [[package]] @@ -492,15 +492,6 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" -[[package]] -name = "wasm-encoder" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef126be0e14bdf355ac1a8b41afc89195289e5c7179f80118e3abddb472f0810" -dependencies = [ - "leb128", -] - [[package]] name = "wasm-encoder" version = "0.23.0" @@ -541,19 +532,9 @@ dependencies = [ "wasmparser 0.101.0", "wasmprinter", "wat", - "wit-bindgen-guest-rust", - "wit-component 0.7.0", - "wit-parser 0.6.1", -] - -[[package]] -name = "wasmparser" -version = "0.99.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ef3b717afc67f848f412d4f02c127dd3e35a0eecd58c684580414df4fde01d3" -dependencies = [ - "indexmap", - "url", + "wit-bindgen", + "wit-component", + "wit-parser", ] [[package]] @@ -675,72 +656,57 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "wit-bindgen" +version = "0.3.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen#fafe05fa4ee90ab63754b45375d38ff6a5c8c9aa" +dependencies = [ + "bitflags", + "wit-bindgen-guest-rust-macro", +] + [[package]] name = "wit-bindgen-core" version = "0.3.0" -source = "git+https://github.com/bytecodealliance/wit-bindgen#98c2b1e4cb10d3757114b7524d112511a4c7459e" +source = "git+https://github.com/bytecodealliance/wit-bindgen#fafe05fa4ee90ab63754b45375d38ff6a5c8c9aa" dependencies = [ "anyhow", - "wit-component 0.4.4", - "wit-parser 0.4.1", + "wit-component", + "wit-parser", ] [[package]] name = "wit-bindgen-gen-guest-rust" version = "0.3.0" -source = "git+https://github.com/bytecodealliance/wit-bindgen#98c2b1e4cb10d3757114b7524d112511a4c7459e" +source = "git+https://github.com/bytecodealliance/wit-bindgen#fafe05fa4ee90ab63754b45375d38ff6a5c8c9aa" dependencies = [ "heck", + "wasm-metadata", "wit-bindgen-core", "wit-bindgen-gen-rust-lib", - "wit-component 0.4.4", + "wit-component", ] [[package]] name = "wit-bindgen-gen-rust-lib" version = "0.3.0" -source = "git+https://github.com/bytecodealliance/wit-bindgen#98c2b1e4cb10d3757114b7524d112511a4c7459e" +source = "git+https://github.com/bytecodealliance/wit-bindgen#fafe05fa4ee90ab63754b45375d38ff6a5c8c9aa" dependencies = [ "heck", "wit-bindgen-core", ] -[[package]] -name = "wit-bindgen-guest-rust" -version = "0.3.0" -source = "git+https://github.com/bytecodealliance/wit-bindgen#98c2b1e4cb10d3757114b7524d112511a4c7459e" -dependencies = [ - "bitflags", - "wit-bindgen-guest-rust-macro", -] - [[package]] name = "wit-bindgen-guest-rust-macro" version = "0.3.0" -source = "git+https://github.com/bytecodealliance/wit-bindgen#98c2b1e4cb10d3757114b7524d112511a4c7459e" +source = "git+https://github.com/bytecodealliance/wit-bindgen#fafe05fa4ee90ab63754b45375d38ff6a5c8c9aa" dependencies = [ "anyhow", "proc-macro2", "syn", "wit-bindgen-core", "wit-bindgen-gen-guest-rust", - "wit-component 0.4.4", -] - -[[package]] -name = "wit-component" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be202ba9a64b6c9531bcb3503b03333a6a75b9b0e12e623e4509887c02298b79" -dependencies = [ - "anyhow", - "bitflags", - "indexmap", - "log", - "url", - "wasm-encoder 0.22.0", - "wasmparser 0.99.0", - "wit-parser 0.4.1", + "wit-component", ] [[package]] @@ -758,22 +724,7 @@ dependencies = [ "wasm-metadata", "wasmparser 0.101.0", "wat", - "wit-parser 0.6.1", -] - -[[package]] -name = "wit-parser" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e60c4242d4cf4394fac7587c0d96c39b3c0fb09e638815c3f244f6bb5356f04" -dependencies = [ - "anyhow", - "id-arena", - "indexmap", - "log", - "pulldown-cmark", - "unicode-xid", - "url", + "wit-parser", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index d4ec29941..99a807de7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,6 @@ wasmprinter = "0.2.51" wasmparser = "0.101.0" wasm-encoder = "0.24.0" wat = "1.0.59" -wit-bindgen-guest-rust = { git = 'https://github.com/bytecodealliance/wit-bindgen', default-features = false, features = ['macros'] } +wit-bindgen = { git = 'https://github.com/bytecodealliance/wit-bindgen', default-features = false, features = ['macros'] } wit-component = { version = "0.7.0", features = ['dummy-module'] } wit-parser = "0.6.1" diff --git a/crates/js-component-bindgen-component/Cargo.toml b/crates/js-component-bindgen-component/Cargo.toml index bd5344657..7860cd7ec 100644 --- a/crates/js-component-bindgen-component/Cargo.toml +++ b/crates/js-component-bindgen-component/Cargo.toml @@ -15,7 +15,7 @@ heck = { workspace = true } clap = { workspace = true, optional = true } js-component-bindgen = { path = "../js-component-bindgen", features = ['raw-bindgen'] } wasmtime-environ = { workspace = true, features = ['component-model'] } -wit-bindgen-guest-rust = { workspace = true, features = ['default'] } +wit-bindgen = { workspace = true, features = ['default'] } wit-component = { workspace = true } wit-parser = { workspace = true } indexmap = { workspace = true } diff --git a/crates/js-component-bindgen-component/src/lib.rs b/crates/js-component-bindgen-component/src/lib.rs index 3635e34a0..c328791ba 100644 --- a/crates/js-component-bindgen-component/src/lib.rs +++ b/crates/js-component-bindgen-component/src/lib.rs @@ -28,7 +28,7 @@ macro_rules! uwriteln { }; } -wit_bindgen_guest_rust::generate!("js-component-bindgen"); +wit_bindgen::generate!("js-component-bindgen"); use crate::exports::*; diff --git a/crates/js-component-bindgen/Cargo.toml b/crates/js-component-bindgen/Cargo.toml index a5250a374..ee18dadbf 100644 --- a/crates/js-component-bindgen/Cargo.toml +++ b/crates/js-component-bindgen/Cargo.toml @@ -17,7 +17,7 @@ anyhow = { workspace = true } heck = { workspace = true } clap = { workspace = true, optional = true } wasmtime-environ = { workspace = true, features = ['component-model'] } -wit-bindgen-guest-rust = { workspace = true, features = ['default'] } +wit-bindgen = { workspace = true, features = ['default'] } wit-component = { workspace = true } wit-parser = { workspace = true } indexmap = { workspace = true } diff --git a/crates/js-component-bindgen/src/bindgen.rs b/crates/js-component-bindgen/src/bindgen.rs index 4e295fbc2..b71bef87d 100644 --- a/crates/js-component-bindgen/src/bindgen.rs +++ b/crates/js-component-bindgen/src/bindgen.rs @@ -406,10 +406,11 @@ impl JsBindgen { files, AbiVariant::GuestImport, ); - let camel = name.to_upper_camel_case(); + let upper_camel = name.to_upper_camel_case(); + let lower_camel = name.to_lower_camel_case(); uwriteln!( self.import_object, - "export const {name}: typeof {camel}Imports;" + "declare const {lower_camel}: typeof {upper_camel}Imports;" ); } @@ -509,6 +510,20 @@ impl JsBindgen { WorldItem::Type(_) => unimplemented!("type imports"), } } + // We will be following the ECMA262 normative: + // https://github.com/tc39/ecma262/pull/2154 + uwriteln!(self.import_object, "export {{"); + for (name, import) in world.imports.iter() { + match import { + WorldItem::Function(_) => {} + WorldItem::Interface(_) => { + let camel = name.to_lower_camel_case(); + uwriteln!(self.import_object, "{camel} as '{name}',"); + } + WorldItem::Type(_) => {} + } + } + uwriteln!(self.import_object, "}};"); if !funcs.is_empty() { self.import_funcs(resolve, id, &funcs, files); } diff --git a/crates/wasm-tools-component/Cargo.toml b/crates/wasm-tools-component/Cargo.toml index a9167736a..0ca15b428 100644 --- a/crates/wasm-tools-component/Cargo.toml +++ b/crates/wasm-tools-component/Cargo.toml @@ -15,6 +15,6 @@ wasmparser = { workspace = true } wasmprinter = { workspace = true } wasm-encoder = { workspace = true } wat = { workspace = true } -wit-bindgen-guest-rust = { workspace = true, features = ['default'] } +wit-bindgen = { workspace = true, features = ['default'] } wit-component = { workspace = true } wit-parser = { workspace = true } diff --git a/crates/wasm-tools-component/src/lib.rs b/crates/wasm-tools-component/src/lib.rs index 048196752..05369bcfe 100644 --- a/crates/wasm-tools-component/src/lib.rs +++ b/crates/wasm-tools-component/src/lib.rs @@ -4,7 +4,7 @@ use wasmparser; use wit_component::{ComponentEncoder, DecodedWasm, DocumentPrinter, StringEncoding}; use wit_parser::{Resolve, UnresolvedPackage}; -wit_bindgen_guest_rust::generate!("wasm-tools"); +wit_bindgen::generate!("wasm-tools"); struct WasmToolsJs;