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 python3 || command -v python2 || command -v python)
12 echo "Unable to locate build-dependency python!" 1>&2
16 # validate python-dependency
17 # useful in case of explicitly set option.
18 if ! command -v $PYTHON > /dev/null
20 echo "Unable to locate build-dependency python ($PYTHON)!" 1>&2
28 echo "Usage: $0 [BuildArch] [BuildType] [-verbose] [-coverage] [-cross] [-clangx.y] [-ninja] [-configureonly] [-skipconfigure] [-skipnative] [-skipmanaged] [-skipmscorlib] [-skiptests] [-stripsymbols] [-ignorewarnings] [-cmakeargs] [-bindir]"
29 echo "BuildArch can be: -x64, -x86, -arm, -armel, -arm64"
30 echo "BuildType can be: -debug, -checked, -release"
31 echo "-coverage - optional argument to enable code coverage build (currently supported only for Linux and OSX)."
32 echo "-ninja - target ninja instead of GNU make"
33 echo "-clangx.y - optional argument to build using clang version x.y."
34 echo "-cross - optional argument to signify cross compilation,"
35 echo " - will use ROOTFS_DIR environment variable if set."
36 echo "-nopgooptimize - do not use profile guided optimizations."
37 echo "-pgoinstrument - generate instrumented code for profile guided optimization enabled binaries."
38 echo "-ibcinstrument - generate IBC-tuning-enabled native images when invoking crossgen."
39 echo "-configureonly - do not perform any builds; just configure the build."
40 echo "-skipconfigure - skip build configuration."
41 echo "-skipnative - do not build native components."
42 echo "-skipmanaged - do not build managed components."
43 echo "-skipmscorlib - do not build mscorlib.dll."
44 echo "-skiptests - skip the tests in the 'tests' subdirectory."
45 echo "-skipnuget - skip building nuget packages."
46 echo "-skiprestoreoptdata - skip restoring optimization data used by profile-based optimizations."
47 echo "-skipcrossgen - skip native image generation"
48 echo "-crossgenonly - only run native image generation"
49 echo "-partialngen - build CoreLib as PartialNGen"
50 echo "-verbose - optional argument to enable verbose build output."
51 echo "-skiprestore: skip restoring packages ^(default: packages are restored during build^)."
52 echo "-disableoss: Disable Open Source Signing for System.Private.CoreLib."
53 echo "-officialbuildid=^<ID^>: specify the official build ID to be used by this build."
54 echo "-stripSymbols - Optional argument to strip native symbols during the build."
55 echo "-skipgenerateversion - disable version generation even if MSBuild is supported."
56 echo "-ignorewarnings - do not treat warnings as errors"
57 echo "-cmakeargs - user-settable additional arguments passed to CMake."
58 echo "-bindir - output directory (defaults to $__ProjectRoot/bin)"
59 echo "-msbuildonunsupportedplatform - build managed binaries even if distro is not officially supported."
60 echo "-numproc - set the number of build processes."
67 if [ "$__HostOS" == "Linux" ]; then
68 if [ -e /etc/os-release ]; then
69 source /etc/os-release
70 if [[ $ID == "rhel" ]]; then
71 # remove the last version digit
72 VERSION_ID=${VERSION_ID%.*}
74 __HostDistroRid="$ID.$VERSION_ID-$__HostArch"
75 if [[ $ID == "alpine" ]]; then
76 __HostDistroRid="linux-musl-$__HostArch"
78 elif [ -e /etc/redhat-release ]; then
79 local redhatRelease=$(</etc/redhat-release)
80 if [[ $redhatRelease == "CentOS release 6."* || $redhatRelease == "Red Hat Enterprise Linux Server release 6."* ]]; then
81 __HostDistroRid="rhel.6-$__HostArch"
83 if [[ $redhatRelease == "CentOS Linux release 7."* ]]; then
84 __HostDistroRid="rhel.7-$__Arch"
88 if [ "$__HostOS" == "FreeBSD" ]; then
89 __freebsd_version=`sysctl -n kern.osrelease | cut -f1 -d'.'`
90 __HostDistroRid="freebsd.$__freebsd_version-$__HostArch"
93 if [ "$__HostDistroRid" == "" ]; then
94 echo "WARNING: Can not determine runtime id for current distro."
100 if [ $__CrossBuild == 1 ]; then
101 if [ "$__BuildOS" == "Linux" ]; then
102 if [ ! -e $ROOTFS_DIR/etc/os-release ]; then
103 if [ -e $ROOTFS_DIR/android_platform ]; then
104 source $ROOTFS_DIR/android_platform
105 export __DistroRid="$RID"
107 echo "WARNING: Can not determine runtime id for current distro."
108 export __DistroRid=""
111 source $ROOTFS_DIR/etc/os-release
112 export __DistroRid="$ID.$VERSION_ID-$__BuildArch"
116 export __DistroRid="$__HostDistroRid"
119 if [ "$__BuildOS" == "OSX" ]; then
123 # Portable builds target the base RID
124 if [ $__PortableBuild == 1 ]; then
125 if [ "$__BuildOS" == "Linux" ]; then
126 export __DistroRid="linux-$__BuildArch"
127 elif [ "$__BuildOS" == "OSX" ]; then
128 export __DistroRid="osx-$__BuildArch"
129 elif [ "$__BuildOS" == "FreeBSD" ]; then
130 export __DistroRid="freebsd-$__BuildArch"
137 echo Setting up directories for build
139 mkdir -p "$__RootBinDir"
141 mkdir -p "$__LogsDir"
142 mkdir -p "$__IntermediatesDir"
144 if [ $__CrossBuild == 1 ]; then
145 mkdir -p "$__CrossComponentBinDir"
149 # Check the system to ensure the right prereqs are in place
153 echo "Checking prerequisites..."
155 # Check presence of CMake on the path
156 hash cmake 2>/dev/null || { echo >&2 "Please install cmake before running this script"; exit 1; }
159 # Minimum required version of clang is version 4.0 for arm/armel cross build
160 if [[ $__CrossBuild == 1 && ("$__BuildArch" == "arm" || "$__BuildArch" == "armel") ]]; then
161 if ! [[ "$__ClangMajorVersion" -ge "4" ]]; then
162 echo "Please install clang4.0 or latest for arm/armel cross build"; exit 1;
167 __ClangCombinedDottedVersion=$__ClangMajorVersion;
168 if [[ "$__ClangMinorVersion" != "" ]]; then
169 __ClangCombinedDottedVersion=$__ClangCombinedDottedVersion.$__ClangMinorVersion
171 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; }
177 # we only need optdata on a Release build
178 if [[ "$__BuildType" != "Release" ]]; then __SkipRestoreOptData=1; fi
180 if [[ ( $__SkipRestoreOptData == 0 ) && ( $__isMSBuildOnNETCoreSupported == 1 ) ]]; then
181 echo "Restoring the OptimizationData package"
182 "$__ProjectRoot/run.sh" build -optdata $__RunArgs $__UnprocessedBuildArgs
184 echo "Failed to restore the optimization data package."
189 if [ $__isMSBuildOnNETCoreSupported == 1 ]; then
190 # Parse the optdata package versions out of msbuild so that we can pass them on to CMake
191 local DotNetCli="$__ProjectRoot/Tools/dotnetcli/dotnet"
192 if [ ! -f $DotNetCli ]; then
193 source "$__ProjectRoot/init-tools.sh"
195 echo "Failed to restore buildtools."
199 local OptDataProjectFilePath="$__ProjectRoot/src/.nuget/optdata/optdata.csproj"
200 __PgoOptDataVersion=$(DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 $DotNetCli msbuild $OptDataProjectFilePath /t:DumpPgoDataPackageVersion /nologo | sed 's/^\s*//')
201 __IbcOptDataVersion=$(DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 $DotNetCli msbuild $OptDataProjectFilePath /t:DumpIbcDataPackageVersion /nologo | sed 's/^[[:blank:]]*//')
205 generate_event_logging_sources()
208 __ConsumingBuildSystem=$2
210 __OutputIncDir="$__OutputDir/src/inc"
211 __OutputEventingDir="$__OutputDir/eventing"
212 __OutputEventProviderDir="$__OutputEventingDir/eventprovider"
214 echo "Laying out dynamically generated files consumed by $__ConsumingBuildSystem"
215 echo "Laying out dynamically generated Event test files, etmdummy stub functions, and external linkages"
217 __PythonWarningFlags="-Wall"
218 if [[ $__IgnoreWarnings == 0 ]]; then
219 __PythonWarningFlags="$__PythonWarningFlags -Werror"
222 $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genEventing.py" --inc $__OutputIncDir --dummy $__OutputIncDir/etmdummy.h --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --testdir "$__OutputEventProviderDir/tests"
223 if [[ $? != 0 ]]; then
227 echo "Laying out dynamically generated EventPipe Implementation"
228 $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genEventPipe.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventingDir/eventpipe"
230 echo "Laying out dynamically generated EventSource classes"
231 $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genRuntimeEventSources.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventingDir"
233 # determine the logging system
236 echo "Laying out dynamically generated Event Logging Implementation of Lttng"
237 $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genLttngProvider.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventProviderDir"
238 if [[ $? != 0 ]]; then
243 echo "Laying out dummy event logging provider"
244 $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genDummyProvider.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventProviderDir"
245 if [[ $? != 0 ]]; then
252 generate_event_logging()
254 # Event Logging Infrastructure
255 if [[ $__SkipCoreCLR == 0 || $__SkipMSCorLib == 0 || $__ConfigureOnly == 1 ]]; then
256 generate_event_logging_sources "$__IntermediatesDir" "the native build system"
264 intermediatesForBuild="$3"
265 extraCmakeArguments="$4"
268 if [ $skipCondition == 1 ]; then
269 echo "Skipping $message build."
273 # All set to commence the build
274 echo "Commencing build of $message for $__BuildOS.$__BuildArch.$__BuildType in $intermediatesForBuild"
279 if [ $__UseNinja == 1 ]; then
281 buildFile="build.ninja"
282 if ! buildTool=$(command -v ninja || command -v ninja-build); then
283 echo "Unable to locate ninja!" 1>&2
288 if [ $__SkipConfigure == 0 ]; then
289 # if msbuild is not supported, then set __SkipGenerateVersion to 1
290 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then __SkipGenerateVersion=1; fi
291 # Drop version.cpp file
292 __versionSourceFile="$intermediatesForBuild/version.cpp"
293 if [ $__SkipGenerateVersion == 0 ]; then
295 "$__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
297 # Generate the dummy version.cpp, but only if it didn't exist to make sure we don't trigger unnecessary rebuild
298 __versionSourceLine="static char sccsid[] __attribute__((used)) = \"@(#)No version information produced\";"
299 if [ -e $__versionSourceFile ]; then
300 read existingVersionSourceLine < $__versionSourceFile
302 if [ "$__versionSourceLine" != "$existingVersionSourceLine" ]; then
303 echo $__versionSourceLine > $__versionSourceFile
308 pushd "$intermediatesForBuild"
309 # Regenerate the CMake solution
310 echo "Invoking \"$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh\" \"$__ProjectRoot\" $__ClangMajorVersion \"$__ClangMinorVersion\" $platformArch $__BuildType $__CodeCoverage $generator $extraCmakeArguments $__cmakeargs"
311 "$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh" "$__ProjectRoot" $__ClangMajorVersion "$__ClangMinorVersion" $platformArch $__BuildType $__CodeCoverage $generator "$extraCmakeArguments" "$__cmakeargs"
315 if [ ! -f "$intermediatesForBuild/$buildFile" ]; then
316 echo "Failed to generate $message build project!"
321 if [ $__ConfigureOnly == 1 ]; then
322 echo "Finish configuration & skipping $message build."
326 # Check that the makefiles were created.
327 pushd "$intermediatesForBuild"
329 echo "Executing $buildTool install -j $__NumProc"
331 $buildTool install -j $__NumProc
333 echo "Failed to build $message."
340 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
351 # check supported cross-architecture components host(__HostArch)/target(__BuildArch) pair
352 if [[ ("$__BuildArch" == "arm" || "$__BuildArch" == "armel") && ("$__CrossArch" == "x86" || "$__CrossArch" == "x64") ]]; then
353 __SkipCrossArchBuild=0
354 elif [[ "$__BuildArch" == "arm64" && "$__CrossArch" == "x64" ]]; then
355 __SkipCrossArchBuild=0
361 export __CMakeBinDir="$crossArchBinDir"
362 export CROSSCOMPILE=0
364 __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"
365 build_native $__SkipCrossArchBuild "$__CrossArch" "$intermediatesForBuild" "$__ExtraCmakeArgs" "cross-architecture components"
367 export CROSSCOMPILE=1
370 isMSBuildOnNETCoreSupported()
372 __isMSBuildOnNETCoreSupported=$__msbuildonunsupportedplatform
374 if [ $__isMSBuildOnNETCoreSupported == 1 ]; then
378 if [ $__SkipManaged == 1 ]; then
379 __isMSBuildOnNETCoreSupported=0
383 if [ "$__HostArch" == "x64" ]; then
384 if [ "$__HostOS" == "Linux" ]; then
385 __isMSBuildOnNETCoreSupported=1
386 # note: the RIDs below can use globbing patterns
387 UNSUPPORTED_RIDS=("debian.9-x64" "ubuntu.17.04-x64")
388 for UNSUPPORTED_RID in "${UNSUPPORTED_RIDS[@]}"
390 if [[ $__HostDistroRid == $UNSUPPORTED_RID ]]; then
391 __isMSBuildOnNETCoreSupported=0
395 elif [ "$__HostOS" == "OSX" ]; then
396 __isMSBuildOnNETCoreSupported=1
397 elif [ "$__HostOS" == "FreeBSD" ]; then
398 __isMSBuildOnNETCoreSupported=1
406 local __CrossGenExec=$1
408 if [ $__PartialNgen == 1 ]; then
409 export COMPlus_PartialNGen=1
412 if [ -e $__CrossGenCoreLibLog ]; then
413 rm $__CrossGenCoreLibLog
415 echo "Generating native image of System.Private.CoreLib.dll for $__BuildOS.$__BuildArch.$__BuildType. Logging to \"$__CrossGenCoreLibLog\"."
416 echo "$__CrossGenExec /Platform_Assemblies_Paths $__BinDir/IL $__IbcTuning /out $__BinDir/System.Private.CoreLib.dll $__BinDir/IL/System.Private.CoreLib.dll"
417 $__CrossGenExec /Platform_Assemblies_Paths $__BinDir/IL $__IbcTuning /out $__BinDir/System.Private.CoreLib.dll $__BinDir/IL/System.Private.CoreLib.dll >> $__CrossGenCoreLibLog 2>&1
418 if [ $? -ne 0 ]; then
419 echo "Failed to generate native image for System.Private.CoreLib. Refer to $__CrossGenCoreLibLog"
423 if [ "$__BuildOS" == "Linux" ]; then
424 echo "Generating symbol file for System.Private.CoreLib.dll"
425 echo "$__CrossGenExec /Platform_Assemblies_Paths $__BinDir /CreatePerfMap $__BinDir $__BinDir/System.Private.CoreLib.dll"
426 $__CrossGenExec /Platform_Assemblies_Paths $__BinDir /CreatePerfMap $__BinDir $__BinDir/System.Private.CoreLib.dll >> $__CrossGenCoreLibLog 2>&1
427 if [ $? -ne 0 ]; then
428 echo "Failed to generate symbol file for System.Private.CoreLib. Refer to $__CrossGenCoreLibLog"
436 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
437 echo "System.Private.CoreLib.dll build unsupported."
441 if [ $__SkipMSCorLib == 1 ]; then
442 echo "Skipping building System.Private.CoreLib."
446 echo "Commencing build of managed components for $__BuildOS.$__BuildArch.$__BuildType"
450 if [[ "$__IbcTuning" == "" ]]; then
451 __ExtraBuildArgs="$__ExtraBuildArgs -OptimizationDataDir=\"$__PackagesDir/optimization.$__BuildOS-$__BuildArch.IBC.CoreCLR/$__IbcOptDataVersion/data/\""
452 __ExtraBuildArgs="$__ExtraBuildArgs -EnableProfileGuidedOptimization=true"
455 if [[ "$__BuildManagedTools" -eq "1" ]]; then
456 __ExtraBuildArgs="$__ExtraBuildArgs -BuildManagedTools=true"
459 $__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
461 if [ $? -ne 0 ]; then
462 echo "Failed to build managed components."
466 if [ $__SkipCrossgen == 1 ]; then
467 echo "Skipping generating native image"
471 # The cross build generates a crossgen with the target architecture.
472 if [ $__CrossBuild == 0 ]; then
473 if [ $__SkipCoreCLR == 1 ]; then
477 # The architecture of host pc must be same architecture with target.
478 if [[ ( "$__HostArch" == "$__BuildArch" ) ]]; then
479 build_CoreLib_ni "$__BinDir/crossgen"
480 elif [[ ( "$__HostArch" == "x64" ) && ( "$__BuildArch" == "x86" ) ]]; then
481 build_CoreLib_ni "$__BinDir/crossgen"
482 elif [[ ( "$__HostArch" == "arm64" ) && ( "$__BuildArch" == "arm" ) ]]; then
483 build_CoreLib_ni "$__BinDir/crossgen"
488 if [[ ( "$__CrossArch" == "x86" ) && ( "$__BuildArch" == "arm" ) ]]; then
489 build_CoreLib_ni "$__CrossComponentBinDir/crossgen"
490 elif [[ ( "$__CrossArch" == "x64" ) && ( "$__BuildArch" == "arm" ) ]]; then
491 build_CoreLib_ni "$__CrossComponentBinDir/crossgen"
492 elif [[ ( "$__HostArch" == "x64" ) && ( "$__BuildArch" == "arm64" ) ]]; then
493 build_CoreLib_ni "$__CrossComponentBinDir/crossgen"
498 generate_NugetPackages()
500 # We can only generate nuget package if we also support building mscorlib as part of this build.
501 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
502 echo "Nuget package generation unsupported."
506 # Since we can build mscorlib for this OS, did we build the native components as well?
507 if [[ $__SkipCoreCLR == 1 && $__CrossgenOnly == 0 ]]; then
508 echo "Unable to generate nuget packages since native components were not built."
512 echo "Generating nuget packages for "$__BuildOS
513 echo "DistroRid is "$__DistroRid
514 echo "ROOTFS_DIR is "$ROOTFS_DIR
516 $__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
518 if [ $? -ne 0 ]; then
519 echo "Failed to generate Nuget packages."
524 echo "Commencing CoreCLR Repo build"
526 # Argument types supported by this script:
528 # Build architecture - valid values are: x64, ARM.
529 # Build Type - valid values are: Debug, Checked, Release
531 # Set the default arguments for build
533 # Obtain the location of the bash script to figure out where the root of the repo is.
534 __ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
536 # Use uname to determine what the CPU is.
538 # Some Linux platforms report unknown for platform, but the arch for machine.
539 if [ "$CPUName" == "unknown" ]; then
545 echo "Unsupported CPU $CPUName detected, build might not succeed!"
556 echo "Unsupported CPU $CPUName detected, build might not succeed!"
571 echo "Unknown CPU $CPUName detected, configuring as if for x64"
577 # Use uname to determine what the OS is.
611 echo "Unsupported OS $OSName detected, configuring as if for Linux"
621 # Set the various build properties here so that CMake and MSBuild can pick them up
622 __ProjectDir="$__ProjectRoot"
623 __SourceDir="$__ProjectDir/src"
624 __PackagesDir="${DotNetRestorePackagesPath:-${__ProjectDir}/packages}"
625 __RootBinDir="$__ProjectDir/bin"
626 __UnprocessedBuildArgs=
641 __SkipRestoreOptData=0
647 __ClangMajorVersion=0
648 __ClangMinorVersion=0
649 __NuGetPath="$__PackagesDir/NuGet.exe"
653 __SkipGenerateVersion=0
655 __msbuildonunsupportedplatform=0
656 __PgoOptDataVersion=""
657 __IbcOptDataVersion=""
658 __BuildManagedTools=1
660 # Get the number of processors available to the scheduler
661 # Other techniques such as `nproc` only get the number of
662 # processors available to a single process.
663 if [ `uname` = "FreeBSD" ]; then
664 __NumProc=`sysctl hw.ncpu | awk '{ print $2+1 }'`
665 elif [ `uname` = "NetBSD" ]; then
666 __NumProc=$(($(getconf NPROCESSORS_ONLN)+1))
667 elif [ `uname` = "Darwin" ]; then
668 __NumProc=$(($(getconf _NPROCESSORS_ONLN)+1))
670 __NumProc=$(nproc --all)
674 if [ $# -le 0 ]; then
678 lowerI="$(echo $1 | awk '{print tolower($0)}')"
718 __CodeCoverage=Coverage
725 -portablebuild=false)
733 stripsymbols|-stripsymbols)
734 __cmakeargs="$__cmakeargs -DSTRIP_SYMBOLS=true"
738 __ClangMajorVersion=3
739 __ClangMinorVersion=5
743 __ClangMajorVersion=3
744 __ClangMinorVersion=6
748 __ClangMajorVersion=3
749 __ClangMinorVersion=7
753 __ClangMajorVersion=3
754 __ClangMinorVersion=8
758 __ClangMajorVersion=3
759 __ClangMinorVersion=9
763 __ClangMajorVersion=4
764 __ClangMinorVersion=0
768 __ClangMajorVersion=5
769 __ClangMinorVersion=0
773 __ClangMajorVersion=6
774 __ClangMinorVersion=0
778 __ClangMajorVersion=7
786 pgoinstrument|-pgoinstrument)
790 nopgooptimize|-nopgooptimize)
792 __SkipRestoreOptData=1
795 ibcinstrument|-ibcinstrument)
796 __IbcTuning="/Tuning"
799 configureonly|-configureonly)
805 skipconfigure|-skipconfigure)
809 skipnative|-skipnative)
810 # Use "skipnative" to use the same option name as build.cmd.
814 skipcoreclr|-skipcoreclr)
815 # Accept "skipcoreclr" for backwards-compatibility.
819 skipmanaged|-skipmanaged)
823 skipmscorlib|-skipmscorlib)
827 skipgenerateversion|-skipgenerateversion)
828 __SkipGenerateVersion=1
831 skiprestoreoptdata|-skiprestoreoptdata)
832 __SkipRestoreOptData=1
835 skipcrossgen|-skipcrossgen)
839 crossgenonly|-crossgenonly)
844 partialngen|-partialngen)
848 skiptests|-skiptests)
852 skipnuget|-skipnuget|skipbuildpackages|-skipbuildpackages)
856 ignorewarnings|-ignorewarnings)
858 __cmakeargs="$__cmakeargs -DCLR_CMAKE_WARNINGS_ARE_ERRORS=OFF"
861 cmakeargs|-cmakeargs)
863 __cmakeargs="$__cmakeargs $2"
866 echo "ERROR: 'cmakeargs' requires a non-empty option argument"
874 if [ ! -d $__RootBinDir ]; then
877 __RootBinParent=$(dirname $__RootBinDir)
878 __RootBinName=${__RootBinDir##*/}
879 __RootBinDir="$(cd $__RootBinParent &>/dev/null && printf %s/%s $PWD $__RootBinName)"
882 echo "ERROR: 'bindir' requires a non-empty option argument"
886 msbuildonunsupportedplatform|-msbuildonunsupportedplatform)
887 __msbuildonunsupportedplatform=1
894 echo "ERROR: 'numproc' requires a non-empty option argument"
903 echo "ERROR: 'osgroup' requires a non-empty option argument"
908 echo "ERROR: 'Rebuild' is not supported. Please remove it."
913 __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1"
920 __RunArgs="-BuildArch=$__BuildArch -BuildType=$__BuildType -BuildOS=$__BuildOS"
922 # Configure environment if we are doing a verbose build
923 if [ $__VerboseBuild == 1 ]; then
925 __RunArgs="$__RunArgs -verbose"
928 # Set default clang version
929 if [[ $__ClangMajorVersion == 0 && $__ClangMinorVersion == 0 ]]; then
930 if [[ "$__BuildArch" == "arm" || "$__BuildArch" == "armel" ]]; then
931 __ClangMajorVersion=5
932 __ClangMinorVersion=0
934 __ClangMajorVersion=3
935 __ClangMinorVersion=9
939 if [[ "$__BuildArch" == "armel" ]]; then
940 # Armel cross build is Tizen specific and does not support Portable RID build
944 if [ $__PortableBuild == 0 ]; then
945 __RunArgs="$__RunArgs -PortableBuild=false"
948 # Set dependent variables
949 __LogsDir="$__RootBinDir/Logs"
951 # init the host distro name
954 # Set the remaining variables based upon the determined build configuration
955 __BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType"
956 __PackagesBinDir="$__BinDir/.nuget"
957 __ToolsDir="$__RootBinDir/tools"
958 __TestWorkingDir="$__RootBinDir/tests/$__BuildOS.$__BuildArch.$__BuildType"
959 export __IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType"
960 __TestIntermediatesDir="$__RootBinDir/tests/obj/$__BuildOS.$__BuildArch.$__BuildType"
961 __isMSBuildOnNETCoreSupported=0
962 __CrossComponentBinDir="$__BinDir"
964 __CrossArch="$__HostArch"
965 if [ $__CrossBuild == 1 ]; then
966 __CrossComponentBinDir="$__CrossComponentBinDir/$__CrossArch"
968 __CrossGenCoreLibLog="$__LogsDir/CrossgenCoreLib_$__BuildOS.$__BuildArch.$__BuildType.log"
970 # Init if MSBuild for .NET Core is supported for this platform
971 isMSBuildOnNETCoreSupported
973 # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set.
974 # This is needed by CLI to function.
975 if [ -z "$HOME" ]; then
976 if [ ! -d "$__ProjectDir/temp_home" ]; then
979 export HOME=$__ProjectDir/temp_home
980 echo "HOME not defined; setting it to $HOME"
983 # Specify path to be set for CMAKE_INSTALL_PREFIX.
984 # This is where all built CoreClr libraries will copied to.
985 export __CMakeBinDir="$__BinDir"
987 # Configure environment if we are doing a cross compile.
988 if [ $__CrossBuild == 1 ]; then
989 export CROSSCOMPILE=1
990 if ! [[ -n "$ROOTFS_DIR" ]]; then
991 export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__BuildArch"
995 # init the target distro name
998 # Make the directories necessary for build if they don't exist
1004 # Restore the package containing profile counts for profile-guided optimizations
1007 # Generate event logging infrastructure sources
1008 generate_event_logging
1010 # Build the coreclr (native) components.
1011 __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"
1013 # [TODO] Remove this when the `build-test.sh` script properly builds and deploys test assets.
1014 if [ $__SkipTests != 1 ]; then
1015 echo "Adding CMake flags to build native tests for $__BuildOS.$__BuildArch.$__BuildType"
1016 __ExtraCmakeArgs="$__ExtraCmakeArgs -DCLR_CMAKE_BUILD_TESTS=ON"
1019 build_native $__SkipCoreCLR "$__BuildArch" "$__IntermediatesDir" "$__ExtraCmakeArgs" "CoreCLR component"
1021 # Build cross-architecture components
1022 if [[ $__CrossBuild == 1 ]]; then
1023 build_cross_architecture_components
1026 # Build System.Private.CoreLib.
1030 if [ $__CrossgenOnly == 1 ]; then
1031 build_CoreLib_ni "$__BinDir/crossgen"
1034 # Generate nuget packages
1035 if [ $__SkipNuget != 1 ]; then
1036 generate_NugetPackages
1042 echo "Repo successfully built."
1043 echo "Product binaries are available at $__BinDir"