Skip to content

[native] Skip cmake reconfigure on no-op builds#11704

Open
jonathanpeppers wants to merge 1 commit into
mainfrom
jonathanpeppers/skip-cmake-reconfigure-noop
Open

[native] Skip cmake reconfigure on no-op builds#11704
jonathanpeppers wants to merge 1 commit into
mainfrom
jonathanpeppers/skip-cmake-reconfigure-noop

Conversation

@jonathanpeppers

Copy link
Copy Markdown
Member

Why

On every dotnet build (with no source changes), the _ConfigureRuntimes target was re-running cmake for every supported ABI × {Debug, Release} (~10 directories), regenerating CMakeCache.txt, build.ninja, rules.ninja, .ninja_log, etc. That in turn invalidated _BuildAndroidRuntimes's inputs, so ninja was re-invoked for every ABI × configuration too -- on a build where literally nothing had changed.

Root cause

_ConfigureRuntimesInputs in src/native/native.targets referenced two CMakeLists.txt files that no longer exist in the tree:

  • common/libstub/CMakeLists.txt was deleted in [native] Common infrastructure for native shared library linking #9990 (April 2025).
  • mono/xamarin-app-debug-helper/CMakeLists.txt never existed at this path. The sibling directory mono/xamarin-debug-app-helper (note the swapped words) is referenced from _FindRuntimeSources, but neither directory has ever shipped a CMakeLists.

MSBuild's Inputs/Outputs incremental skip requires every declared input file to exist on disk. When an explicit input is missing, MSBuild cannot compute whether outputs are up to date and re-runs the target on every build. That defeated the incremental skip for _ConfigureRuntimes and cascaded into _BuildAndroidRuntimes re-invoking ninja for every ABI × configuration.

What changed

  • Drop the two missing CMakeLists.txt entries from _ConfigureRuntimesInputs.
  • Drop a duplicate mono/shared/CMakeLists.txt entry that was listed twice.
  • Drop the matching dead globs in _FindRuntimeSources for common/libstub/*.{cc,hh} and mono/xamarin-debug-app-helper/*.{cc,hh}. Globs against missing directories evaluate to empty, so those are purely a code-hygiene cleanup -- they were not contributing to the rerun.

Validation

Two consecutive no-op dotnet build Xamarin.Android.sln runs after the fix:

  • Wall time ~15s (steady state).
  • Zero CMakeCache.txt, build.ninja, rules.ninja, or .ninja_log files touched under src/native/obj/.

Before the fix, the same no-op build touched all of those files across every ABI × {Debug, Release} directory on every invocation.

On every `dotnet build` (no source changes), the `_ConfigureRuntimes`

target was re-running `cmake` for every supported ABI x Debug/Release,

regenerating `CMakeCache.txt`, `build.ninja`, `rules.ninja`, etc. That

in turn invalidated `_BuildAndroidRuntimes`'s inputs, so `ninja` was

re-invoked for every ABI x configuration too.

Root cause: `_ConfigureRuntimesInputs` referenced two `CMakeLists.txt`

files that no longer exist in the tree:

  - `common/libstub/CMakeLists.txt` was deleted in #9990 (April 2025).

  - `mono/xamarin-app-debug-helper/CMakeLists.txt` never existed at

    this path (a sibling directory `mono/xamarin-debug-app-helper` was

    referenced from `_FindRuntimeSources` with the opposite typo).

MSBuild's `Inputs`/`Outputs` incremental skip requires every declared

input file to exist. When an input is missing, the target re-runs on

every build, defeating incremental skip and causing `_BuildAndroidRuntimes`

to invoke `ninja` for every ABI x configuration too.

Also drop a duplicate `mono/shared/CMakeLists.txt` entry and the

matching `common/libstub/*.{cc,hh}` / `mono/xamarin-debug-app-helper/*.{cc,hh}`

globs in `_FindRuntimeSources` -- those evaluate to empty against the

missing directories, so removing them is purely a code-hygiene change.

Validated with two consecutive no-op `dotnet build Xamarin.Android.sln`

runs after the fix:

  - No `CMakeCache.txt`/`build.ninja`/`.ninja_log`/`rules.ninja`

    files are touched in `src/native/obj`.

  - Wall time: ~15s (steady state).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 19, 2026 00:38

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.

Pull request overview

This PR improves incremental native runtime builds by fixing MSBuild Inputs/Outputs for the _ConfigureRuntimes target so CMake configure (and downstream Ninja invocations) can be skipped on true no-op builds.

Changes:

  • Removed non-existent/duplicate CMakeLists.txt entries from _ConfigureRuntimesInputs to restore incremental skipping.
  • Cleaned up _FindRuntimeSources globs, intended to remove dead source patterns.

Comment thread src/native/native.targets
Comment on lines 222 to 228
<ItemGroup Condition=" '$(CMakeRuntimeFlavor)' == 'MonoVM' ">
<_RuntimeSources Include="mono\monodroid\*.cc;mono\monodroid\*.hh" />
<_RuntimeSources Include="mono\runtime-base\*.cc;mono\runtime-base\*.hh" />
<_RuntimeSources Include="mono\shared\*.cc;mono\shared\*.hh" />
<_RuntimeSources Include="mono\tracing\*.cc;mono\tracing\*.hh" />
<_RuntimeSources Include="mono\xamarin-app-stub\*.cc;mono\xamarin-app-stub\*.hh" />
<_RuntimeSources Include="mono\xamarin-debug-app-helper\*.cc;mono\xamarin-debug-app-helper\*.hh" />
</ItemGroup>
Comment thread src/native/native.targets
Comment on lines 49 to 55
<ItemGroup Condition=" '$(CMakeRuntimeFlavor)' == 'MonoVM' ">
<_ConfigureRuntimesInputs Include="mono\monodroid\CMakeLists.txt" />
<_ConfigureRuntimesInputs Include="mono\runtime-base\CMakeLists.txt" />
<_ConfigureRuntimesInputs Include="mono\shared\CMakeLists.txt" />
<_ConfigureRuntimesInputs Include="mono\shared\CMakeLists.txt" />
<_ConfigureRuntimesInputs Include="mono\tracing\CMakeLists.txt" />
<_ConfigureRuntimesInputs Include="mono\xamarin-app-debug-helper\CMakeLists.txt" />
<_ConfigureRuntimesInputs Include="mono\xamarin-app-stub\CMakeLists.txt" />

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants