From 902452cf9ba5ac23358ff6db90252c944b7fbd8e Mon Sep 17 00:00:00 2001 From: springmin Date: Mon, 31 Aug 2026 00:03:59 +0800 Subject: [PATCH 1/7] Add linux-ohos (HarmonyOS) build infrastructure --- eng/RuntimeIdentifier.props | 4 +- eng/Subsets.props | 10 +++-- eng/build.sh | 11 ++++-- eng/liveBuilds.targets | 1 + eng/native/build-commons.sh | 41 ++++++++++++++++++-- eng/native/configurecompiler.cmake | 17 ++++++++ eng/native/configureplatform.cmake | 11 ++++++ eng/native/configuretools.cmake | 24 ++++++++++-- eng/native/gen-buildsys.sh | 7 +++- src/coreclr/clr.featuredefines.props | 2 +- src/coreclr/runtime.proj | 1 + src/native/corehost/corehost.proj | 1 + src/native/libs/System.Native/CMakeLists.txt | 2 +- src/native/libs/build-native.proj | 1 + src/native/libs/build-native.sh | 2 +- 15 files changed, 116 insertions(+), 19 deletions(-) diff --git a/eng/RuntimeIdentifier.props b/eng/RuntimeIdentifier.props index a3c396d8e6b6c7..86a42ce61f074c 100644 --- a/eng/RuntimeIdentifier.props +++ b/eng/RuntimeIdentifier.props @@ -19,6 +19,7 @@ linux-musl linux-bionic + linux-ohos $(PortableOS)-$(TargetArchitecture) @@ -50,7 +51,8 @@ true true true - true + true + true true true true diff --git a/eng/Subsets.props b/eng/Subsets.props index 898741f170e185..85846de2c37b11 100644 --- a/eng/Subsets.props +++ b/eng/Subsets.props @@ -56,7 +56,7 @@ true <_UseNativeAotForComponentsCrossOS Condition="'$(CrossBuild)' == 'true' and '$(_hostArchitecture)' == '$(_targetArchitecture)' and '$(_hostOS)' != 'windows'">true - true + true @@ -77,6 +77,9 @@ clr+libs+host+packs clr.nativeaotruntime+clr.nativeaotlibs+mono+libs+host+packs clr.nativeaotruntime+clr.nativeaotlibs+libs+packs + clr.nativeaotruntime+clr.nativeaotlibs+clr+mono+libs+host+packs + clr.nativeaotruntime+clr.nativeaotlibs+clr+libs+host+packs + clr.nativeaotruntime+clr.nativeaotlibs+mono+libs+host+packs clr+libs+tools+host+packs clr+libs+tools+host+packs @@ -384,8 +387,9 @@ --> - <_BuildAnyCrossArch Condition="('$(CrossBuild)' == 'true' or '$(BuildArchitecture)' != '$(TargetArchitecture)' or '$(HostOS)' != '$(TargetOS)' or '$(TargetsLinuxBionic)' == 'true' or '$(EnableNativeSanitizers)' != '')">true + It always targets the bionic libc via the NDK though, so host tools must be built separately. + linux-ohos (HarmonyOS) similarly reports TargetOS as 'linux' and uses its own NDK toolchain. --> + <_BuildAnyCrossArch Condition="('$(CrossBuild)' == 'true' or '$(BuildArchitecture)' != '$(TargetArchitecture)' or '$(HostOS)' != '$(TargetOS)' or '$(TargetsLinuxBionic)' == 'true' or '$(TargetOpenHarmony)' == 'true' or '$(EnableNativeSanitizers)' != '')">true <_BuildCrossComponents Condition="$(_subset.Contains('+clr.crossarchtools+'))">true <_BuildCrossComponents Condition="'$(ClrRuntimeBuildSubsets)' != '' and ('$(PrimaryRuntimeFlavor)' == 'CoreCLR' or '$(TargetsMobile)' == 'true')">true <_CrossBitwidthBuild Condition="'$(BuildArchitecture)' == 'x64' and ('$(TargetArchitecture)' == 'x86' or '$(TargetArchitecture)' == 'arm')">true diff --git a/eng/build.sh b/eng/build.sh index b4496e0bc362f1..c21ae714389875 100755 --- a/eng/build.sh +++ b/eng/build.sh @@ -32,7 +32,7 @@ usage() echo " [Default: Debug]" echo " --os Target operating system: windows, linux, freebsd, osx, maccatalyst, tvos," echo " tvossimulator, ios, iossimulator, android, browser, wasi, netbsd, illumos, solaris" - echo " linux-musl, linux-bionic, tizen, or haiku." + echo " linux-musl, linux-bionic, linux-ohos, tizen, or haiku." echo " [Default: Your machine's OS.]" echo " --targetrid Optional argument that overrides the target rid name." echo " --projects Project or solution file(s) to build." @@ -146,8 +146,9 @@ initDistroRid() local isCrossBuild="$3" # Only pass ROOTFS_DIR if __DoCrossArchBuild is specified and the current platform is not an Apple platform (that doesn't use rootfs) - if [[ $isCrossBuild == 1 && "$targetOs" != "osx" && "$targetOs" != "android" && "$targetOs" != "ios" && "$targetOs" != "iossimulator" && "$targetOs" != "tvos" && "$targetOs" != "tvossimulator" && "$targetOs" != "maccatalyst" ]]; then - passedRootfsDir=${ROOTFS_DIR} + # HarmonyOS uses its NDK toolchain, so no rootfs is required either. + if [[ $isCrossBuild == 1 && "$targetOs" != "osx" && "$targetOs" != "android" && "$targetOs" != "ios" && "$targetOs" != "iossimulator" && "$targetOs" != "tvos" && "$targetOs" != "tvossimulator" && "$targetOs" != "maccatalyst" && "${__PortableTargetOS:-}" != "linux-ohos" ]]; then + passedRootfsDir=${ROOTFS_DIR:-} fi initDistroRidGlobal "${targetOs}" "${targetArch}" "${passedRootfsDir}" } @@ -310,6 +311,10 @@ while [[ $# -gt 0 ]]; do os="linux" __PortableTargetOS=linux-musl ;; + linux-ohos) + os="linux" + __PortableTargetOS=linux-ohos + ;; haiku) os="haiku" ;; *) diff --git a/eng/liveBuilds.targets b/eng/liveBuilds.targets index e494ca933bdbea..b56886ca5e8569 100644 --- a/eng/liveBuilds.targets +++ b/eng/liveBuilds.targets @@ -15,6 +15,7 @@ $([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'artifacts', 'bin', 'coreclr', '$(TargetOS).$(TargetArchitecture).$(CoreCLRConfiguration)')) + $([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'artifacts', 'bin', 'coreclr', 'linux-ohos.$(TargetArchitecture).$(CoreCLRConfiguration)')) $([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'artifacts', 'bin', 'mono', '$(TargetOS).$(TargetArchitecture).$(MonoConfiguration)')) $([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'artifacts')) $([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'artifacts')) diff --git a/eng/native/build-commons.sh b/eng/native/build-commons.sh index fdf156b16fec2e..6409a7efb16728 100755 --- a/eng/native/build-commons.sh +++ b/eng/native/build-commons.sh @@ -7,7 +7,7 @@ initTargetDistroRid() local passedRootfsDir="" # Only pass ROOTFS_DIR if cross is specified and the target platform is not Darwin that doesn't use rootfs - if [[ "$__CrossBuild" == 1 && "$platform" != "darwin" ]]; then + if [[ "$__CrossBuild" == 1 && "$platform" != "darwin" && "$__TargetOS" != "linux-ohos" ]]; then passedRootfsDir="$ROOTFS_DIR" fi @@ -137,6 +137,38 @@ build_native() echo "Error: Unknown Android architecture $hostArch." exit 1 fi + elif [[ "$targetOS" == linux-ohos ]]; then + # HarmonyOS (OpenHarmony) NDK-style toolchain. The OHOS NDK provides its + # own CMake toolchain file (ohos.toolchain.cmake) which sets CMAKE_SYSTEM_NAME=OHOS + # and selects the aarch64/arm/x86_64 linux-ohos clang wrappers + sysroot. + if [[ -z "$OHOS_NDK_HOME" ]]; then + echo "Error: You need to set the OHOS_NDK_HOME environment variable pointing to the HarmonyOS NDK root." + exit 1 + fi + + local ohosToolchainFile="$OHOS_NDK_HOME/native/build/cmake/ohos.toolchain.cmake" + if [[ ! -f "$ohosToolchainFile" ]]; then + echo "Error: OHOS CMake toolchain file not found at $ohosToolchainFile. Verify OHOS_NDK_HOME." + exit 1 + fi + + cmakeArgs="-DCMAKE_TOOLCHAIN_FILE=$ohosToolchainFile $cmakeArgs" + cmakeArgs="-DOHOS_NDK_HOME=$OHOS_NDK_HOME $cmakeArgs" + cmakeArgs="-C $__RepoRootDir/eng/native/tryrun.cmake $cmakeArgs" + + # Don't try to set CC/CXX in init-compiler.sh - it's handled in ohos.toolchain.cmake already + __Compiler="default" + + if [[ "$hostArch" == arm64 ]]; then + cmakeArgs="-DOHOS_ARCH=arm64-v8a $cmakeArgs" + elif [[ "$hostArch" == arm ]]; then + cmakeArgs="-DOHOS_ARCH=armeabi-v7a $cmakeArgs" + elif [[ "$hostArch" == x64 ]]; then + cmakeArgs="-DOHOS_ARCH=x86_64 $cmakeArgs" + else + echo "Error: Unknown OHOS architecture $hostArch." + exit 1 + fi elif [[ "$targetOS" == iossimulator ]]; then cmakeArgs="-C $__RepoRootDir/eng/native/tryrun_ios_tvos.cmake $cmakeArgs" @@ -596,6 +628,9 @@ elif [[ "$__TargetOS" == osx || "$__TargetOS" == maccatalyst ]]; then elif [[ "$__TargetOS" == android ]]; then # nothing to do here true +elif [[ "$__TargetOS" == linux-ohos ]]; then + # HarmonyOS uses its NDK toolchain, no rootfs required + true else __CMakeArgs="-DFEATURE_DISTRO_AGNOSTIC_SSL=$__PortableBuild $__CMakeArgs" fi @@ -604,8 +639,8 @@ fi if [[ "$__CrossBuild" == 1 ]]; then CROSSCOMPILE=1 export CROSSCOMPILE - # Darwin that doesn't use rootfs - if [[ -z "$ROOTFS_DIR" && "$platform" != "darwin" ]]; then + # Darwin that doesn't use rootfs; HarmonyOS uses its NDK toolchain + if [[ -z "$ROOTFS_DIR" && "$platform" != "darwin" && "$__TargetOS" != "linux-ohos" ]]; then ROOTFS_DIR="$__RepoRootDir/.tools/rootfs/$__TargetArch" export ROOTFS_DIR fi diff --git a/eng/native/configurecompiler.cmake b/eng/native/configurecompiler.cmake index bc5fcb1733acb7..55b1bfb309afbf 100644 --- a/eng/native/configurecompiler.cmake +++ b/eng/native/configurecompiler.cmake @@ -653,6 +653,20 @@ if (CLR_CMAKE_HOST_UNIX OR CLR_CMAKE_HOST_WASI) add_compile_options(-fstack-protector-strong) endif() + if(CLR_CMAKE_HOST_OPENHARMONY) + # The OHOS NDK toolchain injects --gcc-toolchain (via CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN) + # which clang reports as unused; silence it (in CMAKE_C_FLAGS so try_compile checks + # inherit it) so -Werror doesn't fail the build. Applies to assembly too. + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Qunused-arguments") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments") + set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Qunused-arguments") + # The arm64 asm helpers access t_ThreadStatics/t_runtime_thread_locals via TLS + # descriptors; the C++ definitions must use native (non-emulated) TLS with the + # global-dynamic model to match. + add_compile_options(-fno-emulated-tls) + add_compile_options(-ftls-model=global-dynamic) + endif() + # Suppress warnings-as-errors in release branches to reduce servicing churn if (PRERELEASE) add_compile_options(-Werror) @@ -845,6 +859,9 @@ if(CLR_CMAKE_TARGET_UNIX) if(CLR_CMAKE_TARGET_LINUX_MUSL) add_compile_definitions($<$>>:TARGET_LINUX_MUSL>) endif() + if(CLR_CMAKE_TARGET_OPENHARMONY) + add_compile_definitions($<$>>:TARGET_OPENHARMONY>) + endif() if(CLR_CMAKE_TARGET_ANDROID) add_compile_definitions($<$>>:TARGET_ANDROID>) endif() diff --git a/eng/native/configureplatform.cmake b/eng/native/configureplatform.cmake index 2ccced093f6b38..f04fba710b8cae 100644 --- a/eng/native/configureplatform.cmake +++ b/eng/native/configureplatform.cmake @@ -11,6 +11,13 @@ set(PRERELEASE 1) #---------------------------------------- set(CLR_CMAKE_HOST_OS ${CMAKE_SYSTEM_NAME}) string(TOLOWER ${CLR_CMAKE_HOST_OS} CLR_CMAKE_HOST_OS) +# HarmonyOS (OpenHarmony) uses the OHOS NDK CMake toolchain which sets +# CMAKE_SYSTEM_NAME=OHOS. Its libc is musl-based, so treat it as a linux/musl target. +if(CLR_CMAKE_HOST_OS STREQUAL ohos) + set(CLR_CMAKE_HOST_OS linux) + set(CLR_CMAKE_HOST_LINUX_MUSL 1) + set(CLR_CMAKE_HOST_OPENHARMONY 1) +endif() if(CLR_CMAKE_HOST_OS STREQUAL linux) set(CLR_CMAKE_HOST_UNIX 1) if(CLR_CROSS_COMPONENTS_BUILD) @@ -357,6 +364,10 @@ if(CLR_CMAKE_HOST_LINUX_MUSL OR CLR_CMAKE_TARGET_OS STREQUAL alpine) set(CLR_CMAKE_TARGET_LINUX_MUSL 1) endif(CLR_CMAKE_HOST_LINUX_MUSL OR CLR_CMAKE_TARGET_OS STREQUAL alpine) +if(CLR_CMAKE_HOST_OPENHARMONY) + set(CLR_CMAKE_TARGET_OPENHARMONY 1) +endif() + macro(set_cache_value) set(${ARGV0} ${ARGV1} CACHE STRING "Result from TRY_RUN" FORCE) set(${ARGV0}__TRYRUN_OUTPUT "dummy output" CACHE STRING "Output from TRY_RUN" FORCE) diff --git a/eng/native/configuretools.cmake b/eng/native/configuretools.cmake index 16d039acc39830..6d3fa2c59799d5 100644 --- a/eng/native/configuretools.cmake +++ b/eng/native/configuretools.cmake @@ -28,11 +28,27 @@ if(NOT WIN32 AND NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI) return() endif() + # For NDK-style toolchains (HarmonyOS) the compiler lives outside PATH. + # Hint find_program at the compiler's directory so tools like llvm-ar/nm are located. + # Guarded to OHOS only so other platforms keep their existing lookup behavior. + if(CLR_CMAKE_HOST_OPENHARMONY) + get_filename_component(CLR_COMPILER_DIR "${CMAKE_C_COMPILER}" DIRECTORY) + endif() + unset(EXEC_LOCATION_${exec} CACHE) - find_program(EXEC_LOCATION_${exec} - NAMES - "${TOOLSET_PREFIX}${exec}${CLR_CMAKE_COMPILER_FILE_NAME_VERSION}" - "${TOOLSET_PREFIX}${exec}") + if(CLR_CMAKE_HOST_OPENHARMONY) + find_program(EXEC_LOCATION_${exec} + NAMES + "${TOOLSET_PREFIX}${exec}${CLR_CMAKE_COMPILER_FILE_NAME_VERSION}" + "${TOOLSET_PREFIX}${exec}" + HINTS + "${CLR_COMPILER_DIR}") + else() + find_program(EXEC_LOCATION_${exec} + NAMES + "${TOOLSET_PREFIX}${exec}${CLR_CMAKE_COMPILER_FILE_NAME_VERSION}" + "${TOOLSET_PREFIX}${exec}") + endif() if (required AND EXEC_LOCATION_${exec} STREQUAL "EXEC_LOCATION_${exec}-NOTFOUND") message(FATAL_ERROR "Unable to find toolchain executable. Name: '${exec}', Prefix: '${TOOLSET_PREFIX}'") diff --git a/eng/native/gen-buildsys.sh b/eng/native/gen-buildsys.sh index 72b82a136ce17d..63c005859df273 100755 --- a/eng/native/gen-buildsys.sh +++ b/eng/native/gen-buildsys.sh @@ -63,8 +63,8 @@ done cmake_extra_defines= if [[ "$CROSSCOMPILE" == "1" ]]; then platform="$(uname -s | tr '[:upper:]' '[:lower:]')" - # OSX doesn't use rootfs - if ! [[ -n "$ROOTFS_DIR" || "$platform" == "darwin" ]]; then + # OSX doesn't use rootfs; HarmonyOS uses its NDK toolchain + if ! [[ -n "$ROOTFS_DIR" || "$platform" == "darwin" || "$target_os" == "linux-ohos" ]]; then echo "ROOTFS_DIR not set for crosscompile" exit 1 fi @@ -76,6 +76,9 @@ if [[ "$CROSSCOMPILE" == "1" ]]; then if [[ "$platform" == "darwin" ]]; then cmake_extra_defines="$cmake_extra_defines -DCMAKE_SYSTEM_NAME=Darwin" + elif [[ "$target_os" == "linux-ohos" ]]; then + # HarmonyOS NDK toolchain is injected by build-commons.sh; do not override it. + true else cmake_extra_defines="$cmake_extra_defines -DCMAKE_TOOLCHAIN_FILE=$scriptroot/../common/cross/toolchain.cmake" fi diff --git a/src/coreclr/clr.featuredefines.props b/src/coreclr/clr.featuredefines.props index 4ce076aabd2fc0..3ca3390d194df5 100644 --- a/src/coreclr/clr.featuredefines.props +++ b/src/coreclr/clr.featuredefines.props @@ -41,7 +41,7 @@ - true + true true diff --git a/src/coreclr/runtime.proj b/src/coreclr/runtime.proj index b20e9a35fc87ab..8cfba3fe01f998 100644 --- a/src/coreclr/runtime.proj +++ b/src/coreclr/runtime.proj @@ -3,6 +3,7 @@ <_BuildNativeTargetOS>$(TargetOS) <_BuildNativeTargetOS Condition="'$(TargetsLinuxBionic)' == 'true'">linux-bionic + <_BuildNativeTargetOS Condition="'$(TargetOpenHarmony)' == 'true'">linux-ohos true GetPgoDataPackagePath $(BuildRuntimeDependsOnTargets);InitializeSourceControlInformationFromSourceControlManager diff --git a/src/native/corehost/corehost.proj b/src/native/corehost/corehost.proj index 05a479acd8884b..118ecf080f422f 100644 --- a/src/native/corehost/corehost.proj +++ b/src/native/corehost/corehost.proj @@ -62,6 +62,7 @@ <_CoreHostUnixTargetOS>$(TargetOS) <_CoreHostUnixTargetOS Condition="'$(TargetsLinuxBionic)' == 'true'">linux-bionic + <_CoreHostUnixTargetOS Condition="'$(TargetOpenHarmony)' == 'true'">linux-ohos $(Configuration) $(TargetArchitecture) -commithash "$([MSBuild]::ValueOrDefault('$(SourceRevisionId)', 'N/A'))" -os $(_CoreHostUnixTargetOS) $(BuildArgs) -cmakeargs "-DVERSION_FILE_PATH=$(NativeVersionFile)" diff --git a/src/native/libs/System.Native/CMakeLists.txt b/src/native/libs/System.Native/CMakeLists.txt index 5930703021940b..8273eb07010019 100644 --- a/src/native/libs/System.Native/CMakeLists.txt +++ b/src/native/libs/System.Native/CMakeLists.txt @@ -57,7 +57,7 @@ else() # WASI ) endif() -if (CLR_CMAKE_TARGET_APPLE OR CLR_CMAKE_TARGET_ANDROID OR CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI OR CLR_CMAKE_TARGET_OPENBSD OR CLR_CMAKE_TARGET_HAIKU) +if (CLR_CMAKE_TARGET_APPLE OR CLR_CMAKE_TARGET_ANDROID OR CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI OR CLR_CMAKE_TARGET_OPENBSD OR CLR_CMAKE_TARGET_HAIKU OR CLR_CMAKE_TARGET_OPENHARMONY) # These platforms do not support robust mutexes. # Keep an OS list instead of CMake configure checks since we also need to synchronize this with # the compile-time guards on the managed code side at diff --git a/src/native/libs/build-native.proj b/src/native/libs/build-native.proj index ac7308eb4e0f25..c202a1400572ac 100644 --- a/src/native/libs/build-native.proj +++ b/src/native/libs/build-native.proj @@ -9,6 +9,7 @@ .NET Runtime <_BuildNativeTargetOS>$(TargetOS) <_BuildNativeTargetOS Condition="'$(TargetsLinuxBionic)' == 'true'">linux-bionic + <_BuildNativeTargetOS Condition="'$(TargetOpenHarmony)' == 'true'">linux-ohos <_BuildNativeOutConfig>$(NetCoreAppCurrent)-$(TargetOS)-$(Configuration)-$(TargetArchitecture) <_BuildNativeArgs>$(TargetArchitecture) $(Configuration) outconfig $(_BuildNativeOutConfig) -os $(_BuildNativeTargetOS) <_BuildNativeArgs Condition="'$(EnableNativeSanitizers)' != ''">$(_BuildNativeArgs) -fsanitize=$(EnableNativeSanitizers) diff --git a/src/native/libs/build-native.sh b/src/native/libs/build-native.sh index 05b77499d7d40a..a6e850daa5873b 100755 --- a/src/native/libs/build-native.sh +++ b/src/native/libs/build-native.sh @@ -58,7 +58,7 @@ else __CMakeArgs="-DFEATURE_DISTRO_AGNOSTIC_SSL=$__PortableBuild $__CMakeArgs" __CMakeArgs="-DCMAKE_STATIC_LIB_LINK=$__StaticLibLink $__CMakeArgs" - if [[ "$__TargetOS" != linux-bionic && "$__TargetArch" != x86 && "$__TargetArch" != x64 && "$__TargetArch" != "$__HostArch" ]]; then + if [[ "$__TargetOS" != linux-bionic && "$__TargetOS" != linux-ohos && "$__TargetArch" != x86 && "$__TargetArch" != x64 && "$__TargetArch" != "$__HostArch" ]]; then __CrossBuild=1 echo "Set CrossBuild for $__TargetArch build" fi From a8160bfd54e246ca64185ba643f888679b5abf86 Mon Sep 17 00:00:00 2001 From: springmin Date: Mon, 31 Aug 2026 09:51:28 +0800 Subject: [PATCH 2/7] Rename TargetOpenHarmony to TargetsOpenHarmony per review --- eng/RuntimeIdentifier.props | 4 ++-- eng/Subsets.props | 10 +++++----- eng/liveBuilds.targets | 2 +- src/coreclr/clr.featuredefines.props | 2 +- src/coreclr/runtime.proj | 2 +- src/native/corehost/corehost.proj | 2 +- src/native/libs/build-native.proj | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/eng/RuntimeIdentifier.props b/eng/RuntimeIdentifier.props index 86a42ce61f074c..3d2589c52b986b 100644 --- a/eng/RuntimeIdentifier.props +++ b/eng/RuntimeIdentifier.props @@ -51,8 +51,8 @@ true true true - true - true + true + true true true true diff --git a/eng/Subsets.props b/eng/Subsets.props index 85846de2c37b11..8ef03f869122b4 100644 --- a/eng/Subsets.props +++ b/eng/Subsets.props @@ -56,7 +56,7 @@ true <_UseNativeAotForComponentsCrossOS Condition="'$(CrossBuild)' == 'true' and '$(_hostArchitecture)' == '$(_targetArchitecture)' and '$(_hostOS)' != 'windows'">true - true + true @@ -77,9 +77,9 @@ clr+libs+host+packs clr.nativeaotruntime+clr.nativeaotlibs+mono+libs+host+packs clr.nativeaotruntime+clr.nativeaotlibs+libs+packs - clr.nativeaotruntime+clr.nativeaotlibs+clr+mono+libs+host+packs - clr.nativeaotruntime+clr.nativeaotlibs+clr+libs+host+packs - clr.nativeaotruntime+clr.nativeaotlibs+mono+libs+host+packs + clr.nativeaotruntime+clr.nativeaotlibs+clr+mono+libs+host+packs + clr.nativeaotruntime+clr.nativeaotlibs+clr+libs+host+packs + clr.nativeaotruntime+clr.nativeaotlibs+mono+libs+host+packs clr+libs+tools+host+packs clr+libs+tools+host+packs @@ -389,7 +389,7 @@ - <_BuildAnyCrossArch Condition="('$(CrossBuild)' == 'true' or '$(BuildArchitecture)' != '$(TargetArchitecture)' or '$(HostOS)' != '$(TargetOS)' or '$(TargetsLinuxBionic)' == 'true' or '$(TargetOpenHarmony)' == 'true' or '$(EnableNativeSanitizers)' != '')">true + <_BuildAnyCrossArch Condition="('$(CrossBuild)' == 'true' or '$(BuildArchitecture)' != '$(TargetArchitecture)' or '$(HostOS)' != '$(TargetOS)' or '$(TargetsLinuxBionic)' == 'true' or '$(TargetsOpenHarmony)' == 'true' or '$(EnableNativeSanitizers)' != '')">true <_BuildCrossComponents Condition="$(_subset.Contains('+clr.crossarchtools+'))">true <_BuildCrossComponents Condition="'$(ClrRuntimeBuildSubsets)' != '' and ('$(PrimaryRuntimeFlavor)' == 'CoreCLR' or '$(TargetsMobile)' == 'true')">true <_CrossBitwidthBuild Condition="'$(BuildArchitecture)' == 'x64' and ('$(TargetArchitecture)' == 'x86' or '$(TargetArchitecture)' == 'arm')">true diff --git a/eng/liveBuilds.targets b/eng/liveBuilds.targets index b56886ca5e8569..7faf8023c9c85e 100644 --- a/eng/liveBuilds.targets +++ b/eng/liveBuilds.targets @@ -15,7 +15,7 @@ $([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'artifacts', 'bin', 'coreclr', '$(TargetOS).$(TargetArchitecture).$(CoreCLRConfiguration)')) - $([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'artifacts', 'bin', 'coreclr', 'linux-ohos.$(TargetArchitecture).$(CoreCLRConfiguration)')) + $([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'artifacts', 'bin', 'coreclr', 'linux-ohos.$(TargetArchitecture).$(CoreCLRConfiguration)')) $([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'artifacts', 'bin', 'mono', '$(TargetOS).$(TargetArchitecture).$(MonoConfiguration)')) $([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'artifacts')) $([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'artifacts')) diff --git a/src/coreclr/clr.featuredefines.props b/src/coreclr/clr.featuredefines.props index 3ca3390d194df5..131a54c1606ddd 100644 --- a/src/coreclr/clr.featuredefines.props +++ b/src/coreclr/clr.featuredefines.props @@ -41,7 +41,7 @@ - true + true true diff --git a/src/coreclr/runtime.proj b/src/coreclr/runtime.proj index 8cfba3fe01f998..674499d2194afd 100644 --- a/src/coreclr/runtime.proj +++ b/src/coreclr/runtime.proj @@ -3,7 +3,7 @@ <_BuildNativeTargetOS>$(TargetOS) <_BuildNativeTargetOS Condition="'$(TargetsLinuxBionic)' == 'true'">linux-bionic - <_BuildNativeTargetOS Condition="'$(TargetOpenHarmony)' == 'true'">linux-ohos + <_BuildNativeTargetOS Condition="'$(TargetsOpenHarmony)' == 'true'">linux-ohos true GetPgoDataPackagePath $(BuildRuntimeDependsOnTargets);InitializeSourceControlInformationFromSourceControlManager diff --git a/src/native/corehost/corehost.proj b/src/native/corehost/corehost.proj index 118ecf080f422f..a43a04446bc5c7 100644 --- a/src/native/corehost/corehost.proj +++ b/src/native/corehost/corehost.proj @@ -62,7 +62,7 @@ <_CoreHostUnixTargetOS>$(TargetOS) <_CoreHostUnixTargetOS Condition="'$(TargetsLinuxBionic)' == 'true'">linux-bionic - <_CoreHostUnixTargetOS Condition="'$(TargetOpenHarmony)' == 'true'">linux-ohos + <_CoreHostUnixTargetOS Condition="'$(TargetsOpenHarmony)' == 'true'">linux-ohos $(Configuration) $(TargetArchitecture) -commithash "$([MSBuild]::ValueOrDefault('$(SourceRevisionId)', 'N/A'))" -os $(_CoreHostUnixTargetOS) $(BuildArgs) -cmakeargs "-DVERSION_FILE_PATH=$(NativeVersionFile)" diff --git a/src/native/libs/build-native.proj b/src/native/libs/build-native.proj index c202a1400572ac..cf0e9018be4564 100644 --- a/src/native/libs/build-native.proj +++ b/src/native/libs/build-native.proj @@ -9,7 +9,7 @@ .NET Runtime <_BuildNativeTargetOS>$(TargetOS) <_BuildNativeTargetOS Condition="'$(TargetsLinuxBionic)' == 'true'">linux-bionic - <_BuildNativeTargetOS Condition="'$(TargetOpenHarmony)' == 'true'">linux-ohos + <_BuildNativeTargetOS Condition="'$(TargetsOpenHarmony)' == 'true'">linux-ohos <_BuildNativeOutConfig>$(NetCoreAppCurrent)-$(TargetOS)-$(Configuration)-$(TargetArchitecture) <_BuildNativeArgs>$(TargetArchitecture) $(Configuration) outconfig $(_BuildNativeOutConfig) -os $(_BuildNativeTargetOS) <_BuildNativeArgs Condition="'$(EnableNativeSanitizers)' != ''">$(_BuildNativeArgs) -fsanitize=$(EnableNativeSanitizers) From cda829627843896f2e7f116478622cf0e5bcf0fa Mon Sep 17 00:00:00 2001 From: springmin Date: Tue, 1 Sep 2026 22:48:05 +0800 Subject: [PATCH 3/7] Rename RID linux-ohos to ohos (kernel-agnostic, per jkoritzinsky decision) --- eng/RuntimeIdentifier.props | 4 ++-- eng/Subsets.props | 4 +--- eng/build.sh | 14 ++++++++++---- eng/liveBuilds.targets | 2 +- eng/native/build-commons.sh | 10 +++++----- eng/native/gen-buildsys.sh | 4 ++-- src/coreclr/runtime.proj | 2 +- src/native/corehost/corehost.proj | 2 +- src/native/libs/build-native.proj | 2 +- src/native/libs/build-native.sh | 2 +- 10 files changed, 25 insertions(+), 21 deletions(-) diff --git a/eng/RuntimeIdentifier.props b/eng/RuntimeIdentifier.props index 3d2589c52b986b..d4cedf17090ad4 100644 --- a/eng/RuntimeIdentifier.props +++ b/eng/RuntimeIdentifier.props @@ -19,7 +19,7 @@ linux-musl linux-bionic - linux-ohos + ohos $(PortableOS)-$(TargetArchitecture) @@ -51,7 +51,7 @@ true true true - true + true true true true diff --git a/eng/Subsets.props b/eng/Subsets.props index 8ef03f869122b4..0d148a8f599313 100644 --- a/eng/Subsets.props +++ b/eng/Subsets.props @@ -388,7 +388,7 @@ + ohos (HarmonyOS) similarly reports TargetOS as 'linux' and uses its own NDK toolchain. --> <_BuildAnyCrossArch Condition="('$(CrossBuild)' == 'true' or '$(BuildArchitecture)' != '$(TargetArchitecture)' or '$(HostOS)' != '$(TargetOS)' or '$(TargetsLinuxBionic)' == 'true' or '$(TargetsOpenHarmony)' == 'true' or '$(EnableNativeSanitizers)' != '')">true <_BuildCrossComponents Condition="$(_subset.Contains('+clr.crossarchtools+'))">true <_BuildCrossComponents Condition="'$(ClrRuntimeBuildSubsets)' != '' and ('$(PrimaryRuntimeFlavor)' == 'CoreCLR' or '$(TargetsMobile)' == 'true')">true @@ -517,8 +517,6 @@ - Optional argument that overrides the target rid name." echo " --projects Project or solution file(s) to build." @@ -147,7 +147,7 @@ initDistroRid() # Only pass ROOTFS_DIR if __DoCrossArchBuild is specified and the current platform is not an Apple platform (that doesn't use rootfs) # HarmonyOS uses its NDK toolchain, so no rootfs is required either. - if [[ $isCrossBuild == 1 && "$targetOs" != "osx" && "$targetOs" != "android" && "$targetOs" != "ios" && "$targetOs" != "iossimulator" && "$targetOs" != "tvos" && "$targetOs" != "tvossimulator" && "$targetOs" != "maccatalyst" && "${__PortableTargetOS:-}" != "linux-ohos" ]]; then + if [[ $isCrossBuild == 1 && "$targetOs" != "osx" && "$targetOs" != "android" && "$targetOs" != "ios" && "$targetOs" != "iossimulator" && "$targetOs" != "tvos" && "$targetOs" != "tvossimulator" && "$targetOs" != "maccatalyst" && "${__PortableTargetOS:-}" != "ohos" ]]; then passedRootfsDir=${ROOTFS_DIR:-} fi initDistroRidGlobal "${targetOs}" "${targetArch}" "${passedRootfsDir}" @@ -311,9 +311,9 @@ while [[ $# -gt 0 ]]; do os="linux" __PortableTargetOS=linux-musl ;; - linux-ohos) + ohos) os="linux" - __PortableTargetOS=linux-ohos + __PortableTargetOS=ohos ;; haiku) os="haiku" ;; @@ -631,6 +631,12 @@ export DOTNETSDK_ALLOW_TARGETING_PACK_CACHING=0 # In *proj files (XML docs), URL-encoded string are rendered in their decoded form. cmakeargs="${cmakeargs// /%20}" arguments+=("/p:TargetArchitecture=$arch" "/p:BuildArchitecture=$hostArch") +# Propagate the portable target OS (e.g. 'ohos', 'linux-musl', 'linux-bionic') to MSBuild. +# TargetOS stays 'linux' for these flavors; PortableOS in RuntimeIdentifier.props +# derives from __PortableTargetOS, and downstream (packaging, live builds) relies on it. +if [[ -n "${__PortableTargetOS:-}" ]]; then + arguments+=("/p:__PortableTargetOS=$__PortableTargetOS") +fi arguments+=("/p:CMakeArgs=\"$cmakeargs\"" ${extraargs[@]+"${extraargs[@]}"}) if [[ "$bootstrap" == "1" ]]; then diff --git a/eng/liveBuilds.targets b/eng/liveBuilds.targets index 7faf8023c9c85e..406d0bf3ebeb89 100644 --- a/eng/liveBuilds.targets +++ b/eng/liveBuilds.targets @@ -15,7 +15,7 @@ $([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'artifacts', 'bin', 'coreclr', '$(TargetOS).$(TargetArchitecture).$(CoreCLRConfiguration)')) - $([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'artifacts', 'bin', 'coreclr', 'linux-ohos.$(TargetArchitecture).$(CoreCLRConfiguration)')) + $([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'artifacts', 'bin', 'coreclr', 'ohos.$(TargetArchitecture).$(CoreCLRConfiguration)')) $([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'artifacts', 'bin', 'mono', '$(TargetOS).$(TargetArchitecture).$(MonoConfiguration)')) $([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'artifacts')) $([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'artifacts')) diff --git a/eng/native/build-commons.sh b/eng/native/build-commons.sh index 6409a7efb16728..015df6a87888e2 100755 --- a/eng/native/build-commons.sh +++ b/eng/native/build-commons.sh @@ -7,7 +7,7 @@ initTargetDistroRid() local passedRootfsDir="" # Only pass ROOTFS_DIR if cross is specified and the target platform is not Darwin that doesn't use rootfs - if [[ "$__CrossBuild" == 1 && "$platform" != "darwin" && "$__TargetOS" != "linux-ohos" ]]; then + if [[ "$__CrossBuild" == 1 && "$platform" != "darwin" && "$__TargetOS" != "ohos" ]]; then passedRootfsDir="$ROOTFS_DIR" fi @@ -137,10 +137,10 @@ build_native() echo "Error: Unknown Android architecture $hostArch." exit 1 fi - elif [[ "$targetOS" == linux-ohos ]]; then + elif [[ "$targetOS" == ohos ]]; then # HarmonyOS (OpenHarmony) NDK-style toolchain. The OHOS NDK provides its # own CMake toolchain file (ohos.toolchain.cmake) which sets CMAKE_SYSTEM_NAME=OHOS - # and selects the aarch64/arm/x86_64 linux-ohos clang wrappers + sysroot. + # and selects the aarch64/arm/x86_64 ohos clang wrappers + sysroot. if [[ -z "$OHOS_NDK_HOME" ]]; then echo "Error: You need to set the OHOS_NDK_HOME environment variable pointing to the HarmonyOS NDK root." exit 1 @@ -628,7 +628,7 @@ elif [[ "$__TargetOS" == osx || "$__TargetOS" == maccatalyst ]]; then elif [[ "$__TargetOS" == android ]]; then # nothing to do here true -elif [[ "$__TargetOS" == linux-ohos ]]; then +elif [[ "$__TargetOS" == ohos ]]; then # HarmonyOS uses its NDK toolchain, no rootfs required true else @@ -640,7 +640,7 @@ if [[ "$__CrossBuild" == 1 ]]; then CROSSCOMPILE=1 export CROSSCOMPILE # Darwin that doesn't use rootfs; HarmonyOS uses its NDK toolchain - if [[ -z "$ROOTFS_DIR" && "$platform" != "darwin" && "$__TargetOS" != "linux-ohos" ]]; then + if [[ -z "$ROOTFS_DIR" && "$platform" != "darwin" && "$__TargetOS" != "ohos" ]]; then ROOTFS_DIR="$__RepoRootDir/.tools/rootfs/$__TargetArch" export ROOTFS_DIR fi diff --git a/eng/native/gen-buildsys.sh b/eng/native/gen-buildsys.sh index 63c005859df273..79f3863245a14b 100755 --- a/eng/native/gen-buildsys.sh +++ b/eng/native/gen-buildsys.sh @@ -64,7 +64,7 @@ cmake_extra_defines= if [[ "$CROSSCOMPILE" == "1" ]]; then platform="$(uname -s | tr '[:upper:]' '[:lower:]')" # OSX doesn't use rootfs; HarmonyOS uses its NDK toolchain - if ! [[ -n "$ROOTFS_DIR" || "$platform" == "darwin" || "$target_os" == "linux-ohos" ]]; then + if ! [[ -n "$ROOTFS_DIR" || "$platform" == "darwin" || "$target_os" == "ohos" ]]; then echo "ROOTFS_DIR not set for crosscompile" exit 1 fi @@ -76,7 +76,7 @@ if [[ "$CROSSCOMPILE" == "1" ]]; then if [[ "$platform" == "darwin" ]]; then cmake_extra_defines="$cmake_extra_defines -DCMAKE_SYSTEM_NAME=Darwin" - elif [[ "$target_os" == "linux-ohos" ]]; then + elif [[ "$target_os" == "ohos" ]]; then # HarmonyOS NDK toolchain is injected by build-commons.sh; do not override it. true else diff --git a/src/coreclr/runtime.proj b/src/coreclr/runtime.proj index 674499d2194afd..a0d3b5c0707eb1 100644 --- a/src/coreclr/runtime.proj +++ b/src/coreclr/runtime.proj @@ -3,7 +3,7 @@ <_BuildNativeTargetOS>$(TargetOS) <_BuildNativeTargetOS Condition="'$(TargetsLinuxBionic)' == 'true'">linux-bionic - <_BuildNativeTargetOS Condition="'$(TargetsOpenHarmony)' == 'true'">linux-ohos + <_BuildNativeTargetOS Condition="'$(TargetsOpenHarmony)' == 'true'">ohos true GetPgoDataPackagePath $(BuildRuntimeDependsOnTargets);InitializeSourceControlInformationFromSourceControlManager diff --git a/src/native/corehost/corehost.proj b/src/native/corehost/corehost.proj index a43a04446bc5c7..3c59d7118cfa41 100644 --- a/src/native/corehost/corehost.proj +++ b/src/native/corehost/corehost.proj @@ -62,7 +62,7 @@ <_CoreHostUnixTargetOS>$(TargetOS) <_CoreHostUnixTargetOS Condition="'$(TargetsLinuxBionic)' == 'true'">linux-bionic - <_CoreHostUnixTargetOS Condition="'$(TargetsOpenHarmony)' == 'true'">linux-ohos + <_CoreHostUnixTargetOS Condition="'$(TargetsOpenHarmony)' == 'true'">ohos $(Configuration) $(TargetArchitecture) -commithash "$([MSBuild]::ValueOrDefault('$(SourceRevisionId)', 'N/A'))" -os $(_CoreHostUnixTargetOS) $(BuildArgs) -cmakeargs "-DVERSION_FILE_PATH=$(NativeVersionFile)" diff --git a/src/native/libs/build-native.proj b/src/native/libs/build-native.proj index cf0e9018be4564..0b8f351268a611 100644 --- a/src/native/libs/build-native.proj +++ b/src/native/libs/build-native.proj @@ -9,7 +9,7 @@ .NET Runtime <_BuildNativeTargetOS>$(TargetOS) <_BuildNativeTargetOS Condition="'$(TargetsLinuxBionic)' == 'true'">linux-bionic - <_BuildNativeTargetOS Condition="'$(TargetsOpenHarmony)' == 'true'">linux-ohos + <_BuildNativeTargetOS Condition="'$(TargetsOpenHarmony)' == 'true'">ohos <_BuildNativeOutConfig>$(NetCoreAppCurrent)-$(TargetOS)-$(Configuration)-$(TargetArchitecture) <_BuildNativeArgs>$(TargetArchitecture) $(Configuration) outconfig $(_BuildNativeOutConfig) -os $(_BuildNativeTargetOS) <_BuildNativeArgs Condition="'$(EnableNativeSanitizers)' != ''">$(_BuildNativeArgs) -fsanitize=$(EnableNativeSanitizers) diff --git a/src/native/libs/build-native.sh b/src/native/libs/build-native.sh index a6e850daa5873b..77a616cd9c0ec0 100755 --- a/src/native/libs/build-native.sh +++ b/src/native/libs/build-native.sh @@ -58,7 +58,7 @@ else __CMakeArgs="-DFEATURE_DISTRO_AGNOSTIC_SSL=$__PortableBuild $__CMakeArgs" __CMakeArgs="-DCMAKE_STATIC_LIB_LINK=$__StaticLibLink $__CMakeArgs" - if [[ "$__TargetOS" != linux-bionic && "$__TargetOS" != linux-ohos && "$__TargetArch" != x86 && "$__TargetArch" != x64 && "$__TargetArch" != "$__HostArch" ]]; then + if [[ "$__TargetOS" != linux-bionic && "$__TargetOS" != ohos && "$__TargetArch" != x86 && "$__TargetArch" != x64 && "$__TargetArch" != "$__HostArch" ]]; then __CrossBuild=1 echo "Set CrossBuild for $__TargetArch build" fi From d6dfed1d4bd2ca02285c1e07e531b715c1bf3166 Mon Sep 17 00:00:00 2001 From: springmin Date: Tue, 1 Sep 2026 23:09:55 +0800 Subject: [PATCH 4/7] Refer to OpenHarmony (not HarmonyOS) in comments per review --- eng/Subsets.props | 2 +- eng/build.sh | 2 +- eng/native/build-commons.sh | 8 ++++---- eng/native/configureplatform.cmake | 2 +- eng/native/configuretools.cmake | 2 +- eng/native/gen-buildsys.sh | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/eng/Subsets.props b/eng/Subsets.props index 0d148a8f599313..98aaf2aeb2d4e0 100644 --- a/eng/Subsets.props +++ b/eng/Subsets.props @@ -388,7 +388,7 @@ + ohos (OpenHarmony) similarly reports TargetOS as 'linux' and uses its own NDK toolchain. --> <_BuildAnyCrossArch Condition="('$(CrossBuild)' == 'true' or '$(BuildArchitecture)' != '$(TargetArchitecture)' or '$(HostOS)' != '$(TargetOS)' or '$(TargetsLinuxBionic)' == 'true' or '$(TargetsOpenHarmony)' == 'true' or '$(EnableNativeSanitizers)' != '')">true <_BuildCrossComponents Condition="$(_subset.Contains('+clr.crossarchtools+'))">true <_BuildCrossComponents Condition="'$(ClrRuntimeBuildSubsets)' != '' and ('$(PrimaryRuntimeFlavor)' == 'CoreCLR' or '$(TargetsMobile)' == 'true')">true diff --git a/eng/build.sh b/eng/build.sh index 14dcbaa021679c..222cd84bea1070 100755 --- a/eng/build.sh +++ b/eng/build.sh @@ -146,7 +146,7 @@ initDistroRid() local isCrossBuild="$3" # Only pass ROOTFS_DIR if __DoCrossArchBuild is specified and the current platform is not an Apple platform (that doesn't use rootfs) - # HarmonyOS uses its NDK toolchain, so no rootfs is required either. + # OpenHarmony uses its NDK toolchain, so no rootfs is required either. if [[ $isCrossBuild == 1 && "$targetOs" != "osx" && "$targetOs" != "android" && "$targetOs" != "ios" && "$targetOs" != "iossimulator" && "$targetOs" != "tvos" && "$targetOs" != "tvossimulator" && "$targetOs" != "maccatalyst" && "${__PortableTargetOS:-}" != "ohos" ]]; then passedRootfsDir=${ROOTFS_DIR:-} fi diff --git a/eng/native/build-commons.sh b/eng/native/build-commons.sh index 015df6a87888e2..657906c9353dbf 100755 --- a/eng/native/build-commons.sh +++ b/eng/native/build-commons.sh @@ -138,11 +138,11 @@ build_native() exit 1 fi elif [[ "$targetOS" == ohos ]]; then - # HarmonyOS (OpenHarmony) NDK-style toolchain. The OHOS NDK provides its + # OpenHarmony NDK-style toolchain. The OHOS NDK provides its # own CMake toolchain file (ohos.toolchain.cmake) which sets CMAKE_SYSTEM_NAME=OHOS # and selects the aarch64/arm/x86_64 ohos clang wrappers + sysroot. if [[ -z "$OHOS_NDK_HOME" ]]; then - echo "Error: You need to set the OHOS_NDK_HOME environment variable pointing to the HarmonyOS NDK root." + echo "Error: You need to set the OHOS_NDK_HOME environment variable pointing to the OpenHarmony NDK root." exit 1 fi @@ -629,7 +629,7 @@ elif [[ "$__TargetOS" == android ]]; then # nothing to do here true elif [[ "$__TargetOS" == ohos ]]; then - # HarmonyOS uses its NDK toolchain, no rootfs required + # OpenHarmony uses its NDK toolchain, no rootfs required true else __CMakeArgs="-DFEATURE_DISTRO_AGNOSTIC_SSL=$__PortableBuild $__CMakeArgs" @@ -639,7 +639,7 @@ fi if [[ "$__CrossBuild" == 1 ]]; then CROSSCOMPILE=1 export CROSSCOMPILE - # Darwin that doesn't use rootfs; HarmonyOS uses its NDK toolchain + # Darwin that doesn't use rootfs; OpenHarmony uses its NDK toolchain if [[ -z "$ROOTFS_DIR" && "$platform" != "darwin" && "$__TargetOS" != "ohos" ]]; then ROOTFS_DIR="$__RepoRootDir/.tools/rootfs/$__TargetArch" export ROOTFS_DIR diff --git a/eng/native/configureplatform.cmake b/eng/native/configureplatform.cmake index f04fba710b8cae..700e508c84f5f8 100644 --- a/eng/native/configureplatform.cmake +++ b/eng/native/configureplatform.cmake @@ -11,7 +11,7 @@ set(PRERELEASE 1) #---------------------------------------- set(CLR_CMAKE_HOST_OS ${CMAKE_SYSTEM_NAME}) string(TOLOWER ${CLR_CMAKE_HOST_OS} CLR_CMAKE_HOST_OS) -# HarmonyOS (OpenHarmony) uses the OHOS NDK CMake toolchain which sets +# OpenHarmony uses the OHOS NDK CMake toolchain which sets # CMAKE_SYSTEM_NAME=OHOS. Its libc is musl-based, so treat it as a linux/musl target. if(CLR_CMAKE_HOST_OS STREQUAL ohos) set(CLR_CMAKE_HOST_OS linux) diff --git a/eng/native/configuretools.cmake b/eng/native/configuretools.cmake index 6d3fa2c59799d5..555c35f5ca035e 100644 --- a/eng/native/configuretools.cmake +++ b/eng/native/configuretools.cmake @@ -28,7 +28,7 @@ if(NOT WIN32 AND NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI) return() endif() - # For NDK-style toolchains (HarmonyOS) the compiler lives outside PATH. + # For NDK-style toolchains (OpenHarmony) the compiler lives outside PATH. # Hint find_program at the compiler's directory so tools like llvm-ar/nm are located. # Guarded to OHOS only so other platforms keep their existing lookup behavior. if(CLR_CMAKE_HOST_OPENHARMONY) diff --git a/eng/native/gen-buildsys.sh b/eng/native/gen-buildsys.sh index 79f3863245a14b..087353cd3feac0 100755 --- a/eng/native/gen-buildsys.sh +++ b/eng/native/gen-buildsys.sh @@ -63,7 +63,7 @@ done cmake_extra_defines= if [[ "$CROSSCOMPILE" == "1" ]]; then platform="$(uname -s | tr '[:upper:]' '[:lower:]')" - # OSX doesn't use rootfs; HarmonyOS uses its NDK toolchain + # OSX doesn't use rootfs; OpenHarmony uses its NDK toolchain if ! [[ -n "$ROOTFS_DIR" || "$platform" == "darwin" || "$target_os" == "ohos" ]]; then echo "ROOTFS_DIR not set for crosscompile" exit 1 @@ -77,7 +77,7 @@ if [[ "$CROSSCOMPILE" == "1" ]]; then if [[ "$platform" == "darwin" ]]; then cmake_extra_defines="$cmake_extra_defines -DCMAKE_SYSTEM_NAME=Darwin" elif [[ "$target_os" == "ohos" ]]; then - # HarmonyOS NDK toolchain is injected by build-commons.sh; do not override it. + # OpenHarmony NDK toolchain is injected by build-commons.sh; do not override it. true else cmake_extra_defines="$cmake_extra_defines -DCMAKE_TOOLCHAIN_FILE=$scriptroot/../common/cross/toolchain.cmake" From ce1cbb893af0c1205a71e0bb74d4d9fcce54140a Mon Sep 17 00:00:00 2001 From: springmin Date: Wed, 2 Sep 2026 14:39:44 +0800 Subject: [PATCH 5/7] Restore ILCompiler.DependencyAnalysisFramework.Tests in clr.toolstests subset --- eng/Subsets.props | 2 ++ 1 file changed, 2 insertions(+) diff --git a/eng/Subsets.props b/eng/Subsets.props index 98aaf2aeb2d4e0..7eb49b926adc13 100644 --- a/eng/Subsets.props +++ b/eng/Subsets.props @@ -517,6 +517,8 @@ + Date: Wed, 2 Sep 2026 15:32:54 +0800 Subject: [PATCH 6/7] Simplify OHOS DefaultSubsets: CoreCLR+NativeAOT only, no Mono variants (per review) --- eng/Subsets.props | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/eng/Subsets.props b/eng/Subsets.props index 7eb49b926adc13..84595a388ae7ce 100644 --- a/eng/Subsets.props +++ b/eng/Subsets.props @@ -77,9 +77,8 @@ clr+libs+host+packs clr.nativeaotruntime+clr.nativeaotlibs+mono+libs+host+packs clr.nativeaotruntime+clr.nativeaotlibs+libs+packs - clr.nativeaotruntime+clr.nativeaotlibs+clr+mono+libs+host+packs - clr.nativeaotruntime+clr.nativeaotlibs+clr+libs+host+packs - clr.nativeaotruntime+clr.nativeaotlibs+mono+libs+host+packs + + clr.nativeaotruntime+clr.nativeaotlibs+clr+libs+host+packs clr+libs+tools+host+packs clr+libs+tools+host+packs From 155df040d43cb3a6459ae01e707f3f4774d2cc90 Mon Sep 17 00:00:00 2001 From: springmin Date: Wed, 2 Sep 2026 15:47:17 +0800 Subject: [PATCH 7/7] Set TargetOS to ohos natively; drop now-unnecessary path/OS overrides (per review) --- eng/RuntimeIdentifier.props | 8 ++++++-- eng/Subsets.props | 5 ++--- eng/build.sh | 2 +- eng/liveBuilds.targets | 1 - src/coreclr/clr.featuredefines.props | 2 +- src/coreclr/runtime.proj | 1 - src/native/corehost/corehost.proj | 1 - src/native/libs/build-native.proj | 1 - 8 files changed, 10 insertions(+), 11 deletions(-) diff --git a/eng/RuntimeIdentifier.props b/eng/RuntimeIdentifier.props index d4cedf17090ad4..7a85c173a61d6a 100644 --- a/eng/RuntimeIdentifier.props +++ b/eng/RuntimeIdentifier.props @@ -8,7 +8,9 @@ + And, for flavors of Linux, like 'linux-musl' and 'linux-bionic', TargetOS is 'linux'. + ohos is an exception: its RID is kernel-agnostic, so TargetOS is 'ohos' (not 'linux'), + and it opts into the Linux family flags explicitly below. --> $(TargetOS.ToLowerInvariant()) win @@ -48,7 +50,9 @@ true true true - true + + true true true true diff --git a/eng/Subsets.props b/eng/Subsets.props index 84595a388ae7ce..3c20c2eb937d59 100644 --- a/eng/Subsets.props +++ b/eng/Subsets.props @@ -386,9 +386,8 @@ --> - <_BuildAnyCrossArch Condition="('$(CrossBuild)' == 'true' or '$(BuildArchitecture)' != '$(TargetArchitecture)' or '$(HostOS)' != '$(TargetOS)' or '$(TargetsLinuxBionic)' == 'true' or '$(TargetsOpenHarmony)' == 'true' or '$(EnableNativeSanitizers)' != '')">true + It always targets the bionic libc via the NDK though, so host tools must be built separately. --> + <_BuildAnyCrossArch Condition="('$(CrossBuild)' == 'true' or '$(BuildArchitecture)' != '$(TargetArchitecture)' or '$(HostOS)' != '$(TargetOS)' or '$(TargetsLinuxBionic)' == 'true' or '$(EnableNativeSanitizers)' != '')">true <_BuildCrossComponents Condition="$(_subset.Contains('+clr.crossarchtools+'))">true <_BuildCrossComponents Condition="'$(ClrRuntimeBuildSubsets)' != '' and ('$(PrimaryRuntimeFlavor)' == 'CoreCLR' or '$(TargetsMobile)' == 'true')">true <_CrossBitwidthBuild Condition="'$(BuildArchitecture)' == 'x64' and ('$(TargetArchitecture)' == 'x86' or '$(TargetArchitecture)' == 'arm')">true diff --git a/eng/build.sh b/eng/build.sh index 222cd84bea1070..f0b85a3f45c379 100755 --- a/eng/build.sh +++ b/eng/build.sh @@ -312,7 +312,7 @@ while [[ $# -gt 0 ]]; do __PortableTargetOS=linux-musl ;; ohos) - os="linux" + os="ohos" __PortableTargetOS=ohos ;; haiku) diff --git a/eng/liveBuilds.targets b/eng/liveBuilds.targets index 406d0bf3ebeb89..e494ca933bdbea 100644 --- a/eng/liveBuilds.targets +++ b/eng/liveBuilds.targets @@ -15,7 +15,6 @@ $([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'artifacts', 'bin', 'coreclr', '$(TargetOS).$(TargetArchitecture).$(CoreCLRConfiguration)')) - $([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'artifacts', 'bin', 'coreclr', 'ohos.$(TargetArchitecture).$(CoreCLRConfiguration)')) $([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'artifacts', 'bin', 'mono', '$(TargetOS).$(TargetArchitecture).$(MonoConfiguration)')) $([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'artifacts')) $([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'artifacts')) diff --git a/src/coreclr/clr.featuredefines.props b/src/coreclr/clr.featuredefines.props index 131a54c1606ddd..4ce076aabd2fc0 100644 --- a/src/coreclr/clr.featuredefines.props +++ b/src/coreclr/clr.featuredefines.props @@ -41,7 +41,7 @@ - true + true true diff --git a/src/coreclr/runtime.proj b/src/coreclr/runtime.proj index a0d3b5c0707eb1..b20e9a35fc87ab 100644 --- a/src/coreclr/runtime.proj +++ b/src/coreclr/runtime.proj @@ -3,7 +3,6 @@ <_BuildNativeTargetOS>$(TargetOS) <_BuildNativeTargetOS Condition="'$(TargetsLinuxBionic)' == 'true'">linux-bionic - <_BuildNativeTargetOS Condition="'$(TargetsOpenHarmony)' == 'true'">ohos true GetPgoDataPackagePath $(BuildRuntimeDependsOnTargets);InitializeSourceControlInformationFromSourceControlManager diff --git a/src/native/corehost/corehost.proj b/src/native/corehost/corehost.proj index 3c59d7118cfa41..05a479acd8884b 100644 --- a/src/native/corehost/corehost.proj +++ b/src/native/corehost/corehost.proj @@ -62,7 +62,6 @@ <_CoreHostUnixTargetOS>$(TargetOS) <_CoreHostUnixTargetOS Condition="'$(TargetsLinuxBionic)' == 'true'">linux-bionic - <_CoreHostUnixTargetOS Condition="'$(TargetsOpenHarmony)' == 'true'">ohos $(Configuration) $(TargetArchitecture) -commithash "$([MSBuild]::ValueOrDefault('$(SourceRevisionId)', 'N/A'))" -os $(_CoreHostUnixTargetOS) $(BuildArgs) -cmakeargs "-DVERSION_FILE_PATH=$(NativeVersionFile)" diff --git a/src/native/libs/build-native.proj b/src/native/libs/build-native.proj index 0b8f351268a611..ac7308eb4e0f25 100644 --- a/src/native/libs/build-native.proj +++ b/src/native/libs/build-native.proj @@ -9,7 +9,6 @@ .NET Runtime <_BuildNativeTargetOS>$(TargetOS) <_BuildNativeTargetOS Condition="'$(TargetsLinuxBionic)' == 'true'">linux-bionic - <_BuildNativeTargetOS Condition="'$(TargetsOpenHarmony)' == 'true'">ohos <_BuildNativeOutConfig>$(NetCoreAppCurrent)-$(TargetOS)-$(Configuration)-$(TargetArchitecture) <_BuildNativeArgs>$(TargetArchitecture) $(Configuration) outconfig $(_BuildNativeOutConfig) -os $(_BuildNativeTargetOS) <_BuildNativeArgs Condition="'$(EnableNativeSanitizers)' != ''">$(_BuildNativeArgs) -fsanitize=$(EnableNativeSanitizers)