3 # Work around Jenkins CI + msbuild problem: Jenkins sometimes creates very large environment
4 # variables, and msbuild can't handle environment blocks with such large variables. So clear
5 # out the variables that might be too large.
6 export ghprbCommentBody=
8 # resolve python-version to use
9 if [ "$PYTHON" == "" ] ; then
10 if ! PYTHON=$(command -v python2.7 || command -v python2 || command -v python)
12 echo "Unable to locate build-dependency python2.x!" 1>&2
17 # validate python-dependency
18 # useful in case of explicitly set option.
19 if ! command -v $PYTHON > /dev/null
21 echo "Unable to locate build-dependency python2.x ($PYTHON)!" 1>&2
29 echo "Usage: $0 [BuildArch] [BuildType] [-verbose] [-coverage] [-cross] [-clangx.y] [-ninja] [-configureonly] [-skipconfigure] [-skipnative] [-skipmanaged] [-skipmscorlib] [-skiptests] [-stripsymbols] [-ignorewarnings] [-cmakeargs] [-bindir]"
30 echo "BuildArch can be: -x64, -x86, -arm, -armel, -arm64"
31 echo "BuildType can be: -debug, -checked, -release"
32 echo "-coverage - optional argument to enable code coverage build (currently supported only for Linux and OSX)."
33 echo "-ninja - target ninja instead of GNU make"
34 echo "-clangx.y - optional argument to build using clang version x.y."
35 echo "-cross - optional argument to signify cross compilation,"
36 echo " - will use ROOTFS_DIR environment variable if set."
37 echo "-nopgooptimize - do not use profile guided optimizations."
38 echo "-pgoinstrument - generate instrumented code for profile guided optimization enabled binaries."
39 echo "-ibcinstrument - generate IBC-tuning-enabled native images when invoking crossgen."
40 echo "-configureonly - do not perform any builds; just configure the build."
41 echo "-skipconfigure - skip build configuration."
42 echo "-skipnative - do not build native components."
43 echo "-skipmanaged - do not build managed components."
44 echo "-skipmscorlib - do not build mscorlib.dll."
45 echo "-skiptests - skip the tests in the 'tests' subdirectory."
46 echo "-skipnuget - skip building nuget packages."
47 echo "-skiprestoreoptdata - skip restoring optimization data used by profile-based optimizations."
48 echo "-skipcrossgen - skip native image generation"
49 echo "-crossgenonly - only run native image generation"
50 echo "-partialngen - build CoreLib as PartialNGen"
51 echo "-verbose - optional argument to enable verbose build output."
52 echo "-skiprestore: skip restoring packages ^(default: packages are restored during build^)."
53 echo "-disableoss: Disable Open Source Signing for System.Private.CoreLib."
54 echo "-officialbuildid=^<ID^>: specify the official build ID to be used by this build."
55 echo "-stripSymbols - Optional argument to strip native symbols during the build."
56 echo "-skipgenerateversion - disable version generation even if MSBuild is supported."
57 echo "-ignorewarnings - do not treat warnings as errors"
58 echo "-cmakeargs - user-settable additional arguments passed to CMake."
59 echo "-bindir - output directory (defaults to $__ProjectRoot/bin)"
60 echo "-msbuildonunsupportedplatform - build managed binaries even if distro is not officially supported."
61 echo "-numproc - set the number of build processes."
68 if [ "$__HostOS" == "Linux" ]; then
69 if [ -e /etc/os-release ]; then
70 source /etc/os-release
71 if [[ $ID == "rhel" ]]; then
72 # remove the last version digit
73 VERSION_ID=${VERSION_ID%.*}
75 __HostDistroRid="$ID.$VERSION_ID-$__HostArch"
76 if [[ $ID == "alpine" ]]; then
77 __HostDistroRid="linux-musl-$__HostArch"
79 elif [ -e /etc/redhat-release ]; then
80 local redhatRelease=$(</etc/redhat-release)
81 if [[ $redhatRelease == "CentOS release 6."* || $redhatRelease == "Red Hat Enterprise Linux Server release 6."* ]]; then
82 __HostDistroRid="rhel.6-$__HostArch"
86 if [ "$__HostOS" == "FreeBSD" ]; then
87 __freebsd_version=`sysctl -n kern.osrelease | cut -f1 -d'.'`
88 __HostDistroRid="freebsd.$__freebsd_version-$__HostArch"
91 if [ "$__HostDistroRid" == "" ]; then
92 echo "WARNING: Can not determine runtime id for current distro."
98 if [ $__CrossBuild == 1 ]; then
99 if [ "$__BuildOS" == "Linux" ]; then
100 if [ ! -e $ROOTFS_DIR/etc/os-release ]; then
101 if [ -e $ROOTFS_DIR/android_platform ]; then
102 source $ROOTFS_DIR/android_platform
103 export __DistroRid="$RID"
105 echo "WARNING: Can not determine runtime id for current distro."
106 export __DistroRid=""
109 source $ROOTFS_DIR/etc/os-release
110 export __DistroRid="$ID.$VERSION_ID-$__BuildArch"
114 export __DistroRid="$__HostDistroRid"
117 if [ "$__BuildOS" == "OSX" ]; then
121 # Portable builds target the base RID
122 if [ $__PortableBuild == 1 ]; then
123 if [ "$__BuildOS" == "Linux" ]; then
124 export __DistroRid="linux-$__BuildArch"
125 elif [ "$__BuildOS" == "OSX" ]; then
126 export __DistroRid="osx-$__BuildArch"
127 elif [ "$__BuildOS" == "FreeBSD" ]; then
128 export __DistroRid="freebsd-$__BuildArch"
135 echo Setting up directories for build
137 mkdir -p "$__RootBinDir"
139 mkdir -p "$__LogsDir"
140 mkdir -p "$__IntermediatesDir"
142 if [ $__CrossBuild == 1 ]; then
143 mkdir -p "$__CrossComponentBinDir"
147 # Check the system to ensure the right prereqs are in place
151 echo "Checking prerequisites..."
153 # Check presence of CMake on the path
154 hash cmake 2>/dev/null || { echo >&2 "Please install cmake before running this script"; exit 1; }
157 # Minimum required version of clang is version 4.0 for arm/armel cross build
158 if [[ $__CrossBuild == 1 && ("$__BuildArch" == "arm" || "$__BuildArch" == "armel") ]]; then
159 if ! [[ "$__ClangMajorVersion" -ge "4" ]]; then
160 echo "Please install clang4.0 or latest for arm/armel cross build"; exit 1;
165 __ClangCombinedDottedVersion=$__ClangMajorVersion;
166 if [[ "$__ClangMinorVersion" != "" ]]; then
167 __ClangCombinedDottedVersion=$__ClangCombinedDottedVersion.$__ClangMinorVersion
169 hash clang-$__ClangCombinedDottedVersion 2>/dev/null || hash clang$__ClangMajorVersion$__ClangMinorVersion 2>/dev/null || hash clang 2>/dev/null || { echo >&2 "Please install clang-$__ClangMajorVersion.$__ClangMinorVersion before running this script"; exit 1; }
175 # we only need optdata on a Release build
176 if [[ "$__BuildType" != "Release" ]]; then __SkipRestoreOptData=1; fi
178 if [[ ( $__SkipRestoreOptData == 0 ) && ( $__isMSBuildOnNETCoreSupported == 1 ) ]]; then
179 echo "Restoring the OptimizationData package"
180 "$__ProjectRoot/run.sh" build -optdata $__RunArgs $__UnprocessedBuildArgs
182 echo "Failed to restore the optimization data package."
187 if [ $__isMSBuildOnNETCoreSupported == 1 ]; then
188 # Parse the optdata package versions out of msbuild so that we can pass them on to CMake
189 local DotNetCli="$__ProjectRoot/Tools/dotnetcli/dotnet"
190 if [ ! -f $DotNetCli ]; then
191 source "$__ProjectRoot/init-tools.sh"
193 echo "Failed to restore buildtools."
197 local OptDataProjectFilePath="$__ProjectRoot/src/.nuget/optdata/optdata.csproj"
198 __PgoOptDataVersion=$(DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 $DotNetCli msbuild $OptDataProjectFilePath /t:DumpPgoDataPackageVersion /nologo | sed 's/^\s*//')
199 __IbcOptDataVersion=$(DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 $DotNetCli msbuild $OptDataProjectFilePath /t:DumpIbcDataPackageVersion /nologo | sed 's/^[[:blank:]]*//')
203 generate_event_logging_sources()
206 __ConsumingBuildSystem=$2
208 __OutputIncDir="$__OutputDir/src/inc"
209 __OutputEventingDir="$__OutputDir/eventing"
210 __OutputEventProviderDir="$__OutputEventingDir/eventprovider"
212 echo "Laying out dynamically generated files consumed by $__ConsumingBuildSystem"
213 echo "Laying out dynamically generated Event test files, etmdummy stub functions, and external linkages"
215 __PythonWarningFlags="-Wall"
216 if [[ $__IgnoreWarnings == 0 ]]; then
217 __PythonWarningFlags="$__PythonWarningFlags -Werror"
220 $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genEventing.py" --inc $__OutputIncDir --dummy $__OutputIncDir/etmdummy.h --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --testdir "$__OutputEventProviderDir/tests"
221 if [[ $? != 0 ]]; then
225 echo "Laying out dynamically generated EventPipe Implementation"
226 $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genEventPipe.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventingDir/eventpipe"
228 echo "Laying out dynamically generated EventSource classes"
229 $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genRuntimeEventSources.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventingDir"
231 # determine the logging system
234 echo "Laying out dynamically generated Event Logging Implementation of Lttng"
235 $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genLttngProvider.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventProviderDir"
236 if [[ $? != 0 ]]; then
241 echo "Laying out dummy event logging provider"
242 $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genDummyProvider.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventProviderDir"
243 if [[ $? != 0 ]]; then
250 generate_event_logging()
252 # Event Logging Infrastructure
253 if [[ $__SkipCoreCLR == 0 || $__SkipMSCorLib == 0 || $__ConfigureOnly == 1 ]]; then
254 generate_event_logging_sources "$__IntermediatesDir" "the native build system"
262 intermediatesForBuild="$3"
263 extraCmakeArguments="$4"
266 if [ $skipCondition == 1 ]; then
267 echo "Skipping $message build."
271 # All set to commence the build
272 echo "Commencing build of $message for $__BuildOS.$__BuildArch.$__BuildType in $intermediatesForBuild"
277 if [ $__UseNinja == 1 ]; then
279 buildFile="build.ninja"
280 if ! buildTool=$(command -v ninja || command -v ninja-build); then
281 echo "Unable to locate ninja!" 1>&2
286 if [ $__SkipConfigure == 0 ]; then
287 # if msbuild is not supported, then set __SkipGenerateVersion to 1
288 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then __SkipGenerateVersion=1; fi
289 # Drop version.cpp file
290 __versionSourceFile="$intermediatesForBuild/version.cpp"
291 if [ $__SkipGenerateVersion == 0 ]; then
293 "$__ProjectRoot/run.sh" build -Project=$__ProjectDir/build.proj -generateHeaderUnix -NativeVersionSourceFile=$__versionSourceFile -MsBuildEventLogging="/l:BinClashLogger,Tools/Microsoft.DotNet.Build.Tasks.dll;LogFile=binclash.log" $__RunArgs $__UnprocessedBuildArgs
295 # Generate the dummy version.cpp, but only if it didn't exist to make sure we don't trigger unnecessary rebuild
296 __versionSourceLine="static char sccsid[] __attribute__((used)) = \"@(#)No version information produced\";"
297 if [ -e $__versionSourceFile ]; then
298 read existingVersionSourceLine < $__versionSourceFile
300 if [ "$__versionSourceLine" != "$existingVersionSourceLine" ]; then
301 echo $__versionSourceLine > $__versionSourceFile
306 pushd "$intermediatesForBuild"
307 # Regenerate the CMake solution
308 echo "Invoking \"$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh\" \"$__ProjectRoot\" $__ClangMajorVersion \"$__ClangMinorVersion\" $platformArch $__BuildType $__CodeCoverage $generator $extraCmakeArguments $__cmakeargs"
309 "$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh" "$__ProjectRoot" $__ClangMajorVersion "$__ClangMinorVersion" $platformArch $__BuildType $__CodeCoverage $generator "$extraCmakeArguments" "$__cmakeargs"
313 if [ ! -f "$intermediatesForBuild/$buildFile" ]; then
314 echo "Failed to generate $message build project!"
319 if [ $__ConfigureOnly == 1 ]; then
320 echo "Finish configuration & skipping $message build."
324 # Check that the makefiles were created.
325 pushd "$intermediatesForBuild"
327 echo "Executing $buildTool install -j $__NumProc"
329 $buildTool install -j $__NumProc
331 echo "Failed to build $message."
338 build_cross_architecture_components()
342 local intermediatesForBuild="$__IntermediatesDir/Host$crossArch/crossgen"
343 local crossArchBinDir="$__BinDir/$crossArch"
345 mkdir -p "$intermediatesForBuild"
346 mkdir -p "$crossArchBinDir"
348 generate_event_logging_sources "$intermediatesForBuild" "the crossarch build system"
350 __SkipCrossArchBuild=1
352 # check supported cross-architecture components host(__HostArch)/target(__BuildArch) pair
353 if [[ ("$__BuildArch" == "arm" || "$__BuildArch" == "armel") && "$crossArch" == "x86" ]]; then
354 export CROSSCOMPILE=0
355 __SkipCrossArchBuild=0
357 # building x64-host/arm-target cross-architecture component need to use cross toolchain of x86
358 if [ "$__HostArch" == "x64" ]; then
359 export CROSSCOMPILE=1
361 elif [[ ("$__BuildArch" == "arm64") && "$crossArch" == "x64" ]]; then
362 export CROSSCOMPILE=0
363 __SkipCrossArchBuild=0
364 elif [[ ("$__BuildArch" == "arm" || "$__BuildArch" == "armel") && "$crossArch" == "x64" ]]; then
365 export CROSSCOMPILE=0
366 __SkipCrossArchBuild=0
372 export __CMakeBinDir="$crossArchBinDir"
373 export CROSSCOMPONENT=1
375 if [ $CROSSCOMPILE == 1 ]; then
376 TARGET_ROOTFS="$ROOTFS_DIR"
377 if [ -n "$CAC_ROOTFS_DIR" ]; then
378 export ROOTFS_DIR="$CAC_ROOTFS_DIR"
380 export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__CrossArch"
384 __ExtraCmakeArgs="-DCLR_CMAKE_TARGET_ARCH=$__BuildArch -DCLR_CMAKE_TARGET_OS=$__BuildOS -DCLR_CMAKE_PACKAGES_DIR=$__PackagesDir -DCLR_CMAKE_PGO_INSTRUMENT=$__PgoInstrument -DCLR_CMAKE_OPTDATA_VERSION=$__PgoOptDataVersion -DCLR_CMAKE_PGO_OPTIMIZE=$__PgoOptimize -DCLR_CROSS_COMPONENTS_BUILD=1"
385 build_native $__SkipCrossArchBuild "$crossArch" "$intermediatesForBuild" "$__ExtraCmakeArgs" "cross-architecture components"
387 # restore ROOTFS_DIR and CROSSCOMPILE
388 if [ -n "$TARGET_ROOTFS" ]; then
389 export ROOTFS_DIR="$TARGET_ROOTFS"
391 export CROSSCOMPILE=1
394 isMSBuildOnNETCoreSupported()
396 __isMSBuildOnNETCoreSupported=$__msbuildonunsupportedplatform
398 if [ $__isMSBuildOnNETCoreSupported == 1 ]; then
402 if [ $__SkipManaged == 1 ]; then
403 __isMSBuildOnNETCoreSupported=0
407 if [ "$__HostArch" == "x64" ]; then
408 if [ "$__HostOS" == "Linux" ]; then
409 __isMSBuildOnNETCoreSupported=1
410 # note: the RIDs below can use globbing patterns
411 UNSUPPORTED_RIDS=("debian.9-x64" "ubuntu.17.04-x64")
412 for UNSUPPORTED_RID in "${UNSUPPORTED_RIDS[@]}"
414 if [[ $__HostDistroRid == $UNSUPPORTED_RID ]]; then
415 __isMSBuildOnNETCoreSupported=0
419 elif [ "$__HostOS" == "OSX" ]; then
420 __isMSBuildOnNETCoreSupported=1
421 elif [ "$__HostOS" == "FreeBSD" ]; then
422 __isMSBuildOnNETCoreSupported=1
430 local __CrossGenExec=$1
432 if [ $__PartialNgen == 1 ]; then
433 export COMPlus_PartialNGen=1
436 if [ -e $__CrossGenCoreLibLog ]; then
437 rm $__CrossGenCoreLibLog
439 echo "Generating native image of System.Private.CoreLib.dll for $__BuildOS.$__BuildArch.$__BuildType. Logging to \"$__CrossGenCoreLibLog\"."
440 echo "$__CrossGenExec /Platform_Assemblies_Paths $__BinDir/IL $__IbcTuning /out $__BinDir/System.Private.CoreLib.dll $__BinDir/IL/System.Private.CoreLib.dll"
441 $__CrossGenExec /Platform_Assemblies_Paths $__BinDir/IL $__IbcTuning /out $__BinDir/System.Private.CoreLib.dll $__BinDir/IL/System.Private.CoreLib.dll >> $__CrossGenCoreLibLog 2>&1
442 if [ $? -ne 0 ]; then
443 echo "Failed to generate native image for System.Private.CoreLib. Refer to $__CrossGenCoreLibLog"
447 if [ "$__BuildOS" == "Linux" ]; then
448 echo "Generating symbol file for System.Private.CoreLib.dll"
449 echo "$__CrossGenExec /Platform_Assemblies_Paths $__BinDir /CreatePerfMap $__BinDir $__BinDir/System.Private.CoreLib.dll"
450 $__CrossGenExec /Platform_Assemblies_Paths $__BinDir /CreatePerfMap $__BinDir $__BinDir/System.Private.CoreLib.dll >> $__CrossGenCoreLibLog 2>&1
451 if [ $? -ne 0 ]; then
452 echo "Failed to generate symbol file for System.Private.CoreLib. Refer to $__CrossGenCoreLibLog"
460 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
461 echo "System.Private.CoreLib.dll build unsupported."
465 if [ $__SkipMSCorLib == 1 ]; then
466 echo "Skipping building System.Private.CoreLib."
470 echo "Commencing build of managed components for $__BuildOS.$__BuildArch.$__BuildType"
474 if [[ "$__IbcTuning" == "" ]]; then
475 __ExtraBuildArgs="$__ExtraBuildArgs -OptimizationDataDir=\"$__PackagesDir/optimization.$__BuildOS-$__BuildArch.IBC.CoreCLR/$__IbcOptDataVersion/data/\""
476 __ExtraBuildArgs="$__ExtraBuildArgs -EnableProfileGuidedOptimization=true"
479 if [[ "$__BuildManagedTools" -eq "1" ]]; then
480 __ExtraBuildArgs="$__ExtraBuildArgs -BuildManagedTools=true"
483 $__ProjectRoot/run.sh build -Project=$__ProjectDir/build.proj -MsBuildEventLogging="/l:BinClashLogger,Tools/Microsoft.DotNet.Build.Tasks.dll;LogFile=binclash.log" -MsBuildLog="/flp:Verbosity=normal;LogFile=$__LogsDir/System.Private.CoreLib_$__BuildOS__$__BuildArch__$__BuildType.log" -BuildTarget -__IntermediatesDir=$__IntermediatesDir -__RootBinDir=$__RootBinDir -BuildNugetPackage=false -UseSharedCompilation=false $__RunArgs $__ExtraBuildArgs $__UnprocessedBuildArgs
485 if [ $? -ne 0 ]; then
486 echo "Failed to build managed components."
490 if [ $__SkipCrossgen == 1 ]; then
491 echo "Skipping generating native image"
495 # The cross build generates a crossgen with the target architecture.
496 if [ $__CrossBuild == 0 ]; then
497 if [ $__SkipCoreCLR == 1 ]; then
501 # The architecture of host pc must be same architecture with target.
502 if [[ ( "$__HostArch" == "$__BuildArch" ) ]]; then
503 build_CoreLib_ni "$__BinDir/crossgen"
504 elif [[ ( "$__HostArch" == "x64" ) && ( "$__BuildArch" == "x86" ) ]]; then
505 build_CoreLib_ni "$__BinDir/crossgen"
506 elif [[ ( "$__HostArch" == "arm64" ) && ( "$__BuildArch" == "arm" ) ]]; then
507 build_CoreLib_ni "$__BinDir/crossgen"
512 if [[ ( "$__CrossArch" == "x86" ) && ( "$__BuildArch" == "arm" ) ]]; then
513 build_CoreLib_ni "$__CrossComponentBinDir/crossgen"
514 elif [[ ( "$__CrossArch" == "x64" ) && ( "$__BuildArch" == "arm" ) ]]; then
515 build_CoreLib_ni "$__CrossComponentBinDir/crossgen"
516 elif [[ ( "$__HostArch" == "x64" ) && ( "$__BuildArch" == "arm64" ) ]]; then
517 build_CoreLib_ni "$__CrossComponentBinDir/crossgen"
522 generate_NugetPackages()
524 # We can only generate nuget package if we also support building mscorlib as part of this build.
525 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
526 echo "Nuget package generation unsupported."
530 # Since we can build mscorlib for this OS, did we build the native components as well?
531 if [[ $__SkipCoreCLR == 1 && $__CrossgenOnly == 0 ]]; then
532 echo "Unable to generate nuget packages since native components were not built."
536 echo "Generating nuget packages for "$__BuildOS
537 echo "DistroRid is "$__DistroRid
538 echo "ROOTFS_DIR is "$ROOTFS_DIR
540 $__ProjectRoot/run.sh build -Project=$__SourceDir/.nuget/packages.builds -MsBuildEventLogging="/l:BinClashLogger,Tools/Microsoft.DotNet.Build.Tasks.dll;LogFile=binclash.log" -MsBuildLog="/flp:Verbosity=normal;LogFile=$__LogsDir/Nuget_$__BuildOS__$__BuildArch__$__BuildType.log" -BuildTarget -__IntermediatesDir=$__IntermediatesDir -__RootBinDir=$__RootBinDir -BuildNugetPackage=false -UseSharedCompilation=false -__DoCrossArchBuild=$__CrossBuild $__RunArgs $__UnprocessedBuildArgs
542 if [ $? -ne 0 ]; then
543 echo "Failed to generate Nuget packages."
548 echo "Commencing CoreCLR Repo build"
550 # Argument types supported by this script:
552 # Build architecture - valid values are: x64, ARM.
553 # Build Type - valid values are: Debug, Checked, Release
555 # Set the default arguments for build
557 # Obtain the location of the bash script to figure out where the root of the repo is.
558 __ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
560 # Use uname to determine what the CPU is.
562 # Some Linux platforms report unknown for platform, but the arch for machine.
563 if [ "$CPUName" == "unknown" ]; then
569 echo "Unsupported CPU $CPUName detected, build might not succeed!"
580 echo "Unsupported CPU $CPUName detected, build might not succeed!"
595 echo "Unknown CPU $CPUName detected, configuring as if for x64"
601 # Use uname to determine what the OS is.
635 echo "Unsupported OS $OSName detected, configuring as if for Linux"
645 # Set the various build properties here so that CMake and MSBuild can pick them up
646 __ProjectDir="$__ProjectRoot"
647 __SourceDir="$__ProjectDir/src"
648 __PackagesDir="${DotNetRestorePackagesPath:-${__ProjectDir}/packages}"
649 __RootBinDir="$__ProjectDir/bin"
650 __UnprocessedBuildArgs=
665 __SkipRestoreOptData=0
671 __ClangMajorVersion=0
672 __ClangMinorVersion=0
673 __NuGetPath="$__PackagesDir/NuGet.exe"
677 __SkipGenerateVersion=0
679 __msbuildonunsupportedplatform=0
680 __PgoOptDataVersion=""
681 __IbcOptDataVersion=""
682 __BuildManagedTools=1
684 # Get the number of processors available to the scheduler
685 # Other techniques such as `nproc` only get the number of
686 # processors available to a single process.
687 if [ `uname` = "FreeBSD" ]; then
688 __NumProc=`sysctl hw.ncpu | awk '{ print $2+1 }'`
689 elif [ `uname` = "NetBSD" ]; then
690 __NumProc=$(($(getconf NPROCESSORS_ONLN)+1))
691 elif [ `uname` = "Darwin" ]; then
692 __NumProc=$(($(getconf _NPROCESSORS_ONLN)+1))
694 __NumProc=$(nproc --all)
698 if [ $# -le 0 ]; then
702 lowerI="$(echo $1 | awk '{print tolower($0)}')"
742 __CodeCoverage=Coverage
749 -portablebuild=false)
757 stripsymbols|-stripsymbols)
758 __cmakeargs="$__cmakeargs -DSTRIP_SYMBOLS=true"
762 __ClangMajorVersion=3
763 __ClangMinorVersion=5
767 __ClangMajorVersion=3
768 __ClangMinorVersion=6
772 __ClangMajorVersion=3
773 __ClangMinorVersion=7
777 __ClangMajorVersion=3
778 __ClangMinorVersion=8
782 __ClangMajorVersion=3
783 __ClangMinorVersion=9
787 __ClangMajorVersion=4
788 __ClangMinorVersion=0
792 __ClangMajorVersion=5
793 __ClangMinorVersion=0
797 __ClangMajorVersion=6
798 __ClangMinorVersion=0
802 __ClangMajorVersion=7
810 pgoinstrument|-pgoinstrument)
814 nopgooptimize|-nopgooptimize)
816 __SkipRestoreOptData=1
819 ibcinstrument|-ibcinstrument)
820 __IbcTuning="/Tuning"
823 configureonly|-configureonly)
829 skipconfigure|-skipconfigure)
833 skipnative|-skipnative)
834 # Use "skipnative" to use the same option name as build.cmd.
838 skipcoreclr|-skipcoreclr)
839 # Accept "skipcoreclr" for backwards-compatibility.
843 crosscomponent|-crosscomponent)
844 # Accept "crosscomponent" for backward-compatibility but ignore it.
845 echo "WARNING: 'crosscomponent' is obsolete and should not be used"
848 skipmanaged|-skipmanaged)
852 skipmscorlib|-skipmscorlib)
856 skipgenerateversion|-skipgenerateversion)
857 __SkipGenerateVersion=1
860 skiprestoreoptdata|-skiprestoreoptdata)
861 __SkipRestoreOptData=1
864 skipcrossgen|-skipcrossgen)
868 crossgenonly|-crossgenonly)
873 partialngen|-partialngen)
877 skiptests|-skiptests)
881 skipnuget|-skipnuget|skipbuildpackages|-skipbuildpackages)
885 ignorewarnings|-ignorewarnings)
887 __cmakeargs="$__cmakeargs -DCLR_CMAKE_WARNINGS_ARE_ERRORS=OFF"
890 cmakeargs|-cmakeargs)
892 __cmakeargs="$__cmakeargs $2"
895 echo "ERROR: 'cmakeargs' requires a non-empty option argument"
903 if [ ! -d $__RootBinDir ]; then
906 __RootBinParent=$(dirname $__RootBinDir)
907 __RootBinName=${__RootBinDir##*/}
908 __RootBinDir="$(cd $__RootBinParent &>/dev/null && printf %s/%s $PWD $__RootBinName)"
911 echo "ERROR: 'bindir' requires a non-empty option argument"
915 msbuildonunsupportedplatform|-msbuildonunsupportedplatform)
916 __msbuildonunsupportedplatform=1
923 echo "ERROR: 'numproc' requires a non-empty option argument"
932 echo "ERROR: 'osgroup' requires a non-empty option argument"
937 echo "ERROR: 'Rebuild' is not supported. Please remove it."
942 __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1"
949 __RunArgs="-BuildArch=$__BuildArch -BuildType=$__BuildType -BuildOS=$__BuildOS"
951 # Configure environment if we are doing a verbose build
952 if [ $__VerboseBuild == 1 ]; then
954 __RunArgs="$__RunArgs -verbose"
957 # Set default clang version
958 if [[ $__ClangMajorVersion == 0 && $__ClangMinorVersion == 0 ]]; then
959 if [[ "$__BuildArch" == "arm" || "$__BuildArch" == "armel" ]]; then
960 __ClangMajorVersion=5
961 __ClangMinorVersion=0
963 __ClangMajorVersion=3
964 __ClangMinorVersion=9
968 if [[ "$__BuildArch" == "armel" ]]; then
969 # Armel cross build is Tizen specific and does not support Portable RID build
973 if [ $__PortableBuild == 0 ]; then
974 __RunArgs="$__RunArgs -PortableBuild=false"
977 # Set dependent variables
978 __LogsDir="$__RootBinDir/Logs"
980 # init the host distro name
983 # Set the remaining variables based upon the determined build configuration
984 __BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType"
985 __PackagesBinDir="$__BinDir/.nuget"
986 __ToolsDir="$__RootBinDir/tools"
987 __TestWorkingDir="$__RootBinDir/tests/$__BuildOS.$__BuildArch.$__BuildType"
988 export __IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType"
989 __TestIntermediatesDir="$__RootBinDir/tests/obj/$__BuildOS.$__BuildArch.$__BuildType"
990 __isMSBuildOnNETCoreSupported=0
991 __CrossComponentBinDir="$__BinDir"
993 __CrossArch="$__HostArch"
994 if [ $__CrossBuild == 1 ]; then
995 __CrossComponentBinDir="$__CrossComponentBinDir/$__CrossArch"
997 __CrossGenCoreLibLog="$__LogsDir/CrossgenCoreLib_$__BuildOS.$__BuildArch.$__BuildType.log"
999 # Init if MSBuild for .NET Core is supported for this platform
1000 isMSBuildOnNETCoreSupported
1002 # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set.
1003 # This is needed by CLI to function.
1004 if [ -z "$HOME" ]; then
1005 if [ ! -d "$__ProjectDir/temp_home" ]; then
1008 export HOME=$__ProjectDir/temp_home
1009 echo "HOME not defined; setting it to $HOME"
1012 # Specify path to be set for CMAKE_INSTALL_PREFIX.
1013 # This is where all built CoreClr libraries will copied to.
1014 export __CMakeBinDir="$__BinDir"
1016 # Configure environment if we are doing a cross compile.
1017 if [ $__CrossBuild == 1 ]; then
1018 export CROSSCOMPILE=1
1019 if ! [[ -n "$ROOTFS_DIR" ]]; then
1020 export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__BuildArch"
1024 # init the target distro name
1027 # Make the directories necessary for build if they don't exist
1033 # Restore the package containing profile counts for profile-guided optimizations
1036 # Generate event logging infrastructure sources
1037 generate_event_logging
1039 # Build the coreclr (native) components.
1040 __ExtraCmakeArgs="-DCLR_CMAKE_TARGET_OS=$__BuildOS -DCLR_CMAKE_PACKAGES_DIR=$__PackagesDir -DCLR_CMAKE_PGO_INSTRUMENT=$__PgoInstrument -DCLR_CMAKE_OPTDATA_VERSION=$__PgoOptDataVersion -DCLR_CMAKE_PGO_OPTIMIZE=$__PgoOptimize"
1042 # [TODO] Remove this when the `build-test.sh` script properly builds and deploys test assets.
1043 if [ $__SkipTests != 1 ]; then
1044 echo "Adding CMake flags to build native tests for $__BuildOS.$__BuildArch.$__BuildType"
1045 __ExtraCmakeArgs="$__ExtraCmakeArgs -DCLR_CMAKE_BUILD_TESTS=ON"
1048 build_native $__SkipCoreCLR "$__BuildArch" "$__IntermediatesDir" "$__ExtraCmakeArgs" "CoreCLR component"
1050 # Build cross-architecture components
1051 if [[ $__CrossBuild == 1 ]]; then
1052 build_cross_architecture_components "$__CrossArch"
1054 # For now, continue building Hostx86/arm crossgen
1055 if [[ "$__HostArch" == "x64" && "$__BuildArch" == "arm" ]]; then
1056 build_cross_architecture_components "x86"
1060 # Build System.Private.CoreLib.
1064 if [ $__CrossgenOnly == 1 ]; then
1065 build_CoreLib_ni "$__BinDir/crossgen"
1068 # Generate nuget packages
1069 if [ $__SkipNuget != 1 ]; then
1070 generate_NugetPackages
1076 echo "Repo successfully built."
1077 echo "Product binaries are available at $__BinDir"