Skip to content

Don't build native host tests when building clr subset#125861

Open
elinor-fung wants to merge 2 commits intodotnet:mainfrom
elinor-fung:host-native-tests-build
Open

Don't build native host tests when building clr subset#125861
elinor-fung wants to merge 2 commits intodotnet:mainfrom
elinor-fung:host-native-tests-build

Conversation

@elinor-fung
Copy link
Member

@elinor-fung elinor-fung commented Mar 20, 2026

Building the clr subset includes host.native, which previously unconditionally built native test assets (mockcoreclr, mockhostfxr, mockhostpolicy, nativehost, etc.) via add_subdirectory(test) in the corehost CMakeLists.txt. These test assets are not needed for a normal dev build like ./build.sh libs+clr -rc Release. Since that is part of the baseline build agents are instructed to do, this also reduces the amount of work/time for all agents working in this repo.

Changes

Add two CMake variables to control what gets built:

  • CLR_CMAKE_BUILD_HOST_PRODUCT: gates product-only targets (fxr, hostpolicy, apphost, dotnet, comhost)
  • CLR_CMAKE_BUILD_HOST_TESTS: gates the test subdirectory

These are driven by MSBuild properties BuildNativeHostProduct and BuildNativeHostTests in corehost.proj, which default to true and f alse respectively.

In eng/Subsets.props, the host.tests subset now invokes corehost.proj with BuildNativeHostTests=true and BuildNativeHostProduct=false, so only test assets and their required dependencies (hostcommon, hostmisc, nethost, ijwhost) are built.

Subset behavior

Subset Product Tests
host.native (used by clr) ✅ Built ❌ Skipped
host.tests ❌ Skipped (deps only) ✅ Built
host (full) ✅ Built (via host.native) ✅ Built (via host.tests)

Fixes #73711

Building the clr subset includes host.native, which previously
unconditionally built native test assets (mockcoreclr, mockhostfxr,
mockhostpolicy, nativehost, etc.) via add_subdirectory(test) in the
corehost CMakeLists.txt. These test assets are not needed for a
normal dev build like './build.sh libs+clr -rc Release'.

Add two CMake variables to control what gets built:
- CLR_CMAKE_BUILD_HOST_PRODUCT: gates product-only targets (fxr,
  hostpolicy, apphost, dotnet, comhost)
- CLR_CMAKE_BUILD_HOST_TESTS: gates the test subdirectory

These are driven by MSBuild properties BuildNativeHostProduct and
BuildNativeHostTests in corehost.proj, which default to true and
false respectively.

In eng/Subsets.props, the host.tests subset now invokes corehost.proj
with BuildNativeHostTests=true and BuildNativeHostProduct=false, so
only test assets and their required dependencies (hostcommon, hostmisc,
nethost, ijwhost) are built.

Fixes dotnet#73711

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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 refactors the native host build so that building the clr subset no longer implicitly builds native host test assets, while still allowing host.tests to build the test assets without building full host “product” binaries.

Changes:

  • Add MSBuild properties in corehost.proj to drive two new CMake variables controlling host product vs. host tests build.
  • Gate src/native/corehost CMake subdirectories (fxr/hostpolicy/apphost/dotnet, test, and comhost) behind those variables.
  • Update eng/Subsets.props so host.tests explicitly builds corehost.proj with tests enabled and product disabled.

Reviewed changes

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

File Description
src/native/corehost/corehost.proj Adds BuildNativeHostTests / BuildNativeHostProduct defaults and forwards them to CMake via -cmakeargs.
src/native/corehost/CMakeLists.txt Conditionally includes product and test subdirectories (and ASAN install locations) based on the new CMake variables.
eng/Subsets.props Updates host.tests subset to invoke corehost.proj with tests on and product off.

Define default values so standalone CMake invocations (without
MSBuild passing -D flags) produce a correct product build.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

Building clr shouldn't build host tests

3 participants