Skip to content

Commit

Permalink
c#: Ensure imports aren't duplicated across world fragments (#1106)
Browse files Browse the repository at this point in the history
Signed-off-by: James Sturtevant <[email protected]>
  • Loading branch information
jsturtevant authored Dec 17, 2024
1 parent 9c94446 commit f675254
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions crates/csharp/src/csproj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ impl CSProjectLLVMBuilder {
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<!-- treat these are errors so they are caught during code generation tests -->
<WarningsAsErrors>CS0105</WarningsAsErrors>
</PropertyGroup>
<PropertyGroup>
Expand Down Expand Up @@ -182,6 +184,8 @@ impl CSProjectMonoBuilder {
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<!-- treat these are errors so they are caught during code generation tests -->
<WarningsAsErrors>CS0105</WarningsAsErrors>
</PropertyGroup>
<PropertyGroup>
Expand Down
4 changes: 4 additions & 0 deletions crates/csharp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,10 +647,14 @@ impl WorldGenerator for CSharp {
.world_fragments
.iter()
.flat_map(|f| &f.interop_usings)
.into_iter()
.collect::<HashSet<&String>>() // de-dup across world_fragments
.iter()
.map(|s| "using ".to_owned() + s + ";")
.collect::<Vec<String>>()
.join("\n"),
);
src.push_str("\n");

src.push_str(&format!("{access} static class {name}World\n"));
src.push_str("{");
Expand Down
3 changes: 2 additions & 1 deletion tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ There are a few pre-requisites to testing the project. You only need the languag
- Rust - wasi target: `rustup target add wasm32-wasip1`
- Java - TeaVM-WASI `ci/download-teamvm.sh`
- C - [Clang](https://clang.llvm.org/)
- C# - [Dotnet 8](https://dotnet.microsoft.com/en-us/download/dotnet/8.0)
- C# - [Dotnet 9](https://dotnet.microsoft.com/en-us/download/dotnet/9.0)

There are two suites of tests: [codegen](#testing-wit-bindgen---codegen) and [runtime](#testing-wit-bindgen---runtime). To run all possible tests, across all supported languages, ensure the dependency above are installed then run:

Expand Down Expand Up @@ -52,6 +52,7 @@ Note that this directory can have whatever it wants since nothing implements the
interfaces or tries to call them.

It also contains git submodules for the wasi proposals like `wasi-http`.
Use `git submodule init` + `git submodule update` before running the tests.

The tests are generated by a macro `codegen_tests` in [crates/test-helpers](../crates/test-helpers/).

Expand Down
6 changes: 6 additions & 0 deletions tests/codegen/import_export_func.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package foo:foo;

world foo {
import foo: func();
export foo1: func();
}

0 comments on commit f675254

Please sign in to comment.