Skip to content

Commit af8b7cb

Browse files
committed
fix(csharp): embed component type via binary WIT package
Earlier attempt used `NativeFileReference` on the component-type object, but NativeAOT's LLVM pipeline did not propagate the custom section into the final module, leaving every C# component import unresolvable. Using a binary-encoded WIT package (which `wasm-component-ld --component-type` accepts alongside the text form) preserves the existing linker path and also lets map<K,V> round-trip since decoding skips the default WIT parser that rejects gated features. Signed-off-by: Yordis Prieto <[email protected]>
1 parent 1388017 commit af8b7cb

2 files changed

Lines changed: 3 additions & 15 deletions

File tree

crates/csharp/src/csproj.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl CSProjectLLVMBuilder {
9494
</ItemGroup>
9595
9696
<ItemGroup>
97-
<NativeFileReference Include=\"{camel}_component_type.o\" Condition=\"Exists('{camel}_component_type.o')\" />
97+
<CustomLinkerArg Include=\"-Wl,--component-type,{camel}_component_type.wasm\" />
9898
</ItemGroup>
9999
"
100100
);

crates/csharp/src/world_generator.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use std::fmt::Write;
99
use std::ops::Deref;
1010
use std::{iter, mem};
1111
use wit_bindgen_core::{Direction, Files, InterfaceGenerator as _, Types, WorldGenerator, uwrite};
12-
use wit_component::WitPrinter;
1312
use wit_parser::abi::WasmType;
1413
use wit_parser::{
1514
Function, InterfaceId, Resolve, SizeAlign, Type, TypeDefKind, TypeId, TypeOwner, WorldId,
@@ -839,20 +838,9 @@ impl WorldGenerator for CSharp {
839838
)?;
840839
let pkg = resolve.worlds[world].package.unwrap();
841840

842-
let mut printer = WitPrinter::default();
843-
printer.emit_docs(false);
844-
printer.print(
845-
&resolve,
846-
pkg,
847-
&resolve
848-
.packages
849-
.iter()
850-
.filter_map(|(id, _)| if id == pkg { None } else { Some(id) })
851-
.collect::<Vec<_>>(),
852-
)?;
853841
files.push(
854-
&format!("{world_namespace}_component_type.wit"),
855-
String::from(printer.output).as_bytes(),
842+
&format!("{world_namespace}_component_type.wasm"),
843+
wit_component::encode(&resolve, pkg)?.as_slice(),
856844
);
857845
}
858846

0 commit comments

Comments
 (0)