Skip to content

Make some lib projects platform-agnostic - #132218

Merged
jkotas merged 8 commits into
dotnet:mainfrom
am11:patch-59
Nov 12, 2026
Merged

jkotas merged 8 commits into
dotnet:mainfrom
am11:patch-59

Conversation

@am11

@am11 am11 commented Aug 12, 2026

Copy link
Copy Markdown
Member

No description provided.

@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Aug 12, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @karelz, @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it.

am11 added 5 commits October 25, 2026 12:30
linux, freebsd, openbsd and haiku compiled the identical OpenSSL code path; build them as a single unix flavor.
linux and freebsd compiled the same sources; platform differences are already handled at runtime in msquic.cs. Remove the unused SOCKADDR_HAS_LENGTH define and the FreeBSD Interop.Libraries.cs which only duplicated the MsQuic library name.
linux, freebsd and openbsd shared the inotify implementation; build it as a single unix flavor and keep osx/maccatalyst on FSEvents. Throw PlatformNotSupportedException when inotify is unavailable instead of a generic IOException.
Build the OpenLDAP implementation for unix instead of linux only.
Replace the linux, freebsd, openbsd, illumos, solaris and haiku flavors with a single unix flavor that selects the Linux or BSD implementation via OperatingSystem checks, which are JIT/trim time constants. NetworkChange.IsSupported becomes a partial property so the unix flavor can compute it.
@azure-pipelines

azure-pipelines Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 4 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@am11
am11 marked this pull request as ready for review October 25, 2026 14:05
@am11

am11 commented Oct 25, 2026

Copy link
Copy Markdown
Member Author

@jkotas, I've reworked it; published apps have no difference in size. There is a small 17.5 KB increase in shared framework size because in "library mode" we use ref assemblies and OperatingSystem.IsXx isn't trimmed.

@jkotas

jkotas commented Oct 26, 2026

Copy link
Copy Markdown
Member

There is a small 17.5 KB increase in shared framework size because in "library mode" we use ref assemblies and OperatingSystem.IsXx isn't trimmed.

17.5 kB is not prohibitive on its own. The challenge is that this approach doesn't scale. So far, we've preferred build-time checks to exclude OS-specific types rather than relying on runtime checks. If we were to start favoring runtime checks more broadly, the cumulative size increase will be much more significant. This PR moves us away from having consistent preference. How are we going to decide between build-time and runtime checks for OS-specific types going forward?

@am11

am11 commented Oct 26, 2026

Copy link
Copy Markdown
Member Author

If we were to start favoring runtime checks more broadly, the cumulative size increase will be much more significant.

I don't think this framing is accurate because we are using mixed bag of #if TARGET_FOO and if (OperatingSystem.IsFoo()) in libraries (in my estimation, we are using OS.IsFoo more these days). Secondly, we have only five non-corelib projects left using per unix-flavor TPM. After this PR, there will be one.

Also, trimming of OperatingSystem.IsXX in library mode is a illinker.targets fix, which levels the assembly size (I have it locally).

@jkotas

jkotas commented Oct 26, 2026

Copy link
Copy Markdown
Member

trimming of OperatingSystem.IsXX in library mode is a illinker.targets fix, which levels the assembly size (I have it locally).

Could you please submit this fix in a separate PR? This refactoring will be much easier to accept once there is no size regression.

@am11

am11 commented Nov 12, 2026

Copy link
Copy Markdown
Member Author

@jkotas, now that #136495 is merged, there are zero diffs in the shared framework size.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The resolver registration can conflict with an existing application resolver, causing static initialization to fail and breaking LDAP and BER operations; a composable fallback and regression test are needed.

No open issues 🎉

What changed in this PR

This PR consolidates several library projects onto shared Unix targets, reducing OS-specific build variants while retaining runtime platform selection and unsupported-platform behavior.

Changes:

  • Replace individual Unix targets with shared -unix targets in library and test projects.
  • Consolidate network-information dispatch and OpenLDAP implementation files.
  • Update native-library loading, unsupported-platform handling, and test exclusions.
File Description
src/​libraries/​tests.proj Clarifies the QUIC test-exclusion comment.
src/​libraries/​System.Net.Security/​src/​System.Net.Security.csproj Consolidates Unix build targets.
src/​libraries/​System.Net.Quic/​tests/​FunctionalTests/​System.Net.Quic.Functional.Tests.csproj Uses the shared Unix test target.
src/​libraries/​System.Net.Quic/​src/​System.Net.Quic.csproj Consolidates Unix sources and adds explicit unsupported Apple-mobile targets.
src/​libraries/​System.Net.NetworkInformation/​src/​System/​Net/​NetworkInformation/​NetworkInterfacePal.UnknownUnix.cs Removes the separate unsupported-platform implementation.
src/​libraries/​System.Net.NetworkInformation/​src/​System/​Net/​NetworkInformation/​NetworkInterfacePal.Unix.cs Selects Linux or BSD interfaces at runtime.
src/​libraries/​System.Net.NetworkInformation/​src/​System/​Net/​NetworkInformation/​NetworkAddressChange.Windows.cs Supplies Windows notification support status.
src/​libraries/​System.Net.NetworkInformation/​src/​System/​Net/​NetworkInformation/​NetworkAddressChange.UnknownUnix.cs Removes the separate unsupported notification implementation.
src/​libraries/​System.Net.NetworkInformation/​src/​System/​Net/​NetworkInformation/​NetworkAddressChange.Unix.cs Adds runtime support checks for notifications.
src/​libraries/​System.Net.NetworkInformation/​src/​System/​Net/​NetworkInformation/​NetworkAddressChange.OSX.cs Supplies Apple notification support status.
src/​libraries/​System.Net.NetworkInformation/​src/​System/​Net/​NetworkInformation/​NetworkAddressChange.cs Makes support status platform-implemented.
src/​libraries/​System.Net.NetworkInformation/​src/​System/​Net/​NetworkInformation/​NetworkAddressChange.Android.cs Supplies Android notification support status.
src/​libraries/​System.Net.NetworkInformation/​src/​System/​Net/​NetworkInformation/​IPGlobalPropertiesPal.Unix.cs Selects Linux or BSD global properties at runtime.
src/​libraries/​System.Net.NetworkInformation/​src/​System/​Net/​NetworkInformation/​IPGlobalPropertiesPal.Linux.cs Removes the Linux-only factory.
src/​libraries/​System.Net.NetworkInformation/​src/​System.Net.NetworkInformation.csproj Combines Linux and BSD implementations in the Unix target.
src/​libraries/​System.IO.FileSystem.Watcher/​tests/​System.IO.FileSystem.Watcher.Tests.csproj Consolidates Unix test targets and source selection.
src/​libraries/​System.IO.FileSystem.Watcher/​src/​System/​IO/​FileSystemWatcher.Linux.cs Maps unsupported inotify initialization to a platform exception.
src/​libraries/​System.IO.FileSystem.Watcher/​src/​System.IO.FileSystem.Watcher.csproj Consolidates Unix targets and preserves unsupported Apple-mobile variants.
src/​libraries/​System.DirectoryServices.Protocols/​tests/​System.DirectoryServices.Protocols.Tests.csproj Uses a Unix target and excludes Apple-mobile CI runs.
src/​libraries/​System.DirectoryServices.Protocols/​src/​System/​DirectoryServices/​Protocols/​ldap/​LdapSessionOptions.Unix.cs Provides session options under the Unix implementation name.
src/​libraries/​System.DirectoryServices.Protocols/​src/​System/​DirectoryServices/​Protocols/​ldap/​LdapConnection.Unix.cs Provides connection handling under the Unix implementation name.
src/​libraries/​System.DirectoryServices.Protocols/​src/​System/​DirectoryServices/​Protocols/​Interop/​SafeHandles.Unix.cs Provides Unix LDAP and BER handle management.
src/​libraries/​System.DirectoryServices.Protocols/​src/​System/​DirectoryServices/​Protocols/​Interop/​LdapPal.Unix.cs Provides the shared Unix LDAP abstraction.
src/​libraries/​System.DirectoryServices.Protocols/​src/​System/​DirectoryServices/​Protocols/​Interop/​BerPal.Unix.cs Provides the shared Unix BER abstraction.
src/​libraries/​System.DirectoryServices.Protocols/​src/​System/​DirectoryServices/​Protocols/​common/​QuotaControl.Unix.cs Provides Unix quota-control behavior.
src/​libraries/​System.DirectoryServices.Protocols/​src/​System/​DirectoryServices/​Protocols/​common/​BerConverter.Unix.cs Provides Unix bit-string decoding behavior.
src/​libraries/​System.DirectoryServices.Protocols/​src/​System.DirectoryServices.Protocols.csproj Selects shared Unix sources and unsupported Apple-mobile variants.
src/​libraries/​Common/​src/​Interop/​Unix/​OpenLdap/​Interop.Ldap.cs Centralizes the OpenLDAP import name and changes library resolution.
src/​libraries/​Common/​src/​Interop/​Unix/​OpenLdap/​Interop.Ber.cs Places BER interop in the shared Unix location.
src/​libraries/​Common/​src/​Interop/​OSX/​Interop.Libraries.cs Removes the platform-specific OpenLDAP constant.
src/​libraries/​Common/​src/​Interop/​Linux/​Interop.Libraries.cs Removes the platform-specific OpenLDAP constant.
src/​libraries/​Common/​src/​Interop/​FreeBSD/​Interop.Libraries.cs Removes the redundant FreeBSD MsQuic constant file.

Review effort: Balanced

@jkotas
jkotas merged commit e008d35 into dotnet:main Nov 12, 2026
87 checks passed
@am11
am11 deleted the patch-59 branch November 12, 2026 07:56
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Net community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants