Skip to content

Default to ninja for faster builds (mac & linux)#124041

Open
steveisok wants to merge 5 commits intodotnet:mainfrom
steveisok:test-ninja-build
Open

Default to ninja for faster builds (mac & linux)#124041
steveisok wants to merge 5 commits intodotnet:mainfrom
steveisok:test-ninja-build

Conversation

@steveisok
Copy link
Member

@steveisok steveisok commented Feb 5, 2026

Benchmarking showed ninja provides ~8.8% faster builds on macOS (avg 654s vs 718s per build). This change defaults to using ninja for both MacOS and Linux.

Changes:

  • eng/build.sh: default to using ninja
  • eng/native/build-commons.sh: Default -ninja on macOS, add -ninja false opt-out

Users can opt out with --ninja false (or -ninja false for native builds).

Contributes to #54022 (#54022)

Benchmarking showed ninja provides ~8.8% faster builds on macOS
(avg 654s vs 718s per build). This change defaults to using ninja
when the host OS is macOS.

Changes:
- eng/build.sh: Default --ninja true on macOS, track explicit user override
- eng/native/build-commons.sh: Default -ninja on macOS, add -ninja false opt-out

Users can opt out with --ninja false (or -ninja false for native builds).
@steveisok steveisok requested review from a team and Copilot February 5, 2026 13:01
@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 Feb 5, 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 PR improves macOS build performance by defaulting to the Ninja build system instead of Make, achieving approximately 8.8% faster build times (654s vs 718s average). The change is opt-out via --ninja false to maintain flexibility.

Changes:

  • Default ninja build system on macOS for improved performance
  • Add explicit flag tracking to prevent overriding user preferences
  • Update help text to document the new default and opt-out mechanism

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
eng/build.sh Adds macOS-specific ninja default with tracking to avoid overriding explicit user settings
eng/native/build-commons.sh Sets ninja as default on macOS and enhances -ninja flag to accept true/false values

@jkotas
Copy link
Member

jkotas commented Feb 5, 2026

docs\workflow\requirements\macos-requirements.md needs to be updated - ninja is no longer optional by default after this change.

@jkotas jkotas added area-Infrastructure and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Feb 5, 2026
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/runtime-infrastructure
See info in area-owners.md if you want to be subscribed.

@am11
Copy link
Member

am11 commented Feb 5, 2026

Windows also defaults to ninja. Maybe we should flip the switch: --skipninja and cherry-pick installation script change a2b49ec. It's a tiny script dependency considering everything else required by the build.

@jkotas
Copy link
Member

jkotas commented Feb 5, 2026

--skipninja

Nit: Avoiding negations in names is a generally better UX design. I like -ninja false better than -skipninja.

- Use single useNinja variable in eng/build.sh instead of tracking explicit-ness
- Initialize __UseNinja=0 in build-commons.sh, then override to 1 on macOS
- Remove __UseNinja=0 initialization from build-runtime.sh and tests/build.sh
  so the macOS default takes effect
- Update macOS requirements docs to reflect ninja is now default
@jkoritzinsky
Copy link
Member

I was just talking with @agocke about requiring Ninja on macOS to make it easier to maintain our Swift usage (as CMake only supports Swift with Ninja and XCode) so we don't need to manually invoke the Swift compiler and do our own object file handling.

I think this is a great first step in that direction!

Based on PR feedback, default to using Ninja for native builds on any
Unix platform where ninja is installed, rather than only on macOS.
This aligns with the Mono subtree behavior and provides faster builds
when ninja is available.
Copilot AI review requested due to automatic review settings February 5, 2026 22:48
@steveisok steveisok changed the title Default to ninja on macOS for faster builds Default to ninja if installed for faster builds (mac & linux) Feb 5, 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

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Require ninja by default for a predictable build experience on Unix
platforms. Users can opt out with --ninja false.

Contributes to dotnet#54022
Copilot AI review requested due to automatic review settings February 5, 2026 23:44
@steveisok steveisok changed the title Default to ninja if installed for faster builds (mac & linux) Default to ninja for faster builds (mac & linux) Feb 5, 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

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

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

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

5 participants