-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use GeneratedDllImport in System.Console #52740
Use GeneratedDllImport in System.Console #52740
Conversation
@@ -14,7 +14,12 @@ internal static partial class Kernel32 | |||
|
|||
internal delegate bool ConsoleCtrlHandlerRoutine(int controlType); | |||
|
|||
#if DLLIMPORTGENERATOR_ENABLED |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Who is setting this define? I don't see it set anywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The DllImportGenerator package itself sets it:
https://github.com/dotnet/runtimelab/blob/feature/DllImportGenerator/DllImportGenerator/DllImportGenerator/Microsoft.Interop.DllImportGenerator.props#L20
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the DllImportGenerator going to be an "opt-in" feature? Or will it be built-in to a user's project by default when they target net6.0+
?
If it is the latter, then this define constant doesn't seem to add much value, since every net6.0+
project will get it by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current plan is for DllImportGenerator to be "opt-in" and for .NET 6.0 to be used internally only.
The point of the define is to enable a well-defined constant so we can provide a code fix that conditionally changes the code to use GeneratedDllImport when on .NET 6.0 and still use DllImport downlevel.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the moment, it is not going to be exposed to users for net6.0
at all. We are just targeting runtime right now, but it would be opt-in later.
The define is an attempt to make it easier for multi-targeting scenarios - like this file that also gets used for non-net6.0+
.
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_ReadStdin", SetLastError = true)] | ||
internal static extern unsafe int ReadStdin(byte* buffer, int bufferSize); | ||
[GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_ReadStdin", SetLastError = true)] | ||
internal static unsafe partial int ReadStdin(byte* buffer, int bufferSize); | ||
|
||
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_InitializeConsoleBeforeRead")] | ||
internal static extern void InitializeConsoleBeforeRead(byte minChars = 1, byte decisecondsTimeout = 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why aren't we using GeneratedDllImport
on InitializeConsoleBeforeRead
and UninitializeConsoleAfterRead
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only targeted the ones that had non-blittable types or had settings that would require runtime handling (SetLastError=true
for example), since the others would already be inline-able.
f7a9d35
to
74dc0e2
Compare
cc @AaronRobinsonMSFT @jkoritzinsky