Skip to content

Commit

Permalink
Make the cross-component build just another invocation of the build-r…
Browse files Browse the repository at this point in the history
…untime script (#67108)
  • Loading branch information
jkoritzinsky committed Apr 1, 2022
1 parent 490c166 commit 7d562f9
Show file tree
Hide file tree
Showing 16 changed files with 283 additions and 416 deletions.
22 changes: 22 additions & 0 deletions docs/workflow/building/coreclr/cross-building.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,28 @@ If you wanted to support armv7 CPU with VFPv3-d16, you'd use the following compi
./src/coreclr/build-runtime.sh -cross -arm -cmakeargs -DCLR_ARM_FPU_CAPABILITY=0x3 -cmakeargs -DCLR_ARM_FPU_TYPE=vfpv3-d16
```

Building the Cross-Targeting Tools
------------------------------------

Some parts of our build process need some native components that are built for the current machine architecture, even when you are building for a different target architecture. These tools are referred to as cross-targeting tools or "cross tools". There are two categories of these tools today:

- Crossgen2 JIT tools
- Diagnostic libraries

The Crossgen2 JIT tools are used to run Crossgen2 on libraries built during the current build, such as during the clr.nativecorelib stage. These tools are automatically built when using the `./build.cmd` or `./build.sh` scripts at the root of the repo to build any of the CoreCLR native files, but they are not automatically built when using the `build-runtime.cmd/sh` scripts. To build these tools, you need to pass the `-hostarch` flag with the architecture of the host machine and the `-component crosscomponents` flag to specify that you only want to build the cross-targetting tools. For example:

```
./src/coreclr/build-runtime.sh -arm -hostarch x64 -component crosscomponents -cmakeargs -DCLR_CROSS_COMPONENTS_BUILD=1
```

On Windows, the cross-targeting diagnostic libraries are built with the `linuxdac` and `alpinedac` subsets from the root `build.cmd` script, but they can also be built manually with the `build-runtime.cmd` scripts. These builds also require you to pass the `-os` flag to specify the target OS. For example:

```
src\coreclr\build-runtime.cmd -arm64 -hostarch x64 -os Linux -component crosscomponents -cmakeargs "-DCLR_CROSS_COMPONENTS_BUILD=1"
```

If you're building the cross-components in powershell, you'll need to wrap `"-DCLR_CROSS_COMPONENTS_BUILD=1"` with single quotes (`'`) to ensure things are escaped correctly for CMD.

Build System.Private.CoreLib on Ubuntu
--------------------------------------
The following instructions assume you are on a Linux machine such as Ubuntu 14.04 x86 64bit.
Expand Down
60 changes: 56 additions & 4 deletions eng/Subsets.props
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
</PropertyGroup>

<PropertyGroup>
<DefaultCoreClrSubsets>clr.native+linuxdac+clr.corelib+clr.tools+clr.nativecorelib+clr.packages+clr.nativeaotlibs</DefaultCoreClrSubsets>
<DefaultCoreClrSubsets>clr.native+linuxdac+clr.corelib+clr.tools+clr.nativecorelib+clr.packages+clr.nativeaotlibs+clr.crossarchtools</DefaultCoreClrSubsets>
<!-- Even on platforms that do not support the CoreCLR runtime, we still want to build ilasm/ildasm. -->
<DefaultCoreClrSubsets Condition="'$(PrimaryRuntimeFlavor)' != 'CoreCLR'">clr.iltools+clr.packages</DefaultCoreClrSubsets>

Expand Down Expand Up @@ -108,6 +108,7 @@
<SubsetName Include="Clr.Native" Description="All CoreCLR native non-test components, including the runtime, jits, and other native tools. Includes clr.hosts, clr.runtime, clr.jit, clr.alljits, clr.paltests, clr.iltools, clr.nativeaotruntime, clr.spmi." />
<SubsetName Include="Clr.NativeAotLibs" Description="The CoreCLR native AOT CoreLib and other low level class libraries." />
<SubsetName Include="Clr.NativeAotRuntime" Description="The stripped-down CoreCLR native AOT runtime." />
<SubsetName Include="Clr.CrossArchTools" Description="The cross-targetted CoreCLR tools." />
<SubsetName Include="Clr.PalTests" OnDemand="true" Description="The CoreCLR PAL tests." />
<SubsetName Include="Clr.PalTestList" OnDemand="true" Description="Generate the list of the CoreCLR PAL tests. When using the command line, use Clr.PalTests instead." />
<SubsetName Include="Clr.Hosts" Description="The CoreCLR corerun test host." />
Expand Down Expand Up @@ -221,19 +222,70 @@
</ItemGroup>

<ItemGroup Condition="'$(ClrRuntimeBuildSubsets)' != ''">
<ProjectToBuild Include="$(CoreClrProjectRoot)runtime.proj" AdditionalProperties="%(AdditionalProperties);$(ClrRuntimeBuildSubsets)" Category="clr" />
<ProjectToBuild
Include="$(CoreClrProjectRoot)runtime.proj"
AdditionalProperties="%(AdditionalProperties);$(ClrRuntimeBuildSubsets)"
Category="clr" />
</ItemGroup>

<!-- Build the CoreCLR cross-arch tools when we're doing a cross-architecture build and either we're building any CoreCLR native tools for platforms CoreCLR fully supports or when someone explicitly requests them -->
<ItemGroup Condition="(('$(ClrRuntimeBuildSubsets)' != '' and '$(PrimaryRuntimeFlavor)' == 'CoreCLR' and '$(TargetsMobile)' != 'true') or $(_subset.Contains('+clr.crossarchtools+'))) and '$(BuildArchitecture)' != '$(TargetArchitecture)'">
<ProjectToBuild
Include="$(CoreClrProjectRoot)runtime.proj"
AdditionalProperties="%(AdditionalProperties);
ClrCrossComponentsSubset=true;
HostArchitecture=$(BuildArchitecture);
PgoInstrument=false;
NoPgoOptimize=true;
CrossBuild=false;
CMakeArgs=$(CMakeArgs) -DCLR_CROSS_COMPONENTS_BUILD=1"
Category="clr" />
</ItemGroup>

<ItemGroup Condition="(('$(ClrRuntimeBuildSubsets)' != '' and '$(PrimaryRuntimeFlavor)' == 'CoreCLR' and '$(TargetsMobile)' != 'true') or $(_subset.Contains('+clr.crossarchtools+'))) and $([MSBuild]::IsOsPlatform(Windows)) and '$(TargetArchitecture)' == 'arm' and '$(BuildArchitecture)' == 'x64'">
<ProjectToBuild
Include="$(CoreClrProjectRoot)runtime.proj"
AdditionalProperties="%(AdditionalProperties);
ClrCrossComponentsSubset=true;
HostArchitecture=x86;
PgoInstrument=false;
NoPgoOptimize=true;
CrossBuild=false;
CMakeArgs=$(CMakeArgs) -DCLR_CROSS_COMPONENTS_BUILD=1"
Category="clr" />
</ItemGroup>

<ItemGroup Condition="$(_subset.Contains('+clr.paltestlist+'))">
<ProjectToBuild Include="$(CoreClrProjectRoot)pal/tests/palsuite/producepaltestlist.proj" />
</ItemGroup>

<PropertyGroup>
<CrossDacHostArch>x64</CrossDacHostArch>
<CrossDacHostArch Condition="'$(TargetArchitecture)' == 'arm'">x86</CrossDacHostArch>
</PropertyGroup>

<ItemGroup Condition="$(_subset.Contains('+linuxdac+')) and $([MSBuild]::IsOsPlatform(Windows)) and '$(TargetArchitecture)' != 'x86'">
<ProjectToBuild Include="$(CoreClrProjectRoot)runtime.proj" AdditionalProperties="%(AdditionalProperties);$(ClrDefaultRuntimeBuildSubsets);CrossDac=linux" Category="clr" />
<ProjectToBuild
Include="$(CoreClrProjectRoot)runtime.proj"
AdditionalProperties="%(AdditionalProperties);
ClrCrossComponentsSubset=true;
HostArchitecture=$(CrossDacHostArch);
PgoInstrument=false;
NoPgoOptimize=true;
TargetOS=Linux;
CMakeArgs=$(CMakeArgs) -DCLR_CROSS_COMPONENTS_BUILD=1" Category="clr" />
</ItemGroup>

<ItemGroup Condition="$(_subset.Contains('+alpinedac+')) and $([MSBuild]::IsOsPlatform(Windows)) and '$(TargetArchitecture)' != 'x86'">
<ProjectToBuild Include="$(CoreClrProjectRoot)runtime.proj" AdditionalProperties="%(AdditionalProperties);$(ClrDefaultRuntimeBuildSubsets);CrossDac=alpine" Category="clr" />
<ProjectToBuild
Include="$(CoreClrProjectRoot)runtime.proj"
AdditionalProperties="%(AdditionalProperties);
ClrCrossComponentsSubset=true;
HostArchitecture=$(CrossDacHostArch);
PgoInstrument=false;
NoPgoOptimize=true;
TargetOS=alpine;
CMakeArgs=$(CMakeArgs) -DCLR_CROSS_COMPONENTS_BUILD=1" Category="clr" />
</ItemGroup>

<ItemGroup Condition="$(_subset.Contains('+crossdacpack+'))">
Expand Down
65 changes: 39 additions & 26 deletions eng/native/build-commons.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ initTargetDistroRid()
passedRootfsDir="$ROOTFS_DIR"
fi

initDistroRidGlobal "$__TargetOS" "$__BuildArch" "$__PortableBuild" "$passedRootfsDir"
initDistroRidGlobal "$__TargetOS" "$__TargetArch" "$__PortableBuild" "$passedRootfsDir"
}

setup_dirs()
Expand Down Expand Up @@ -53,23 +53,23 @@ build_native()
fi

targetOS="$1"
platformArch="$2"
hostArch="$2"
cmakeDir="$3"
intermediatesDir="$4"
target="$5"
cmakeArgs="$6"
message="$7"

# All set to commence the build
echo "Commencing build of \"$target\" target in \"$message\" for $__TargetOS.$__BuildArch.$__BuildType in $intermediatesDir"
echo "Commencing build of \"$target\" target in \"$message\" for $__TargetOS.$__TargetArch.$__BuildType in $intermediatesDir"

if [[ "$targetOS" == OSX || "$targetOS" == MacCatalyst ]]; then
if [[ "$platformArch" == x64 ]]; then
if [[ "$hostArch" == x64 ]]; then
cmakeArgs="-DCMAKE_OSX_ARCHITECTURES=\"x86_64\" $cmakeArgs"
elif [[ "$platformArch" == arm64 ]]; then
elif [[ "$hostArch" == arm64 ]]; then
cmakeArgs="-DCMAKE_OSX_ARCHITECTURES=\"arm64\" $cmakeArgs"
else
echo "Error: Unknown OSX architecture $platformArch."
echo "Error: Unknown OSX architecture $hostArch."
exit 1
fi
fi
Expand All @@ -90,16 +90,16 @@ build_native()
# Don't try to set CC/CXX in init-compiler.sh - it's handled in android.toolchain.cmake already
__Compiler="default"

if [[ "$platformArch" == x64 ]]; then
if [[ "$hostArch" == x64 ]]; then
cmakeArgs="-DANDROID_ABI=x86_64 $cmakeArgs"
elif [[ "$platformArch" == x86 ]]; then
elif [[ "$hostArch" == x86 ]]; then
cmakeArgs="-DANDROID_ABI=x86 $cmakeArgs"
elif [[ "$platformArch" == arm64 ]]; then
elif [[ "$hostArch" == arm64 ]]; then
cmakeArgs="-DANDROID_ABI=arm64-v8a $cmakeArgs"
elif [[ "$platformArch" == arm ]]; then
elif [[ "$hostArch" == arm ]]; then
cmakeArgs="-DANDROID_ABI=armeabi-v7a $cmakeArgs"
else
echo "Error: Unknown Android architecture $platformArch."
echo "Error: Unknown Android architecture $hostArch."
exit 1
fi
fi
Expand All @@ -117,7 +117,7 @@ build_native()
scan_build=scan-build
fi

nextCommand="\"$__RepoRootDir/eng/native/gen-buildsys.sh\" \"$cmakeDir\" \"$intermediatesDir\" $platformArch $__Compiler $__BuildType \"$generator\" $scan_build $cmakeArgs"
nextCommand="\"$__RepoRootDir/eng/native/gen-buildsys.sh\" \"$cmakeDir\" \"$intermediatesDir\" $hostArch $__Compiler $__BuildType \"$generator\" $scan_build $cmakeArgs"
echo "Invoking $nextCommand"
eval $nextCommand

Expand Down Expand Up @@ -228,8 +228,7 @@ usage()

source "$__RepoRootDir/eng/native/init-os-and-arch.sh"

__BuildArch=$arch
__HostArch=$arch
__TargetArch=$arch
__TargetOS=$os
__HostOS=$os
__BuildOS=$os
Expand Down Expand Up @@ -267,19 +266,19 @@ while :; do
;;

arm|-arm)
__BuildArch=arm
__TargetArch=arm
;;

armv6|-armv6)
__BuildArch=armv6
__TargetArch=armv6
;;

arm64|-arm64)
__BuildArch=arm64
__TargetArch=arm64
;;

armel|-armel)
__BuildArch=armel
__TargetArch=armel
;;

bindir|-bindir)
Expand Down Expand Up @@ -374,23 +373,23 @@ while :; do
;;

x86|-x86)
__BuildArch=x86
__TargetArch=x86
;;

x64|-x64)
__BuildArch=x64
__TargetArch=x64
;;

loongarch64|-loongarch64)
__BuildArch=loongarch64
__TargetArch=loongarch64
;;

s390x|-s390x)
__BuildArch=s390x
__TargetArch=s390x
;;

wasm|-wasm)
__BuildArch=wasm
__TargetArch=wasm
;;

os|-os)
Expand All @@ -403,6 +402,16 @@ while :; do
fi
;;

hostarch|-hostarch)
if [[ -n "$2" ]]; then
__HostArch="$2"
shift
else
echo "ERROR: 'hostarch' requires a non-empty option argument"
exit 1
fi
;;

*)
handle_arguments "$1" "$2"
if [[ "$__ShiftArgs" == 1 ]]; then
Expand All @@ -415,7 +424,11 @@ while :; do
shift
done

__CommonMSBuildArgs="/p:TargetArchitecture=$__BuildArch /p:Configuration=$__BuildType /p:TargetOS=$__TargetOS /nodeReuse:false $__OfficialBuildIdArg $__SignTypeArg $__SkipRestoreArg"
if [[ -z "$__HostArch" ]]; then
__HostArch=$__TargetArch
fi

__CommonMSBuildArgs="/p:TargetArchitecture=$__TargetArch /p:Configuration=$__BuildType /p:TargetOS=$__TargetOS /nodeReuse:false $__OfficialBuildIdArg $__SignTypeArg $__SkipRestoreArg"

# Configure environment if we are doing a verbose build
if [[ "$__VerboseBuild" == 1 ]]; then
Expand All @@ -428,7 +441,7 @@ if [[ "$__PortableBuild" == 0 ]]; then
__CommonMSBuildArgs="$__CommonMSBuildArgs /p:PortableBuild=false"
fi

if [[ "$__BuildArch" == wasm ]]; then
if [[ "$__TargetArch" == wasm ]]; then
# nothing to do here
true
elif [[ "$__TargetOS" == iOS || "$__TargetOS" == iOSSimulator ]]; then
Expand All @@ -450,7 +463,7 @@ if [[ "$__CrossBuild" == 1 ]]; then
export CROSSCOMPILE
# Darwin that doesn't use rootfs
if [[ -z "$ROOTFS_DIR" && "$platform" != "Darwin" ]]; then
ROOTFS_DIR="$__RepoRootDir/.tools/rootfs/$__BuildArch"
ROOTFS_DIR="$__RepoRootDir/.tools/rootfs/$__TargetArch"
export ROOTFS_DIR
fi
fi
Expand Down
12 changes: 6 additions & 6 deletions eng/native/gen-buildsys.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if [[ "$#" -lt 4 ]]; then
echo "gen-buildsys.sh <path to top level CMakeLists.txt> <path to intermediate directory> <Architecture> <compiler> [build flavor] [ninja] [scan-build] [cmakeargs]"
echo "Specify the path to the top level CMake file."
echo "Specify the path that the build system files are generated in."
echo "Specify the target architecture."
echo "Specify the host architecture (the architecture the built tools should run on)."
echo "Specify the name of compiler (clang or gcc)."
echo "Optionally specify the build configuration (flavor.) Defaults to DEBUG."
echo "Optionally specify 'scan-build' to enable build with clang static analyzer."
Expand All @@ -19,12 +19,12 @@ if [[ "$#" -lt 4 ]]; then
exit 1
fi

build_arch="$3"
host_arch="$3"
compiler="$4"

if [[ "$compiler" != "default" ]]; then
nativescriptroot="$( cd -P "$scriptroot/../common/native" && pwd )"
source "$nativescriptroot/init-compiler.sh" "$nativescriptroot" "$build_arch" "$compiler"
source "$nativescriptroot/init-compiler.sh" "$nativescriptroot" "$host_arch" "$compiler"

CCC_CC="$CC"
CCC_CXX="$CXX"
Expand Down Expand Up @@ -67,7 +67,7 @@ if [[ "$CROSSCOMPILE" == "1" ]]; then
exit 1
fi

TARGET_BUILD_ARCH="$build_arch"
TARGET_BUILD_ARCH="$host_arch"
export TARGET_BUILD_ARCH

cmake_extra_defines="$cmake_extra_defines -C $scriptroot/tryrun.cmake"
Expand All @@ -79,7 +79,7 @@ if [[ "$CROSSCOMPILE" == "1" ]]; then
fi
fi

if [[ "$build_arch" == "armel" ]]; then
if [[ "$host_arch" == "armel" ]]; then
cmake_extra_defines="$cmake_extra_defines -DARM_SOFTFP=1"
fi

Expand All @@ -92,7 +92,7 @@ if [[ "$scan_build" == "ON" && -n "$SCAN_BUILD_COMMAND" ]]; then
cmake_command="$SCAN_BUILD_COMMAND $cmake_command"
fi

if [[ "$build_arch" == "wasm" ]]; then
if [[ "$host_arch" == "wasm" ]]; then
cmake_command="emcmake $cmake_command"
fi

Expand Down
12 changes: 8 additions & 4 deletions eng/nativepgo.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@
<NativeOptimizationDataSupported Condition="'$(TargetOS)' == 'windows' And ('$(TargetArchitecture)' == 'x64' Or '$(TargetArchitecture)' == 'x86')">true</NativeOptimizationDataSupported>
<NativeOptimizationDataSupported Condition="'$(TargetOS)' == 'Linux' And '$(TargetArchitecture)' == 'x64'">true</NativeOptimizationDataSupported>
<NativeOptimizationDataSupported Condition="'$(NoPgoOptimize)' == 'true'">false</NativeOptimizationDataSupported>
<NativeOptimizationDataSupported Condition="'$(DotNetBuildFromSource)' == 'true'">false</NativeOptimizationDataSupported>
<NativeOptimizationDataSupported Condition="'$(Configuration)' != 'Release'">false</NativeOptimizationDataSupported>

<_NativeOptimizationDataPackageTarget>$(TargetOS.ToLower())-$(TargetArchitecture.ToLower())</_NativeOptimizationDataPackageTarget>
<_NativeOptimizationDataPackageTarget Condition="'$(TargetOS)' == 'windows'">windows_nt-$(TargetArchitecture.ToLower())</_NativeOptimizationDataPackageTarget>

</PropertyGroup>
<ItemGroup>
<PackageReference Include="optimization.$(_NativeOptimizationDataPackageTarget).PGO.CoreCLR"
<ItemGroup Condition="'$(optimizationPGOCoreCLRVersion)'!='' and '$(DotNetBuildFromSource)' != 'true'">
<PackageReference Include="optimization.windows_nt-x64.PGO.CoreCLR"
Version="$(optimizationPGOCoreCLRVersion)"
GeneratePathProperty="true" />
<PackageReference Include="optimization.windows_nt-x86.PGO.CoreCLR"
Version="$(optimizationPGOCoreCLRVersion)"
GeneratePathProperty="true" />
<PackageReference Include="optimization.linux-x64.PGO.CoreCLR"
Version="$(optimizationPGOCoreCLRVersion)"
Condition="'$(optimizationPGOCoreCLRVersion)'!='' And '$(NativeOptimizationDataSupported)'=='true'"
GeneratePathProperty="true" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion eng/pipelines/coreclr/templates/build-jit-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ jobs:
- script: $(Build.SourcesDirectory)/src/coreclr/build-runtime$(scriptExt) $(buildConfig) $(archType) $(crossArg) -ci $(compilerArg) -component alljits -component spmi
displayName: Build CoreCLR JIT
- ${{ if eq(parameters.osGroup, 'windows') }}:
- script: set __TestIntermediateDir=int&&$(Build.SourcesDirectory)/src/coreclr/build-runtime$(scriptExt) $(buildConfig) $(archType) -ci -component alljits -component spmi
- script: $(Build.SourcesDirectory)/src/coreclr/build-runtime$(scriptExt) $(buildConfig) $(archType) -ci -component alljits -component spmi
displayName: Build CoreCLR JIT

- ${{ if eq(parameters.uploadAs, 'azureBlob') }}:
Expand Down
Loading

0 comments on commit 7d562f9

Please sign in to comment.