Use LibraryImport instead of DllImport for proper AOT support#323
Merged
Use LibraryImport instead of DllImport for proper AOT support#323
LibraryImport instead of DllImport for proper AOT support#323Conversation
Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com> Agent-Logs-Url: https://github.com/Tyrrrz/CliWrap/sessions/0a4cf4ec-51aa-4428-a618-2e8fd6115de8
Copilot created this pull request from a session on behalf of
Tyrrrz
March 20, 2026 19:56
View session
Tyrrrz
reviewed
Mar 20, 2026
…nsafeBlocks Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com> Agent-Logs-Url: https://github.com/Tyrrrz/CliWrap/sessions/be98739b-de00-4db6-89eb-a67dee97b267
…s due to runtime API requirements Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com> Agent-Logs-Url: https://github.com/Tyrrrz/CliWrap/sessions/9cf901e2-f7e6-4cc2-98a2-9aba5902746b
Tyrrrz
approved these changes
Mar 20, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates CliWrap’s Unix P/Invoke for kill to use LibraryImport on .NET 7+ to improve trimmer/AOT compatibility while retaining DllImport for older target frameworks.
Changes:
- Switched
NativeMethods.Unix.Killto[LibraryImport]forNET7_0_OR_GREATER, keeping[DllImport]for older TFMs via conditional compilation. - Marked
NativeMethods/NativeMethods.Unixaspartialto support source-generated P/Invoke stubs. - Enabled
AllowUnsafeBlocksinCliWrap.csproj(needed by theLibraryImportgenerator output).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| CliWrap/Utils/NativeMethods.cs | Uses LibraryImport for kill on .NET 7+ and keeps DllImport for older frameworks; updates types to partial for source generation. |
| CliWrap/CliWrap.csproj | Enables unsafe blocks to allow compilation of LibraryImport-generated stubs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## prime #323 +/- ##
==========================================
+ Coverage 94.48% 94.73% +0.24%
==========================================
Files 45 45
Lines 1215 1215
Branches 89 87 -2
==========================================
+ Hits 1148 1151 +3
Misses 42 42
+ Partials 25 22 -3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This was referenced Mar 23, 2026
This was referenced Mar 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DllImportis not AOT-compatible;LibraryImport(introduced in .NET 7) uses a source generator to emit the P/Invoke stub at compile time, making it trimmer- and AOT-safe.LibraryImportcannot be used on older targets even with polyfills, because the source generator (while SDK-provided and TFM-agnostic) does not emit an implementation for pre-.NET 7 targets — the generated P/Invoke stub relies on runtime APIs introduced in .NET 7.Changes
CliWrap/Utils/NativeMethods.cs— MadeNativeMethodsandUnixclassespartial; switchedKillto[LibraryImport]onnet7.0+, keeping[DllImport]for older targets via conditional compilation, with a comment explaining why the source generator doesn't help on older targets:CliWrap/CliWrap.csproj— Added<AllowUnsafeBlocks>true</AllowUnsafeBlocks>unconditionally (required by theLibraryImportsource generator onnet7.0+; harmless on older targets).CliWrap.Signaler/Utils/NativeMethods.cs— Left unchanged; the Signaler project targetsnet35whereLibraryImportis unavailable.⚡ Quickly spin up Copilot coding agent tasks from anywhere on your macOS or Windows machine with Raycast.