From d6da02a2150fddb86137a68fc7fd7a2fa2281dc5 Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Wed, 29 May 2024 17:16:07 -0500 Subject: [PATCH 1/9] Fix the mono runtime test config --- tests/runtime/main.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/runtime/main.rs b/tests/runtime/main.rs index 0b3ae64f3..99afeda88 100644 --- a/tests/runtime/main.rs +++ b/tests/runtime/main.rs @@ -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, @@ -563,7 +563,7 @@ 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") @@ -586,7 +586,7 @@ 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_wasm.join(assembly_name); let mut wasm_filename = out_wasm.clone(); wasm_filename.set_extension("wasm"); From dbab74321620cc12c615c7e1d4ec4f836d8bd781 Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Tue, 9 Jul 2024 10:17:50 -0500 Subject: [PATCH 2/9] Some of this will get removed again --- crates/csharp/src/csproj.rs | 13 +++++++++++-- tests/runtime/main.rs | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/crates/csharp/src/csproj.rs b/crates/csharp/src/csproj.rs index 626e89df2..1b86f3ce3 100644 --- a/crates/csharp/src/csproj.rs +++ b/crates/csharp/src/csproj.rs @@ -71,6 +71,8 @@ impl CSProjectLLVMBuilder { enable enable true + wasi-wasm + Library @@ -109,6 +111,7 @@ impl CSProjectLLVMBuilder { + @@ -168,7 +171,7 @@ impl CSProjectMonoBuilder { }; let mut csproj = format!( - " + " net9.0 @@ -182,6 +185,7 @@ impl CSProjectMonoBuilder { enable enable true + true @@ -190,9 +194,14 @@ impl CSProjectMonoBuilder { - + + + + + + " ); diff --git a/tests/runtime/main.rs b/tests/runtime/main.rs index 99afeda88..bd4f38776 100644 --- a/tests/runtime/main.rs +++ b/tests/runtime/main.rs @@ -586,7 +586,7 @@ fn tests(name: &str, dir_name: &str) -> Result> { panic!("failed to compile"); } - let out_wasm = out_wasm.join(assembly_name); + //let out_wasm = out_wasm.join(assembly_name); let mut wasm_filename = out_wasm.clone(); wasm_filename.set_extension("wasm"); From 43ca36b1f4f74e2ac2cbd356187ecbb5363efc9f Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Tue, 9 Jul 2024 11:10:25 -0500 Subject: [PATCH 3/9] Link in the realloc stub --- crates/csharp/src/csproj.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/csharp/src/csproj.rs b/crates/csharp/src/csproj.rs index 1b86f3ce3..48834d192 100644 --- a/crates/csharp/src/csproj.rs +++ b/crates/csharp/src/csproj.rs @@ -194,7 +194,7 @@ impl CSProjectMonoBuilder { - + From 1b1d54994ab23fdc1ddaceec5049fec6c3466184 Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Fri, 30 Aug 2024 11:48:20 -0500 Subject: [PATCH 4/9] Tweak the output path again and attempt to resolve the component linking --- crates/csharp/src/csproj.rs | 6 +++++- tests/runtime/main.rs | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/csharp/src/csproj.rs b/crates/csharp/src/csproj.rs index 48834d192..a34470dc3 100644 --- a/crates/csharp/src/csproj.rs +++ b/crates/csharp/src/csproj.rs @@ -186,6 +186,7 @@ impl CSProjectMonoBuilder { enable true true + true @@ -194,7 +195,10 @@ impl CSProjectMonoBuilder { - + <_WasiLinkStepArgs Include=\"-Wl,--component-type,{camel}_component_type.wit\" /> + diff --git a/tests/runtime/main.rs b/tests/runtime/main.rs index bd4f38776..3be54a8b0 100644 --- a/tests/runtime/main.rs +++ b/tests/runtime/main.rs @@ -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"), @@ -566,7 +567,7 @@ fn tests(name: &str, dir_name: &str) -> Result> { 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,7 +587,7 @@ fn tests(name: &str, dir_name: &str) -> Result> { panic!("failed to compile"); } - //let out_wasm = out_wasm.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"); From 631156d99184ef2056d7a3a4a3e7b48f4d0e3caa Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Fri, 30 Aug 2024 12:01:21 -0500 Subject: [PATCH 5/9] Remove the code causing the problem --- tests/runtime/main.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/tests/runtime/main.rs b/tests/runtime/main.rs index 3be54a8b0..5cc853ece 100644 --- a/tests/runtime/main.rs +++ b/tests/runtime/main.rs @@ -587,7 +587,11 @@ fn tests(name: &str, dir_name: &str) -> Result> { panic!("failed to compile"); } - let out_wasm = out_dir.join("bin").join(configuration).join("net9.0").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"); @@ -595,15 +599,6 @@ fn tests(name: &str, dir_name: &str) -> Result> { 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) { From 902e7924a4a50599aeb2f5f6b67c7660a350b0e4 Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Fri, 30 Aug 2024 12:13:06 -0500 Subject: [PATCH 6/9] Small fixes --- crates/csharp/src/csproj.rs | 3 -- tests/runtime/main.rs | 59 ++----------------------------------- 2 files changed, 3 insertions(+), 59 deletions(-) diff --git a/crates/csharp/src/csproj.rs b/crates/csharp/src/csproj.rs index a34470dc3..0fef4dd8a 100644 --- a/crates/csharp/src/csproj.rs +++ b/crates/csharp/src/csproj.rs @@ -196,9 +196,6 @@ impl CSProjectMonoBuilder { <_WasiLinkStepArgs Include=\"-Wl,--component-type,{camel}_component_type.wit\" /> - diff --git a/tests/runtime/main.rs b/tests/runtime/main.rs index 5cc853ece..040132e17 100644 --- a/tests/runtime/main.rs +++ b/tests/runtime/main.rs @@ -587,7 +587,8 @@ fn tests(name: &str, dir_name: &str) -> Result> { panic!("failed to compile"); } - let out_wasm = out_dir.join("bin") + let out_wasm = out_dir + .join("bin") .join(configuration) .join("net9.0") .join("AppBundle") @@ -595,62 +596,8 @@ fn tests(name: &str, dir_name: &str) -> Result> { 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()) - })?; - - 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); } } From 60295c532cb802b6d0c024eb36e34a0398d58363 Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Fri, 30 Aug 2024 15:18:24 -0500 Subject: [PATCH 7/9] don't enable csharp when csharp-mono is enabled and make them write to different places --- Cargo.toml | 2 +- tests/runtime/main.rs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) 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/tests/runtime/main.rs b/tests/runtime/main.rs index 040132e17..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(); @@ -596,7 +596,6 @@ fn tests(name: &str, dir_name: &str) -> Result> { let mut wasm_filename = out_wasm.clone(); wasm_filename.set_extension("wasm"); - result.push(wasm_filename); } } From 22bbc5884ddd136a4ab59cc25abd1e7724ac71dc Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Fri, 30 Aug 2024 16:03:20 -0500 Subject: [PATCH 8/9] Remove some unrelated changes --- crates/csharp/src/csproj.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/crates/csharp/src/csproj.rs b/crates/csharp/src/csproj.rs index 0fef4dd8a..093dd94d0 100644 --- a/crates/csharp/src/csproj.rs +++ b/crates/csharp/src/csproj.rs @@ -71,8 +71,6 @@ impl CSProjectLLVMBuilder { enable enable true - wasi-wasm - Library @@ -164,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 From 08ae2d85a8ff6033ee2abb1e6f2f8eb9aee325d6 Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Fri, 30 Aug 2024 17:13:47 -0500 Subject: [PATCH 9/9] More cleanup --- crates/csharp/src/csproj.rs | 2 -- crates/csharp/src/lib.rs | 16 ---------------- 2 files changed, 18 deletions(-) diff --git a/crates/csharp/src/csproj.rs b/crates/csharp/src/csproj.rs index 093dd94d0..1589b44c5 100644 --- a/crates/csharp/src/csproj.rs +++ b/crates/csharp/src/csproj.rs @@ -180,8 +180,6 @@ impl CSProjectMonoBuilder { enable enable true - true - true 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