Skip to content

Commit f675254

Browse files
authored
c#: Ensure imports aren't duplicated across world fragments (#1106)
Signed-off-by: James Sturtevant <jsturtevant@gmail.com>
1 parent 9c94446 commit f675254

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

crates/csharp/src/csproj.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ impl CSProjectLLVMBuilder {
7171
<ImplicitUsings>enable</ImplicitUsings>
7272
<Nullable>enable</Nullable>
7373
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
74+
<!-- treat these are errors so they are caught during code generation tests -->
75+
<WarningsAsErrors>CS0105</WarningsAsErrors>
7476
</PropertyGroup>
7577
7678
<PropertyGroup>
@@ -182,6 +184,8 @@ impl CSProjectMonoBuilder {
182184
<ImplicitUsings>enable</ImplicitUsings>
183185
<Nullable>enable</Nullable>
184186
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
187+
<!-- treat these are errors so they are caught during code generation tests -->
188+
<WarningsAsErrors>CS0105</WarningsAsErrors>
185189
</PropertyGroup>
186190
187191
<PropertyGroup>

crates/csharp/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,10 +647,14 @@ impl WorldGenerator for CSharp {
647647
.world_fragments
648648
.iter()
649649
.flat_map(|f| &f.interop_usings)
650+
.into_iter()
651+
.collect::<HashSet<&String>>() // de-dup across world_fragments
652+
.iter()
650653
.map(|s| "using ".to_owned() + s + ";")
651654
.collect::<Vec<String>>()
652655
.join("\n"),
653656
);
657+
src.push_str("\n");
654658

655659
src.push_str(&format!("{access} static class {name}World\n"));
656660
src.push_str("{");

tests/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ There are a few pre-requisites to testing the project. You only need the languag
1111
- Rust - wasi target: `rustup target add wasm32-wasip1`
1212
- Java - TeaVM-WASI `ci/download-teamvm.sh`
1313
- C - [Clang](https://clang.llvm.org/)
14-
- C# - [Dotnet 8](https://dotnet.microsoft.com/en-us/download/dotnet/8.0)
14+
- C# - [Dotnet 9](https://dotnet.microsoft.com/en-us/download/dotnet/9.0)
1515

1616
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:
1717

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

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

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

tests/codegen/import_export_func.wit

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package foo:foo;
2+
3+
world foo {
4+
import foo: func();
5+
export foo1: func();
6+
}

0 commit comments

Comments
 (0)