[native] Skip cmake reconfigure on no-op builds#11704
Open
jonathanpeppers wants to merge 1 commit into
Open
Conversation
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>
Contributor
There was a problem hiding this comment.
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.txtentries from_ConfigureRuntimesInputsto restore incremental skipping. - Cleaned up
_FindRuntimeSourcesglobs, intended to remove dead source patterns.
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 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" /> | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
On every
dotnet build(with no source changes), the_ConfigureRuntimestarget was re-runningcmakefor every supported ABI × {Debug, Release} (~10 directories), regeneratingCMakeCache.txt,build.ninja,rules.ninja,.ninja_log, etc. That in turn invalidated_BuildAndroidRuntimes's inputs, soninjawas re-invoked for every ABI × configuration too -- on a build where literally nothing had changed.Root cause
_ConfigureRuntimesInputsinsrc/native/native.targetsreferenced twoCMakeLists.txtfiles that no longer exist in the tree:common/libstub/CMakeLists.txtwas deleted in [native] Common infrastructure for native shared library linking #9990 (April 2025).mono/xamarin-app-debug-helper/CMakeLists.txtnever existed at this path. The sibling directorymono/xamarin-debug-app-helper(note the swapped words) is referenced from_FindRuntimeSources, but neither directory has ever shipped a CMakeLists.MSBuild's
Inputs/Outputsincremental 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_ConfigureRuntimesand cascaded into_BuildAndroidRuntimesre-invokingninjafor every ABI × configuration.What changed
CMakeLists.txtentries from_ConfigureRuntimesInputs.mono/shared/CMakeLists.txtentry that was listed twice._FindRuntimeSourcesforcommon/libstub/*.{cc,hh}andmono/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.slnruns after the fix:CMakeCache.txt,build.ninja,rules.ninja, or.ninja_logfiles touched undersrc/native/obj/.Before the fix, the same no-op build touched all of those files across every ABI × {Debug, Release} directory on every invocation.