Skip to content

Make some lib projects platform-agnostic - #132218

Open
am11 wants to merge 7 commits into
dotnet:mainfrom
am11:patch-59
Open

am11 wants to merge 7 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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This can be simplified further by using SetLibraryImportResolver

public static NetworkInterface[] GetAllNetworkInterfaces()
{
return LinuxNetworkInterface.GetLinuxNetworkInterfaces();
if (OperatingSystem.IsLinux())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@dotnet/ncl Do you have an opinion about merging some unix variants into same build, and replacing the build time checks with runtime checks?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What would be the argument for the chagne? My current hunch is to leave it as-is, but I will bring it up on for team discussion

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's the continuation of #129926.

@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.

This branch has not been deployed

No deployments
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.

3 participants