Skip to content

Commit ec2859d

Browse files
authored
corehost: derive fallback rid from output rid. (#82163)
1 parent c7ca00b commit ec2859d

File tree

9 files changed

+37
-27
lines changed

9 files changed

+37
-27
lines changed

eng/native/build-commons.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,3 +542,6 @@ initTargetDistroRid
542542
if [ -z "$__OutputRid" ]; then
543543
__OutputRid="$(echo $__DistroRid | tr '[:upper:]' '[:lower:]')"
544544
fi
545+
546+
# When the host runs on an unknown rid, it falls back to the output rid
547+
__HostFallbackOS="${__OutputRid%-*}" # Strip architecture

src/coreclr/build-runtime.cmd

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ set __PgoOptDataPath=
7070
set __CMakeArgs=
7171
set __Ninja=1
7272
set __RequestedBuildComponents=
73+
set __OutputRid=
7374

7475
:Arg_Loop
7576
if "%1" == "" goto ArgsDone
@@ -128,6 +129,7 @@ if [!__PassThroughArgs!]==[] (
128129

129130
if /i "%1" == "-hostarch" (set __HostArch=%2&shift&shift&goto Arg_Loop)
130131
if /i "%1" == "-os" (set __TargetOS=%2&shift&shift&goto Arg_Loop)
132+
if /i "%1" == "-outputrid" (set __OutputRid=%2&shift&shift&goto Arg_Loop)
131133

132134
if /i "%1" == "-cmakeargs" (set __CMakeArgs=%2 %__CMakeArgs%&set __remainingArgs="!__remainingArgs:*%2=!"&shift&shift&goto Arg_Loop)
133135
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
327329
REM ===
328330
REM =========================================================================================
329331

332+
:: When the host runs on an unknown rid, it falls back to the output rid
333+
:: Strip the architecture
334+
for /f "delims=-" %%i in ("%__OutputRid%") do set __HostFallbackOS=%%i
335+
:: The "win" host build is Windows 10 compatible
336+
if "%__HostFallbackOS%" == "win" (set __HostFallbackOS=win10)
337+
:: Default to "win10" fallback
338+
if "%__HostFallbackOS%" == "" (set __HostFallbackOS=win10)
339+
330340
if %__BuildNative% EQU 1 (
331341
REM Scope environment changes start {
332342
setlocal
@@ -355,7 +365,7 @@ if %__BuildNative% EQU 1 (
355365
set __ExtraCmakeArgs="-DCMAKE_BUILD_TYPE=!__BuildType!"
356366
)
357367

358-
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%
368+
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%
359369
echo Calling "%__RepoRootDir%\eng\native\gen-buildsys.cmd" "%__ProjectDir%" "%__IntermediatesDir%" %__VSVersion% %__HostArch% %__TargetOS% !__ExtraCmakeArgs!
360370
call "%__RepoRootDir%\eng\native\gen-buildsys.cmd" "%__ProjectDir%" "%__IntermediatesDir%" %__VSVersion% %__HostArch% %__TargetOS% !__ExtraCmakeArgs!
361371
if not !errorlevel! == 0 (

src/coreclr/build-runtime.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export MSBUILDDEBUGPATH
146146
check_prereqs
147147

148148
# Build the coreclr (native) components.
149-
__CMakeArgs="-DCLR_CMAKE_PGO_INSTRUMENT=$__PgoInstrument -DCLR_CMAKE_OPTDATA_PATH=$__PgoOptDataPath -DCLR_CMAKE_PGO_OPTIMIZE=$__PgoOptimize $__CMakeArgs"
149+
__CMakeArgs="-DCLR_CMAKE_PGO_INSTRUMENT=$__PgoInstrument -DCLR_CMAKE_OPTDATA_PATH=$__PgoOptDataPath -DCLR_CMAKE_PGO_OPTIMIZE=$__PgoOptimize -DCLI_CMAKE_FALLBACK_OS=\"$__HostFallbackOS\" $__CMakeArgs"
150150

151151
if [[ "$__SkipConfigure" == 0 && "$__CodeCoverage" == 1 ]]; then
152152
__CMakeArgs="-DCLR_CMAKE_ENABLE_CODE_COVERAGE=1 $__CMakeArgs"

src/coreclr/runtime.proj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<_CoreClrBuildArg Condition="'$(PgoInstrument)' == 'true'" Include="-pgoinstrument" />
3838
<_CoreClrBuildArg Condition="'$(NativeOptimizationDataSupported)' == 'true' and '$(NoPgoOptimize)' != 'true' and '$(PgoInstrument)' != 'true'" Include="-pgodatapath &quot;$(PgoPackagePath)&quot;" />
3939
<_CoreClrBuildArg Condition="'$(HostArchitecture)' != ''" Include="-hostarch $(HostArchitecture)" />
40+
<_CoreClrBuildArg Include="-outputrid $(OutputRid)" />
4041
</ItemGroup>
4142

4243
<ItemGroup Condition="'$(ClrFullNativeBuild)' != 'true'">

src/native/corehost/build.cmd

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ set __PortableBuild=0
2020
set __ConfigureOnly=0
2121
set __IncrementalNativeBuild=0
2222
set __Ninja=1
23+
set __OutputRid=""
2324

2425
:Arg_Loop
2526
if [%1] == [] goto :InitVSEnv
@@ -35,7 +36,7 @@ if /i [%1] == [amd64] (set __BuildArch=x64&&shift&goto Arg_Loop)
3536
if /i [%1] == [arm64] (set __BuildArch=arm64&&shift&goto Arg_Loop)
3637

3738
if /i [%1] == [portable] (set __PortableBuild=1&&shift&goto Arg_Loop)
38-
if /i [%1] == [rid] (set __TargetRid=%2&&shift&&shift&goto Arg_Loop)
39+
if /i [%1] == [outputrid] (set __OutputRid=%2&&shift&&shift&goto Arg_Loop)
3940
if /i [%1] == [toolsetDir] (set "__ToolsetDir=%2"&&shift&&shift&goto Arg_Loop)
4041
if /i [%1] == [hostver] (set __HostVersion=%2&&shift&&shift&goto Arg_Loop)
4142
if /i [%1] == [apphostver] (set __AppHostVersion=%2&&shift&&shift&goto Arg_Loop)
@@ -70,16 +71,16 @@ echo Configuring corehost native components
7071
echo.
7172

7273
if %__CMakeBinDir% == "" (
73-
set "__CMakeBinDir=%__binDir%\%__TargetRid%.%CMAKE_BUILD_TYPE%"
74+
set "__CMakeBinDir=%__binDir%\%__OutputRid%.%CMAKE_BUILD_TYPE%"
7475
)
7576

7677
if %__IntermediatesDir% == "" (
77-
set "__IntermediatesDir=%__objDir%\%__TargetRid%.%CMAKE_BUILD_TYPE%\corehost"
78+
set "__IntermediatesDir=%__objDir%\%__OutputRid%.%CMAKE_BUILD_TYPE%\corehost"
7879
)
7980
if %__Ninja% == 0 (
8081
set "__IntermediatesDir=%__IntermediatesDir%\ide"
8182
)
82-
set "__ResourcesDir=%__objDir%\%__TargetRid%.%CMAKE_BUILD_TYPE%\hostResourceFiles"
83+
set "__ResourcesDir=%__objDir%\%__OutputRid%.%CMAKE_BUILD_TYPE%\hostResourceFiles"
8384
set "__CMakeBinDir=%__CMakeBinDir:\=/%"
8485
set "__IntermediatesDir=%__IntermediatesDir:\=/%"
8586

@@ -100,8 +101,14 @@ if /i "%__PortableBuild%" == "1" (set cm_BaseRid=win)
100101
set cm_BaseRid=%cm_BaseRid%-%__BuildArch%
101102
echo "Computed RID for native build is %cm_BaseRid%"
102103

104+
:: When the host runs on an unknown rid, it falls back to the output rid
105+
:: Strip the architecture
106+
for /f "delims=-" %%i in ("%__OutputRid%") do set __HostFallbackOS=%%i
107+
:: The "win" host build is Windows 10 compatible
108+
if "%__HostFallbackOS%" == "win" (set __HostFallbackOS=win10)
109+
103110
set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCLI_CMAKE_HOST_VER=%__HostVersion%" "-DCLI_CMAKE_COMMON_HOST_VER=%__AppHostVersion%" "-DCLI_CMAKE_HOST_FXR_VER=%__HostFxrVersion%"
104-
set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCLI_CMAKE_HOST_POLICY_VER=%__HostPolicyVersion%" "-DCLI_CMAKE_PKG_RID=%cm_BaseRid%" "-DCLI_CMAKE_COMMIT_HASH=%__CommitSha%"
111+
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%"
105112
set __ExtraCmakeParams=%__ExtraCmakeParams% "-DRUNTIME_FLAVOR=%__RuntimeFlavor% "
106113
set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCLI_CMAKE_RESOURCE_DIR=%__ResourcesDir%" "-DCMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE%"
107114

src/native/corehost/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ __IntermediatesDir="$__RootBinDir/obj/$__OutputRid.$__BuildType"
8080
export __BinDir __IntermediatesDir __RuntimeFlavor
8181

8282
__CMakeArgs="-DCLI_CMAKE_HOST_VER=\"$__host_ver\" -DCLI_CMAKE_COMMON_HOST_VER=\"$__apphost_ver\" -DCLI_CMAKE_HOST_FXR_VER=\"$__fxr_ver\" $__CMakeArgs"
83-
__CMakeArgs="-DCLI_CMAKE_HOST_POLICY_VER=\"$__policy_ver\" -DCLI_CMAKE_PKG_RID=\"$__OutputRid\" -DCLI_CMAKE_COMMIT_HASH=\"$__commit_hash\" $__CMakeArgs"
83+
__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"
8484
__CMakeArgs="-DRUNTIME_FLAVOR=\"$__RuntimeFlavor\" $__CMakeArgs"
8585
__CMakeArgs="-DFEATURE_DISTRO_AGNOSTIC_SSL=$__PortableBuild $__CMakeArgs"
8686

src/native/corehost/corehost.proj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
<PropertyGroup>
134134
<BuildScript>$([MSBuild]::NormalizePath('$(MSBuildThisFileDirectory)', 'build.cmd'))</BuildScript>
135135

136-
<BuildArgs>$(Configuration) $(TargetArchitecture) apphostver $(AppHostVersion) hostver $(HostVersion) fxrver $(HostResolverVersion) policyver $(HostPolicyVersion) commit $([MSBuild]::ValueOrDefault('$(SourceRevisionId)', 'N/A')) rid $(OutputRid)</BuildArgs>
136+
<BuildArgs>$(Configuration) $(TargetArchitecture) apphostver $(AppHostVersion) hostver $(HostVersion) fxrver $(HostResolverVersion) policyver $(HostPolicyVersion) commit $([MSBuild]::ValueOrDefault('$(SourceRevisionId)', 'N/A')) outputrid $(OutputRid)</BuildArgs>
137137
<BuildArgs Condition="'$(ConfigureOnly)' == 'true'">$(BuildArgs) configureonly</BuildArgs>
138138
<BuildArgs Condition="'$(PortableBuild)' == 'true'">$(BuildArgs) portable</BuildArgs>
139139
<BuildArgs Condition="'$(IncrementalNativeBuild)' == 'true'">$(BuildArgs) incremental-native-build</BuildArgs>

src/native/corehost/hostmisc/pal.h

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,27 +67,12 @@
6767
#if defined(TARGET_WINDOWS)
6868
#define LIB_PREFIX ""
6969
#define LIB_FILE_EXT ".dll"
70-
#define FALLBACK_HOST_RID _X("win10")
7170
#elif defined(TARGET_OSX)
7271
#define LIB_PREFIX "lib"
7372
#define LIB_FILE_EXT ".dylib"
74-
#define FALLBACK_HOST_RID _X("osx.10.12")
7573
#else
7674
#define LIB_PREFIX "lib"
7775
#define LIB_FILE_EXT ".so"
78-
#if defined(TARGET_FREEBSD)
79-
#define FALLBACK_HOST_RID _X("freebsd")
80-
#elif defined(TARGET_ILLUMOS)
81-
#define FALLBACK_HOST_RID _X("illumos")
82-
#elif defined(TARGET_SUNOS)
83-
#define FALLBACK_HOST_RID _X("solaris")
84-
#elif defined(TARGET_LINUX_MUSL)
85-
#define FALLBACK_HOST_RID _X("linux-musl")
86-
#elif defined(TARGET_ANDROID)
87-
#define FALLBACK_HOST_RID _X("linux-bionic")
88-
#else
89-
#define FALLBACK_HOST_RID _X("linux")
90-
#endif
9176
#endif
9277

9378
#define _STRINGIFY(s) _X(s)
@@ -276,9 +261,7 @@ namespace pal
276261
string_t get_current_os_rid_platform();
277262
inline string_t get_current_os_fallback_rid()
278263
{
279-
string_t fallbackRid(FALLBACK_HOST_RID);
280-
281-
return fallbackRid;
264+
return _STRINGIFY(FALLBACK_HOST_OS);
282265
}
283266

284267
const void* mmap_read(const string_t& path, size_t* length = nullptr);

src/native/corehost/setup.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,9 @@ else()
5050
add_definitions(-DREPO_COMMIT_HASH="${CLI_CMAKE_COMMIT_HASH}")
5151
endif()
5252
endif()
53+
54+
if("${CLI_CMAKE_FALLBACK_OS}" STREQUAL "")
55+
message(FATAL_ERROR "Fallback rid needs to be specified to build the host")
56+
else()
57+
add_definitions(-DFALLBACK_HOST_OS="${CLI_CMAKE_FALLBACK_OS}")
58+
endif()

0 commit comments

Comments
 (0)