Skip to content

Cleanup | Preparation for OS-independent builds#3844

Merged
mdaigle merged 8 commits intodotnet:mainfrom
edwardneal:target-single-platform/01-infrastructure-and-public-apis
Apr 16, 2026
Merged

Cleanup | Preparation for OS-independent builds#3844
mdaigle merged 8 commits intodotnet:mainfrom
edwardneal:target-single-platform/01-infrastructure-and-public-apis

Conversation

@edwardneal
Copy link
Copy Markdown
Contributor

Description

This PR lays the groundwork to enable a single build of SqlClient to work for both Windows and non-Windows platforms. It also tests the water on the approach.

#3810 helped the shared SqlClient project to build by using the _WINDOWS and _UNIX conditional compilation symbols; this enables the merge to proceed, but we can move these checks to run-time and make the build process simpler.

I've started this process with a simple IsWindows member in ADP, and using this to throw PlatformNotSupportedExceptions in the three Windows-specific public types: SqlColumnEncryptionCngProvider, SqlColumnEncryptionCspProvider and SqlFileStream. As a result of this, the Unix-specific files are no longer necessary and we can remove them.

SqlFileStream makes a handful of pinvokes, and as a result I've removed the _WINDOWS guard on these pinvokes and their associated types to enable the project to compile. I expect that eventually, this'll happen to the entirety of the interop layer.

I've put some focus here on IL trimming, making sure that publishing for Unix will strip away the Windows interop layer. This procedure seems a little limited: I can't use my preferred approach of using a throw helper, because the trimmer can't see that the method throws, so keeps the code paths which use the Windows interop layer around.

@benrr101 @paulmedynski this intersects with the conversations around TargetOs going on in #3837.

Issues

None.

Testing

While SqlFileStream doesn't have any unit tests to verify that it throws a PNSE on Unix, SqlColumnEncryptionCngProvider and SqlColumnEncryptionCspProvider do. These pass.

I also created a sample application which instantiates a SqlFileStream, then published this using a Linux target with trimming enabled and viewed the result in ILSpy. Every code path except for the one which throws PlatformNotSupportedException was removed, and this led to the Windows interop layer also being removed.

Also clean up the netfx-only s_isWindowsNT variable - this was originally used to distinguish between Windows 9x and Windows NT!
We only throw a PlatformNotSupportedException in the constructor; if this throws, there's no way execution can reach a property or method.
This is necessary because when an application using SqlClient is being published, the IL trimmer doesn't see that the throw helper throws an exception, and thus doesn't eliminate the code paths which call Windows-specific APIs. As a result, the Windows-specific API paths aren't removed from executables published for a Linux platform.
@edwardneal edwardneal requested a review from a team as a code owner December 13, 2025 00:17
@github-project-automation github-project-automation Bot moved this to To triage in SqlClient Board Dec 13, 2025
@paulmedynski paulmedynski self-assigned this Dec 15, 2025
Copy link
Copy Markdown
Contributor

@paulmedynski paulmedynski left a comment

Choose a reason for hiding this comment

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

Looks good to me, with a couple of comments.

Comment thread src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/AdapterUtil.cs Outdated
@github-project-automation github-project-automation Bot moved this from To triage to In progress in SqlClient Board Dec 15, 2025
paulmedynski
paulmedynski previously approved these changes Dec 15, 2025
@paulmedynski
Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 2 pipeline(s).

@github-actions
Copy link
Copy Markdown

This pull request has been marked as stale due to inactivity for more than 30 days.

If you would like to keep this pull request open, please provide an update or respond to any comments. Otherwise, it will be closed automatically in 7 days.

@github-actions github-actions Bot added the Stale The Issue or PR has become stale and will be automatically closed shortly if no activity occurs. label Jan 15, 2026
@edwardneal
Copy link
Copy Markdown
Contributor Author

This PR is not stale.

@github-actions github-actions Bot removed the Stale The Issue or PR has become stale and will be automatically closed shortly if no activity occurs. label Jan 16, 2026
@paulmedynski
Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 2 pipeline(s).

@github-actions
Copy link
Copy Markdown

This pull request has been marked as stale due to inactivity for more than 30 days.

If you would like to keep this pull request open, please provide an update or respond to any comments. Otherwise, it will be closed automatically in 7 days.

@github-actions github-actions Bot added the Stale The Issue or PR has become stale and will be automatically closed shortly if no activity occurs. label Feb 20, 2026
@paulmedynski paulmedynski added this to the 7.1.0-preview1 milestone Feb 20, 2026
@paulmedynski paulmedynski removed the Stale The Issue or PR has become stale and will be automatically closed shortly if no activity occurs. label Feb 20, 2026
@github-actions
Copy link
Copy Markdown

This pull request has been marked as stale due to inactivity for more than 30 days.

If you would like to keep this pull request open, please provide an update or respond to any comments. Otherwise, it will be closed automatically in 7 days.

@github-actions github-actions Bot added the Stale The Issue or PR has become stale and will be automatically closed shortly if no activity occurs. label Mar 23, 2026
@edwardneal
Copy link
Copy Markdown
Contributor Author

This PR is not stale.

@github-actions github-actions Bot removed the Stale The Issue or PR has become stale and will be automatically closed shortly if no activity occurs. label Mar 24, 2026
@paulmedynski
Copy link
Copy Markdown
Contributor

@edwardneal Can you merge main and address the conflicts?

mdaigle
mdaigle previously approved these changes Mar 25, 2026
@edwardneal edwardneal dismissed stale reviews from mdaigle and paulmedynski via 0d8e50a March 25, 2026 20:54
@edwardneal
Copy link
Copy Markdown
Contributor Author

Thanks @paulmedynski, I've just merged.

@paulmedynski
Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 2 pipeline(s).

mdaigle
mdaigle previously approved these changes Mar 25, 2026
@paulmedynski
Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 2 pipeline(s).

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 13, 2026

Codecov Report

❌ Patch coverage is 90.32258% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.48%. Comparing base (52c7149) to head (04ee46d).
⚠️ Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
...lient/src/Microsoft/Data/SqlTypes/SqlFileStream.cs 0.00% 3 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (52c7149) and HEAD (04ee46d). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (52c7149) HEAD (04ee46d)
CI-SqlClient 1 0
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3844      +/-   ##
==========================================
- Coverage   74.27%   64.48%   -9.79%     
==========================================
  Files         279      271       -8     
  Lines       42980    65710   +22730     
==========================================
+ Hits        31922    42373   +10451     
- Misses      11058    23337   +12279     
Flag Coverage Δ
CI-SqlClient ?
PR-SqlClient-Project 64.48% <90.32%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@paulmedynski paulmedynski moved this from In progress to In review in SqlClient Board Apr 14, 2026
@mdaigle mdaigle merged commit b1b93a8 into dotnet:main Apr 16, 2026
299 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in SqlClient Board Apr 16, 2026
@edwardneal edwardneal deleted the target-single-platform/01-infrastructure-and-public-apis branch April 16, 2026 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants