diff --git a/eng/native/build-commons.sh b/eng/native/build-commons.sh index f571bccdcecfd..a1f8f550cdc8b 100755 --- a/eng/native/build-commons.sh +++ b/eng/native/build-commons.sh @@ -542,3 +542,6 @@ initTargetDistroRid if [ -z "$__OutputRid" ]; then __OutputRid="$(echo $__DistroRid | tr '[:upper:]' '[:lower:]')" fi + +# When the host runs on an unknown rid, it falls back to the output rid +__HostFallbackOS="${__OutputRid%-*}" # Strip architecture diff --git a/src/coreclr/build-runtime.cmd b/src/coreclr/build-runtime.cmd index 9086bcb0f7d5d..a8fca255b8611 100644 --- a/src/coreclr/build-runtime.cmd +++ b/src/coreclr/build-runtime.cmd @@ -70,6 +70,7 @@ set __PgoOptDataPath= set __CMakeArgs= set __Ninja=1 set __RequestedBuildComponents= +set __OutputRid= :Arg_Loop if "%1" == "" goto ArgsDone @@ -128,6 +129,7 @@ if [!__PassThroughArgs!]==[] ( if /i "%1" == "-hostarch" (set __HostArch=%2&shift&shift&goto Arg_Loop) if /i "%1" == "-os" (set __TargetOS=%2&shift&shift&goto Arg_Loop) +if /i "%1" == "-outputrid" (set __OutputRid=%2&shift&shift&goto Arg_Loop) if /i "%1" == "-cmakeargs" (set __CMakeArgs=%2 %__CMakeArgs%&set __remainingArgs="!__remainingArgs:*%2=!"&shift&shift&goto Arg_Loop) if /i "%1" == "-configureonly" (set __ConfigureOnly=1&set __BuildNative=1&shift&goto Arg_Loop) @@ -327,6 +329,14 @@ REM === Build Native assets including CLR runtime REM === REM ========================================================================================= +:: When the host runs on an unknown rid, it falls back to the output rid +:: Strip the architecture +for /f "delims=-" %%i in ("%__OutputRid%") do set __HostFallbackOS=%%i +:: The "win" host build is Windows 10 compatible +if "%__HostFallbackOS%" == "win" (set __HostFallbackOS=win10) +:: Default to "win10" fallback +if "%__HostFallbackOS%" == "" (set __HostFallbackOS=win10) + if %__BuildNative% EQU 1 ( REM Scope environment changes start { setlocal @@ -355,7 +365,7 @@ if %__BuildNative% EQU 1 ( set __ExtraCmakeArgs="-DCMAKE_BUILD_TYPE=!__BuildType!" ) - set __ExtraCmakeArgs=!__ExtraCmakeArgs! "-DCLR_CMAKE_TARGET_ARCH=%__TargetArch%" "-DCLR_CMAKE_TARGET_OS=%__TargetOS%" "-DCLR_CMAKE_PGO_INSTRUMENT=%__PgoInstrument%" "-DCLR_CMAKE_OPTDATA_PATH=%__PgoOptDataPath%" "-DCLR_CMAKE_PGO_OPTIMIZE=%__PgoOptimize%" %__CMakeArgs% + set __ExtraCmakeArgs=!__ExtraCmakeArgs! "-DCLR_CMAKE_TARGET_ARCH=%__TargetArch%" "-DCLR_CMAKE_TARGET_OS=%__TargetOS%" "-DCLI_CMAKE_FALLBACK_OS=%__HostFallbackOS%" "-DCLR_CMAKE_PGO_INSTRUMENT=%__PgoInstrument%" "-DCLR_CMAKE_OPTDATA_PATH=%__PgoOptDataPath%" "-DCLR_CMAKE_PGO_OPTIMIZE=%__PgoOptimize%" %__CMakeArgs% echo Calling "%__RepoRootDir%\eng\native\gen-buildsys.cmd" "%__ProjectDir%" "%__IntermediatesDir%" %__VSVersion% %__HostArch% %__TargetOS% !__ExtraCmakeArgs! call "%__RepoRootDir%\eng\native\gen-buildsys.cmd" "%__ProjectDir%" "%__IntermediatesDir%" %__VSVersion% %__HostArch% %__TargetOS% !__ExtraCmakeArgs! if not !errorlevel! == 0 ( diff --git a/src/coreclr/build-runtime.sh b/src/coreclr/build-runtime.sh index f7474ad2350f4..7399088f291d9 100755 --- a/src/coreclr/build-runtime.sh +++ b/src/coreclr/build-runtime.sh @@ -146,7 +146,7 @@ export MSBUILDDEBUGPATH check_prereqs # Build the coreclr (native) components. -__CMakeArgs="-DCLR_CMAKE_PGO_INSTRUMENT=$__PgoInstrument -DCLR_CMAKE_OPTDATA_PATH=$__PgoOptDataPath -DCLR_CMAKE_PGO_OPTIMIZE=$__PgoOptimize $__CMakeArgs" +__CMakeArgs="-DCLR_CMAKE_PGO_INSTRUMENT=$__PgoInstrument -DCLR_CMAKE_OPTDATA_PATH=$__PgoOptDataPath -DCLR_CMAKE_PGO_OPTIMIZE=$__PgoOptimize -DCLI_CMAKE_FALLBACK_OS=\"$__HostFallbackOS\" $__CMakeArgs" if [[ "$__SkipConfigure" == 0 && "$__CodeCoverage" == 1 ]]; then __CMakeArgs="-DCLR_CMAKE_ENABLE_CODE_COVERAGE=1 $__CMakeArgs" diff --git a/src/coreclr/runtime.proj b/src/coreclr/runtime.proj index 6dd2e17fba994..d7744c3433336 100644 --- a/src/coreclr/runtime.proj +++ b/src/coreclr/runtime.proj @@ -37,6 +37,7 @@ <_CoreClrBuildArg Condition="'$(PgoInstrument)' == 'true'" Include="-pgoinstrument" /> <_CoreClrBuildArg Condition="'$(NativeOptimizationDataSupported)' == 'true' and '$(NoPgoOptimize)' != 'true' and '$(PgoInstrument)' != 'true'" Include="-pgodatapath "$(PgoPackagePath)"" /> <_CoreClrBuildArg Condition="'$(HostArchitecture)' != ''" Include="-hostarch $(HostArchitecture)" /> + <_CoreClrBuildArg Include="-outputrid $(OutputRid)" /> diff --git a/src/native/corehost/build.cmd b/src/native/corehost/build.cmd index 84ee51dba022d..470746f4dde9f 100644 --- a/src/native/corehost/build.cmd +++ b/src/native/corehost/build.cmd @@ -20,6 +20,7 @@ set __PortableBuild=0 set __ConfigureOnly=0 set __IncrementalNativeBuild=0 set __Ninja=1 +set __OutputRid="" :Arg_Loop if [%1] == [] goto :InitVSEnv @@ -35,7 +36,7 @@ if /i [%1] == [amd64] (set __BuildArch=x64&&shift&goto Arg_Loop) if /i [%1] == [arm64] (set __BuildArch=arm64&&shift&goto Arg_Loop) if /i [%1] == [portable] (set __PortableBuild=1&&shift&goto Arg_Loop) -if /i [%1] == [rid] (set __TargetRid=%2&&shift&&shift&goto Arg_Loop) +if /i [%1] == [outputrid] (set __OutputRid=%2&&shift&&shift&goto Arg_Loop) if /i [%1] == [toolsetDir] (set "__ToolsetDir=%2"&&shift&&shift&goto Arg_Loop) if /i [%1] == [hostver] (set __HostVersion=%2&&shift&&shift&goto Arg_Loop) if /i [%1] == [apphostver] (set __AppHostVersion=%2&&shift&&shift&goto Arg_Loop) @@ -70,16 +71,16 @@ echo Configuring corehost native components echo. if %__CMakeBinDir% == "" ( - set "__CMakeBinDir=%__binDir%\%__TargetRid%.%CMAKE_BUILD_TYPE%" + set "__CMakeBinDir=%__binDir%\%__OutputRid%.%CMAKE_BUILD_TYPE%" ) if %__IntermediatesDir% == "" ( - set "__IntermediatesDir=%__objDir%\%__TargetRid%.%CMAKE_BUILD_TYPE%\corehost" + set "__IntermediatesDir=%__objDir%\%__OutputRid%.%CMAKE_BUILD_TYPE%\corehost" ) if %__Ninja% == 0 ( set "__IntermediatesDir=%__IntermediatesDir%\ide" ) -set "__ResourcesDir=%__objDir%\%__TargetRid%.%CMAKE_BUILD_TYPE%\hostResourceFiles" +set "__ResourcesDir=%__objDir%\%__OutputRid%.%CMAKE_BUILD_TYPE%\hostResourceFiles" set "__CMakeBinDir=%__CMakeBinDir:\=/%" set "__IntermediatesDir=%__IntermediatesDir:\=/%" @@ -100,8 +101,14 @@ if /i "%__PortableBuild%" == "1" (set cm_BaseRid=win) set cm_BaseRid=%cm_BaseRid%-%__BuildArch% echo "Computed RID for native build is %cm_BaseRid%" +:: When the host runs on an unknown rid, it falls back to the output rid +:: Strip the architecture +for /f "delims=-" %%i in ("%__OutputRid%") do set __HostFallbackOS=%%i +:: The "win" host build is Windows 10 compatible +if "%__HostFallbackOS%" == "win" (set __HostFallbackOS=win10) + set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCLI_CMAKE_HOST_VER=%__HostVersion%" "-DCLI_CMAKE_COMMON_HOST_VER=%__AppHostVersion%" "-DCLI_CMAKE_HOST_FXR_VER=%__HostFxrVersion%" -set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCLI_CMAKE_HOST_POLICY_VER=%__HostPolicyVersion%" "-DCLI_CMAKE_PKG_RID=%cm_BaseRid%" "-DCLI_CMAKE_COMMIT_HASH=%__CommitSha%" +set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCLI_CMAKE_HOST_POLICY_VER=%__HostPolicyVersion%" "-DCLI_CMAKE_PKG_RID=%cm_BaseRid%" "-DCLI_CMAKE_FALLBACK_OS=%__HostFallbackOS%" "-DCLI_CMAKE_COMMIT_HASH=%__CommitSha%" set __ExtraCmakeParams=%__ExtraCmakeParams% "-DRUNTIME_FLAVOR=%__RuntimeFlavor% " set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCLI_CMAKE_RESOURCE_DIR=%__ResourcesDir%" "-DCMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE%" diff --git a/src/native/corehost/build.sh b/src/native/corehost/build.sh index e48ab8cd28770..def574f4839ca 100755 --- a/src/native/corehost/build.sh +++ b/src/native/corehost/build.sh @@ -80,7 +80,7 @@ __IntermediatesDir="$__RootBinDir/obj/$__OutputRid.$__BuildType" export __BinDir __IntermediatesDir __RuntimeFlavor __CMakeArgs="-DCLI_CMAKE_HOST_VER=\"$__host_ver\" -DCLI_CMAKE_COMMON_HOST_VER=\"$__apphost_ver\" -DCLI_CMAKE_HOST_FXR_VER=\"$__fxr_ver\" $__CMakeArgs" -__CMakeArgs="-DCLI_CMAKE_HOST_POLICY_VER=\"$__policy_ver\" -DCLI_CMAKE_PKG_RID=\"$__OutputRid\" -DCLI_CMAKE_COMMIT_HASH=\"$__commit_hash\" $__CMakeArgs" +__CMakeArgs="-DCLI_CMAKE_HOST_POLICY_VER=\"$__policy_ver\" -DCLI_CMAKE_PKG_RID=\"$__OutputRid\" -DCLI_CMAKE_FALLBACK_OS=\"$__HostFallbackOS\" -DCLI_CMAKE_COMMIT_HASH=\"$__commit_hash\" $__CMakeArgs" __CMakeArgs="-DRUNTIME_FLAVOR=\"$__RuntimeFlavor\" $__CMakeArgs" __CMakeArgs="-DFEATURE_DISTRO_AGNOSTIC_SSL=$__PortableBuild $__CMakeArgs" diff --git a/src/native/corehost/corehost.proj b/src/native/corehost/corehost.proj index 7486b3bd40a19..2df956bd476a0 100644 --- a/src/native/corehost/corehost.proj +++ b/src/native/corehost/corehost.proj @@ -133,7 +133,7 @@ $([MSBuild]::NormalizePath('$(MSBuildThisFileDirectory)', 'build.cmd')) - $(Configuration) $(TargetArchitecture) apphostver $(AppHostVersion) hostver $(HostVersion) fxrver $(HostResolverVersion) policyver $(HostPolicyVersion) commit $([MSBuild]::ValueOrDefault('$(SourceRevisionId)', 'N/A')) rid $(OutputRid) + $(Configuration) $(TargetArchitecture) apphostver $(AppHostVersion) hostver $(HostVersion) fxrver $(HostResolverVersion) policyver $(HostPolicyVersion) commit $([MSBuild]::ValueOrDefault('$(SourceRevisionId)', 'N/A')) outputrid $(OutputRid) $(BuildArgs) configureonly $(BuildArgs) portable $(BuildArgs) incremental-native-build diff --git a/src/native/corehost/hostmisc/pal.h b/src/native/corehost/hostmisc/pal.h index dee5bf3c94d44..72aa756a93399 100644 --- a/src/native/corehost/hostmisc/pal.h +++ b/src/native/corehost/hostmisc/pal.h @@ -67,27 +67,12 @@ #if defined(TARGET_WINDOWS) #define LIB_PREFIX "" #define LIB_FILE_EXT ".dll" -#define FALLBACK_HOST_RID _X("win10") #elif defined(TARGET_OSX) #define LIB_PREFIX "lib" #define LIB_FILE_EXT ".dylib" -#define FALLBACK_HOST_RID _X("osx.10.12") #else #define LIB_PREFIX "lib" #define LIB_FILE_EXT ".so" -#if defined(TARGET_FREEBSD) -#define FALLBACK_HOST_RID _X("freebsd") -#elif defined(TARGET_ILLUMOS) -#define FALLBACK_HOST_RID _X("illumos") -#elif defined(TARGET_SUNOS) -#define FALLBACK_HOST_RID _X("solaris") -#elif defined(TARGET_LINUX_MUSL) -#define FALLBACK_HOST_RID _X("linux-musl") -#elif defined(TARGET_ANDROID) -#define FALLBACK_HOST_RID _X("linux-bionic") -#else -#define FALLBACK_HOST_RID _X("linux") -#endif #endif #define _STRINGIFY(s) _X(s) @@ -276,9 +261,7 @@ namespace pal string_t get_current_os_rid_platform(); inline string_t get_current_os_fallback_rid() { - string_t fallbackRid(FALLBACK_HOST_RID); - - return fallbackRid; + return _STRINGIFY(FALLBACK_HOST_OS); } const void* mmap_read(const string_t& path, size_t* length = nullptr); diff --git a/src/native/corehost/setup.cmake b/src/native/corehost/setup.cmake index d2e4715eaf53b..cedabbce6bca8 100644 --- a/src/native/corehost/setup.cmake +++ b/src/native/corehost/setup.cmake @@ -50,3 +50,9 @@ else() add_definitions(-DREPO_COMMIT_HASH="${CLI_CMAKE_COMMIT_HASH}") endif() endif() + +if("${CLI_CMAKE_FALLBACK_OS}" STREQUAL "") + message(FATAL_ERROR "Fallback rid needs to be specified to build the host") +else() + add_definitions(-DFALLBACK_HOST_OS="${CLI_CMAKE_FALLBACK_OS}") +endif()