Skip to content

Commit c8d030c

Browse files
committed
fix: recognize the synthetic wrapping component in codegen when compiling a pure Rust
program.
1 parent 3b11cc9 commit c8d030c

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

codegen/masm/src/lower/component.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,18 @@ impl ToMasmComponent for builtin::Component {
4545
let name = masm::ProcedureName::from_raw_parts(masm::Ident::from_raw_parts(
4646
Span::new(entry_id.function.span, entry_id.function.as_str().into()),
4747
));
48-
let path = LibraryPath::new(entry_id.module).into_diagnostic()?;
48+
49+
let path = if component_path.to_string() == "root_ns:[email protected]" {
50+
// We're inside the synthethic "wrapping" component for pure Rust program
51+
// compilation. Since the user does not know about it their entrypoint does not
52+
// include the synthetic component id. Append the user-provided entrypoint
53+
// module
54+
component_path.clone().append_unchecked(entry_id.module)
55+
} else {
56+
// We're compiling a Wasm component and the component id is included
57+
// in the entrypoint.
58+
LibraryPath::new(entry_id.module).into_diagnostic()?
59+
};
4960
Some(masm::InvocationTarget::AbsoluteProcedurePath { name, path })
5061
}
5162
None => None,

tests/integration/src/testing/setup.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ pub fn build_empty_component_for_test(context: Rc<Context>) -> LinkOutput {
8888
};
8989
let mut world_builder = WorldBuilder::new(world);
9090
let name = Ident::with_empty_span("root".into());
91+
let ns_name = Ident::with_empty_span("root_ns".into());
9192
let component = world_builder
92-
.define_component(name, name, Version::new(1, 0, 0))
93+
.define_component(ns_name, name, Version::new(1, 0, 0))
9394
.unwrap_or_else(|err| panic!("failed to define component:\n{}", format_report(err)));
9495

9596
let mut link_output = LinkOutput {

0 commit comments

Comments
 (0)