Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

corehost: derive fallback rid from output rid. #82163

Merged
merged 8 commits into from
Feb 22, 2023
Merged
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
3 changes: 3 additions & 0 deletions eng/native/build-commons.sh
Original file line number Diff line number Diff line change
Expand Up @@ -490,3 +490,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
12 changes: 11 additions & 1 deletion src/coreclr/build-runtime.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ set __PgoOptDataPath=
set __CMakeArgs=
set __Ninja=1
set __RequestedBuildComponents=
set __OutputRid=

:Arg_Loop
if "%1" == "" goto ArgsDone
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/build-runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/runtime.proj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<_CoreClrBuildArg Condition="'$(PgoInstrument)' == 'true'" Include="-pgoinstrument" />
<_CoreClrBuildArg Condition="'$(NativeOptimizationDataSupported)' == 'true' and '$(NoPgoOptimize)' != 'true' and '$(PgoInstrument)' != 'true'" Include="-pgodatapath &quot;$(PgoPackagePath)&quot;" />
<_CoreClrBuildArg Condition="'$(HostArchitecture)' != ''" Include="-hostarch $(HostArchitecture)" />
<_CoreClrBuildArg Include="-outputrid $(OutputRid)" />
</ItemGroup>

<ItemGroup Condition="'$(ClrFullNativeBuild)' != 'true'">
Expand Down
17 changes: 12 additions & 5 deletions src/native/corehost/build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ set __PortableBuild=0
set __ConfigureOnly=0
set __IncrementalNativeBuild=0
set __Ninja=1
set __OutputRid=""

:Arg_Loop
if [%1] == [] goto :InitVSEnv
Expand All @@ -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)
tmds marked this conversation as resolved.
Show resolved Hide resolved
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)
Expand Down Expand Up @@ -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:\=/%"

Expand All @@ -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%"

Expand Down
2 changes: 1 addition & 1 deletion src/native/corehost/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion src/native/corehost/corehost.proj
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
<PropertyGroup>
<BuildScript>$([MSBuild]::NormalizePath('$(MSBuildThisFileDirectory)', 'build.cmd'))</BuildScript>

<BuildArgs>$(Configuration) $(TargetArchitecture) apphostver $(AppHostVersion) hostver $(HostVersion) fxrver $(HostResolverVersion) policyver $(HostPolicyVersion) commit $([MSBuild]::ValueOrDefault('$(SourceRevisionId)', 'N/A')) rid $(OutputRid)</BuildArgs>
<BuildArgs>$(Configuration) $(TargetArchitecture) apphostver $(AppHostVersion) hostver $(HostVersion) fxrver $(HostResolverVersion) policyver $(HostPolicyVersion) commit $([MSBuild]::ValueOrDefault('$(SourceRevisionId)', 'N/A')) outputrid $(OutputRid)</BuildArgs>
<BuildArgs Condition="'$(ConfigureOnly)' == 'true'">$(BuildArgs) configureonly</BuildArgs>
<BuildArgs Condition="'$(PortableBuild)' == 'true'">$(BuildArgs) portable</BuildArgs>
<BuildArgs Condition="'$(IncrementalNativeBuild)' == 'true'">$(BuildArgs) incremental-native-build</BuildArgs>
Expand Down
19 changes: 1 addition & 18 deletions src/native/corehost/hostmisc/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions src/native/corehost/setup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()