Skip to content

Conversation

@rolfbjarne
Copy link
Member

@rolfbjarne rolfbjarne commented Jan 20, 2026

For background: when building iOS projects on Windows, we run 'dotnet build' on the Windows machine, and then run tasks that need to run on the Mac remotely from the Windows machine using our own remoting logic. This has a few requirements/consequences:

  • Any task that must run remotely must be aware of this fact. Our own tasks can be made aware, external (to the iOS SDK) tasks can't be.
  • The build will fail in confusing ways if a task is executed on Windows when it shouldn't be.

For instance: without this change, building an iOS project on Windows with NativeAOT enabled, will fail because the build fails to run 'xcrun' (which obviously doesn't exist on Windows):

Microsoft.NETCore.Native.Unix.targets(115): error: 'xcrun' not found in PATH. Make sure 'xcrun' is available in PATH.

The fix is to avoid running any tasks on Windows:

  • The 'SetupOSSpecificProps' target runs 'xcrun' to compute the 'SysRoot' property, so avoid running 'xcrun' if 'SysRoot' is already set (which the iOS SDK will do; we already have this value computed).
  • Add an escape hatch for validating that 'SysRoot' exists (it won't exist on Windows), by setting '_SkipiOSLikePlatformValidation=true'.
  • Don't get the Xcode version if we don't need it (it's only used to decide if the classic linker should be used, but if 'UseLdClassicXCodeLinker' is already set, then we don't need to know the Xcode version because a decision has already been made).
  • Don't try to find or validate the presence of a native linker if a native linker isn't needed (when 'NativeLib=Static').

As a side effect this will also make our build on macOS faster, because unnecessary tasks won't be executed.

Contributes towards dotnet/macios#21808.

…eAOT.

For background: when building iOS projects on Windows, we run 'dotnet build' on the
Windows machine, and then run tasks that need to run on the Mac remotely from the
Windows machine using our own remoting logic. This has a few requirements/consequences:

* Any task that must run remotely must be aware of this fact. Our own tasks can
  be made aware, external (to the iOS SDK) tasks can't be.
* The build will fail in confusing ways if a task is executed on Windows when it
  shouldn't be.

For instance: without this change, building an iOS project on Windows with NativeAOT
enabled, will fail because the build fails to run 'xcrun' (which obviously doesn't
exist on Windows):

> Microsoft.NETCore.Native.Unix.targets(115): error: 'xcrun' not found in PATH. Make
sure 'xcrun' is available in PATH.

The fix is to avoid running any tasks on Windows:

* The 'SetupOSSpecificProps' target runs 'xcrun' to compute the 'SysRoot' property,
  so avoid running 'xcrun' if 'SysRoot' is already set (which the iOS SDK will do;
  we already have this value computed).
* Add an escape hatch for validating that 'SysRoot' exists (it won't exist on Windows),
  by setting '_SkipiOSLikePlatformValidation=true'.
* Don't get the Xcode version if we don't need it (it's only used to determine
  if the classic linker should be used, but if 'UseLdClassicXCodeLinker' is already
  set, then we don't need to know the Xcode version because a decision has already
  been made).
* Don't try to find or validate the presence of a native linker if a native linker
  isn't needed (when 'NativeLib=Static').

As a side effect this will also make our build on macOS faster, because unnecessary
tasks won't be executed.

Contributes towards dotnet/macios#21808.
Copilot AI review requested due to automatic review settings January 20, 2026 10:29
@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jan 20, 2026
Copy link
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 pull request optimizes the NativeAOT build process for Unix targets, specifically to enable building iOS projects with NativeAOT on Windows and to improve build performance on macOS by avoiding unnecessary task executions.

Changes:

  • Skip xcrun and SysRoot-related checks when SysRoot is already set or when validation can be skipped
  • Skip Xcode version detection when linker preference is already determined
  • Skip all linker validation and detection when building static libraries (NativeLib=Static)

@am11 am11 added area-NativeAOT-coreclr and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jan 20, 2026
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib
See info in area-owners.md if you want to be subscribed.

@am11
Copy link
Member

am11 commented Jan 20, 2026

Add an escape hatch for validating that 'SysRoot' exists (it won't exist on Windows), by setting '_SkipiOSLikePlatformValidation=true'.

We use _ prefixed props for internal stuff (i.e. local to NativeAOT targets). For props meant to be public facing, we typically don't use the underscore prefix. I can see why iOS SDK contract may make it not exactly public facing, but my take is; if it isn't used within the naot buildintegration, then it's considered public facing.

@rolfbjarne
Copy link
Member Author

Add an escape hatch for validating that 'SysRoot' exists (it won't exist on Windows), by setting '_SkipiOSLikePlatformValidation=true'.

We use _ prefixed props for internal stuff (i.e. local to NativeAOT targets). For props meant to be public facing, we typically don't use the underscore prefix. I can see why iOS SDK contract may make it not exactly public facing, but my take is; if it isn't used within the naot build integration, then it's considered public facing.

I have no problems changing the property name if that's the consensus :)

@rolfbjarne rolfbjarne merged commit e5803f4 into dotnet:main Jan 22, 2026
100 checks passed
@rolfbjarne rolfbjarne deleted the nativeaot-from-windows branch January 22, 2026 07:57
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.

5 participants