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"
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 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; }
171 # we only need optdata on a Release build
172 if [[ "$__BuildType" != "Release" ]]; then __SkipRestoreOptData=1; fi
174 if [[ ( $__SkipRestoreOptData == 0 ) && ( $__isMSBuildOnNETCoreSupported == 1 ) ]]; then
175 echo "Restoring the OptimizationData package"
176 "$__ProjectRoot/run.sh" build -optdata $__RunArgs $__UnprocessedBuildArgs
178 echo "Failed to restore the optimization data package."
183 if [ $__isMSBuildOnNETCoreSupported == 1 ]; then
184 # Parse the optdata package versions out of msbuild so that we can pass them on to CMake
185 local DotNetCli="$__ProjectRoot/Tools/dotnetcli/dotnet"
186 if [ ! -f $DotNetCli ]; then
187 source "$__ProjectRoot/init-tools.sh"
189 echo "Failed to restore buildtools."
193 local OptDataProjectFilePath="$__ProjectRoot/src/.nuget/optdata/optdata.csproj"
194 __PgoOptDataVersion=$(DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 $DotNetCli msbuild $OptDataProjectFilePath /t:DumpPgoDataPackageVersion /nologo | sed 's/^\s*//')
195 __IbcOptDataVersion=$(DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 $DotNetCli msbuild $OptDataProjectFilePath /t:DumpIbcDataPackageVersion /nologo | sed 's/^[[:blank:]]*//')
199 generate_event_logging_sources()
202 __ConsumingBuildSystem=$2
204 __OutputIncDir="$__OutputDir/src/inc"
205 __OutputEventingDir="$__OutputDir/eventing"
206 __OutputEventProviderDir="$__OutputEventingDir/eventprovider"
208 echo "Laying out dynamically generated files consumed by $__ConsumingBuildSystem"
209 echo "Laying out dynamically generated Event test files, etmdummy stub functions, and external linkages"
211 __PythonWarningFlags="-Wall"
212 if [[ $__IgnoreWarnings == 0 ]]; then
213 __PythonWarningFlags="$__PythonWarningFlags -Werror"
216 $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genEventing.py" --inc $__OutputIncDir --dummy $__OutputIncDir/etmdummy.h --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --testdir "$__OutputEventProviderDir/tests"
217 if [[ $? != 0 ]]; then
221 echo "Laying out dynamically generated EventPipe Implementation"
222 $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genEventPipe.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventingDir/eventpipe"
224 echo "Laying out dynamically generated EventSource classes"
225 $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genRuntimeEventSources.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventingDir"
227 # determine the logging system
230 echo "Laying out dynamically generated Event Logging Implementation of Lttng"
231 $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genLttngProvider.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventProviderDir"
232 if [[ $? != 0 ]]; then
237 echo "Laying out dummy event logging provider"
238 $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genDummyProvider.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventProviderDir"
239 if [[ $? != 0 ]]; then
246 generate_event_logging()
248 # Event Logging Infrastructure
249 if [[ $__SkipCoreCLR == 0 || $__SkipMSCorLib == 0 || $__ConfigureOnly == 1 ]]; then
250 generate_event_logging_sources "$__IntermediatesDir" "the native build system"
258 intermediatesForBuild="$3"
259 extraCmakeArguments="$4"
262 if [ $skipCondition == 1 ]; then
263 echo "Skipping $message build."
267 # All set to commence the build
268 echo "Commencing build of $message for $__BuildOS.$__BuildArch.$__BuildType in $intermediatesForBuild"
273 if [ $__UseNinja == 1 ]; then
275 buildFile="build.ninja"
276 if ! buildTool=$(command -v ninja || command -v ninja-build); then
277 echo "Unable to locate ninja!" 1>&2
282 if [ $__SkipConfigure == 0 ]; then
283 # if msbuild is not supported, then set __SkipGenerateVersion to 1
284 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then __SkipGenerateVersion=1; fi
285 # Drop version.cpp file
286 __versionSourceFile="$intermediatesForBuild/version.cpp"
287 if [ $__SkipGenerateVersion == 0 ]; then
289 "$__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
291 # Generate the dummy version.cpp, but only if it didn't exist to make sure we don't trigger unnecessary rebuild
292 __versionSourceLine="static char sccsid[] __attribute__((used)) = \"@(#)No version information produced\";"
293 if [ -e $__versionSourceFile ]; then
294 read existingVersionSourceLine < $__versionSourceFile
296 if [ "$__versionSourceLine" != "$existingVersionSourceLine" ]; then
297 echo $__versionSourceLine > $__versionSourceFile
302 pushd "$intermediatesForBuild"
303 # Regenerate the CMake solution
304 echo "Invoking \"$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh\" \"$__ProjectRoot\" $__ClangMajorVersion $__ClangMinorVersion $platformArch $__BuildType $__CodeCoverage $generator $extraCmakeArguments $__cmakeargs"
305 "$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh" "$__ProjectRoot" $__ClangMajorVersion $__ClangMinorVersion $platformArch $__BuildType $__CodeCoverage $generator "$extraCmakeArguments" "$__cmakeargs"
309 if [ ! -f "$intermediatesForBuild/$buildFile" ]; then
310 echo "Failed to generate $message build project!"
315 if [ $__ConfigureOnly == 1 ]; then
316 echo "Finish configuration & skipping $message build."
320 # Check that the makefiles were created.
321 pushd "$intermediatesForBuild"
323 echo "Executing $buildTool install -j $__NumProc"
325 $buildTool install -j $__NumProc
327 echo "Failed to build $message."
334 build_cross_architecture_components()
338 local intermediatesForBuild="$__IntermediatesDir/Host$crossArch/crossgen"
339 local crossArchBinDir="$__BinDir/$crossArch"
341 mkdir -p "$intermediatesForBuild"
342 mkdir -p "$crossArchBinDir"
344 generate_event_logging_sources "$intermediatesForBuild" "the crossarch build system"
346 __SkipCrossArchBuild=1
348 # check supported cross-architecture components host(__HostArch)/target(__BuildArch) pair
349 if [[ ("$__BuildArch" == "arm" || "$__BuildArch" == "armel") && "$crossArch" == "x86" ]]; then
350 export CROSSCOMPILE=0
351 __SkipCrossArchBuild=0
353 # building x64-host/arm-target cross-architecture component need to use cross toolchain of x86
354 if [ "$__HostArch" == "x64" ]; then
355 export CROSSCOMPILE=1
357 elif [[ ("$__BuildArch" == "arm64") && "$crossArch" == "x64" ]]; then
358 export CROSSCOMPILE=0
359 __SkipCrossArchBuild=0
360 elif [[ ("$__BuildArch" == "arm" || "$__BuildArch" == "armel") && "$crossArch" == "x64" ]]; then
361 export CROSSCOMPILE=0
362 __SkipCrossArchBuild=0
368 export __CMakeBinDir="$crossArchBinDir"
369 export CROSSCOMPONENT=1
371 if [ $CROSSCOMPILE == 1 ]; then
372 TARGET_ROOTFS="$ROOTFS_DIR"
373 if [ -n "$CAC_ROOTFS_DIR" ]; then
374 export ROOTFS_DIR="$CAC_ROOTFS_DIR"
376 export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__CrossArch"
380 __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"
381 build_native $__SkipCrossArchBuild "$crossArch" "$intermediatesForBuild" "$__ExtraCmakeArgs" "cross-architecture components"
383 # restore ROOTFS_DIR, CROSSCOMPONENT, and CROSSCOMPILE
384 if [ -n "$TARGET_ROOTFS" ]; then
385 export ROOTFS_DIR="$TARGET_ROOTFS"
387 export CROSSCOMPONENT=
388 export CROSSCOMPILE=1
391 isMSBuildOnNETCoreSupported()
393 __isMSBuildOnNETCoreSupported=$__msbuildonunsupportedplatform
395 if [ $__isMSBuildOnNETCoreSupported == 1 ]; then
399 if [ $__SkipManaged == 1 ]; then
400 __isMSBuildOnNETCoreSupported=0
404 if [ "$__HostArch" == "x64" ]; then
405 if [ "$__HostOS" == "Linux" ]; then
406 __isMSBuildOnNETCoreSupported=1
407 # note: the RIDs below can use globbing patterns
408 UNSUPPORTED_RIDS=("debian.9-x64" "ubuntu.17.04-x64")
409 for UNSUPPORTED_RID in "${UNSUPPORTED_RIDS[@]}"
411 if [[ $__HostDistroRid == $UNSUPPORTED_RID ]]; then
412 __isMSBuildOnNETCoreSupported=0
416 elif [ "$__HostOS" == "OSX" ]; then
417 __isMSBuildOnNETCoreSupported=1
425 local __CrossGenExec=$1
427 if [ -e $__CrossGenCoreLibLog ]; then
428 rm $__CrossGenCoreLibLog
430 echo "Generating native image of System.Private.CoreLib.dll for $__BuildOS.$__BuildArch.$__BuildType. Logging to \"$__CrossGenCoreLibLog\"."
431 echo "$__CrossGenExec /Platform_Assemblies_Paths $__BinDir/IL $__IbcTuning /out $__BinDir/System.Private.CoreLib.dll $__BinDir/IL/System.Private.CoreLib.dll"
432 $__CrossGenExec /Platform_Assemblies_Paths $__BinDir/IL $__IbcTuning /out $__BinDir/System.Private.CoreLib.dll $__BinDir/IL/System.Private.CoreLib.dll >> $__CrossGenCoreLibLog 2>&1
433 if [ $? -ne 0 ]; then
434 echo "Failed to generate native image for System.Private.CoreLib. Refer to $__CrossGenCoreLibLog"
438 if [ "$__BuildOS" == "Linux" ]; then
439 echo "Generating symbol file for System.Private.CoreLib.dll"
440 echo "$__CrossGenExec /Platform_Assemblies_Paths $__BinDir /CreatePerfMap $__BinDir $__BinDir/System.Private.CoreLib.dll"
441 $__CrossGenExec /Platform_Assemblies_Paths $__BinDir /CreatePerfMap $__BinDir $__BinDir/System.Private.CoreLib.dll >> $__CrossGenCoreLibLog 2>&1
442 if [ $? -ne 0 ]; then
443 echo "Failed to generate symbol file for System.Private.CoreLib. Refer to $__CrossGenCoreLibLog"
451 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
452 echo "System.Private.CoreLib.dll build unsupported."
456 if [ $__SkipMSCorLib == 1 ]; then
457 echo "Skipping building System.Private.CoreLib."
461 echo "Commencing build of managed components for $__BuildOS.$__BuildArch.$__BuildType"
465 if [[ "$__IbcTuning" == "" ]]; then
466 __ExtraBuildArgs="$__ExtraBuildArgs -OptimizationDataDir=\"$__PackagesDir/optimization.$__BuildOS-$__BuildArch.IBC.CoreCLR/$__IbcOptDataVersion/data/\""
467 __ExtraBuildArgs="$__ExtraBuildArgs -EnableProfileGuidedOptimization=true"
470 if [[ "$__BuildManagedTools" -eq "1" ]]; then
471 __ExtraBuildArgs="$__ExtraBuildArgs -BuildManagedTools=true"
474 $__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
476 if [ $? -ne 0 ]; then
477 echo "Failed to build managed components."
481 if [ $__SkipCrossgen == 1 ]; then
482 echo "Skipping generating native image"
486 # The cross build generates a crossgen with the target architecture.
487 if [ $__CrossBuild == 0 ]; then
488 if [ $__SkipCoreCLR == 1 ]; then
492 # The architecture of host pc must be same architecture with target.
493 if [[ ( "$__HostArch" == "$__BuildArch" ) ]]; then
494 build_CoreLib_ni "$__BinDir/crossgen"
495 elif [[ ( "$__HostArch" == "x64" ) && ( "$__BuildArch" == "x86" ) ]]; then
496 build_CoreLib_ni "$__BinDir/crossgen"
497 elif [[ ( "$__HostArch" == "arm64" ) && ( "$__BuildArch" == "arm" ) ]]; then
498 build_CoreLib_ni "$__BinDir/crossgen"
502 elif [ $__DoCrossArchBuild == 1 ]; then
503 if [[ ( "$__CrossArch" == "x86" ) && ( "$__BuildArch" == "arm" || "$__BuildArch" == "armel" ) ]]; then
504 build_CoreLib_ni "$__CrossComponentBinDir/crossgen"
505 elif [[ ( "$__CrossArch" == "x64" ) && ( "$__BuildArch" == "arm" || "$__BuildArch" == "armel" ) ]]; then
506 build_CoreLib_ni "$__CrossComponentBinDir/crossgen"
507 elif [[ ( "$__HostArch" == "x64" ) && ( "$__BuildArch" == "arm64" ) ]]; then
508 build_CoreLib_ni "$__CrossComponentBinDir/crossgen"
513 generate_NugetPackages()
515 # We can only generate nuget package if we also support building mscorlib as part of this build.
516 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
517 echo "Nuget package generation unsupported."
521 # Since we can build mscorlib for this OS, did we build the native components as well?
522 if [ $__SkipCoreCLR == 1 ]; then
523 echo "Unable to generate nuget packages since native components were not built."
527 echo "Generating nuget packages for "$__BuildOS
528 echo "DistroRid is "$__DistroRid
529 echo "ROOTFS_DIR is "$ROOTFS_DIR
531 $__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
533 if [ $? -ne 0 ]; then
534 echo "Failed to generate Nuget packages."
539 echo "Commencing CoreCLR Repo build"
541 # Argument types supported by this script:
543 # Build architecture - valid values are: x64, ARM.
544 # Build Type - valid values are: Debug, Checked, Release
546 # Set the default arguments for build
548 # Obtain the location of the bash script to figure out where the root of the repo is.
549 __ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
551 # Use uname to determine what the CPU is.
553 # Some Linux platforms report unknown for platform, but the arch for machine.
554 if [ "$CPUName" == "unknown" ]; then
560 echo "Unsupported CPU $CPUName detected, build might not succeed!"
571 echo "Unsupported CPU $CPUName detected, build might not succeed!"
586 echo "Unknown CPU $CPUName detected, configuring as if for x64"
592 # Use uname to determine what the OS is.
626 echo "Unsupported OS $OSName detected, configuring as if for Linux"
636 # Set the various build properties here so that CMake and MSBuild can pick them up
637 __ProjectDir="$__ProjectRoot"
638 __SourceDir="$__ProjectDir/src"
639 __PackagesDir="${DotNetRestorePackagesPath:-${__ProjectDir}/packages}"
640 __RootBinDir="$__ProjectDir/bin"
641 __UnprocessedBuildArgs=
656 __SkipRestoreOptData=0
660 __ClangMajorVersion=0
661 __ClangMinorVersion=0
662 __NuGetPath="$__PackagesDir/NuGet.exe"
666 __SkipGenerateVersion=0
669 __msbuildonunsupportedplatform=0
670 __PgoOptDataVersion=""
671 __IbcOptDataVersion=""
672 __BuildManagedTools=1
674 # Get the number of processors available to the scheduler
675 # Other techniques such as `nproc` only get the number of
676 # processors available to a single process.
677 if [ `uname` = "FreeBSD" ]; then
678 __NumProc=`sysctl hw.ncpu | awk '{ print $2+1 }'`
679 elif [ `uname` = "NetBSD" ]; then
680 __NumProc=$(($(getconf NPROCESSORS_ONLN)+1))
681 elif [ `uname` = "Darwin" ]; then
682 __NumProc=$(($(getconf _NPROCESSORS_ONLN)+1))
684 __NumProc=$(nproc --all)
688 if [ $# -le 0 ]; then
692 lowerI="$(echo $1 | awk '{print tolower($0)}')"
732 __CodeCoverage=Coverage
739 -portablebuild=false)
747 stripsymbols|-stripsymbols)
748 __cmakeargs="$__cmakeargs -DSTRIP_SYMBOLS=true"
752 __ClangMajorVersion=3
753 __ClangMinorVersion=5
757 __ClangMajorVersion=3
758 __ClangMinorVersion=6
762 __ClangMajorVersion=3
763 __ClangMinorVersion=7
767 __ClangMajorVersion=3
768 __ClangMinorVersion=8
772 __ClangMajorVersion=3
773 __ClangMinorVersion=9
777 __ClangMajorVersion=4
778 __ClangMinorVersion=0
782 __ClangMajorVersion=5
783 __ClangMinorVersion=0
787 __ClangMajorVersion=6
788 __ClangMinorVersion=0
795 pgoinstrument|-pgoinstrument)
799 nopgooptimize|-nopgooptimize)
801 __SkipRestoreOptData=1
804 ibcinstrument|-ibcinstrument)
805 __IbcTuning="/Tuning"
808 configureonly|-configureonly)
814 skipconfigure|-skipconfigure)
818 skipnative|-skipnative)
819 # Use "skipnative" to use the same option name as build.cmd.
823 skipcoreclr|-skipcoreclr)
824 # Accept "skipcoreclr" for backwards-compatibility.
828 crosscomponent|-crosscomponent)
832 skipmanaged|-skipmanaged)
836 skipmscorlib|-skipmscorlib)
840 skipgenerateversion|-skipgenerateversion)
841 __SkipGenerateVersion=1
844 skiprestoreoptdata|-skiprestoreoptdata)
845 __SkipRestoreOptData=1
848 skipcrossgen|-skipcrossgen)
852 skiptests|-skiptests)
856 skipnuget|-skipnuget|skipbuildpackages|-skipbuildpackages)
860 ignorewarnings|-ignorewarnings)
862 __cmakeargs="$__cmakeargs -DCLR_CMAKE_WARNINGS_ARE_ERRORS=OFF"
865 cmakeargs|-cmakeargs)
867 __cmakeargs="$__cmakeargs $2"
870 echo "ERROR: 'cmakeargs' requires a non-empty option argument"
878 if [ ! -d $__RootBinDir ]; then
881 __RootBinParent=$(dirname $__RootBinDir)
882 __RootBinName=${__RootBinDir##*/}
883 __RootBinDir="$(cd $__RootBinParent &>/dev/null && printf %s/%s $PWD $__RootBinName)"
886 echo "ERROR: 'bindir' requires a non-empty option argument"
890 msbuildonunsupportedplatform|-msbuildonunsupportedplatform)
891 __msbuildonunsupportedplatform=1
898 echo "ERROR: 'numproc' requires a non-empty option argument"
907 echo "ERROR: 'osgroup' requires a non-empty option argument"
912 echo "ERROR: 'Rebuild' is not supported. Please remove it."
917 __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1"
924 __RunArgs="-BuildArch=$__BuildArch -BuildType=$__BuildType -BuildOS=$__BuildOS"
926 # Configure environment if we are doing a verbose build
927 if [ $__VerboseBuild == 1 ]; then
929 __RunArgs="$__RunArgs -verbose"
932 # Set default clang version
933 if [[ $__ClangMajorVersion == 0 && $__ClangMinorVersion == 0 ]]; then
934 if [[ "$__BuildArch" == "arm" || "$__BuildArch" == "armel" ]]; then
935 __ClangMajorVersion=5
936 __ClangMinorVersion=0
938 __ClangMajorVersion=3
939 __ClangMinorVersion=9
943 if [[ "$__BuildArch" == "armel" ]]; then
944 # Armel cross build is Tizen specific and does not support Portable RID build
948 if [ $__PortableBuild == 0 ]; then
949 __RunArgs="$__RunArgs -PortableBuild=false"
952 # Set dependent variables
953 __LogsDir="$__RootBinDir/Logs"
955 # init the host distro name
958 # Set the remaining variables based upon the determined build configuration
959 __BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType"
960 __PackagesBinDir="$__BinDir/.nuget"
961 __ToolsDir="$__RootBinDir/tools"
962 __TestWorkingDir="$__RootBinDir/tests/$__BuildOS.$__BuildArch.$__BuildType"
963 export __IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType"
964 __TestIntermediatesDir="$__RootBinDir/tests/obj/$__BuildOS.$__BuildArch.$__BuildType"
965 __isMSBuildOnNETCoreSupported=0
966 __CrossComponentBinDir="$__BinDir"
968 __CrossArch="$__HostArch"
969 if [ $__CrossBuild == 1 ]; then
970 __CrossComponentBinDir="$__CrossComponentBinDir/$__CrossArch"
972 __CrossGenCoreLibLog="$__LogsDir/CrossgenCoreLib_$__BuildOS.$__BuildArch.$__BuildType.log"
974 # Init if MSBuild for .NET Core is supported for this platform
975 isMSBuildOnNETCoreSupported
977 # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set.
978 # This is needed by CLI to function.
979 if [ -z "$HOME" ]; then
980 if [ ! -d "$__ProjectDir/temp_home" ]; then
983 export HOME=$__ProjectDir/temp_home
984 echo "HOME not defined; setting it to $HOME"
987 # Specify path to be set for CMAKE_INSTALL_PREFIX.
988 # This is where all built CoreClr libraries will copied to.
989 export __CMakeBinDir="$__BinDir"
991 # Configure environment if we are doing a cross compile.
992 if [ $__CrossBuild == 1 ]; then
993 export CROSSCOMPILE=1
994 if ! [[ -n "$ROOTFS_DIR" ]]; then
995 export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__BuildArch"
999 # init the target distro name
1002 # Make the directories necessary for build if they don't exist
1008 # Restore the package containing profile counts for profile-guided optimizations
1011 # Generate event logging infrastructure sources
1012 generate_event_logging
1014 # Build the coreclr (native) components.
1015 __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"
1017 # [TODO] Remove this when the `build-test.sh` script properly builds and deploys test assets.
1018 if [ $__SkipTests != 1 ]; then
1019 echo "Adding CMake flags to build native tests for $__BuildOS.$__BuildArch.$__BuildType"
1020 __ExtraCmakeArgs="$__ExtraCmakeArgs -DCLR_CMAKE_BUILD_TESTS=ON"
1023 build_native $__SkipCoreCLR "$__BuildArch" "$__IntermediatesDir" "$__ExtraCmakeArgs" "CoreCLR component"
1025 # Build cross-architecture components
1026 if [[ $__CrossBuild == 1 && $__DoCrossArchBuild == 1 ]]; then
1027 build_cross_architecture_components "$__CrossArch"
1029 # For now, continue building Hostx86/arm crossgen
1030 if [[ "$__HostArch" == "x64" && ("$__BuildArch" == "arm" || "$__BuildArch" == "armel") ]]; then
1031 build_cross_architecture_components "x86"
1035 # Build System.Private.CoreLib.
1039 # Generate nuget packages
1040 if [ $__SkipNuget != 1 ]; then
1041 generate_NugetPackages
1047 echo "Repo successfully built."
1048 echo "Product binaries are available at $__BinDir"