Skip to content

Commit 6541e44

Browse files
authored
Support C# in wit-bindgen test (#1207)
* Support C# in `wit-bindgen test` Migrate various bits of logic to the new test runner. All codegen tests are migrated and a single "demo" program is available to show the runtime test at least somewhat works. Migrating more tests is left to future work. * Add runner support for C#
1 parent 570f52f commit 6541e44

File tree

10 files changed

+198
-190
lines changed

10 files changed

+198
-190
lines changed

Diff for: .github/workflows/main.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,23 @@ jobs:
9898
shell: powershell
9999
if: matrix.os == 'windows-latest' && matrix.lang == 'moonbit'
100100
101+
# Run (now legacy) crate tests. This'll eventually go away
101102
- run: |
102103
cargo test \
103104
-p wit-bindgen-cli \
104105
-p wit-bindgen-${{ matrix.lang }} \
105106
--no-default-features \
106107
--features ${{ matrix.lang }} \
107108
--release
109+
110+
# Run all codegen tests for this language
108111
- run: |
109-
cargo run test --languages rust,${{ matrix.lang }} tests/codegen \
112+
cargo run test --languages ${{ matrix.lang }} tests/codegen \
110113
--artifacts target/artifacts \
111114
--rust-wit-bindgen-path ./crates/guest-rust
115+
116+
# Run all runtime tests for this language, and also enable Rust in case this
117+
# language only implements either the runner or test component
112118
- run: |
113119
cargo run test --languages rust,${{ matrix.lang }} tests/runtime-new \
114120
--artifacts target/artifacts \

Diff for: Cargo.lock

+1-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: crates/csharp/Cargo.toml

-5
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ clap = { workspace = true, optional = true }
2525
anyhow = { workspace = true }
2626
indexmap = { workspace = true }
2727

28-
[dev-dependencies]
29-
test-helpers = { path = '../test-helpers' }
30-
wasm-encoder = { workspace = true }
31-
wasmparser = { workspace = true }
32-
3328
[features]
3429
default = ["aot"]
3530
aot = []

Diff for: crates/csharp/src/csproj.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub struct CSProjectLLVMBuilder {
1111
aot: bool,
1212
clean_targets: bool,
1313
world_name: String,
14+
binary: bool,
1415
}
1516

1617
pub struct CSProjectMonoBuilder {
@@ -29,6 +30,7 @@ impl CSProject {
2930
aot: false,
3031
clean_targets: false,
3132
world_name: world_name.to_string(),
33+
binary: false,
3234
}
3335
}
3436

@@ -61,9 +63,15 @@ impl CSProjectLLVMBuilder {
6163
),
6264
)?;
6365

66+
let output_type = if self.binary {
67+
"<OutputType>Exe</OutputType>"
68+
} else {
69+
"<OutputType>Library</OutputType>"
70+
};
71+
6472
let mut csproj = format!(
6573
"<Project Sdk=\"Microsoft.NET.Sdk\">
66-
74+
6775
<PropertyGroup>
6876
<TargetFramework>net9.0</TargetFramework>
6977
<LangVersion>preview</LangVersion>
@@ -73,8 +81,9 @@ impl CSProjectLLVMBuilder {
7381
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
7482
<!-- treat these are errors so they are caught during code generation tests -->
7583
<WarningsAsErrors>CS0105</WarningsAsErrors>
84+
{output_type}
7685
</PropertyGroup>
77-
86+
7887
<PropertyGroup>
7988
<PublishTrimmed>true</PublishTrimmed>
8089
<AssemblyName>{name}</AssemblyName>
@@ -156,6 +165,10 @@ impl CSProjectLLVMBuilder {
156165
self.aot = true;
157166
}
158167

168+
pub fn binary(&mut self) {
169+
self.binary = true;
170+
}
171+
159172
pub fn clean(&mut self) -> &mut Self {
160173
self.clean_targets = true;
161174

@@ -178,7 +191,7 @@ impl CSProjectMonoBuilder {
178191

179192
let mut csproj = format!(
180193
"<Project Sdk=\"Microsoft.NET.Sdk\">
181-
194+
182195
<PropertyGroup>
183196
<TargetFramework>net9.0</TargetFramework>
184197
<RuntimeIdentifier>wasi-wasm</RuntimeIdentifier>
@@ -194,7 +207,7 @@ impl CSProjectMonoBuilder {
194207
<!-- treat these are errors so they are caught during code generation tests -->
195208
<WarningsAsErrors>CS0105</WarningsAsErrors>
196209
</PropertyGroup>
197-
210+
198211
<PropertyGroup>
199212
<PublishTrimmed>true</PublishTrimmed>
200213
<AssemblyName>{name}</AssemblyName>

Diff for: crates/csharp/tests/codegen.rs

-174
This file was deleted.

Diff for: crates/test/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ wasmparser = { workspace = true, features = ["features"] }
3030
wat = { workspace = true }
3131
wit-component = { workspace = true }
3232
wit-parser = { workspace = true }
33+
wit-bindgen-csharp = { workspace = true }

0 commit comments

Comments
 (0)