diff --git a/crates/wit-component/src/encoding.rs b/crates/wit-component/src/encoding.rs index f6de9d2a53..2665fbe2e2 100644 --- a/crates/wit-component/src/encoding.rs +++ b/crates/wit-component/src/encoding.rs @@ -94,7 +94,7 @@ const INDIRECT_TABLE_NAME: &str = "$imports"; pub mod docs; mod wit; -pub use wit::{encode, encode_component, encode_world}; +pub use wit::{encode, encode_world}; mod types; use types::{InstanceTypeEncoder, RootTypeEncoder, ValtypeEncoder}; diff --git a/crates/wit-component/src/lib.rs b/crates/wit-component/src/lib.rs index 92205a32f1..e16d252375 100644 --- a/crates/wit-component/src/lib.rs +++ b/crates/wit-component/src/lib.rs @@ -216,7 +216,7 @@ pub fn embed_component_metadata( world: WorldId, encoding: StringEncoding, ) -> Result<()> { - let encoded = metadata::encode(&wit_resolver, world, encoding, None, None)?; + let encoded = metadata::encode(&wit_resolver, world, encoding, None)?; let section = wasm_encoder::CustomSection { name: "component-type".into(), diff --git a/crates/wit-component/src/metadata.rs b/crates/wit-component/src/metadata.rs index 0bd1d5b2b2..2ea73155df 100644 --- a/crates/wit-component/src/metadata.rs +++ b/crates/wit-component/src/metadata.rs @@ -47,7 +47,7 @@ use anyhow::{bail, Context, Result}; use indexmap::IndexMap; use std::borrow::Cow; use wasm_encoder::{ - ComponentBuilder, ComponentExportKind, ComponentType, ComponentTypeRef, CustomSection, Encode, + ComponentBuilder, ComponentExportKind, ComponentType, ComponentTypeRef, CustomSection, }; use wasm_metadata::Producers; use wasmparser::types::ComponentAnyTypeId; @@ -170,94 +170,34 @@ pub fn encode( world: WorldId, string_encoding: StringEncoding, extra_producers: Option<&Producers>, - use_next_encoding: Option, ) -> Result> { - enum EncodingFormat { - // The encoding of the previous format was: - // - // * A version byte, at the time 0x03. - // * A string-encoding byte. - // * A string which is the name of a world. - // * A wasm-encoded WIT package which contains the previous world. - // - // Note that this branch will be deleted in the near future. - Previous, - - // The current format. - Next, + let ty = crate::encoding::encode_world(resolve, world)?; + + let world = &resolve.worlds[world]; + let mut outer_ty = ComponentType::new(); + outer_ty.ty().component(&ty); + outer_ty.export( + &resolve.id_of_name(world.package.unwrap(), &world.name), + ComponentTypeRef::Component(0), + ); + + let mut builder = ComponentBuilder::default(); + + let string_encoding = encode_string_encoding(string_encoding); + builder.custom_section(&CustomSection { + name: CUSTOM_SECTION_NAME.into(), + data: Cow::Borrowed(&[CURRENT_VERSION, string_encoding]), + }); + + let ty = builder.type_component(&outer_ty); + builder.export(&world.name, ComponentExportKind::Type, ty, None); + + let mut producers = crate::base_producers(); + if let Some(p) = extra_producers { + producers.merge(&p); } - - let format = match use_next_encoding { - Some(true) => EncodingFormat::Next, - Some(false) => EncodingFormat::Previous, - None => match std::env::var("WIT_COMPONENT_NEW_ENCODE") { - Ok(s) if s == "0" => EncodingFormat::Previous, - _ => EncodingFormat::Next, - }, - }; - - let ret = match format { - EncodingFormat::Previous => { - let world = &resolve.worlds[world]; - let pkg = &resolve.packages[world.package.unwrap()]; - assert!( - resolve - .packages - .iter() - .filter(|(_, p)| p.name == pkg.name) - .count() - == 1 - ); - - let mut ret = Vec::new(); - ret.push(0x03); - ret.push(encode_string_encoding(string_encoding)); - world.name.encode(&mut ret); - // This appends a wasm binary encoded Component to the ret: - let mut component_builder = - crate::encoding::encode_component(None, resolve, world.package.unwrap())?; - - let mut producers = crate::base_producers(); - if let Some(p) = extra_producers { - producers.merge(&p); - } - component_builder.raw_custom_section(&producers.raw_custom_section()); - - ret.extend(component_builder.finish()); - ret - } - EncodingFormat::Next => { - let ty = crate::encoding::encode_world(resolve, world)?; - - let world = &resolve.worlds[world]; - let mut outer_ty = ComponentType::new(); - outer_ty.ty().component(&ty); - outer_ty.export( - &resolve.id_of_name(world.package.unwrap(), &world.name), - ComponentTypeRef::Component(0), - ); - - let mut builder = ComponentBuilder::default(); - - let string_encoding = encode_string_encoding(string_encoding); - builder.custom_section(&CustomSection { - name: CUSTOM_SECTION_NAME.into(), - data: Cow::Borrowed(&[CURRENT_VERSION, string_encoding]), - }); - - let ty = builder.type_component(&outer_ty); - builder.export(&world.name, ComponentExportKind::Type, ty, None); - - let mut producers = crate::base_producers(); - if let Some(p) = extra_producers { - producers.merge(&p); - } - builder.raw_custom_section(&producers.raw_custom_section()); - builder.finish() - } - }; - - Ok(ret) + builder.raw_custom_section(&producers.raw_custom_section()); + Ok(builder.finish()) } fn decode_custom_section(wasm: &[u8]) -> Result<(Resolve, WorldId, StringEncoding)> { diff --git a/crates/wit-component/tests/components.rs b/crates/wit-component/tests/components.rs index 27871d55e5..84cdfa417f 100644 --- a/crates/wit-component/tests/components.rs +++ b/crates/wit-component/tests/components.rs @@ -205,13 +205,8 @@ fn read_core_module(path: &Path, resolve: &Resolve, pkg: PackageId) -> Result