Skip to content

Fix CMake 4.2.0+ build failure for nativeaot bootstrapper - #122152

Merged
jkoritzinsky merged 2 commits into
mainfrom
copilot/fix-cmake-build-errors
Dec 5, 2025
Merged

jkoritzinsky merged 2 commits into
mainfrom
copilot/fix-cmake-build-errors

Conversation

Copilot AI commented Dec 3, 2025 •

Copy link
Copy Markdown
Contributor

Fixes Issue

main PR

Description

CMake 4.2.0 changed the default PDB location for OBJECT libraries from ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/ to CMakeFiles/<target>.dir/, causing install step failures when the build system couldn't find bootstrapper.pdb.

Changes:

  • Set COMPILE_PDB_OUTPUT_DIRECTORY to "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>" for bootstrapper OBJECT library
  • Unified install path to consistently use $<CONFIG> for all MSVC generators (removed Visual Studio vs. Ninja conditional)

Follows existing pattern from eventpipe-shared-objects OBJECT library.

Customer Impact

Builds fail completely with CMake 4.2.0-rc4+ on Windows. Developers cannot build the repo with latest CMake versions, blocking contribution and testing.

Regression

No. This is a new failure introduced by CMake 4.2.0's behavior change, not a regression in runtime code.

Testing

Build configuration change validated against:

  • Existing pattern used successfully in eventpipe-shared-objects OBJECT library
  • CMake documentation for COMPILE_PDB_OUTPUT_DIRECTORY property
  • Code review and security scan passed

Risk

Low. Minimal change affecting only Windows MSVC builds of OBJECT libraries in nativeaot bootstrapper. No code logic changes, only CMake build configuration to adapt to CMake 4.2.0's new intermediate directory strategy.

Package authoring no longer needed in .NET 9

IMPORTANT: Starting with .NET 9, you no longer need to edit a NuGet package's csproj to enable building and bump the version.
Keep in mind that we still need package authoring in .NET 8 and older versions.

Original prompt

This section details on the original issue you should resolve

<issue_title>Repo doesn't build with latest CMake</issue_title>
<issue_description>### Description

As of today, current version of CMake is: Release Candidate (4.2.0-rc4) which causes build errors.

3.31.9 - works fine.

Reproduction Steps

  • fresh VM
  • install git, latest cmake, VS etc.
  • build -rc Release -s clr+libs

Expected behavior

builds fine

Actual behavior

Error

...
CMake Error at nativeaot/Bootstrap/base/cmake_install.cmake:45 (file):
  file INSTALL cannot find
  "C:/src/runtime/artifacts/obj/coreclr/windows.x64.Release/nativeaot/Bootstrap/base/bootstrapper.pdb":
  File exists.
Call Stack (most recent call first):
  nativeaot/Bootstrap/cmake_install.cmake:42 (include)
  nativeaot/cmake_install.cmake:42 (include)
  cmake_install.cmake:97 (include)


FAILED: CMakeFiles/install.util
C:\Windows\system32\cmd.exe /C "cd /D C:\src\runtime\artifacts\obj\coreclr\windows.x64.Release && "C:\Program Files\CMake\bin\cmake.exe" -P cmake_install.cmake"
ninja: build stopped: subcommand failed.
BUILD: Error: native component build failed. Refer to the build log files for details.
    "C:\src\runtime\artifacts\log\Release\CoreCLR_windows__x64__Release__x64.log"
    "C:\src\runtime\artifacts\log\Release\CoreCLR_windows__x64__Release__x64.wrn"
    "C:\src\runtime\artifacts\log\Release\CoreCLR_windows__x64__Release__x64.err"
C:\src\runtime\src\coreclr\runtime.proj(115,5): error MSB3073: The command ""C:\src\runtime\src\coreclr\build-runtime.cmd" -x64 -release -os windows -pgodatapath "C:\Users\kwicher\.nuget\packages\optimization.windows_nt-x64.pgo.coreclr\1.0.0-prerelease.25502.1" -targetrid win-x64 -cmakeargs "-DCLR_DOTNET_RID=win-x64" -cmakeargs "-DCLR_DOTNET_HOST_PATH=C:\src\runtime\.dotnet\dotnet.exe" -cmakeargs "-DCDAC_BUILD_TOOL_BINARY_PATH=C:\src\runtime\artifacts\bin\coreclr\windows.x64.Release\cdac-build-tool\cdac-build-tool.dll" -cmakeargs "-DCLR_CMAKE_RUNTIME_CORECLR=1" -cmakeargs "-DCMAKE_PRODUCT_VERSION=10.0.0" -cmakeargs "-DCMAKE_CONTINUOUS_INTEGRATION_BUILD=False" -cmakeargs "-DCMAKE_NET_CORE_APP_CURRENT_VERSION=10.0" -cmakeargs "-DCMAKE_BUILD_LIBRARIES_CONFIGURATION=Debug" -cmakeargs "-DCMAKE_BUILD_RUNTIME_CONFIGURATION=Release"" exited with code 1.

Build FAILED.

C:\src\runtime\src\coreclr\runtime.proj(115,5): error MSB3073: The command ""C:\src\runtime\src\coreclr\build-runtime.cmd" -x64 -release -os windows -pgodatapath "C:\Users\kwicher\.nuget\packages\optimization.windows_nt-x64.pgo.coreclr\1.0.0-prerelease.25502.1" -targetrid win-x64 -cmakeargs "-DCLR_DOTNET_RID=win-x64" -cmakeargs "-DCLR_DOTNET_HOST_PATH=C:\src\runtime\.dotnet\dotnet.exe" -cmakeargs "-DCDAC_BUILD_TOOL_BINARY_PATH=C:\src\runtime\artifacts\bin\coreclr\windows.x64.Release\cdac-build-tool\cdac-build-tool.dll" -cmakeargs "-DCLR_CMAKE_RUNTIME_CORECLR=1" -cmakeargs "-DCMAKE_PRODUCT_VERSION=10.0.0" -cmakeargs "-DCMAKE_CONTINUOUS_INTEGRATION_BUILD=False" -cmakeargs "-DCMAKE_NET_CORE_APP_CURRENT_VERSION=10.0" -cmakeargs "-DCMAKE_BUILD_LIBRARIES_CONFIGURATION=Debug" -cmakeargs "-DCMAKE_BUILD_RUNTIME_CONFIGURATION=Release"" exited with code 1.
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:07:08.28
Build failed with exit code 1. Check errors above.
Some builds failed:
        Configuration: Debug, Architecture: x64(this is just end of the log)

Regression?

not on .NET side

Known Workarounds

install old cmake

Configuration

No response

Other information

No response</issue_description>

Comments on the Issue (you are @copilot in this section)

@ericstj I'm hitting the same @agocke any idea how to fix this? I don't see any earlier failure, just that the build didn't produce a PDB in the location that it's trying to install. ``` CMake Error at nativeaot/Bootstrap/base/cmake_install.cmake:45 (file): file INSTALL cannot find "C:/src/dotnet/runtime/artifacts/obj/coreclr/windows.x64.Release/nativeaot/Bootstrap/base/bootstrapper.pdb": File exists. Call Stack (most recent call first): nativeaot/Bootstrap/cmake_install.cmake:42 (include) nativeaot/cmake_install.cmake:42 (include) cmake_install.cmake:97 (include) ```

I do see it in a sub-directory:

C:\src\dotnet\runtime\artifacts>dir /s /b bootstrapper.pdb
C:\src\dotnet\runtime\artifacts\obj\coreclr\windows.x64.Release\nativeaot\Bootstrap\base\CMakeFiles\bootstrapper.dir\bootstrapper.pdb
```</body></comment_new>
<comment_new><author>@agocke</author><body>
I'm not a cmake expert, but we can try copilot.</body></comment_new>
</comments>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@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 Dec 3, 2025
…or bootstrapper OBJECT library

CMake 4.2.0 changed the default location where PDB files for OBJECT libraries are placed.
Without explicitly setting COMPILE_PDB_OUTPUT_DIRECTORY, the PDB ends up in
CMakeFiles/<target>.dir/ instead of the expected location.

This change sets COMPILE_PDB_OUTPUT_DIRECTORY to ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>
and updates the install path to consistently use $<CONFIG>, matching the pattern
used in other OBJECT libraries like eventpipe-shared-objects.

Co-authored-by: agocke <515774+agocke@users.noreply.github.com>

@ericstj ericstj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I pulled this fix locally and it did resolve it for me. I'm building on Windows with Dev18.

@agocke
agocke marked this pull request as ready for review December 5, 2025 18:46
Copilot AI review requested due to automatic review settings December 5, 2025 18:46
@agocke

agocke commented Dec 5, 2025

Copy link
Copy Markdown
Member

@ericstj Thanks for the validation.

This change LGTM, but as I said I'm not a CMake expert.

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 fixes a build failure with CMake 4.2.0+ by updating the nativeaot bootstrapper's PDB file handling to accommodate CMake's changed default PDB location for OBJECT libraries.

Key changes:

  • Set COMPILE_PDB_OUTPUT_DIRECTORY to explicitly place PDB files in the expected $<CONFIG> subdirectory
  • Unified the install path to consistently use $<CONFIG> for all MSVC generators, removing the Visual Studio vs. Ninja conditional

@jkoritzinsky jkoritzinsky left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As the resident CMake expert (or closest we have to it) LGTM

@jkoritzinsky

Copy link
Copy Markdown
Member

/ba-g Helix infra issue

@jkoritzinsky
jkoritzinsky enabled auto-merge (squash) December 5, 2025 19:14
@jkoritzinsky
jkoritzinsky merged commit 3e44f56 into main Dec 5, 2025
104 of 106 checks passed
@MichalStrehovsky
MichalStrehovsky deleted the copilot/fix-cmake-build-errors branch December 5, 2025 22:36
@github-actions github-actions Bot locked and limited conversation to collaborators Jan 5, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Repo doesn't build with latest CMake

5 participants