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/dotnet.sh" msbuild /nologo /verbosity:minimal /clp:Summary \
183 /p:RestoreDefaultOptimizationDataPackage=false /p:PortableBuild=true \
184 /p:UsePartialNGENOptimization=false /maxcpucount \
185 /t:RestoreOptData ./build.proj \
186 $__CommonMSBuildArgs $__UnprocessedBuildArgs
188 echo "Failed to restore the optimization data package."
193 if [ $__isMSBuildOnNETCoreSupported == 1 ]; then
194 # Parse the optdata package versions out of msbuild so that we can pass them on to CMake
195 local DotNetCli="$__ProjectRoot/Tools/dotnetcli/dotnet"
196 if [ ! -f $DotNetCli ]; then
197 source "$__ProjectRoot/init-tools.sh"
199 echo "Failed to restore buildtools."
203 local OptDataProjectFilePath="$__ProjectRoot/src/.nuget/optdata/optdata.csproj"
204 __PgoOptDataVersion=$(DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 $DotNetCli msbuild $OptDataProjectFilePath /t:DumpPgoDataPackageVersion /nologo | sed 's/^\s*//')
205 __IbcOptDataVersion=$(DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 $DotNetCli msbuild $OptDataProjectFilePath /t:DumpIbcDataPackageVersion /nologo | sed 's/^[[:blank:]]*//')
209 generate_event_logging_sources()
212 __ConsumingBuildSystem=$2
214 __OutputIncDir="$__OutputDir/src/inc"
215 __OutputEventingDir="$__OutputDir/eventing"
216 __OutputEventProviderDir="$__OutputEventingDir/eventprovider"
218 echo "Laying out dynamically generated files consumed by $__ConsumingBuildSystem"
219 echo "Laying out dynamically generated Event test files, etmdummy stub functions, and external linkages"
221 __PythonWarningFlags="-Wall"
222 if [[ $__IgnoreWarnings == 0 ]]; then
223 __PythonWarningFlags="$__PythonWarningFlags -Werror"
226 $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genEventing.py" --inc $__OutputIncDir --dummy $__OutputIncDir/etmdummy.h --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --testdir "$__OutputEventProviderDir/tests"
227 if [[ $? != 0 ]]; then
231 echo "Laying out dynamically generated EventPipe Implementation"
232 $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genEventPipe.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventingDir/eventpipe"
234 echo "Laying out dynamically generated EventSource classes"
235 $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genRuntimeEventSources.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventingDir"
237 # determine the logging system
240 echo "Laying out dynamically generated Event Logging Implementation of Lttng"
241 $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genLttngProvider.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventProviderDir"
242 if [[ $? != 0 ]]; then
247 echo "Laying out dummy event logging provider"
248 $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genDummyProvider.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventProviderDir"
249 if [[ $? != 0 ]]; then
256 generate_event_logging()
258 # Event Logging Infrastructure
259 if [[ $__SkipCoreCLR == 0 || $__SkipMSCorLib == 0 || $__ConfigureOnly == 1 ]]; then
260 generate_event_logging_sources "$__IntermediatesDir" "the native build system"
268 intermediatesForBuild="$3"
269 extraCmakeArguments="$4"
272 if [ $skipCondition == 1 ]; then
273 echo "Skipping $message build."
277 # All set to commence the build
278 echo "Commencing build of $message for $__BuildOS.$__BuildArch.$__BuildType in $intermediatesForBuild"
283 if [ $__UseNinja == 1 ]; then
285 buildFile="build.ninja"
286 if ! buildTool=$(command -v ninja || command -v ninja-build); then
287 echo "Unable to locate ninja!" 1>&2
292 if [ $__SkipConfigure == 0 ]; then
293 # if msbuild is not supported, then set __SkipGenerateVersion to 1
294 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then __SkipGenerateVersion=1; fi
295 # Drop version.cpp file
296 __versionSourceFile="$intermediatesForBuild/version.cpp"
297 if [ $__SkipGenerateVersion == 0 ]; then
299 "$__ProjectRoot/dotnet.sh" msbuild /nologo /verbosity:minimal /clp:Summary \
300 /l:BinClashLogger,Tools/Microsoft.DotNet.Build.Tasks.dll\;LogFile=binclash.log \
301 /p:RestoreDefaultOptimizationDataPackage=false /p:PortableBuild=true \
302 /p:UsePartialNGENOptimization=false /maxcpucount \
303 "$__ProjectDir/build.proj" /p:GenerateVersionSourceFile=true /t:GenerateVersionSourceFile /p:NativeVersionSourceFile=$__versionSourceFile \
304 $__CommonMSBuildArgs $__UnprocessedBuildArgs
306 # Generate the dummy version.cpp, but only if it didn't exist to make sure we don't trigger unnecessary rebuild
307 __versionSourceLine="static char sccsid[] __attribute__((used)) = \"@(#)No version information produced\";"
308 if [ -e $__versionSourceFile ]; then
309 read existingVersionSourceLine < $__versionSourceFile
311 if [ "$__versionSourceLine" != "$existingVersionSourceLine" ]; then
312 echo $__versionSourceLine > $__versionSourceFile
317 pushd "$intermediatesForBuild"
318 # Regenerate the CMake solution
319 echo "Invoking \"$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh\" \"$__ProjectRoot\" $__ClangMajorVersion \"$__ClangMinorVersion\" $platformArch $__BuildType $__CodeCoverage $generator $extraCmakeArguments $__cmakeargs"
320 "$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh" "$__ProjectRoot" $__ClangMajorVersion "$__ClangMinorVersion" $platformArch $__BuildType $__CodeCoverage $generator "$extraCmakeArguments" "$__cmakeargs"
324 if [ ! -f "$intermediatesForBuild/$buildFile" ]; then
325 echo "Failed to generate $message build project!"
330 if [ $__ConfigureOnly == 1 ]; then
331 echo "Finish configuration & skipping $message build."
335 # Check that the makefiles were created.
336 pushd "$intermediatesForBuild"
338 echo "Executing $buildTool install -j $__NumProc"
340 $buildTool install -j $__NumProc
342 echo "Failed to build $message."
349 build_cross_architecture_components()
351 local intermediatesForBuild="$__IntermediatesDir/Host$__CrossArch/crossgen"
352 local crossArchBinDir="$__BinDir/$__CrossArch"
354 mkdir -p "$intermediatesForBuild"
355 mkdir -p "$crossArchBinDir"
357 generate_event_logging_sources "$intermediatesForBuild" "the crossarch build system"
359 __SkipCrossArchBuild=1
360 # check supported cross-architecture components host(__HostArch)/target(__BuildArch) pair
361 if [[ ("$__BuildArch" == "arm" || "$__BuildArch" == "armel") && ("$__CrossArch" == "x86" || "$__CrossArch" == "x64") ]]; then
362 __SkipCrossArchBuild=0
363 elif [[ "$__BuildArch" == "arm64" && "$__CrossArch" == "x64" ]]; then
364 __SkipCrossArchBuild=0
370 export __CMakeBinDir="$crossArchBinDir"
371 export CROSSCOMPILE=0
373 __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"
374 build_native $__SkipCrossArchBuild "$__CrossArch" "$intermediatesForBuild" "$__ExtraCmakeArgs" "cross-architecture components"
376 export CROSSCOMPILE=1
379 isMSBuildOnNETCoreSupported()
381 __isMSBuildOnNETCoreSupported=$__msbuildonunsupportedplatform
383 if [ $__isMSBuildOnNETCoreSupported == 1 ]; then
387 if [ $__SkipManaged == 1 ]; then
388 __isMSBuildOnNETCoreSupported=0
392 if [ "$__HostArch" == "x64" ]; then
393 if [ "$__HostOS" == "Linux" ]; then
394 __isMSBuildOnNETCoreSupported=1
395 # note: the RIDs below can use globbing patterns
396 UNSUPPORTED_RIDS=("debian.9-x64" "ubuntu.17.04-x64")
397 for UNSUPPORTED_RID in "${UNSUPPORTED_RIDS[@]}"
399 if [[ $__HostDistroRid == $UNSUPPORTED_RID ]]; then
400 __isMSBuildOnNETCoreSupported=0
404 elif [ "$__HostOS" == "OSX" ]; then
405 __isMSBuildOnNETCoreSupported=1
406 elif [ "$__HostOS" == "FreeBSD" ]; then
407 __isMSBuildOnNETCoreSupported=1
415 local __CrossGenExec=$1
417 if [ $__PartialNgen == 1 ]; then
418 export COMPlus_PartialNGen=1
421 if [ -e $__CrossGenCoreLibLog ]; then
422 rm $__CrossGenCoreLibLog
424 echo "Generating native image of System.Private.CoreLib.dll for $__BuildOS.$__BuildArch.$__BuildType. Logging to \"$__CrossGenCoreLibLog\"."
425 echo "$__CrossGenExec /Platform_Assemblies_Paths $__BinDir/IL $__IbcTuning /out $__BinDir/System.Private.CoreLib.dll $__BinDir/IL/System.Private.CoreLib.dll"
426 $__CrossGenExec /Platform_Assemblies_Paths $__BinDir/IL $__IbcTuning /out $__BinDir/System.Private.CoreLib.dll $__BinDir/IL/System.Private.CoreLib.dll >> $__CrossGenCoreLibLog 2>&1
427 if [ $? -ne 0 ]; then
428 echo "Failed to generate native image for System.Private.CoreLib. Refer to $__CrossGenCoreLibLog"
432 if [ "$__BuildOS" == "Linux" ]; then
433 echo "Generating symbol file for System.Private.CoreLib.dll"
434 echo "$__CrossGenExec /Platform_Assemblies_Paths $__BinDir /CreatePerfMap $__BinDir $__BinDir/System.Private.CoreLib.dll"
435 $__CrossGenExec /Platform_Assemblies_Paths $__BinDir /CreatePerfMap $__BinDir $__BinDir/System.Private.CoreLib.dll >> $__CrossGenCoreLibLog 2>&1
436 if [ $? -ne 0 ]; then
437 echo "Failed to generate symbol file for System.Private.CoreLib. Refer to $__CrossGenCoreLibLog"
445 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
446 echo "System.Private.CoreLib.dll build unsupported."
450 if [ $__SkipMSCorLib == 1 ]; then
451 echo "Skipping building System.Private.CoreLib."
455 echo "Commencing build of managed components for $__BuildOS.$__BuildArch.$__BuildType"
459 if [[ "$__IbcTuning" == "" ]]; then
460 __ExtraBuildArgs="$__ExtraBuildArgs /p:OptimizationDataDir=\"$__PackagesDir/optimization.$__BuildOS-$__BuildArch.IBC.CoreCLR/$__IbcOptDataVersion/data\""
461 __ExtraBuildArgs="$__ExtraBuildArgs /p:EnableProfileGuidedOptimization=true"
464 if [[ "$__BuildManagedTools" -eq "1" ]]; then
465 __ExtraBuildArgs="$__ExtraBuildArgs /p:BuildManagedTools=true"
468 $__ProjectRoot/dotnet.sh msbuild /nologo /verbosity:minimal /clp:Summary \
469 /l:BinClashLogger,Tools/Microsoft.DotNet.Build.Tasks.dll\;LogFile=binclash.log \
470 /p:RestoreDefaultOptimizationDataPackage=false /p:PortableBuild=true \
471 /p:UsePartialNGENOptimization=false /maxcpucount \
472 $__ProjectDir/build.proj \
473 /flp:Verbosity=normal\;LogFile=$__LogsDir/System.Private.CoreLib_$__BuildOS__$__BuildArch__$__BuildType.log \
474 /p:__IntermediatesDir=$__IntermediatesDir /p:__RootBinDir=$__RootBinDir /p:BuildNugetPackage=false /p:UseSharedCompilation=false \
475 $__CommonMSBuildArgs $__ExtraBuildArgs $__UnprocessedBuildArgs
477 if [ $? -ne 0 ]; then
478 echo "Failed to build managed components."
482 if [ $__SkipCrossgen == 1 ]; then
483 echo "Skipping generating native image"
487 # The cross build generates a crossgen with the target architecture.
488 if [ $__CrossBuild == 0 ]; then
489 if [ $__SkipCoreCLR == 1 ]; then
493 # The architecture of host pc must be same architecture with target.
494 if [[ ( "$__HostArch" == "$__BuildArch" ) ]]; then
495 build_CoreLib_ni "$__BinDir/crossgen"
496 elif [[ ( "$__HostArch" == "x64" ) && ( "$__BuildArch" == "x86" ) ]]; then
497 build_CoreLib_ni "$__BinDir/crossgen"
498 elif [[ ( "$__HostArch" == "arm64" ) && ( "$__BuildArch" == "arm" ) ]]; then
499 build_CoreLib_ni "$__BinDir/crossgen"
504 if [[ ( "$__CrossArch" == "x86" ) && ( "$__BuildArch" == "arm" ) ]]; then
505 build_CoreLib_ni "$__CrossComponentBinDir/crossgen"
506 elif [[ ( "$__CrossArch" == "x64" ) && ( "$__BuildArch" == "arm" ) ]]; then
507 build_CoreLib_ni "$__CrossComponentBinDir/crossgen"
508 elif [[ ( "$__HostArch" == "x64" ) && ( "$__BuildArch" == "arm64" ) ]]; then
509 build_CoreLib_ni "$__CrossComponentBinDir/crossgen"
514 generate_NugetPackages()
516 # We can only generate nuget package if we also support building mscorlib as part of this build.
517 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
518 echo "Nuget package generation unsupported."
522 # Since we can build mscorlib for this OS, did we build the native components as well?
523 if [[ $__SkipCoreCLR == 1 && $__CrossgenOnly == 0 ]]; then
524 echo "Unable to generate nuget packages since native components were not built."
528 echo "Generating nuget packages for "$__BuildOS
529 echo "DistroRid is "$__DistroRid
530 echo "ROOTFS_DIR is "$ROOTFS_DIR
532 $__ProjectRoot/dotnet.sh msbuild /nologo /verbosity:minimal /clp:Summary \
533 /l:BinClashLogger,Tools/Microsoft.DotNet.Build.Tasks.dll\;LogFile=binclash.log \
534 /p:RestoreDefaultOptimizationDataPackage=false /p:PortableBuild=true \
535 /p:UsePartialNGENOptimization=false /maxcpucount \
536 $__SourceDir/.nuget/packages.builds \
537 /flp:Verbosity=normal\;LogFile=$__LogsDir/Nuget_$__BuildOS__$__BuildArch__$__BuildType.log \
538 /p:__IntermediatesDir=$__IntermediatesDir /p:__RootBinDir=$__RootBinDir /p:BuildNugetPackages=false /p:UseSharedCompilation=false /p:__DoCrossArchBuild=$__CrossBuild \
539 $__CommonMSBuildArgs $__UnprocessedBuildArgs
541 if [ $? -ne 0 ]; then
542 echo "Failed to generate Nuget packages."
547 echo "Commencing CoreCLR Repo build"
549 # Argument types supported by this script:
551 # Build architecture - valid values are: x64, ARM.
552 # Build Type - valid values are: Debug, Checked, Release
554 # Set the default arguments for build
556 # Obtain the location of the bash script to figure out where the root of the repo is.
557 __ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
559 # Use uname to determine what the CPU is.
561 # Some Linux platforms report unknown for platform, but the arch for machine.
562 if [ "$CPUName" == "unknown" ]; then
568 echo "Unsupported CPU $CPUName detected, build might not succeed!"
579 echo "Unsupported CPU $CPUName detected, build might not succeed!"
594 echo "Unknown CPU $CPUName detected, configuring as if for x64"
600 # Use uname to determine what the OS is.
634 echo "Unsupported OS $OSName detected, configuring as if for Linux"
644 # Set the various build properties here so that CMake and MSBuild can pick them up
645 __ProjectDir="$__ProjectRoot"
646 __SourceDir="$__ProjectDir/src"
647 __PackagesDir="${DotNetRestorePackagesPath:-${__ProjectDir}/packages}"
648 __RootBinDir="$__ProjectDir/bin"
649 __UnprocessedBuildArgs=
664 __SkipRestoreOptData=0
670 __ClangMajorVersion=0
671 __ClangMinorVersion=0
672 __NuGetPath="$__PackagesDir/NuGet.exe"
676 __SkipGenerateVersion=0
678 __msbuildonunsupportedplatform=0
679 __PgoOptDataVersion=""
680 __IbcOptDataVersion=""
681 __BuildManagedTools=1
684 __OfficialBuildIdArg=""
686 # Get the number of processors available to the scheduler
687 # Other techniques such as `nproc` only get the number of
688 # processors available to a single process.
689 if [ `uname` = "FreeBSD" ]; then
690 __NumProc=`sysctl hw.ncpu | awk '{ print $2+1 }'`
691 elif [ `uname` = "NetBSD" ]; then
692 __NumProc=$(($(getconf NPROCESSORS_ONLN)+1))
693 elif [ `uname` = "Darwin" ]; then
694 __NumProc=$(($(getconf _NPROCESSORS_ONLN)+1))
696 __NumProc=$(nproc --all)
700 if [ $# -le 0 ]; then
704 lowerI="$(echo $1 | awk '{print tolower($0)}')"
744 __CodeCoverage=Coverage
751 -portablebuild=false)
759 stripsymbols|-stripsymbols)
760 __cmakeargs="$__cmakeargs -DSTRIP_SYMBOLS=true"
764 __ClangMajorVersion=3
765 __ClangMinorVersion=5
769 __ClangMajorVersion=3
770 __ClangMinorVersion=6
774 __ClangMajorVersion=3
775 __ClangMinorVersion=7
779 __ClangMajorVersion=3
780 __ClangMinorVersion=8
784 __ClangMajorVersion=3
785 __ClangMinorVersion=9
789 __ClangMajorVersion=4
790 __ClangMinorVersion=0
794 __ClangMajorVersion=5
795 __ClangMinorVersion=0
799 __ClangMajorVersion=6
800 __ClangMinorVersion=0
804 __ClangMajorVersion=7
812 pgoinstrument|-pgoinstrument)
816 nopgooptimize|-nopgooptimize)
818 __SkipRestoreOptData=1
821 ibcinstrument|-ibcinstrument)
822 __IbcTuning="/Tuning"
825 configureonly|-configureonly)
831 skipconfigure|-skipconfigure)
835 skipnative|-skipnative)
836 # Use "skipnative" to use the same option name as build.cmd.
840 skipcoreclr|-skipcoreclr)
841 # Accept "skipcoreclr" for backwards-compatibility.
845 skipmanaged|-skipmanaged)
849 skipmscorlib|-skipmscorlib)
853 skipgenerateversion|-skipgenerateversion)
854 __SkipGenerateVersion=1
857 skiprestoreoptdata|-skiprestoreoptdata)
858 __SkipRestoreOptData=1
861 skipcrossgen|-skipcrossgen)
865 crossgenonly|-crossgenonly)
870 partialngen|-partialngen)
874 skiptests|-skiptests)
878 skipnuget|-skipnuget|skipbuildpackages|-skipbuildpackages)
882 ignorewarnings|-ignorewarnings)
884 __cmakeargs="$__cmakeargs -DCLR_CMAKE_WARNINGS_ARE_ERRORS=OFF"
887 cmakeargs|-cmakeargs)
889 __cmakeargs="$__cmakeargs $2"
892 echo "ERROR: 'cmakeargs' requires a non-empty option argument"
900 if [ ! -d $__RootBinDir ]; then
903 __RootBinParent=$(dirname $__RootBinDir)
904 __RootBinName=${__RootBinDir##*/}
905 __RootBinDir="$(cd $__RootBinParent &>/dev/null && printf %s/%s $PWD $__RootBinName)"
908 echo "ERROR: 'bindir' requires a non-empty option argument"
912 msbuildonunsupportedplatform|-msbuildonunsupportedplatform)
913 __msbuildonunsupportedplatform=1
920 echo "ERROR: 'numproc' requires a non-empty option argument"
929 echo "ERROR: 'osgroup' requires a non-empty option argument"
934 echo "ERROR: 'Rebuild' is not supported. Please remove it."
939 __SkipRestoreArg="/p:RestoreDuringBuild=false"
943 __SignTypeArg="/p:SignType=real"
947 __Id=$(echo $1| cut -d'=' -f 2)
948 __OfficialBuildIdArg="/p:OfficialBuildId=$__Id"
952 # Skip -Option=Value style argument passing
956 __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1"
963 __CommonMSBuildArgs="/p:__BuildArch=$__BuildArch /p:__BuildType=$__BuildType /p:__BuildOS=$__BuildOS $__OfficialBuildIdArg $__SignTypeArg $__SkipRestoreArg"
965 # Configure environment if we are doing a verbose build
966 if [ $__VerboseBuild == 1 ]; then
968 __CommonMSBuildArgs="$__CommonMSBuildArgs /v:detailed"
971 # Set default clang version
972 if [[ $__ClangMajorVersion == 0 && $__ClangMinorVersion == 0 ]]; then
973 if [[ "$__BuildArch" == "arm" || "$__BuildArch" == "armel" ]]; then
974 __ClangMajorVersion=5
975 __ClangMinorVersion=0
977 __ClangMajorVersion=3
978 __ClangMinorVersion=9
982 if [[ "$__BuildArch" == "armel" ]]; then
983 # Armel cross build is Tizen specific and does not support Portable RID build
987 if [ $__PortableBuild == 0 ]; then
988 __CommonMSBuildArgs="$__CommonMSBuildArgs /p:PortableBuild=false"
991 # Set dependent variables
992 __LogsDir="$__RootBinDir/Logs"
994 # init the host distro name
997 # Set the remaining variables based upon the determined build configuration
998 __BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType"
999 __PackagesBinDir="$__BinDir/.nuget"
1000 __ToolsDir="$__RootBinDir/tools"
1001 __TestWorkingDir="$__RootBinDir/tests/$__BuildOS.$__BuildArch.$__BuildType"
1002 export __IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType"
1003 __TestIntermediatesDir="$__RootBinDir/tests/obj/$__BuildOS.$__BuildArch.$__BuildType"
1004 __isMSBuildOnNETCoreSupported=0
1005 __CrossComponentBinDir="$__BinDir"
1007 __CrossArch="$__HostArch"
1008 if [ $__CrossBuild == 1 ]; then
1009 __CrossComponentBinDir="$__CrossComponentBinDir/$__CrossArch"
1011 __CrossGenCoreLibLog="$__LogsDir/CrossgenCoreLib_$__BuildOS.$__BuildArch.$__BuildType.log"
1013 # Init if MSBuild for .NET Core is supported for this platform
1014 isMSBuildOnNETCoreSupported
1016 # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set.
1017 # This is needed by CLI to function.
1018 if [ -z "$HOME" ]; then
1019 if [ ! -d "$__ProjectDir/temp_home" ]; then
1022 export HOME=$__ProjectDir/temp_home
1023 echo "HOME not defined; setting it to $HOME"
1026 # Specify path to be set for CMAKE_INSTALL_PREFIX.
1027 # This is where all built CoreClr libraries will copied to.
1028 export __CMakeBinDir="$__BinDir"
1030 # Configure environment if we are doing a cross compile.
1031 if [ $__CrossBuild == 1 ]; then
1032 export CROSSCOMPILE=1
1033 if ! [[ -n "$ROOTFS_DIR" ]]; then
1034 export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__BuildArch"
1038 # init the target distro name
1041 # Make the directories necessary for build if they don't exist
1047 # Restore the package containing profile counts for profile-guided optimizations
1050 # Generate event logging infrastructure sources
1051 generate_event_logging
1053 # Build the coreclr (native) components.
1054 __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"
1056 # [TODO] Remove this when the `build-test.sh` script properly builds and deploys test assets.
1057 if [ $__SkipTests != 1 ]; then
1058 echo "Adding CMake flags to build native tests for $__BuildOS.$__BuildArch.$__BuildType"
1059 __ExtraCmakeArgs="$__ExtraCmakeArgs -DCLR_CMAKE_BUILD_TESTS=ON"
1062 build_native $__SkipCoreCLR "$__BuildArch" "$__IntermediatesDir" "$__ExtraCmakeArgs" "CoreCLR component"
1064 # Build cross-architecture components
1065 if [[ $__CrossBuild == 1 ]]; then
1066 build_cross_architecture_components
1069 # Build System.Private.CoreLib.
1073 if [ $__CrossgenOnly == 1 ]; then
1074 build_CoreLib_ni "$__BinDir/crossgen"
1077 # Generate nuget packages
1078 if [ $__SkipNuget != 1 ]; then
1079 generate_NugetPackages
1085 echo "Repo successfully built."
1086 echo "Product binaries are available at $__BinDir"