Skip to content

Commit 4ae0276

Browse files
authored
update C# generator to match latest ILC package (#1025)
This also locks the ILC dependencies to a specific version to avoid future surprises. Signed-off-by: Joel Dice <[email protected]>
1 parent 3f8e0fb commit 4ae0276

File tree

3 files changed

+6
-73
lines changed

3 files changed

+6
-73
lines changed

crates/csharp/src/csproj.rs

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -77,51 +77,27 @@ impl CSProjectLLVMBuilder {
7777
<PublishTrimmed>true</PublishTrimmed>
7878
<AssemblyName>{name}</AssemblyName>
7979
</PropertyGroup>
80+
8081
<ItemGroup>
81-
<NativeLibrary Include=\"{camel}_component_type.o\" />
82-
<NativeLibrary Include=\"$(MSBuildProjectDirectory)/{camel}_cabi_realloc.o\" />
82+
<RdXmlFile Include=\"rd.xml\" />
8383
</ItemGroup>
8484
8585
<ItemGroup>
86-
<RdXmlFile Include=\"rd.xml\" />
86+
<CustomLinkerArg Include=\"-Wl,--component-type,{camel}_component_type.wit\" />
8787
</ItemGroup>
8888
"
8989
);
9090

9191
if self.aot {
92-
//TODO: Is this handled by the source generator? (Temporary just to test with numbers and strings)
9392
csproj.push_str(
9493
r#"
9594
<ItemGroup>
96-
<CustomLinkerArg Include="-Wl,--export,_initialize" />
97-
<CustomLinkerArg Include="-Wl,--no-entry" />
98-
<CustomLinkerArg Include="-mexec-model=reactor" />
99-
</ItemGroup>
100-
101-
<ItemGroup>
102-
<PackageReference Include="Microsoft.DotNet.ILCompiler.LLVM" Version="9.0.0-*" />
103-
<PackageReference Include="runtime.win-x64.Microsoft.DotNet.ILCompiler.LLVM" Version="9.0.0-*" />
95+
<PackageReference Include="Microsoft.DotNet.ILCompiler.LLVM" Version="9.0.0-rc.1.24412.1" />
96+
<PackageReference Include="runtime.win-x64.Microsoft.DotNet.ILCompiler.LLVM" Version="9.0.0-rc.1.24412.1" />
10497
</ItemGroup>
105-
106-
<Target Name="CheckWasmSdks">
107-
<Error Text="Wasi SDK not found, not compiling to WebAssembly. To enable WebAssembly compilation, install Wasi SDK and ensure the WASI_SDK_PATH environment variable points to the directory containing share/wasi-sysroot"
108-
Condition="'$(WASI_SDK_PATH)' == ''" />
109-
<Warning Text="The WASI SDK version is too low. Please use WASI SDK 22 or newer with a 64 bit Clang."
110-
Condition="!Exists('$(WASI_SDK_PATH)/VERSION')" />
111-
</Target>
11298
"#,
11399
);
114100

115-
csproj.push_str(&format!("
116-
<Target Name=\"CompileCabiRealloc\" BeforeTargets=\"IlcCompile\" DependsOnTargets=\"CheckWasmSdks\"
117-
Inputs=\"$(MSBuildProjectDirectory)/{camel}_cabi_realloc.c\"
118-
Outputs=\"$(MSBuildProjectDirectory)/{camel}_cabi_realloc.o\"
119-
>
120-
<Exec Command=\"&quot;$(WASI_SDK_PATH)/bin/clang&quot; --target=wasm32-wasi &quot;$(MSBuildProjectDirectory)/{camel}_cabi_realloc.c&quot; -c -o &quot;$(MSBuildProjectDirectory)/{camel}_cabi_realloc.o&quot;\"/>
121-
</Target>
122-
"
123-
));
124-
125101
fs::write(
126102
self.dir.join("nuget.config"),
127103
r#"<?xml version="1.0" encoding="utf-8"?>

crates/csharp/src/lib.rs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -692,31 +692,6 @@ impl WorldGenerator for CSharp {
692692
}
693693

694694
if !self.opts.skip_support_files {
695-
let cabi_relloc_src = r#"
696-
#include <stdlib.h>
697-
698-
/* Done in C so we can avoid initializing the dotnet runtime and hence WASI libc */
699-
/* It would be preferable to do this in C# but the constraints of cabi_realloc and the demands */
700-
/* of WASI libc prevent us doing so. */
701-
/* See https://github.com/bytecodealliance/wit-bindgen/issues/777 */
702-
/* and https://github.com/WebAssembly/wasi-libc/issues/452 */
703-
/* The component model `start` function might be an alternative to this depending on whether it */
704-
/* has the same constraints as `cabi_realloc` */
705-
__attribute__((__weak__, __export_name__("cabi_realloc")))
706-
void *cabi_realloc(void *ptr, size_t old_size, size_t align, size_t new_size) {
707-
(void) old_size;
708-
if (new_size == 0) return (void*) align;
709-
void *ret = realloc(ptr, new_size);
710-
if (!ret) abort();
711-
return ret;
712-
}
713-
"#;
714-
715-
files.push(
716-
&format!("{name}World_cabi_realloc.c"),
717-
indent(cabi_relloc_src).as_bytes(),
718-
);
719-
720695
//TODO: This is currently needed for mono even if it's built as a library.
721696
if self.opts.runtime == CSharpRuntime::Mono {
722697
files.push(

tests/runtime/main.rs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -749,25 +749,7 @@ fn tests(name: &str, dir_name: &str) -> Result<Vec<PathBuf>> {
749749
panic!("failed to compile");
750750
}
751751

752-
// Translate the canonical ABI module into a component.
753-
754-
let module = fs::read(&wasm_filename).expect("failed to read wasm file");
755-
let component = ComponentEncoder::default()
756-
.module(module.as_slice())
757-
.expect("pull custom sections from module")
758-
.validate(true)
759-
.adapter("wasi_snapshot_preview1", &wasi_adapter)
760-
.expect("adapter failed to get loaded")
761-
.realloc_via_memory_grow(true)
762-
.encode()
763-
.expect(&format!(
764-
"module {:?} can be translated to a component",
765-
out_wasm
766-
));
767-
let component_path = out_wasm.with_extension("component.wasm");
768-
fs::write(&component_path, component).expect("write component to disk");
769-
770-
result.push(component_path);
752+
result.push(wasm_filename);
771753
}
772754
}
773755

0 commit comments

Comments
 (0)