Skip to content

Add TreatWarningsAsErrors -> True for release builds, cleanup - #14

Merged
drasticactions merged 2 commits into
masterfrom
dev/timill/cleanup
Jul 1, 2026
Merged

drasticactions merged 2 commits into
masterfrom
dev/timill/cleanup

Conversation

@drasticactions

Copy link
Copy Markdown
Contributor

InteropGen would generate code that would result in hundreds of warnings in the test project. To prevent this, I enabled TreatWarningsAsErrors and fixed the resulting errors in generation and in the other projects. For the codebase, it's enabled for Release builds, so it should trigger tests if we regress it there, but it won't break local debug builds.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Enables stricter compilation by treating warnings as errors in Release builds, and updates InteropGen’s model/codegen to satisfy nullable/initialization analysis so generated code and projects don’t produce large warning counts.

Changes:

  • Added root Directory.Build.props to set TreatWarningsAsErrors=true for Release configuration.
  • Added an external/Directory.Build.props shim to prevent the root props from impacting external projects.
  • Updated InteropGen model/codegen to reduce nullable/initialization warnings and to correctly handle nullable handle returns for non-New functions.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/InteropGen/NativeModel.cs Marks key model properties as required to avoid uninitialized non-nullable property warnings.
src/InteropGen/Generator.cs Improves nullable annotations and fixes nullable handle-return codegen for non-New handle functions.
external/Directory.Build.props Prevents root build props from flowing into external projects.
Directory.Build.props Enables TreatWarningsAsErrors in Release builds.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/InteropGen/Generator.cs Outdated
Comment on lines +311 to +316
// New-suffixed factories return a SafeHandle from P/Invoke (compare to null);
// other handle-returning functions return a raw IntPtr (compare to IntPtr.Zero).
if (f.Name.EndsWith("New"))
gen.Line("if(ret == null) return null;");
else
gen.Line("if(ret == global::System.IntPtr.Zero) return null;");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running it locally, that code would break the generation because that logic doesn't hold for the code being passed in.

323df43
Updated here to make it clear for the future.

@drasticactions
drasticactions merged commit 2f1f2b4 into master Jul 1, 2026
2 checks passed
@drasticactions
drasticactions deleted the dev/timill/cleanup branch July 1, 2026 02:15
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.

2 participants