Skip to content

Extend xcrun SDK resolution to all Apple platforms for NativeAOT linker#126893

Merged
agocke merged 3 commits intomainfrom
copilot/fix-nativeaot-build-issue
Apr 17, 2026
Merged

Extend xcrun SDK resolution to all Apple platforms for NativeAOT linker#126893
agocke merged 3 commits intomainfrom
copilot/fix-nativeaot-build-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 14, 2026

Description

NativeAOT builds fail intermittently on macOS-15 arm64 because Swift auto-linked libraries (swift_Builtin_float, swift_errno, etc.) from libSystem.Security.Cryptography.Native.Apple.a cannot be found. The linker targets hardcode -L/usr/lib/swift, but on macOS 15+ these shims may only exist under the Xcode SDK path.

iOS-like platforms are unaffected because they already resolve the SDK via xcrun --show-sdk-path and pass -isysroot which makes Apple's ld remap all -L paths relative to the sysroot. macOS desktop targets (_targetOS == 'osx') previously didn't participate in this SDK resolution, so the hardcoded /usr/lib/swift path was the only search location.

Changes:

  • Set _AppleSdkName to macosx for osx targets, matching how iOS-like platforms already define their SDK names
  • Broaden the existing Xcrun property initialization, command -v check, and xcrun --show-sdk-path conditions from _IsiOSLikePlatform to _IsApplePlatform so macOS also resolves its SDK path into SysRoot
  • The existing -isysroot "$(SysRoot)" linker argument (already conditioned on _IsApplePlatform) then automatically remaps -L/usr/lib/swift to <SDK>/usr/lib/swift
  • Error conditions for missing xcrun and missing SDK remain scoped to _IsiOSLikePlatform so macOS builds degrade gracefully if xcrun is unavailable (e.g., cross-compilation from non-macOS hosts where SysRoot would be set manually)

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

On macOS 15+, Swift stdlib shims may only exist under the Xcode SDK
path and not in /usr/lib/swift. This causes NativeAOT builds to fail
intermittently when linking libSystem.Security.Cryptography.Native.Apple.a.

Resolve the macOS SDK path via `xcrun --show-sdk-path` and add it as
an additional -L linker search path. iOS-like platforms are unaffected
since they already pass -isysroot which remaps -L paths automatically.

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/1ea30f49-d15d-45c6-be1d-9572f6f8bf28

Co-authored-by: agocke <515774+agocke@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot April 14, 2026 18:11
Copilot AI changed the title [WIP] Fix random NativeAOT build failures on arm64 macOS-15 Add macOS SDK Swift library path to NativeAOT linker arguments Apr 14, 2026
Copilot AI requested a review from agocke April 14, 2026 18:13
Comment thread src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets Outdated
@agocke
Copy link
Copy Markdown
Member

agocke commented Apr 15, 2026

OK, after going back and forth with copilot, the operating theory is that this is a difference in xcode-select and whether or not the machine has been configured for full command line tools, vs full xcode config.

I'm not sure that's right, but I think it's plausible. So this fix seems reasonable.

@agocke agocke marked this pull request as ready for review April 15, 2026 04:57
Copilot AI review requested due to automatic review settings April 15, 2026 04:57
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the NativeAOT Unix MSBuild targets to improve macOS 15+ linking reliability by adding an additional Swift library search path derived from the Xcode macOS SDK, addressing missing auto-linked Swift shim libraries during linking.

Changes:

  • Resolves the macOS SDK path for osx targets by invoking xcrun --show-sdk-path (best-effort).
  • Adds -L<macOS SDK>/usr/lib/swift to NativeAOT linker arguments for macOS, while keeping the existing /usr/lib/swift fallback.

Comment thread src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets Outdated
…of separate macOS block

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/1cf65e66-4b7b-409c-bd4c-58c477560e6f

Co-authored-by: agocke <515774+agocke@users.noreply.github.com>
Copilot AI changed the title Add macOS SDK Swift library path to NativeAOT linker arguments Extend xcrun SDK resolution to all Apple platforms for NativeAOT linker Apr 15, 2026
@agocke
Copy link
Copy Markdown
Member

agocke commented Apr 16, 2026

/azp run runtime-native aot-outerloop

@azure-pipelines
Copy link
Copy Markdown

No pipelines are associated with this pull request.

@agocke
Copy link
Copy Markdown
Member

agocke commented Apr 16, 2026

/azp run runtime-nativeaot-outerloop

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@agocke
Copy link
Copy Markdown
Member

agocke commented Apr 17, 2026

/ba-g Mac platforms are passing

@agocke agocke merged commit e238ea0 into main Apr 17, 2026
129 of 138 checks passed
@agocke agocke deleted the copilot/fix-nativeaot-build-issue branch April 17, 2026 01:51
@github-project-automation github-project-automation bot moved this to Done in AppModel Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

NativeAOT builds fail randomly on arm64 macOS-15 with 'Could not find or use auto-linked library'

4 participants