Skip to content

Cleanup | OS-independent build of non-SNI types#4207

Open
edwardneal wants to merge 7 commits intodotnet:mainfrom
edwardneal:target-single-platforms/02-leaf-types-and-appcontext-switches
Open

Cleanup | OS-independent build of non-SNI types#4207
edwardneal wants to merge 7 commits intodotnet:mainfrom
edwardneal:target-single-platforms/02-leaf-types-and-appcontext-switches

Conversation

@edwardneal
Copy link
Copy Markdown
Contributor

Description

This follows up #3844. Where the first PR laid the groundwork and performed OS-independent builds of the public types, this one handles the wider codebase.

I've moved through the dependencies in sequence:

  1. Enums and delegate types used by the native SNI
  2. Structs (which usually reference the enums/delegates from step 1)
  3. Windows-specific PInvokes (and the SafeHandle type which their declaration needs)

With the Interop.Windows.Kernel32 and Interop.Windows.Sni namespaces now available, more conditional compilations became unnecessary and could be cleared up.

When testing the IL trimming, I noticed that ILLink.Substitutions.xml had the wrong name in the shared project and that the value in LocalAppContextSwitches.UseManagedNetworking wasn't being substituted for a constant. This is fixed, and more conditional compilations disappeared.

Finally, I've performed a merge of the managed SNI's LocalDB integration. This is a useful stopping point - the remaining references to _WINDOWS and _UNIX past this will all need to be done at once because they depend upon ISniNativeMethods, SniNativeWrapper, SNIHandle or SNILoadHandle.

Issues

None.

Testing

Existing tests continue to pass, as expected.

Publishing a simple sample application, enabling trimming and checking with ILSpy and sizoscope confirms that these types are removed by the trimming process (once the resource had the correct name!)

@mdaigle
Copy link
Copy Markdown
Contributor

mdaigle commented Apr 20, 2026

/azp run

@mdaigle mdaigle added this to the 7.1.0-preview1 milestone Apr 20, 2026
@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 2 pipeline(s).

@benrr101 benrr101 self-assigned this Apr 21, 2026
Copy link
Copy Markdown
Contributor

@benrr101 benrr101 left a comment

Choose a reason for hiding this comment

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

I feel like this PR is missing a lot of the intended changes? Like, just unconditionally including all the files isn't going to do everything, right?

Eg, do the Microsoft.Win32.SafeHandles namespace exist when compiling for a non-windows runtime?

@github-project-automation github-project-automation Bot moved this from To triage to In progress in SqlClient Board Apr 21, 2026
@benrr101 benrr101 moved this from In progress to In review in SqlClient Board Apr 21, 2026
@edwardneal
Copy link
Copy Markdown
Contributor Author

It's not going to do everything, but it's not designed to. There are four steps:

  • Set up the basic OS-specific infrastructure and prove the principle (Cleanup | Preparation for OS-independent builds #3844)
  • Handle the simplest references to _WINDOWS and _UNIX, stopping at around 25-30 files (this PR)
  • Update the SNI layer, replacing the OS-specific compilation with runtime switches (next PR, another 20-30 files)
  • Deal with the build, pipelines and packaging

I've split them up because changing the non-SNI and the SNI types at the same time will lead to a PR which changes ~50 files and which also performs the logic changes needed for the runtime-level switching. I felt that'd be harder to review and more likely to generate merge conflicts, so we end up with this PR for the simple changes and a follow-up for the SNI layer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

4 participants