Skip to content

Fix swift compilation to use a release build on release - #138038

Merged
akoeplinger merged 1 commit into
dotnet:mainfrom
vcsjones:fix-swift-compiler-opts
Nov 21, 2026
Merged

akoeplinger merged 1 commit into
dotnet:mainfrom
vcsjones:fix-swift-compiler-opts

Conversation

@vcsjones

Copy link
Copy Markdown
Member

I don't believe we ever correctly fixed building swift libraries in release mode. In #104383 we added changes to cmake to make this work, but it used the wrong casing, and Cmake's STREQUAL is case-sensitive.

For libraries builds, CMAKE_BUILD_TYPE always appears to be upper case:

CMAKE_BUILD_TYPE gets set here to $buildtype

"-DCMAKE_BUILD_TYPE=$buildtype" \

And buildtype is set here:

case "$upperI" in
# Possible build types are DEBUG, CHECKED, RELEASE, RELWITHDEBINFO.
DEBUG | CHECKED | RELEASE | RELWITHDEBINFO)
buildtype="$upperI"

upperI is the uppercase version of the build, so the string comparison would fail.

This change instead uses the UPPERCASE_CMAKE_BUILD_TYPE explicitly, and compares it to the uppercase version.

This makes the System.Security.Cryptography.Apple.dylib about 16% smaller. It also gives a modest performance improvement to things that go through the swift shim.

@vcsjones vcsjones added this to the 12.0.0 milestone Nov 20, 2026
@vcsjones
vcsjones requested a review from akoeplinger November 20, 2026 20:43
@vcsjones vcsjones self-assigned this Nov 20, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 4 pipeline(s).
11 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: @dotnet/area-infrastructure-libraries
See info in area-owners.md if you want to be subscribed.

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.

🟢 Approval recommended

No active review issues were identified for the Swift optimization-flag selection change.

No open issues 🎉

What changed in this PR

Fixes build-type matching for the Apple cryptography Swift shim so release builds select the intended optimization flag.

Changes:

  • Uses UPPERCASE_CMAKE_BUILD_TYPE with uppercase values for CMake’s case-sensitive comparisons.
  • Correctly selects -Onone for debug builds and -O for release builds.
File Description
src/​native/​libs/​System.Security.Cryptography.Native.Apple/​CMakeLists.txt Corrects the debug and release conditions used to select Swift optimization flags.

Review effort: Balanced

@akoeplinger
akoeplinger merged commit 257af3f into dotnet:main Nov 21, 2026
79 of 80 checks passed
@akoeplinger

Copy link
Copy Markdown
Member

nice find! seems like a backport candidate?

@akoeplinger

akoeplinger commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Actually, given that https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html explicitly documents Debug, Release etc and we're also using that casing in a couple places in this repo it sounds like we should also fix passing the correct casing to CMAKE_BUILD_TYPE

https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#id80 discusses this some more and says to always compare against e.g. uppercase but I see no reason to not just follow the established casing.

@vcsjones

Copy link
Copy Markdown
Member Author

seems like a backport candidate?

I’m not so sure. I’m reluctant to change anything about how the swift object is built in servicing. Just recently we ran into this with the SHA-3 work because of complex interactions. I don’t expect anything to break, but I also think I would bucket it as a “medium” risk. Given that it doesn’t actually fix anything, and it’s been this way… forever… my personal opinion is it should be left as is.

we're also using that casing in a couple places in this repo it sounds like we should also fix passing the correct casing to CMAKE_BUILD_TYPE

Yeah that seems like a good idea. I will file an issue for it, but for this fix since it explicitly uses the _UPPER variable now, I think it’s fine.

@akoeplinger

Copy link
Copy Markdown
Member

Thanks for catching this! The follow-up is in #138121. It passes canonical CMAKE_BUILD_TYPE names from the build scripts and fixes the remaining case-sensitive checks outside Mono.

Note

This comment was generated with GitHub Copilot.

@vcsjones
vcsjones deleted the fix-swift-compiler-opts branch November 23, 2026 15:21
akoeplinger added a commit that referenced this pull request Nov 24, 2026
<!-- -->

Follow-up to #138038, where an uppercase `CMAKE_BUILD_TYPE` exposed a
case-sensitive comparison in the Apple crypto Swift build.

- Have `build-commons.sh` pass the canonical build type explicitly. Both
generator wrappers now forward `-DCMAKE_BUILD_TYPE` unchanged.
- Share the case-insensitive comparison value and canonical cache
choices across single-config generators. Make Rollup use the same
case-insensitive Release check for its configuration and optimization
mode.
- Install the IJW test Debug CRT based on the configuration being
installed, rather than the configure-time build type.

Built and linked `System.Security.Cryptography.Native.Apple` locally
with Ninja on macOS arm64 in both Debug and Release. The verbose build
confirmed `swiftc -Onone` for Debug and `swiftc -O` for Release.

Focused CMake checks covered argument forwarding and overrides,
mixed-case native library optimization flags, and Debug-only CRT
installation with Ninja and Ninja Multi-Config. The unmodified zstd
target built with the canonical Debug value, and a Node smoke check
covered mixed-case Rollup settings. A native Windows IJW build was not
run.

> [!NOTE]
> This description was generated with GitHub Copilot.

Co-authored-by: Copilot App <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants