Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions eng/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ usage()
echo " --ninja Optional argument: use Ninja instead of Make (default: true, use --ninja false to disable)."
echo " --pgoinstrument Optional argument: build PGO-instrumented runtime"
echo " --fsanitize Optional argument: Specify native sanitizers to instrument the native build with. Supported values are: 'address'."
echo " --validate-config Validate that the platform CMake cache matches the current system configuration."
echo " --regenerate-config Regenerate the platform CMake cache if it differs from the current system."
echo ""

echo "Command line arguments starting with '/p:' are passed through to MSBuild."
Expand Down Expand Up @@ -549,13 +551,67 @@ while [[ $# -gt 0 ]]; do
shift 1
;;

-validate-config|-validateconfig)
validateConfig=1
shift 1
;;

-regenerate-config|-regenerateconfig)
regenerateConfig=1
shift 1
;;

-sourcebuild|-source-build|-sb)
# Export env var to disable platform cache for source builds
export CLR_CMAKE_SKIP_PLATFORM_CACHE=1
extraargs+=("$1")
shift 1
;;

*)
extraargs+=("$1")
shift 1
;;
esac
done

# Handle --validate-config and --regenerate-config
if [[ "${validateConfig:-0}" == "1" || "${regenerateConfig:-0}" == "1" ]]; then
# Determine platform string
platform=""
case "$os" in
osx)
platform="osx-$arch"
;;
linux)
platform="linux-$arch"
;;
browser)
platform="browser"
;;
ios|tvos|iossimulator|tvossimulator)
platform="ios"
;;
*)
echo "No platform cache defined for $os-$arch"
exit 0
;;
esac

validateScript="$scriptroot/native/validate-platform-cache.sh"
if [[ ! -f "$validateScript" ]]; then
echo "Error: validate-platform-cache.sh not found at $validateScript"
exit 1
fi

if [[ "${regenerateConfig:-0}" == "1" ]]; then
"$validateScript" --regenerate "$platform"
else
"$validateScript" "$platform"
fi
exit $?
fi

if [ ${#actInt[@]} -eq 0 ]; then
arguments=("-restore" "-build" ${arguments[@]+"${arguments[@]}"})
fi
Expand Down
16 changes: 16 additions & 0 deletions eng/native/gen-buildsys.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,22 @@ if [[ "$host_arch" == "armel" ]]; then
cmake_extra_defines="$cmake_extra_defines -DARM_SOFTFP=1"
fi

# Use platform-specific tryrun cache to speed up CMake configure (opt-out via CLR_CMAKE_SKIP_PLATFORM_CACHE=1)
if [[ "$CLR_CMAKE_SKIP_PLATFORM_CACHE" != "1" ]]; then
if [[ "$target_os" == "osx" && "$host_arch" == "arm64" && -f "$scriptroot/tryrun.osx-arm64.cmake" ]]; then
# Extract current AppleClang major version
current_clang_version=$(clang --version 2>/dev/null | head -1 | sed -n 's/.*clang version \([0-9]*\)\..*/\1/p')
# Extract expected version from cache file
cache_clang_version=$(grep -o 'CLR_CMAKE_PLATFORM_CACHE_COMPILER_VERSION "[0-9]*"' "$scriptroot/tryrun.osx-arm64.cmake" 2>/dev/null | sed 's/.*"\([0-9]*\)".*/\1/')

if [[ -n "$current_clang_version" && -n "$cache_clang_version" && "$current_clang_version" == "$cache_clang_version" ]]; then
cmake_extra_defines="-C $scriptroot/tryrun.osx-arm64.cmake $cmake_extra_defines"
elif [[ -n "$current_clang_version" && -n "$cache_clang_version" ]]; then
echo "Skipping platform cache: AppleClang version mismatch (current: $current_clang_version, cache: $cache_clang_version)"
fi
fi
Comment on lines +88 to +101
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

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

This block can run during cross-compiles to macOS arm64 as well (when CROSSCOMPILE=1, target_os=osx, host_arch=arm64). In that case tryrun.cmake is already loaded earlier, and adding tryrun.osx-arm64.cmake can override TRY_RUN results (e.g., Darwin values in eng/native/tryrun.cmake), leading to inconsistent configuration between cross and native paths. Consider skipping the platform cache when CROSSCOMPILE=1 (or otherwise ensuring the two caches cannot conflict).

Copilot uses AI. Check for mistakes.
fi
Comment on lines 88 to 102
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

When cross-compiling to macOS ARM64, both the new platform-specific cache (line 91) and the cross-compilation cache (line 75) will be loaded. Since tryrun.osx-arm64.cmake is prepended, CMake processes it first, but values can be overridden by the later tryrun.cmake.

There's a specific value discrepancy: HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP_EXITCODE is set to 255 in tryrun.osx-arm64.cmake (line 233) but 1 in tryrun.cmake for Darwin ARM64 (line 75 context). In cross-compile scenarios, tryrun.cmake's value of 1 will override. However, for native macOS ARM64 builds, the value of 255 from tryrun.osx-arm64.cmake will be used.

Additionally, tryrun.osx-arm64.cmake is missing several _EXITCODE variables that are defined in tryrun.cmake for Darwin (HAVE_BROKEN_FIFO_SELECT_EXITCODE, HAVE_CLOCK_MONOTONIC_COARSE_EXITCODE, HAVE_CLOCK_GETTIME_NSEC_NP_EXITCODE, HAVE_MMAP_DEV_ZERO_EXITCODE, HAVE_SCHED_GETCPU_EXITCODE, MMAP_ANON_IGNORES_PROTECTION_EXITCODE, SEM_INIT_MODIFIES_ERRNO_EXITCODE).

Consider adding a check to skip loading tryrun.osx-arm64.cmake when CROSSCOMPILE is set to avoid any potential conflicts, or verify that these value differences are intentional and correct for the different build scenarios.

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

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

This looks like a valid point.

We are effectively maintaining a smaller version of this cache for the runtime checks for cross-builds. We should avoid the duplication.

The runtime checks have a high likelihood of being forward compatible (if an API works on version X, we assume that it works on version X+1 too),. They do not have the fragility that comes with compiler checks

I am wondering how much we can make this better by combination of:

  • Use the existing cross-build runtime check cache even for native builds
  • Delete checks that are no longer relevant
  • Restructure the build to reduce duplicated checks


if ! cmake_command=$(command -v cmake); then
echo "CMake was not found in PATH."
exit 1
Expand Down
Loading
Loading