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] [-skipcrossarchnative] [-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 "-skipcrossarchnative - do not build cross-architecture 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"
84 if [[ $redhatRelease == "CentOS Linux release 7."* ]]; then
85 __HostDistroRid="rhel.7-$__Arch"
89 if [ "$__HostOS" == "FreeBSD" ]; then
90 __freebsd_version=`sysctl -n kern.osrelease | cut -f1 -d'.'`
91 __HostDistroRid="freebsd.$__freebsd_version-$__HostArch"
94 if [ "$__HostDistroRid" == "" ]; then
95 echo "WARNING: Can not determine runtime id for current distro."
101 if [ $__CrossBuild == 1 ]; then
102 if [ "$__BuildOS" == "Linux" ]; then
103 if [ ! -e $ROOTFS_DIR/etc/os-release ]; then
104 if [ -e $ROOTFS_DIR/android_platform ]; then
105 source $ROOTFS_DIR/android_platform
106 export __DistroRid="$RID"
108 echo "WARNING: Can not determine runtime id for current distro."
109 export __DistroRid=""
112 source $ROOTFS_DIR/etc/os-release
113 export __DistroRid="$ID.$VERSION_ID-$__BuildArch"
117 export __DistroRid="$__HostDistroRid"
120 if [ "$__BuildOS" == "OSX" ]; then
124 # Portable builds target the base RID
125 if [ $__PortableBuild == 1 ]; then
126 if [ "$__BuildOS" == "Linux" ]; then
127 export __DistroRid="linux-$__BuildArch"
128 elif [ "$__BuildOS" == "OSX" ]; then
129 export __DistroRid="osx-$__BuildArch"
130 elif [ "$__BuildOS" == "FreeBSD" ]; then
131 export __DistroRid="freebsd-$__BuildArch"
138 echo Setting up directories for build
140 mkdir -p "$__RootBinDir"
142 mkdir -p "$__LogsDir"
143 mkdir -p "$__IntermediatesDir"
145 if [ $__CrossBuild == 1 ]; then
146 mkdir -p "$__CrossComponentBinDir"
150 # Check the system to ensure the right prereqs are in place
154 echo "Checking prerequisites..."
156 # Check presence of CMake on the path
157 hash cmake 2>/dev/null || { echo >&2 "Please install cmake before running this script"; exit 1; }
160 # Minimum required version of clang is version 4.0 for arm/armel cross build
161 if [[ $__CrossBuild == 1 && ("$__BuildArch" == "arm" || "$__BuildArch" == "armel") ]]; then
162 if ! [[ "$__ClangMajorVersion" -ge "4" ]]; then
163 echo "Please install clang4.0 or latest for arm/armel cross build"; exit 1;
168 __ClangCombinedDottedVersion=$__ClangMajorVersion;
169 if [[ "$__ClangMinorVersion" != "" ]]; then
170 __ClangCombinedDottedVersion=$__ClangCombinedDottedVersion.$__ClangMinorVersion
172 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; }
178 # we only need optdata on a Release build
179 if [[ "$__BuildType" != "Release" ]]; then __SkipRestoreOptData=1; fi
181 if [[ ( $__SkipRestoreOptData == 0 ) && ( $__isMSBuildOnNETCoreSupported == 1 ) ]]; then
182 echo "Restoring the OptimizationData package"
183 "$__ProjectRoot/dotnet.sh" msbuild /nologo /verbosity:minimal /clp:Summary \
184 /p:RestoreDefaultOptimizationDataPackage=false /p:PortableBuild=true \
185 /p:UsePartialNGENOptimization=false /maxcpucount \
186 /t:RestoreOptData ./build.proj \
187 $__CommonMSBuildArgs $__UnprocessedBuildArgs
189 echo "Failed to restore the optimization data package."
194 if [ $__isMSBuildOnNETCoreSupported == 1 ]; then
195 # Parse the optdata package versions out of msbuild so that we can pass them on to CMake
196 local DotNetCli="$__ProjectRoot/Tools/dotnetcli/dotnet"
197 if [ ! -f $DotNetCli ]; then
198 source "$__ProjectRoot/init-tools.sh"
200 echo "Failed to restore buildtools."
204 local OptDataProjectFilePath="$__ProjectRoot/src/.nuget/optdata/optdata.csproj"
205 __PgoOptDataVersion=$(DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 $DotNetCli msbuild $OptDataProjectFilePath /t:DumpPgoDataPackageVersion /nologo | sed 's/^\s*//')
206 __IbcOptDataVersion=$(DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 $DotNetCli msbuild $OptDataProjectFilePath /t:DumpIbcDataPackageVersion /nologo | sed 's/^[[:blank:]]*//')
210 generate_event_logging_sources()
213 __ConsumingBuildSystem=$2
215 __OutputIncDir="$__OutputDir/src/inc"
216 __OutputEventingDir="$__OutputDir/eventing"
217 __OutputEventProviderDir="$__OutputEventingDir/eventprovider"
219 echo "Laying out dynamically generated files consumed by $__ConsumingBuildSystem"
220 echo "Laying out dynamically generated Event test files, etmdummy stub functions, and external linkages"
222 __PythonWarningFlags="-Wall"
223 if [[ $__IgnoreWarnings == 0 ]]; then
224 __PythonWarningFlags="$__PythonWarningFlags -Werror"
227 $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genEventing.py" --inc $__OutputIncDir --dummy $__OutputIncDir/etmdummy.h --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --testdir "$__OutputEventProviderDir/tests"
228 if [[ $? != 0 ]]; then
232 echo "Laying out dynamically generated EventPipe Implementation"
233 $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genEventPipe.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventingDir/eventpipe"
235 echo "Laying out dynamically generated EventSource classes"
236 $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genRuntimeEventSources.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventingDir"
238 # determine the logging system
241 echo "Laying out dynamically generated Event Logging Implementation of Lttng"
242 $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genLttngProvider.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventProviderDir"
243 if [[ $? != 0 ]]; then
248 echo "Laying out dummy event logging provider"
249 $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genDummyProvider.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventProviderDir"
250 if [[ $? != 0 ]]; then
257 generate_event_logging()
259 # Event Logging Infrastructure
260 if [[ $__SkipCoreCLR == 0 || $__SkipMSCorLib == 0 || $__ConfigureOnly == 1 ]]; then
261 generate_event_logging_sources "$__IntermediatesDir" "the native build system"
269 intermediatesForBuild="$3"
270 extraCmakeArguments="$4"
273 if [ $skipCondition == 1 ]; then
274 echo "Skipping $message build."
278 # All set to commence the build
279 echo "Commencing build of $message for $__BuildOS.$__BuildArch.$__BuildType in $intermediatesForBuild"
284 if [ $__UseNinja == 1 ]; then
286 buildFile="build.ninja"
287 if ! buildTool=$(command -v ninja || command -v ninja-build); then
288 echo "Unable to locate ninja!" 1>&2
293 if [ $__SkipConfigure == 0 ]; then
294 # if msbuild is not supported, then set __SkipGenerateVersion to 1
295 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then __SkipGenerateVersion=1; fi
296 # Drop version.cpp file
297 __versionSourceFile="$intermediatesForBuild/version.cpp"
298 if [ $__SkipGenerateVersion == 0 ]; then
300 "$__ProjectRoot/dotnet.sh" msbuild /nologo /verbosity:minimal /clp:Summary \
301 /l:BinClashLogger,Tools/Microsoft.DotNet.Build.Tasks.dll\;LogFile=binclash.log \
302 /p:RestoreDefaultOptimizationDataPackage=false /p:PortableBuild=true \
303 /p:UsePartialNGENOptimization=false /maxcpucount \
304 "$__ProjectDir/build.proj" /p:GenerateVersionSourceFile=true /t:GenerateVersionSourceFile /p:NativeVersionSourceFile=$__versionSourceFile \
305 $__CommonMSBuildArgs $__UnprocessedBuildArgs
307 # Generate the dummy version.cpp, but only if it didn't exist to make sure we don't trigger unnecessary rebuild
308 __versionSourceLine="static char sccsid[] __attribute__((used)) = \"@(#)No version information produced\";"
309 if [ -e $__versionSourceFile ]; then
310 read existingVersionSourceLine < $__versionSourceFile
312 if [ "$__versionSourceLine" != "$existingVersionSourceLine" ]; then
313 echo $__versionSourceLine > $__versionSourceFile
318 pushd "$intermediatesForBuild"
319 # Regenerate the CMake solution
320 echo "Invoking \"$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh\" \"$__ProjectRoot\" $__ClangMajorVersion \"$__ClangMinorVersion\" $platformArch $__BuildType $__CodeCoverage $generator $extraCmakeArguments $__cmakeargs"
321 "$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh" "$__ProjectRoot" $__ClangMajorVersion "$__ClangMinorVersion" $platformArch $__BuildType $__CodeCoverage $generator "$extraCmakeArguments" "$__cmakeargs"
325 if [ ! -f "$intermediatesForBuild/$buildFile" ]; then
326 echo "Failed to generate $message build project!"
331 if [ $__ConfigureOnly == 1 ]; then
332 echo "Finish configuration & skipping $message build."
336 # Check that the makefiles were created.
337 pushd "$intermediatesForBuild"
339 echo "Executing $buildTool install -j $__NumProc"
341 $buildTool install -j $__NumProc
343 echo "Failed to build $message."
350 build_cross_architecture_components()
352 local intermediatesForBuild="$__IntermediatesDir/Host$__CrossArch/crossgen"
353 local crossArchBinDir="$__BinDir/$__CrossArch"
355 mkdir -p "$intermediatesForBuild"
356 mkdir -p "$crossArchBinDir"
358 generate_event_logging_sources "$intermediatesForBuild" "the crossarch build system"
360 __SkipCrossArchBuild=1
361 # check supported cross-architecture components host(__HostArch)/target(__BuildArch) pair
362 if [[ ("$__BuildArch" == "arm" || "$__BuildArch" == "armel") && ("$__CrossArch" == "x86" || "$__CrossArch" == "x64") ]]; then
363 __SkipCrossArchBuild=0
364 elif [[ "$__BuildArch" == "arm64" && "$__CrossArch" == "x64" ]]; then
365 __SkipCrossArchBuild=0
371 export __CMakeBinDir="$crossArchBinDir"
372 export CROSSCOMPILE=0
374 __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"
375 build_native $__SkipCrossArchBuild "$__CrossArch" "$intermediatesForBuild" "$__ExtraCmakeArgs" "cross-architecture components"
377 export CROSSCOMPILE=1
380 isMSBuildOnNETCoreSupported()
382 __isMSBuildOnNETCoreSupported=$__msbuildonunsupportedplatform
384 if [ $__isMSBuildOnNETCoreSupported == 1 ]; then
388 if [ $__SkipManaged == 1 ]; then
389 __isMSBuildOnNETCoreSupported=0
393 if [ "$__HostArch" == "x64" ]; then
394 if [ "$__HostOS" == "Linux" ]; then
395 __isMSBuildOnNETCoreSupported=1
396 # note: the RIDs below can use globbing patterns
397 UNSUPPORTED_RIDS=("debian.9-x64" "ubuntu.17.04-x64")
398 for UNSUPPORTED_RID in "${UNSUPPORTED_RIDS[@]}"
400 if [[ $__HostDistroRid == $UNSUPPORTED_RID ]]; then
401 __isMSBuildOnNETCoreSupported=0
405 elif [ "$__HostOS" == "OSX" ]; then
406 __isMSBuildOnNETCoreSupported=1
407 elif [ "$__HostOS" == "FreeBSD" ]; then
408 __isMSBuildOnNETCoreSupported=1
416 local __CrossGenExec=$1
418 if [ $__PartialNgen == 1 ]; then
419 export COMPlus_PartialNGen=1
422 if [ -e $__CrossGenCoreLibLog ]; then
423 rm $__CrossGenCoreLibLog
425 echo "Generating native image of System.Private.CoreLib.dll for $__BuildOS.$__BuildArch.$__BuildType. Logging to \"$__CrossGenCoreLibLog\"."
426 echo "$__CrossGenExec /Platform_Assemblies_Paths $__BinDir/IL $__IbcTuning /out $__BinDir/System.Private.CoreLib.dll $__BinDir/IL/System.Private.CoreLib.dll"
427 $__CrossGenExec /Platform_Assemblies_Paths $__BinDir/IL $__IbcTuning /out $__BinDir/System.Private.CoreLib.dll $__BinDir/IL/System.Private.CoreLib.dll >> $__CrossGenCoreLibLog 2>&1
428 if [ $? -ne 0 ]; then
429 echo "Failed to generate native image for System.Private.CoreLib. Refer to $__CrossGenCoreLibLog"
433 if [ "$__BuildOS" == "Linux" ]; then
434 echo "Generating symbol file for System.Private.CoreLib.dll"
435 echo "$__CrossGenExec /Platform_Assemblies_Paths $__BinDir /CreatePerfMap $__BinDir $__BinDir/System.Private.CoreLib.dll"
436 $__CrossGenExec /Platform_Assemblies_Paths $__BinDir /CreatePerfMap $__BinDir $__BinDir/System.Private.CoreLib.dll >> $__CrossGenCoreLibLog 2>&1
437 if [ $? -ne 0 ]; then
438 echo "Failed to generate symbol file for System.Private.CoreLib. Refer to $__CrossGenCoreLibLog"
446 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
447 echo "System.Private.CoreLib.dll build unsupported."
451 if [ $__SkipMSCorLib == 1 ]; then
452 echo "Skipping building System.Private.CoreLib."
456 echo "Commencing build of managed components for $__BuildOS.$__BuildArch.$__BuildType"
460 if [[ "$__IbcTuning" == "" ]]; then
461 __ExtraBuildArgs="$__ExtraBuildArgs /p:OptimizationDataDir=\"$__PackagesDir/optimization.$__BuildOS-$__BuildArch.IBC.CoreCLR/$__IbcOptDataVersion/data\""
462 __ExtraBuildArgs="$__ExtraBuildArgs /p:EnableProfileGuidedOptimization=true"
465 if [[ "$__BuildManagedTools" -eq "1" ]]; then
466 __ExtraBuildArgs="$__ExtraBuildArgs /p:BuildManagedTools=true"
469 $__ProjectRoot/dotnet.sh msbuild /nologo /verbosity:minimal /clp:Summary \
470 /l:BinClashLogger,Tools/Microsoft.DotNet.Build.Tasks.dll\;LogFile=binclash.log \
471 /p:RestoreDefaultOptimizationDataPackage=false /p:PortableBuild=true \
472 /p:UsePartialNGENOptimization=false /maxcpucount \
473 $__ProjectDir/build.proj \
474 /flp:Verbosity=normal\;LogFile=$__LogsDir/System.Private.CoreLib_$__BuildOS__$__BuildArch__$__BuildType.log \
475 /p:__IntermediatesDir=$__IntermediatesDir /p:__RootBinDir=$__RootBinDir /p:BuildNugetPackage=false /p:UseSharedCompilation=false \
476 $__CommonMSBuildArgs $__ExtraBuildArgs $__UnprocessedBuildArgs
478 if [ $? -ne 0 ]; then
479 echo "Failed to build managed components."
483 if [ $__SkipCrossgen == 1 ]; then
484 echo "Skipping generating native image"
488 # The cross build generates a crossgen with the target architecture.
489 if [ $__CrossBuild == 0 ]; then
490 if [ $__SkipCoreCLR == 1 ]; then
494 # The architecture of host pc must be same architecture with target.
495 if [[ ( "$__HostArch" == "$__BuildArch" ) ]]; then
496 build_CoreLib_ni "$__BinDir/crossgen"
497 elif [[ ( "$__HostArch" == "x64" ) && ( "$__BuildArch" == "x86" ) ]]; then
498 build_CoreLib_ni "$__BinDir/crossgen"
499 elif [[ ( "$__HostArch" == "arm64" ) && ( "$__BuildArch" == "arm" ) ]]; then
500 build_CoreLib_ni "$__BinDir/crossgen"
505 if [[ ( "$__CrossArch" == "x86" ) && ( "$__BuildArch" == "arm" ) ]]; then
506 build_CoreLib_ni "$__CrossComponentBinDir/crossgen"
507 elif [[ ( "$__CrossArch" == "x64" ) && ( "$__BuildArch" == "arm" ) ]]; then
508 build_CoreLib_ni "$__CrossComponentBinDir/crossgen"
509 elif [[ ( "$__HostArch" == "x64" ) && ( "$__BuildArch" == "arm64" ) ]]; then
510 build_CoreLib_ni "$__CrossComponentBinDir/crossgen"
515 generate_NugetPackages()
517 # We can only generate nuget package if we also support building mscorlib as part of this build.
518 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
519 echo "Nuget package generation unsupported."
523 # Since we can build mscorlib for this OS, did we build the native components as well?
524 if [[ $__SkipCoreCLR == 1 && $__CrossgenOnly == 0 ]]; then
525 echo "Unable to generate nuget packages since native components were not built."
529 echo "Generating nuget packages for "$__BuildOS
530 echo "DistroRid is "$__DistroRid
531 echo "ROOTFS_DIR is "$ROOTFS_DIR
533 $__ProjectRoot/dotnet.sh msbuild /nologo /verbosity:minimal /clp:Summary \
534 /l:BinClashLogger,Tools/Microsoft.DotNet.Build.Tasks.dll\;LogFile=binclash.log \
535 /p:RestoreDefaultOptimizationDataPackage=false /p:PortableBuild=true \
536 /p:UsePartialNGENOptimization=false /maxcpucount \
537 $__SourceDir/.nuget/packages.builds \
538 /flp:Verbosity=normal\;LogFile=$__LogsDir/Nuget_$__BuildOS__$__BuildArch__$__BuildType.log \
539 /p:__IntermediatesDir=$__IntermediatesDir /p:__RootBinDir=$__RootBinDir /p:BuildNugetPackages=false /p:UseSharedCompilation=false /p:__DoCrossArchBuild=$__CrossBuild \
540 $__CommonMSBuildArgs $__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=
664 __SkipCrossArchNative=0
666 __SkipRestoreOptData=0
672 __ClangMajorVersion=0
673 __ClangMinorVersion=0
674 __NuGetPath="$__PackagesDir/NuGet.exe"
678 __SkipGenerateVersion=0
680 __msbuildonunsupportedplatform=0
681 __PgoOptDataVersion=""
682 __IbcOptDataVersion=""
683 __BuildManagedTools=1
686 __OfficialBuildIdArg=""
688 # Get the number of processors available to the scheduler
689 # Other techniques such as `nproc` only get the number of
690 # processors available to a single process.
691 if [ `uname` = "FreeBSD" ]; then
692 __NumProc=`sysctl hw.ncpu | awk '{ print $2+1 }'`
693 elif [ `uname` = "NetBSD" ]; then
694 __NumProc=$(($(getconf NPROCESSORS_ONLN)+1))
695 elif [ `uname` = "Darwin" ]; then
696 __NumProc=$(($(getconf _NPROCESSORS_ONLN)+1))
698 __NumProc=$(nproc --all)
702 if [ $# -le 0 ]; then
706 lowerI="$(echo $1 | awk '{print tolower($0)}')"
746 __CodeCoverage=Coverage
753 -portablebuild=false)
761 stripsymbols|-stripsymbols)
762 __cmakeargs="$__cmakeargs -DSTRIP_SYMBOLS=true"
766 __ClangMajorVersion=3
767 __ClangMinorVersion=5
771 __ClangMajorVersion=3
772 __ClangMinorVersion=6
776 __ClangMajorVersion=3
777 __ClangMinorVersion=7
781 __ClangMajorVersion=3
782 __ClangMinorVersion=8
786 __ClangMajorVersion=3
787 __ClangMinorVersion=9
791 __ClangMajorVersion=4
792 __ClangMinorVersion=0
796 __ClangMajorVersion=5
797 __ClangMinorVersion=0
801 __ClangMajorVersion=6
802 __ClangMinorVersion=0
806 __ClangMajorVersion=7
814 pgoinstrument|-pgoinstrument)
818 nopgooptimize|-nopgooptimize)
820 __SkipRestoreOptData=1
823 ibcinstrument|-ibcinstrument)
824 __IbcTuning="/Tuning"
827 configureonly|-configureonly)
833 skipconfigure|-skipconfigure)
837 skipnative|-skipnative)
838 # Use "skipnative" to use the same option name as build.cmd.
842 skipcoreclr|-skipcoreclr)
843 # Accept "skipcoreclr" for backwards-compatibility.
847 skipcrossarchnative|-skipcrossarchnative)
848 __SkipCrossArchNative=1
851 skipmanaged|-skipmanaged)
855 skipmscorlib|-skipmscorlib)
859 skipgenerateversion|-skipgenerateversion)
860 __SkipGenerateVersion=1
863 skiprestoreoptdata|-skiprestoreoptdata)
864 __SkipRestoreOptData=1
867 skipcrossgen|-skipcrossgen)
871 crossgenonly|-crossgenonly)
876 partialngen|-partialngen)
880 skiptests|-skiptests)
884 skipnuget|-skipnuget|skipbuildpackages|-skipbuildpackages)
888 ignorewarnings|-ignorewarnings)
890 __cmakeargs="$__cmakeargs -DCLR_CMAKE_WARNINGS_ARE_ERRORS=OFF"
893 cmakeargs|-cmakeargs)
895 __cmakeargs="$__cmakeargs $2"
898 echo "ERROR: 'cmakeargs' requires a non-empty option argument"
906 if [ ! -d $__RootBinDir ]; then
909 __RootBinParent=$(dirname $__RootBinDir)
910 __RootBinName=${__RootBinDir##*/}
911 __RootBinDir="$(cd $__RootBinParent &>/dev/null && printf %s/%s $PWD $__RootBinName)"
914 echo "ERROR: 'bindir' requires a non-empty option argument"
918 msbuildonunsupportedplatform|-msbuildonunsupportedplatform)
919 __msbuildonunsupportedplatform=1
926 echo "ERROR: 'numproc' requires a non-empty option argument"
935 echo "ERROR: 'osgroup' requires a non-empty option argument"
940 echo "ERROR: 'Rebuild' is not supported. Please remove it."
945 __SkipRestoreArg="/p:RestoreDuringBuild=false"
949 __SignTypeArg="/p:SignType=real"
953 __Id=$(echo $1| cut -d'=' -f 2)
954 __OfficialBuildIdArg="/p:OfficialBuildId=$__Id"
958 # Skip -Option=Value style argument passing
962 __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1"
969 __CommonMSBuildArgs="/p:__BuildArch=$__BuildArch /p:__BuildType=$__BuildType /p:__BuildOS=$__BuildOS $__OfficialBuildIdArg $__SignTypeArg $__SkipRestoreArg"
971 # Configure environment if we are doing a verbose build
972 if [ $__VerboseBuild == 1 ]; then
974 __CommonMSBuildArgs="$__CommonMSBuildArgs /v:detailed"
977 # Set default clang version
978 if [[ $__ClangMajorVersion == 0 && $__ClangMinorVersion == 0 ]]; then
979 if [[ "$__BuildArch" == "arm" || "$__BuildArch" == "armel" ]]; then
980 __ClangMajorVersion=5
981 __ClangMinorVersion=0
983 __ClangMajorVersion=3
984 __ClangMinorVersion=9
988 if [[ "$__BuildArch" == "armel" ]]; then
989 # Armel cross build is Tizen specific and does not support Portable RID build
993 if [ $__PortableBuild == 0 ]; then
994 __CommonMSBuildArgs="$__CommonMSBuildArgs /p:PortableBuild=false"
997 # Set dependent variables
998 __LogsDir="$__RootBinDir/Logs"
1000 # init the host distro name
1003 # Set the remaining variables based upon the determined build configuration
1004 __BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType"
1005 __PackagesBinDir="$__BinDir/.nuget"
1006 __ToolsDir="$__RootBinDir/tools"
1007 __TestWorkingDir="$__RootBinDir/tests/$__BuildOS.$__BuildArch.$__BuildType"
1008 export __IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType"
1009 __TestIntermediatesDir="$__RootBinDir/tests/obj/$__BuildOS.$__BuildArch.$__BuildType"
1010 __isMSBuildOnNETCoreSupported=0
1011 __CrossComponentBinDir="$__BinDir"
1013 __CrossArch="$__HostArch"
1014 if [ $__CrossBuild == 1 ]; then
1015 __CrossComponentBinDir="$__CrossComponentBinDir/$__CrossArch"
1017 __CrossGenCoreLibLog="$__LogsDir/CrossgenCoreLib_$__BuildOS.$__BuildArch.$__BuildType.log"
1019 # Init if MSBuild for .NET Core is supported for this platform
1020 isMSBuildOnNETCoreSupported
1022 # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set.
1023 # This is needed by CLI to function.
1024 if [ -z "$HOME" ]; then
1025 if [ ! -d "$__ProjectDir/temp_home" ]; then
1028 export HOME=$__ProjectDir/temp_home
1029 echo "HOME not defined; setting it to $HOME"
1032 # Specify path to be set for CMAKE_INSTALL_PREFIX.
1033 # This is where all built CoreClr libraries will copied to.
1034 export __CMakeBinDir="$__BinDir"
1036 # Configure environment if we are doing a cross compile.
1037 if [ $__CrossBuild == 1 ]; then
1038 export CROSSCOMPILE=1
1039 if ! [[ -n "$ROOTFS_DIR" ]]; then
1040 export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__BuildArch"
1044 # init the target distro name
1047 # Make the directories necessary for build if they don't exist
1053 # Restore the package containing profile counts for profile-guided optimizations
1056 # Generate event logging infrastructure sources
1057 generate_event_logging
1059 # Build the coreclr (native) components.
1060 __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"
1062 # [TODO] Remove this when the `build-test.sh` script properly builds and deploys test assets.
1063 if [ $__SkipTests != 1 ]; then
1064 echo "Adding CMake flags to build native tests for $__BuildOS.$__BuildArch.$__BuildType"
1065 __ExtraCmakeArgs="$__ExtraCmakeArgs -DCLR_CMAKE_BUILD_TESTS=ON"
1068 build_native $__SkipCoreCLR "$__BuildArch" "$__IntermediatesDir" "$__ExtraCmakeArgs" "CoreCLR component"
1070 # Build cross-architecture components
1071 if [ $__SkipCrossArchNative != 1 ]; then
1072 if [[ $__CrossBuild == 1 ]]; then
1073 build_cross_architecture_components
1077 # Build System.Private.CoreLib.
1081 if [ $__CrossgenOnly == 1 ]; then
1082 build_CoreLib_ni "$__BinDir/crossgen"
1085 # Generate nuget packages
1086 if [ $__SkipNuget != 1 ]; then
1087 generate_NugetPackages
1093 echo "Repo successfully built."
1094 echo "Product binaries are available at $__BinDir"