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 "-crosscomponent - optional argument to build cross-architecture component,"
38 echo " - will use CAC_ROOTFS_DIR environment variable if set."
39 echo "-nopgooptimize - do not use profile guided optimizations."
40 echo "-pgoinstrument - generate instrumented code for profile guided optimization enabled binaries."
41 echo "-ibcinstrument - generate IBC-tuning-enabled native images when invoking crossgen."
42 echo "-configureonly - do not perform any builds; just configure the build."
43 echo "-skipconfigure - skip build configuration."
44 echo "-skipnative - do not build native components."
45 echo "-skipmanaged - do not build managed components."
46 echo "-skipmscorlib - do not build mscorlib.dll."
47 echo "-skiptests - skip the tests in the 'tests' subdirectory."
48 echo "-skipnuget - skip building nuget packages."
49 echo "-skiprestoreoptdata - skip restoring optimization data used by profile-based optimizations."
50 echo "-skipcrossgen - skip native image generation"
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"
144 mkdir -p "$__CrossCompIntermediatesDir"
148 # Check the system to ensure the right prereqs are in place
152 echo "Checking prerequisites..."
154 # Check presence of CMake on the path
155 hash cmake 2>/dev/null || { echo >&2 "Please install cmake before running this script"; exit 1; }
158 # Minimum required version of clang is version 4.0 for arm/armel cross build
159 if [[ $__CrossBuild == 1 && ("$__BuildArch" == "arm" || "$__BuildArch" == "armel") ]]; then
160 if ! [[ "$__ClangMajorVersion" -ge "4" ]]; then
161 echo "Please install clang4.0 or latest for arm/armel cross build"; exit 1;
166 hash clang-$__ClangMajorVersion.$__ClangMinorVersion 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; }
172 # we only need optdata on a Release build
173 if [[ "$__BuildType" != "Release" ]]; then __SkipRestoreOptData=1; fi
175 if [[ ( $__SkipRestoreOptData == 0 ) && ( $__isMSBuildOnNETCoreSupported == 1 ) ]]; then
176 echo "Restoring the OptimizationData package"
177 "$__ProjectRoot/run.sh" build -optdata $__RunArgs $__UnprocessedBuildArgs
179 echo "Failed to restore the optimization data package."
184 if [ $__isMSBuildOnNETCoreSupported == 1 ]; then
185 # Parse the optdata package versions out of msbuild so that we can pass them on to CMake
186 local DotNetCli="$__ProjectRoot/Tools/dotnetcli/dotnet"
187 if [ ! -f $DotNetCli ]; then
188 source "$__ProjectRoot/init-tools.sh"
190 echo "Failed to restore buildtools."
194 local OptDataProjectFilePath="$__ProjectRoot/src/.nuget/optdata/optdata.csproj"
195 __PgoOptDataVersion=$(DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 $DotNetCli msbuild $OptDataProjectFilePath /t:DumpPgoDataPackageVersion /nologo | sed 's/^\s*//')
196 __IbcOptDataVersion=$(DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 $DotNetCli msbuild $OptDataProjectFilePath /t:DumpIbcDataPackageVersion /nologo | sed 's/^\s*//')
200 generate_event_logging_sources()
203 __ConsumingBuildSystem=$2
205 __OutputIncDir="$__OutputDir/src/inc"
206 __OutputEventingDir="$__OutputDir/eventing"
207 __OutputEventProviderDir="$__OutputEventingDir/eventprovider"
209 echo "Laying out dynamically generated files consumed by $__ConsumingBuildSystem"
210 echo "Laying out dynamically generated Event test files, etmdummy stub functions, and external linkages"
212 __PythonWarningFlags="-Wall"
213 if [[ $__IgnoreWarnings == 0 ]]; then
214 __PythonWarningFlags="$__PythonWarningFlags -Werror"
217 $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genEventing.py" --inc $__OutputIncDir --dummy $__OutputIncDir/etmdummy.h --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --testdir "$__OutputEventProviderDir/tests"
218 if [[ $? != 0 ]]; then
222 echo "Laying out dynamically generated EventPipe Implementation"
223 $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genEventPipe.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventingDir/eventpipe"
225 echo "Laying out dynamically generated EventSource classes"
226 $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genRuntimeEventSources.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventingDir"
228 # determine the logging system
231 echo "Laying out dynamically generated Event Logging Implementation of Lttng"
232 $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genLttngProvider.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventProviderDir"
233 if [[ $? != 0 ]]; then
238 echo "Laying out dummy event logging provider"
239 $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genDummyProvider.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventProviderDir"
240 if [[ $? != 0 ]]; then
247 generate_event_logging()
249 # Event Logging Infrastructure
250 if [[ $__SkipCoreCLR == 0 || $__SkipMSCorLib == 0 || $__ConfigureOnly == 1 ]]; then
251 generate_event_logging_sources "$__IntermediatesDir" "the native build system"
254 if [[ $__CrossBuild == 1 && $__DoCrossArchBuild == 1 ]]; then
255 generate_event_logging_sources "$__CrossCompIntermediatesDir" "the crossarch build system"
263 intermediatesForBuild="$3"
264 extraCmakeArguments="$4"
267 if [ $skipCondition == 1 ]; then
268 echo "Skipping $message build."
272 # All set to commence the build
273 echo "Commencing build of $message for $__BuildOS.$__BuildArch.$__BuildType in $intermediatesForBuild"
278 if [ $__UseNinja == 1 ]; then
280 buildFile="build.ninja"
281 if ! buildTool=$(command -v ninja || command -v ninja-build); then
282 echo "Unable to locate ninja!" 1>&2
287 if [ $__SkipConfigure == 0 ]; then
288 # if msbuild is not supported, then set __SkipGenerateVersion to 1
289 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then __SkipGenerateVersion=1; fi
290 # Drop version.cpp file
291 __versionSourceFile="$intermediatesForBuild/version.cpp"
292 if [ $__SkipGenerateVersion == 0 ]; then
294 "$__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
296 # Generate the dummy version.cpp, but only if it didn't exist to make sure we don't trigger unnecessary rebuild
297 __versionSourceLine="static char sccsid[] __attribute__((used)) = \"@(#)No version information produced\";"
298 if [ -e $__versionSourceFile ]; then
299 read existingVersionSourceLine < $__versionSourceFile
301 if [ "$__versionSourceLine" != "$existingVersionSourceLine" ]; then
302 echo $__versionSourceLine > $__versionSourceFile
307 pushd "$intermediatesForBuild"
308 # Regenerate the CMake solution
309 echo "Invoking \"$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh\" \"$__ProjectRoot\" $__ClangMajorVersion $__ClangMinorVersion $platformArch $__BuildType $__CodeCoverage $generator $extraCmakeArguments $__cmakeargs"
310 "$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh" "$__ProjectRoot" $__ClangMajorVersion $__ClangMinorVersion $platformArch $__BuildType $__CodeCoverage $generator "$extraCmakeArguments" "$__cmakeargs"
314 if [ ! -f "$intermediatesForBuild/$buildFile" ]; then
315 echo "Failed to generate $message build project!"
320 if [ $__ConfigureOnly == 1 ]; then
321 echo "Finish configuration & skipping $message build."
325 # Check that the makefiles were created.
326 pushd "$intermediatesForBuild"
328 echo "Executing $buildTool install -j $__NumProc"
330 $buildTool install -j $__NumProc
332 echo "Failed to build $message."
339 build_cross_arch_component()
341 __SkipCrossArchBuild=1
343 # check supported cross-architecture components host(__HostArch)/target(__BuildArch) pair
344 if [[ ("$__BuildArch" == "arm" || "$__BuildArch" == "armel") && "$__CrossArch" == "x86" ]]; then
345 export CROSSCOMPILE=0
346 __SkipCrossArchBuild=0
348 # building x64-host/arm-target cross-architecture component need to use cross toolchain of x86
349 if [ "$__HostArch" == "x64" ]; then
350 export CROSSCOMPILE=1
352 elif [[ ("$__BuildArch" == "arm64") && "$__CrossArch" == "x64" ]]; then
353 export CROSSCOMPILE=0
354 __SkipCrossArchBuild=0
360 export __CMakeBinDir="$__CrossComponentBinDir"
361 export CROSSCOMPONENT=1
363 if [ $CROSSCOMPILE == 1 ]; then
364 TARGET_ROOTFS="$ROOTFS_DIR"
365 if [ -n "$CAC_ROOTFS_DIR" ]; then
366 export ROOTFS_DIR="$CAC_ROOTFS_DIR"
368 export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__CrossArch"
372 __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"
373 build_native $__SkipCrossArchBuild "$__CrossArch" "$__CrossCompIntermediatesDir" "$__ExtraCmakeArgs" "cross-architecture component"
375 # restore ROOTFS_DIR, CROSSCOMPONENT, and CROSSCOMPILE
376 if [ -n "$TARGET_ROOTFS" ]; then
377 export ROOTFS_DIR="$TARGET_ROOTFS"
379 export CROSSCOMPONENT=
380 export CROSSCOMPILE=1
383 isMSBuildOnNETCoreSupported()
385 __isMSBuildOnNETCoreSupported=$__msbuildonunsupportedplatform
387 if [ $__isMSBuildOnNETCoreSupported == 1 ]; then
391 if [ $__SkipManaged == 1 ]; then
392 __isMSBuildOnNETCoreSupported=0
396 if [ "$__HostArch" == "x64" ]; then
397 if [ "$__HostOS" == "Linux" ]; then
398 __isMSBuildOnNETCoreSupported=1
399 # note: the RIDs below can use globbing patterns
400 UNSUPPORTED_RIDS=("debian.9-x64" "ubuntu.17.04-x64")
401 for UNSUPPORTED_RID in "${UNSUPPORTED_RIDS[@]}"
403 if [[ $__HostDistroRid == $UNSUPPORTED_RID ]]; then
404 __isMSBuildOnNETCoreSupported=0
408 elif [ "$__HostOS" == "OSX" ]; then
409 __isMSBuildOnNETCoreSupported=1
417 local __CrossGenExec=$1
419 echo "Generating native image for System.Private.CoreLib.dll"
420 echo "$__CrossGenExec /Platform_Assemblies_Paths $__BinDir/IL $__IbcTuning /out $__BinDir/System.Private.CoreLib.dll $__BinDir/IL/System.Private.CoreLib.dll"
421 $__CrossGenExec /Platform_Assemblies_Paths $__BinDir/IL $__IbcTuning /out $__BinDir/System.Private.CoreLib.dll $__BinDir/IL/System.Private.CoreLib.dll
422 if [ $? -ne 0 ]; then
423 echo "Failed to generate native image for System.Private.CoreLib."
427 if [ "$__BuildOS" == "Linux" ]; then
428 echo "Generating symbol file for System.Private.CoreLib.dll"
429 echo "$__CrossGenExec /Platform_Assemblies_Paths $__BinDir /CreatePerfMap $__BinDir $__BinDir/System.Private.CoreLib.dll"
430 $__CrossGenExec /Platform_Assemblies_Paths $__BinDir /CreatePerfMap $__BinDir $__BinDir/System.Private.CoreLib.dll
431 if [ $? -ne 0 ]; then
432 echo "Failed to generate symbol file for System.Private.CoreLib."
440 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
441 echo "System.Private.CoreLib.dll build unsupported."
445 if [ $__SkipMSCorLib == 1 ]; then
446 echo "Skipping building System.Private.CoreLib."
450 echo "Commencing build of managed components for $__BuildOS.$__BuildArch.$__BuildType"
454 if [[ "$__IbcTuning" -eq "" ]]; then
455 __ExtraBuildArgs="$__ExtraBuildArgs -OptimizationDataDir=\"$__PackagesDir/optimization.$__BuildOS-$__BuildArch.IBC.CoreCLR/$__IbcOptDataVersion/data/\""
456 __ExtraBuildArgs="$__ExtraBuildArgs -EnableProfileGuidedOptimization=true"
459 if [[ "$__BuildManagedTools" -eq "1" ]]; then
460 __ExtraBuildArgs="$__ExtraBuildArgs -BuildManagedTools=true"
463 $__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
465 if [ $? -ne 0 ]; then
466 echo "Failed to build managed components."
470 if [ $__SkipCrossgen == 1 ]; then
471 echo "Skipping generating native image"
475 # The cross build generates a crossgen with the target architecture.
476 if [ $__CrossBuild == 0 ]; then
477 if [ $__SkipCoreCLR == 1 ]; then
481 # The architecture of host pc must be same architecture with target.
482 if [[ ( "$__HostArch" == "$__BuildArch" ) ]]; then
483 build_CoreLib_ni "$__BinDir/crossgen"
484 elif [[ ( "$__HostArch" == "x64" ) && ( "$__BuildArch" == "x86" ) ]]; then
485 build_CoreLib_ni "$__BinDir/crossgen"
486 elif [[ ( "$__HostArch" == "arm64" ) && ( "$__BuildArch" == "arm" ) ]]; then
487 build_CoreLib_ni "$__BinDir/crossgen"
491 elif [ $__DoCrossArchBuild == 1 ]; then
492 if [[ ( "$__CrossArch" == "x86" ) && ( "$__BuildArch" == "arm" ) ]]; then
493 build_CoreLib_ni "$__CrossComponentBinDir/crossgen"
494 elif [[ ( "$__HostArch" == "x64" ) && ( "$__BuildArch" == "arm64" ) ]]; then
495 build_CoreLib_ni "$__CrossComponentBinDir/crossgen"
500 generate_NugetPackages()
502 # We can only generate nuget package if we also support building mscorlib as part of this build.
503 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
504 echo "Nuget package generation unsupported."
508 # Since we can build mscorlib for this OS, did we build the native components as well?
509 if [ $__SkipCoreCLR == 1 ]; then
510 echo "Unable to generate nuget packages since native components were not built."
514 echo "Generating nuget packages for "$__BuildOS
515 echo "DistroRid is "$__DistroRid
516 echo "ROOTFS_DIR is "$ROOTFS_DIR
518 $__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=$__DoCrossArchBuild $__RunArgs $__UnprocessedBuildArgs
520 if [ $? -ne 0 ]; then
521 echo "Failed to generate Nuget packages."
526 echo "Commencing CoreCLR Repo build"
528 # Argument types supported by this script:
530 # Build architecture - valid values are: x64, ARM.
531 # Build Type - valid values are: Debug, Checked, Release
533 # Set the default arguments for build
535 # Obtain the location of the bash script to figure out where the root of the repo is.
536 __ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
538 # Use uname to determine what the CPU is.
540 # Some Linux platforms report unknown for platform, but the arch for machine.
541 if [ "$CPUName" == "unknown" ]; then
547 echo "Unsupported CPU $CPUName detected, build might not succeed!"
558 echo "Unsupported CPU $CPUName detected, build might not succeed!"
573 echo "Unknown CPU $CPUName detected, configuring as if for x64"
579 # Use uname to determine what the OS is.
613 echo "Unsupported OS $OSName detected, configuring as if for Linux"
623 # Set the various build properties here so that CMake and MSBuild can pick them up
624 __ProjectDir="$__ProjectRoot"
625 __SourceDir="$__ProjectDir/src"
626 __PackagesDir="${DotNetRestorePackagesPath:-${__ProjectDir}/packages}"
627 __RootBinDir="$__ProjectDir/bin"
628 __UnprocessedBuildArgs=
643 __SkipRestoreOptData=0
647 __ClangMajorVersion=0
648 __ClangMinorVersion=0
649 __NuGetPath="$__PackagesDir/NuGet.exe"
653 __SkipGenerateVersion=0
656 __msbuildonunsupportedplatform=0
657 __PgoOptDataVersion=""
658 __IbcOptDataVersion=""
659 __BuildManagedTools=1
661 # Get the number of processors available to the scheduler
662 # Other techniques such as `nproc` only get the number of
663 # processors available to a single process.
664 if [ `uname` = "FreeBSD" ]; then
665 __NumProc=`sysctl hw.ncpu | awk '{ print $2+1 }'`
666 elif [ `uname` = "NetBSD" ]; then
667 __NumProc=$(($(getconf NPROCESSORS_ONLN)+1))
668 elif [ `uname` = "Darwin" ]; then
669 __NumProc=$(($(getconf _NPROCESSORS_ONLN)+1))
671 __NumProc=$(nproc --all)
675 if [ $# -le 0 ]; then
679 lowerI="$(echo $1 | awk '{print tolower($0)}')"
719 __CodeCoverage=Coverage
726 -portablebuild=false)
734 stripsymbols|-stripsymbols)
735 __cmakeargs="$__cmakeargs -DSTRIP_SYMBOLS=true"
739 __ClangMajorVersion=3
740 __ClangMinorVersion=5
744 __ClangMajorVersion=3
745 __ClangMinorVersion=6
749 __ClangMajorVersion=3
750 __ClangMinorVersion=7
754 __ClangMajorVersion=3
755 __ClangMinorVersion=8
759 __ClangMajorVersion=3
760 __ClangMinorVersion=9
764 __ClangMajorVersion=4
765 __ClangMinorVersion=0
769 __ClangMajorVersion=5
770 __ClangMinorVersion=0
774 __ClangMajorVersion=6
775 __ClangMinorVersion=0
782 pgoinstrument|-pgoinstrument)
786 nopgooptimize|-nopgooptimize)
788 __SkipRestoreOptData=1
791 ibcinstrument|-ibcinstrument)
792 __IbcTuning="/Tuning"
795 configureonly|-configureonly)
801 skipconfigure|-skipconfigure)
805 skipnative|-skipnative)
806 # Use "skipnative" to use the same option name as build.cmd.
810 skipcoreclr|-skipcoreclr)
811 # Accept "skipcoreclr" for backwards-compatibility.
815 crosscomponent|-crosscomponent)
819 skipmanaged|-skipmanaged)
823 skipmscorlib|-skipmscorlib)
827 skipgenerateversion|-skipgenerateversion)
828 __SkipGenerateVersion=1
831 skiprestoreoptdata|-skiprestoreoptdata)
832 __SkipRestoreOptData=1
835 skipcrossgen|-skipcrossgen)
839 skiptests|-skiptests)
843 skipnuget|-skipnuget|skipbuildpackages|-skipbuildpackages)
847 ignorewarnings|-ignorewarnings)
849 __cmakeargs="$__cmakeargs -DCLR_CMAKE_WARNINGS_ARE_ERRORS=OFF"
852 cmakeargs|-cmakeargs)
854 __cmakeargs="$__cmakeargs $2"
857 echo "ERROR: 'cmakeargs' requires a non-empty option argument"
865 if [ ! -d $__RootBinDir ]; then
868 __RootBinParent=$(dirname $__RootBinDir)
869 __RootBinName=${__RootBinDir##*/}
870 __RootBinDir="$(cd $__RootBinParent &>/dev/null && printf %s/%s $PWD $__RootBinName)"
873 echo "ERROR: 'bindir' requires a non-empty option argument"
877 msbuildonunsupportedplatform|-msbuildonunsupportedplatform)
878 __msbuildonunsupportedplatform=1
885 echo "ERROR: 'numproc' requires a non-empty option argument"
894 echo "ERROR: 'osgroup' requires a non-empty option argument"
899 echo "ERROR: 'Rebuild' is not supported. Please remove it."
904 __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1"
911 __RunArgs="-BuildArch=$__BuildArch -BuildType=$__BuildType -BuildOS=$__BuildOS"
913 # Configure environment if we are doing a verbose build
914 if [ $__VerboseBuild == 1 ]; then
916 __RunArgs="$__RunArgs -verbose"
919 # Set default clang version
920 if [[ $__ClangMajorVersion == 0 && $__ClangMinorVersion == 0 ]]; then
921 if [[ "$__BuildArch" == "arm" || "$__BuildArch" == "armel" ]]; then
922 __ClangMajorVersion=5
923 __ClangMinorVersion=0
925 __ClangMajorVersion=3
926 __ClangMinorVersion=9
930 if [[ "$__BuildArch" == "armel" ]]; then
931 # Armel cross build is Tizen specific and does not support Portable RID build
935 if [ $__PortableBuild == 0 ]; then
936 __RunArgs="$__RunArgs -PortableBuild=false"
939 # Set dependent variables
940 __LogsDir="$__RootBinDir/Logs"
942 # init the host distro name
945 # Set the remaining variables based upon the determined build configuration
946 __BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType"
947 __PackagesBinDir="$__BinDir/.nuget"
948 __ToolsDir="$__RootBinDir/tools"
949 __TestWorkingDir="$__RootBinDir/tests/$__BuildOS.$__BuildArch.$__BuildType"
950 export __IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType"
951 __TestIntermediatesDir="$__RootBinDir/tests/obj/$__BuildOS.$__BuildArch.$__BuildType"
952 __isMSBuildOnNETCoreSupported=0
953 __CrossComponentBinDir="$__BinDir"
954 __CrossCompIntermediatesDir="$__IntermediatesDir/crossgen"
956 __CrossArch="$__HostArch"
957 if [[ "$__HostArch" == "x64" && ("$__BuildArch" == "arm" || "$__BuildArch" == "armel") ]]; then
960 if [ $__CrossBuild == 1 ]; then
961 __CrossComponentBinDir="$__CrossComponentBinDir/$__CrossArch"
963 __CrossgenCoreLibLog="$__LogsDir/CrossgenCoreLib_$__BuildOS.$BuildArch.$__BuildType.log"
964 __CrossgenExe="$__CrossComponentBinDir/crossgen"
966 # Init if MSBuild for .NET Core is supported for this platform
967 isMSBuildOnNETCoreSupported
969 # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set.
970 # This is needed by CLI to function.
971 if [ -z "$HOME" ]; then
972 if [ ! -d "$__ProjectDir/temp_home" ]; then
975 export HOME=$__ProjectDir/temp_home
976 echo "HOME not defined; setting it to $HOME"
979 # Specify path to be set for CMAKE_INSTALL_PREFIX.
980 # This is where all built CoreClr libraries will copied to.
981 export __CMakeBinDir="$__BinDir"
983 # Configure environment if we are doing a cross compile.
984 if [ $__CrossBuild == 1 ]; then
985 export CROSSCOMPILE=1
986 if ! [[ -n "$ROOTFS_DIR" ]]; then
987 export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__BuildArch"
991 # init the target distro name
994 # Make the directories necessary for build if they don't exist
1000 # Restore the package containing profile counts for profile-guided optimizations
1003 # Generate event logging infrastructure sources
1004 generate_event_logging
1006 # Build the coreclr (native) components.
1007 __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"
1009 # [TODO] Remove this when the `build-test.sh` script properly builds and deploys test assets.
1010 if [ $__SkipTests != 1 ]; then
1011 echo "Adding CMake flags to build native tests for $__BuildOS.$__BuildArch.$__BuildType"
1012 __ExtraCmakeArgs="$__ExtraCmakeArgs -DCLR_CMAKE_BUILD_TESTS=ON"
1015 build_native $__SkipCoreCLR "$__BuildArch" "$__IntermediatesDir" "$__ExtraCmakeArgs" "CoreCLR component"
1017 # Build cross-architecture components
1018 if [[ $__CrossBuild == 1 && $__DoCrossArchBuild == 1 ]]; then
1019 build_cross_arch_component
1022 # Build System.Private.CoreLib.
1026 # Generate nuget packages
1027 if [ $__SkipNuget != 1 ]; then
1028 generate_NugetPackages
1034 echo "Repo successfully built."
1035 echo "Product binaries are available at $__BinDir"