diff --git a/Cargo.toml b/Cargo.toml
index d0074e2a1..265263f10 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -81,7 +81,7 @@ markdown = ['dep:wit-bindgen-markdown']
teavm-java = ['dep:wit-bindgen-teavm-java']
go = ['dep:wit-bindgen-go']
csharp = ['dep:wit-bindgen-csharp']
-csharp-mono = ['csharp']
+csharp-mono = ['dep:wit-bindgen-csharp']
moonbit = ['dep:wit-bindgen-moonbit']
[dev-dependencies]
diff --git a/crates/csharp/src/csproj.rs b/crates/csharp/src/csproj.rs
index 626e89df2..1589b44c5 100644
--- a/crates/csharp/src/csproj.rs
+++ b/crates/csharp/src/csproj.rs
@@ -109,6 +109,7 @@ impl CSProjectLLVMBuilder {
+
@@ -161,23 +162,20 @@ impl CSProjectMonoBuilder {
let camel = format!("{}World", world.to_upper_camel_case());
let aot = self.aot;
-
- let maybe_aot = match aot {
- true => format!("{aot}"),
- false => String::new(),
- };
+ let tfm = "net9.0";
let mut csproj = format!(
- "
+ "
- net9.0
+ {tfm}
wasi-wasm
Library
- {maybe_aot}
{aot}
false
true
+ true
+ true
{name}
enable
enable
@@ -190,9 +188,14 @@ impl CSProjectMonoBuilder {
-
+ <_WasiLinkStepArgs Include=\"-Wl,--component-type,{camel}_component_type.wit\" />
+
+
+
+
+
"
);
diff --git a/crates/csharp/src/lib.rs b/crates/csharp/src/lib.rs
index e4d574d3b..c48d448b2 100644
--- a/crates/csharp/src/lib.rs
+++ b/crates/csharp/src/lib.rs
@@ -690,22 +690,6 @@ impl WorldGenerator for CSharp {
}
if !self.opts.skip_support_files {
- //TODO: This is currently needed for mono even if it's built as a library.
- if self.opts.runtime == CSharpRuntime::Mono {
- files.push(
- &format!("MonoEntrypoint.cs",),
- indent(&format!(
- r#"
- {access} class MonoEntrypoint() {{
- {access} static void Main() {{
- }}
- }}
- "#
- ))
- .as_bytes(),
- );
- }
-
// For the time being, we generate both a .wit file and a .o file to
// represent the component type. Newer releases of the .NET runtime
// will be able to use the former, but older ones will need the
diff --git a/tests/runtime/main.rs b/tests/runtime/main.rs
index 0b3ae64f3..678c6ebe2 100644
--- a/tests/runtime/main.rs
+++ b/tests/runtime/main.rs
@@ -502,7 +502,7 @@ fn tests(name: &str, dir_name: &str) -> Result> {
let (resolve, world) = resolve_wit_dir(&dir);
for path in c_sharp.iter() {
let world_name = &resolve.worlds[world].name;
- let out_dir = out_dir.join(format!("csharp-{}", world_name));
+ let out_dir = out_dir.join(format!("csharp-mono-{}", world_name));
drop(fs::remove_dir_all(&out_dir));
fs::create_dir_all(&out_dir).unwrap();
@@ -540,7 +540,7 @@ fn tests(name: &str, dir_name: &str) -> Result> {
fs::write(dst, contents).unwrap();
}
- let mut csproj = wit_bindgen_csharp::CSProject::new_mono(
+ let csproj = wit_bindgen_csharp::CSProject::new_mono(
out_dir.clone(),
&assembly_name,
world_name,
@@ -553,6 +553,7 @@ fn tests(name: &str, dir_name: &str) -> Result> {
csproj.generate()?;
let dotnet_root_env = "DOTNET_ROOT";
+ let configuration = "Debug";
let dotnet_cmd: PathBuf;
match env::var(dotnet_root_env) {
Ok(val) => dotnet_cmd = Path::new(&val).join("dotnet"),
@@ -563,10 +564,10 @@ fn tests(name: &str, dir_name: &str) -> Result> {
cmd.current_dir(&out_dir);
- cmd.arg("build")
+ cmd.arg("publish")
.arg(out_dir.join(format!("{camel}.csproj")))
.arg("-c")
- .arg("Debug")
+ .arg(configuration)
.arg("/p:PlatformTarget=AnyCPU")
.arg("--self-contained")
.arg("-o")
@@ -586,75 +587,16 @@ fn tests(name: &str, dir_name: &str) -> Result> {
panic!("failed to compile");
}
- let out_wasm = out_wasm.join("AppBundle").join(assembly_name);
+ let out_wasm = out_dir
+ .join("bin")
+ .join(configuration)
+ .join("net9.0")
+ .join("AppBundle")
+ .join(assembly_name);
let mut wasm_filename = out_wasm.clone();
wasm_filename.set_extension("wasm");
- let module = fs::read(&wasm_filename).with_context(|| {
- format!("failed to read wasm file: {}", wasm_filename.display())
- })?;
-
- // Translate the canonical ABI module into a component.
- let component_type_filename = out_dir.join(format!("{camel}_component_type.o"));
- let component_type = fs::read(&component_type_filename).with_context(|| {
- format!(
- "failed to read component type file: {}",
- component_type_filename.display()
- )
- })?;
-
- let mut new_module = wasm_encoder::Module::new();
-
- for payload in wasmparser::Parser::new(0).parse_all(&module) {
- let payload = payload.unwrap();
- match payload {
- _ => {
- if let Some((id, range)) = payload.as_section() {
- new_module.section(&wasm_encoder::RawSection {
- id,
- data: &module[range],
- });
- }
- }
- }
- }
-
- for payload in wasmparser::Parser::new(0).parse_all(&component_type) {
- let payload = payload.unwrap();
- match payload {
- wasmparser::Payload::CustomSection(_) => {
- if let Some((id, range)) = payload.as_section() {
- new_module.section(&wasm_encoder::RawSection {
- id,
- data: &component_type[range],
- });
- }
- }
- _ => {
- continue;
- }
- }
- }
-
- let module = new_module.finish();
-
- let component = ComponentEncoder::default()
- .module(&module)
- .expect("pull custom sections from module")
- .validate(true)
- .adapter("wasi_snapshot_preview1", &wasi_adapter)
- .expect("adapter failed to get loaded")
- .realloc_via_memory_grow(true)
- .encode()
- .expect(&format!(
- "module {:?} can be translated to a component",
- out_wasm
- ));
- let component_path = out_wasm.with_extension("component.wasm");
- println!("COMPONENT WASM File name: {}", component_path.display());
- fs::write(&component_path, component).expect("write component to disk");
-
- result.push(component_path);
+ result.push(wasm_filename);
}
}