Skip to content

Make the cli's csharp feature actually turn csharp off - #1690

Closed
Lstarsky0 wants to merge 1 commit into
bytecodealliance:mainfrom
Lstarsky0:fix/csharp-optional-in-test
Closed

Make the cli's csharp feature actually turn csharp off#1690
Lstarsky0 wants to merge 1 commit into
bytecodealliance:mainfrom
Lstarsky0:fix/csharp-optional-in-test

Conversation

@Lstarsky0

Copy link
Copy Markdown
Contributor

wit-bindgen-csharp is optional = true in the cli, but the cli also depends on
wit-bindgen-test unconditionally, and that crate depended on wit-bindgen-csharp
outright. So the feature never actually removed anything:

$ cargo tree --no-default-features -i wit-bindgen-csharp
wit-bindgen-csharp v0.60.0 (crates/csharp)
├── wit-bindgen-cli v0.60.0 (.)
└── wit-bindgen-test v0.60.0 (crates/test)

After this it's out of the graph for --no-default-features and for any single
non-csharp language, and still in for the default build and for
--no-default-features --features csharp.

crates/test is the only test driver that links a bindgen crate — the others shell
out — and it does so for CSProject, to write the .csproj. So mod csharp and the
Language::Csharp variant go behind the same feature. With csharp off the harness
no longer knows the cs extension and falls through to the --custom lookup, which
says the extension is unknown. Happy to keep the variant always present and error at
run time instead if you'd rather.

Closes #1510

`wit-bindgen-csharp` is optional in the cli, but the cli depends on
`wit-bindgen-test` unconditionally and that crate had a hard dependency
on it, so the crate was always built no matter what features were
picked. Make it optional there too and forward the cli's feature.

`crates/test` is the only test driver that links a bindgen crate at all
-- it needs `CSProject` to write the .csproj -- so `mod csharp` and the
`Language::Csharp` variant go behind the same feature.
@alexcrichton

Copy link
Copy Markdown
Member

Thanks! I'm a bit hesitant to do this though because it's a pretty minor gain (removing a crate at compile time), and this otherwise makes the internal implementation of the test framework inconsistent where C# gets a cargo feature but nothing else does.

One thing that I'm not certain of, however, is the original motivations of #1510. Do you have your own motivations for fixing this issue? Or are you mostly looking to contribute and that seemed a good bug to fix?

@Lstarsky0

Copy link
Copy Markdown
Contributor Author

No motivation of my own here — I'm not a C# user and I don't build with --no-default-features. I was looking for issues I could verify end to end without a language toolchain, and this one fit.

I'd also narrow what I wrote in the description: the feature does still gate the csharp subcommand, it's only the build graph that's unaffected. So the gain is smaller than I made it sound, and I agree it isn't worth being the one place in the test framework with a cargo feature.

Closing. Leaving #1510 open in case someone shows up who actually wants the smaller build.

@Lstarsky0 Lstarsky0 closed this Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Csharp dep is marked as optional even when it's a hard dep of test

2 participants