-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Add PlatformNeutralAssembly property for targeted builds of cross platform assembly #53626
Conversation
I tried this change locally and unfortunately it doesn't work as expected. I commented out the check for "not android" in here: Making it look like: [SupportedOSPlatformGuard("linux")]
[SupportedOSPlatformGuard("macOS")]
[SupportedOSPlatformGuard("Windows")]
internal static bool IsHttp3Supported() => OperatingSystem.IsLinux() || OperatingSystem.IsWindows() || OperatingSystem.IsMacOS(); And the build didn't produce any warnings/errors for Android. And obviously the resulted dll contains the calls into the guarded methods. I also noticed that the dll still contains this: [assembly: TargetPlatform("Android1.0")]
[assembly: SupportedOSPlatform("Android")] Which I think plays some role in making this work. I did fresh rebuild on @buyaa-n branch ( |
I am not that sure what you exactly did, but the value/expression returned from the method has no effect, only think matters is the guard attributes. Now no matter if you have or not For windows removing
Yes the dll would still have those, we did not change anything in the assembly attribute
I don't think so |
I think that I now understand the limitations here, although I still think that they are unfortunate. It seems like What I'd love to see here is something like this: // No `SupportedOSPlatformGuard` attribute.
internal static bool IsHttp3Supported() => (OperatingSystem.IsLinux() && !OperatingSystem.IsAndroid()) || OperatingSystem.IsWindows() || OperatingSystem.IsMacOS();
...
// Code guarded with IsHttp3Supported
if (IsHttp3Supported())
{
_http3Enabled = _poolManager.Settings._maxHttpVersion >= HttpVersion.Version30 && (_poolManager.Settings._quicImplementationProvider ?? QuicImplementationProviders.Default).IsSupported;
} Basically have |
Yes, guard attributes have no connection to runtime/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/SocketsHttpHandler.cs Lines 45 to 46 in 0d7c498
It is static analysis, should/could not depend and on runtime value, for your example, it is clear that the expression could be used as a guard, but that is not true for all cases |
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.
LGTM, thanks!
Fixes dotnet/roslyn-analyzers#5023
When cross-platform assembly having targeted builds for specific platforms MSBuild would add an assembly-level attribute for that target which disables the API annotations inside the assembly by the "child APIs should not extend parent platform support" rule. Even though it is an expected scenario by design it is unfortunate to not get any warning about this inconsistency or possible reference of incompatible APIs within the same assembly
For getting warnings in targeted builds in cross-platform assembly we need some way to distinguish between real platform-specific assembly and cross-platform assembly with platform-specific builds. For that, I used MSBuild
PlatformNeutralAssembly
property which we are adding into targeted builds of cross-platform assembly with this PR and updating the analyzer version which supports this property