Skip to content

Commit 614c2ed

Browse files
zacharywhitleyZachary Whitley
andauthored
feat(wasm-encoder): add ComponentBuilder::instantiate_exports (#2655)
The core-level analogue `core_instantiate_exports` already exists on `ComponentBuilder` and mirrors the `Instance::FromExports` variant of the core instance section. The component-level side had no equivalent: `ComponentInstanceSection::export_items` is public but only reachable through the manual section-append path, not the builder facade. Add `instantiate_exports` next to `instantiate` so callers rebuilding a component structurally from a parsed one can round-trip `ComponentInstance::FromExports` the same way core-level `Instance::FromExports` already round-trips. The signature follows the section-level `ComponentInstanceSection:: export_items` — `N: Into<ComponentExternName<'a>>` in the name slot, preserving the rich name form (`implements` / `version_suffix` / `external_id`) an item can carry. `&'a str` satisfies the bound via the existing `From<&'a str> for ComponentExternName<'a>`, so callers that only need a plain name write the same call as with `core_instantiate_exports`. Co-authored-by: Zachary Whitley <zachary.whitley@tegmentum.ai>
1 parent e248d28 commit 614c2ed

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

crates/wasm-encoder/src/component/builder.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,19 @@ impl ComponentBuilder {
482482
base
483483
}
484484

485+
/// Creates a new component instance from the `exports` provided.
486+
///
487+
/// Returns the index of the component instance created.
488+
pub fn instantiate_exports<'a, E, N>(&mut self, debug_name: Option<&str>, exports: E) -> u32
489+
where
490+
E: IntoIterator<Item = (N, ComponentExportKind, u32)>,
491+
E::IntoIter: ExactSizeIterator,
492+
N: Into<ComponentExternName<'a>>,
493+
{
494+
self.component_instances().export_items(exports);
495+
self.instances.add(debug_name)
496+
}
497+
485498
/// Declares a new `resource.drop` intrinsic.
486499
pub fn resource_drop(&mut self, ty: u32) -> u32 {
487500
self.canonical_functions().resource_drop(ty);

0 commit comments

Comments
 (0)