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 || command -v py)
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] [-gccx.y] [-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 "-gccx.y - optional argument to build using gcc version x.y."
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 "-nopgooptimize - do not use profile guided optimizations."
38 echo "-pgoinstrument - generate instrumented code for profile guided optimization enabled binaries."
39 echo "-ibcinstrument - generate IBC-tuning-enabled native images when invoking crossgen."
40 echo "-configureonly - do not perform any builds; just configure the build."
41 echo "-skipconfigure - skip build configuration."
42 echo "-skipnative - do not build native components."
43 echo "-skipcrossarchnative - do not build cross-architecture native components."
44 echo "-skipmanaged - do not build managed components."
45 echo "-skipmscorlib - do not build mscorlib.dll."
46 echo "-skiptests - skip the tests in the 'tests' subdirectory."
47 echo "-skipnuget - skip building nuget packages."
48 echo "-skiprestoreoptdata - skip restoring optimization data used by profile-based optimizations."
49 echo "-skipcrossgen - skip native image generation"
50 echo "-crossgenonly - only run native image generation"
51 echo "-partialngen - build CoreLib as PartialNGen"
52 echo "-verbose - optional argument to enable verbose build output."
53 echo "-skiprestore: skip restoring packages ^(default: packages are restored during build^)."
54 echo "-disableoss: Disable Open Source Signing for System.Private.CoreLib."
55 echo "-officialbuildid=^<ID^>: specify the official build ID to be used by this build."
56 echo "-stripSymbols - Optional argument to strip native symbols during the build."
57 echo "-skipgenerateversion - disable version generation even if MSBuild is supported."
58 echo "-ignorewarnings - do not treat warnings as errors"
59 echo "-cmakeargs - user-settable additional arguments passed to CMake."
60 echo "-bindir - output directory (defaults to $__ProjectRoot/bin)"
61 echo "-msbuildonunsupportedplatform - build managed binaries even if distro is not officially supported."
62 echo "-numproc - set the number of build processes."
63 echo "-portablebuild - pass -portablebuild=false to force a non-portable build."
64 echo "-staticanalyzer - build with clang static analyzer enabled."
70 source init-distro-rid.sh
72 local passedRootfsDir=""
74 # Only pass ROOTFS_DIR if cross is specified.
75 if (( ${__CrossBuild} == 1 )); then
76 passedRootfsDir=${ROOTFS_DIR}
77 elif [ "${__BuildArch}" != "${__HostArch}" ]; then
78 echo "Error, you are building a cross scenario without passing -cross."
82 initDistroRidGlobal ${__BuildOS} ${__BuildArch} ${__PortableBuild} ${passedRootfsDir}
87 echo Setting up directories for build
89 mkdir -p "$__RootBinDir"
92 mkdir -p "$__MsbuildDebugLogsDir"
93 mkdir -p "$__IntermediatesDir"
95 if [ $__CrossBuild == 1 ]; then
96 mkdir -p "$__CrossComponentBinDir"
100 # Check the system to ensure the right prereqs are in place
104 echo "Checking prerequisites..."
106 # Check presence of CMake on the path
107 hash cmake 2>/dev/null || { echo >&2 "Please install cmake before running this script"; exit 1; }
110 # Minimum required version of clang is version 4.0 for arm/armel cross build
111 if [[ $__CrossBuild == 1 && $__GccBuild == 0 && ("$__BuildArch" == "arm" || "$__BuildArch" == "armel") ]]; then
112 if ! [[ "$__ClangMajorVersion" -ge "4" ]]; then
113 echo "Please install clang4.0 or latest for arm/armel cross build"; exit 1;
118 if [[ $__GccBuild == 0 ]]; then
119 __ClangCombinedDottedVersion=$__ClangMajorVersion;
120 if [[ "$__ClangMinorVersion" != "" ]]; then
121 __ClangCombinedDottedVersion=$__ClangCombinedDottedVersion.$__ClangMinorVersion
123 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; }
125 __GccCombinedDottedVersion=$__GccMajorVersion;
126 if [[ "$__GccMinorVersion" != "" ]]; then
127 __GccCombinedDottedVersion=$__GccCombinedDottedVersion.$__GccMinorVersion
129 hash gcc-$__GccCombinedDottedVersion 2>/dev/null || hash gcc$__GccMajorVersion$__GccMinorVersion 2>/dev/null || hash gcc 2>/dev/null || { echo >&2 "Please install gcc-$__GccMajorVersion.$__GccMinorVersion before running this script"; exit 1; }
136 # we only need optdata on a Release build
137 if [[ "$__BuildType" != "Release" ]]; then __SkipRestoreOptData=1; fi
139 if [[ ( $__SkipRestoreOptData == 0 ) && ( $__isMSBuildOnNETCoreSupported == 1 ) ]]; then
140 echo "Restoring the OptimizationData package"
141 "$__ProjectRoot/dotnet.sh" msbuild /nologo /verbosity:minimal /clp:Summary \
142 /p:RestoreDefaultOptimizationDataPackage=false /p:PortableBuild=true \
143 /p:UsePartialNGENOptimization=false /maxcpucount \
144 /t:RestoreOptData ./build.proj \
145 $__CommonMSBuildArgs $__UnprocessedBuildArgs
147 echo "Failed to restore the optimization data package."
152 if [ $__isMSBuildOnNETCoreSupported == 1 ]; then
153 # Parse the optdata package versions out of msbuild so that we can pass them on to CMake
154 local DotNetCli="$__ProjectRoot/.dotnet/dotnet"
155 if [ ! -f $DotNetCli ]; then
156 source "$__ProjectRoot/init-tools.sh"
158 echo "Failed to restore buildtools."
162 local OptDataProjectFilePath="$__ProjectRoot/src/.nuget/optdata/optdata.csproj"
163 __PgoOptDataVersion=$(DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 $DotNetCli msbuild $OptDataProjectFilePath /t:DumpPgoDataPackageVersion /nologo | sed 's/^\s*//')
164 __IbcOptDataVersion=$(DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 $DotNetCli msbuild $OptDataProjectFilePath /t:DumpIbcDataPackageVersion /nologo | sed 's/^[[:blank:]]*//')
168 generate_event_logging_sources()
171 __ConsumingBuildSystem=$2
173 __OutputIncDir="$__OutputDir/src/inc"
174 __OutputEventingDir="$__OutputDir/Eventing"
175 __OutputEventProviderDir="$__OutputEventingDir/eventprovider"
177 echo "Laying out dynamically generated files consumed by $__ConsumingBuildSystem"
178 echo "Laying out dynamically generated Event test files, etmdummy stub functions, and external linkages"
180 __PythonWarningFlags="-Wall"
181 if [[ $__IgnoreWarnings == 0 ]]; then
182 __PythonWarningFlags="$__PythonWarningFlags -Werror"
185 $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genEventing.py" --inc $__OutputIncDir --dummy $__OutputIncDir/etmdummy.h --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --testdir "$__OutputEventProviderDir/tests"
186 if [[ $? != 0 ]]; then
190 echo "Laying out dynamically generated EventPipe Implementation"
191 $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genEventPipe.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventingDir/eventpipe"
193 echo "Laying out dynamically generated EventSource classes"
194 $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genRuntimeEventSources.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventingDir"
196 # determine the logging system
199 echo "Laying out dynamically generated Event Logging Implementation of Lttng"
200 $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genLttngProvider.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventProviderDir"
201 if [[ $? != 0 ]]; then
206 echo "Laying out dummy event logging provider"
207 $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genDummyProvider.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventProviderDir"
208 if [[ $? != 0 ]]; then
215 generate_event_logging()
217 # Event Logging Infrastructure
218 if [[ $__SkipCoreCLR == 0 || $__SkipMSCorLib == 0 || $__ConfigureOnly == 1 ]]; then
219 generate_event_logging_sources "$__IntermediatesDir" "the native build system"
227 intermediatesForBuild="$3"
228 extraCmakeArguments="$4"
231 if [ $skipCondition == 1 ]; then
232 echo "Skipping $message build."
236 # All set to commence the build
237 echo "Commencing build of $message for $__BuildOS.$__BuildArch.$__BuildType in $intermediatesForBuild"
242 if [ $__UseNinja == 1 ]; then
244 buildFile="build.ninja"
245 if ! buildTool=$(command -v ninja || command -v ninja-build); then
246 echo "Unable to locate ninja!" 1>&2
251 if [ $__SkipConfigure == 0 ]; then
252 # if msbuild is not supported, then set __SkipGenerateVersion to 1
253 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then __SkipGenerateVersion=1; fi
254 # Drop version.c file
255 __versionSourceFile="$intermediatesForBuild/version.c"
256 if [ $__SkipGenerateVersion == 0 ]; then
258 "$__ProjectRoot/dotnet.sh" msbuild /nologo /verbosity:minimal /clp:Summary \
259 /l:BinClashLogger,Tools/Microsoft.DotNet.Build.Tasks.dll\;LogFile=binclash.log \
260 /p:RestoreDefaultOptimizationDataPackage=false /p:PortableBuild=true \
261 /p:UsePartialNGENOptimization=false /maxcpucount \
262 "$__ProjectDir/build.proj" /p:GenerateVersionSourceFile=true /t:GenerateVersionSourceFile /p:NativeVersionSourceFile=$__versionSourceFile \
263 $__CommonMSBuildArgs $__UnprocessedBuildArgs
265 # Generate the dummy version.c, but only if it didn't exist to make sure we don't trigger unnecessary rebuild
266 __versionSourceLine="static char sccsid[] __attribute__((used)) = \"@(#)No version information produced\";"
267 if [ -e $__versionSourceFile ]; then
268 read existingVersionSourceLine < $__versionSourceFile
270 if [ "$__versionSourceLine" != "$existingVersionSourceLine" ]; then
271 echo $__versionSourceLine > $__versionSourceFile
276 pushd "$intermediatesForBuild"
277 # Regenerate the CMake solution
279 scriptDir="$__ProjectRoot/src/pal/tools"
280 if [[ $__GccBuild == 0 ]]; then
282 if [[ $__StaticAnalyzer == 1 ]]; then
283 scan_build=scan-build
285 echo "Invoking \"$scriptDir/gen-buildsys-clang.sh\" \"$__ProjectRoot\" $__ClangMajorVersion \"$__ClangMinorVersion\" $platformArch "$scriptDir" $__BuildType $__CodeCoverage $scan_build $generator $extraCmakeArguments $__cmakeargs"
286 source "$scriptDir/gen-buildsys-clang.sh" "$__ProjectRoot" $__ClangMajorVersion "$__ClangMinorVersion" $platformArch "$scriptDir" $__BuildType $__CodeCoverage $scan_build $generator "$extraCmakeArguments" "$__cmakeargs"
288 echo "Invoking \"$scriptDir/gen-buildsys-gcc.sh\" \"$__ProjectRoot\" $__GccMajorVersion \"$__GccMinorVersion\" $platformArch "$scriptDir" $__BuildType $__CodeCoverage $generator $extraCmakeArguments $__cmakeargs"
289 source "$scriptDir/gen-buildsys-gcc.sh" "$__ProjectRoot" "$__GccMajorVersion" "$__CGccMinorVersion" $platformArch "$scriptDir" $__BuildType $__CodeCoverage $generator "$extraCmakeArguments" "$__cmakeargs"
294 if [ ! -f "$intermediatesForBuild/$buildFile" ]; then
295 echo "Failed to generate $message build project!"
300 if [ $__ConfigureOnly == 1 ]; then
301 echo "Finish configuration & skipping $message build."
305 # Check that the makefiles were created.
306 pushd "$intermediatesForBuild"
308 if [ $__StaticAnalyzer == 1 ]; then
309 buildTool="$SCAN_BUILD_COMMAND $buildTool"
312 echo "Executing $buildTool install -j $__NumProc"
314 $buildTool install -j $__NumProc
316 echo "Failed to build $message."
323 build_cross_architecture_components()
325 local intermediatesForBuild="$__IntermediatesDir/Host$__CrossArch/crossgen"
326 local crossArchBinDir="$__BinDir/$__CrossArch"
328 mkdir -p "$intermediatesForBuild"
329 mkdir -p "$crossArchBinDir"
331 generate_event_logging_sources "$intermediatesForBuild" "the crossarch build system"
333 __SkipCrossArchBuild=1
334 # check supported cross-architecture components host(__HostArch)/target(__BuildArch) pair
335 if [[ ("$__BuildArch" == "arm" || "$__BuildArch" == "armel") && ("$__CrossArch" == "x86" || "$__CrossArch" == "x64") ]]; then
336 __SkipCrossArchBuild=0
337 elif [[ "$__BuildArch" == "arm64" && "$__CrossArch" == "x64" ]]; then
338 __SkipCrossArchBuild=0
344 export __CMakeBinDir="$crossArchBinDir"
345 export CROSSCOMPILE=0
347 __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"
348 build_native $__SkipCrossArchBuild "$__CrossArch" "$intermediatesForBuild" "$__ExtraCmakeArgs" "cross-architecture components"
350 export CROSSCOMPILE=1
353 isMSBuildOnNETCoreSupported()
355 __isMSBuildOnNETCoreSupported=$__msbuildonunsupportedplatform
357 if [ $__isMSBuildOnNETCoreSupported == 1 ]; then
361 if [ $__SkipManaged == 1 ]; then
362 __isMSBuildOnNETCoreSupported=0
366 if [ "$__HostArch" == "x64" ]; then
367 if [ "$__HostOS" == "Linux" ]; then
368 __isMSBuildOnNETCoreSupported=1
369 # note: the RIDs below can use globbing patterns
370 UNSUPPORTED_RIDS=("ubuntu.17.04-x64")
371 for UNSUPPORTED_RID in "${UNSUPPORTED_RIDS[@]}"
373 if [[ ${__DistroRid} == $UNSUPPORTED_RID ]]; then
374 __isMSBuildOnNETCoreSupported=0
378 elif [ "$__HostOS" == "OSX" ]; then
379 __isMSBuildOnNETCoreSupported=1
380 elif [ "$__HostOS" == "FreeBSD" ]; then
381 __isMSBuildOnNETCoreSupported=1
389 local __CrossGenExec=$1
391 if [ $__PartialNgen == 1 ]; then
392 export COMPlus_PartialNGen=1
395 if [ -e $__CrossGenCoreLibLog ]; then
396 rm $__CrossGenCoreLibLog
398 echo "Generating native image of System.Private.CoreLib.dll for $__BuildOS.$__BuildArch.$__BuildType. Logging to \"$__CrossGenCoreLibLog\"."
399 echo "$__CrossGenExec /Platform_Assemblies_Paths $__BinDir/IL $__IbcTuning /out $__BinDir/System.Private.CoreLib.dll $__BinDir/IL/System.Private.CoreLib.dll"
400 $__CrossGenExec /Platform_Assemblies_Paths $__BinDir/IL $__IbcTuning /out $__BinDir/System.Private.CoreLib.dll $__BinDir/IL/System.Private.CoreLib.dll >> $__CrossGenCoreLibLog 2>&1
401 if [ $? -ne 0 ]; then
402 echo "Failed to generate native image for System.Private.CoreLib. Refer to $__CrossGenCoreLibLog"
406 if [ "$__BuildOS" == "Linux" ]; then
407 echo "Generating symbol file for System.Private.CoreLib.dll"
408 echo "$__CrossGenExec /Platform_Assemblies_Paths $__BinDir /CreatePerfMap $__BinDir $__BinDir/System.Private.CoreLib.dll"
409 $__CrossGenExec /Platform_Assemblies_Paths $__BinDir /CreatePerfMap $__BinDir $__BinDir/System.Private.CoreLib.dll >> $__CrossGenCoreLibLog 2>&1
410 if [ $? -ne 0 ]; then
411 echo "Failed to generate symbol file for System.Private.CoreLib. Refer to $__CrossGenCoreLibLog"
419 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
420 echo "System.Private.CoreLib.dll build unsupported."
424 if [ $__SkipMSCorLib == 1 ]; then
425 echo "Skipping building System.Private.CoreLib."
429 echo "Commencing build of managed components for $__BuildOS.$__BuildArch.$__BuildType"
433 if [[ "$__IbcTuning" == "" ]]; then
434 __ExtraBuildArgs="$__ExtraBuildArgs /p:OptimizationDataDir=\"$__PackagesDir/optimization.$__BuildOS-$__BuildArch.IBC.CoreCLR/$__IbcOptDataVersion/data\""
435 __ExtraBuildArgs="$__ExtraBuildArgs /p:EnableProfileGuidedOptimization=true"
438 if [[ "$__BuildManagedTools" -eq "1" ]]; then
439 __ExtraBuildArgs="$__ExtraBuildArgs /p:BuildManagedTools=true"
442 $__ProjectRoot/dotnet.sh msbuild /nologo /verbosity:minimal /clp:Summary \
443 /l:BinClashLogger,Tools/Microsoft.DotNet.Build.Tasks.dll\;LogFile=binclash.log \
444 /p:RestoreDefaultOptimizationDataPackage=false /p:PortableBuild=true \
445 /p:UsePartialNGENOptimization=false /maxcpucount \
446 $__ProjectDir/build.proj \
447 /flp:Verbosity=normal\;LogFile=$__LogsDir/System.Private.CoreLib_$__BuildOS__$__BuildArch__$__BuildType.log \
448 /p:__IntermediatesDir=$__IntermediatesDir /p:__RootBinDir=$__RootBinDir /p:BuildNugetPackage=false \
449 $__CommonMSBuildArgs $__ExtraBuildArgs $__UnprocessedBuildArgs
451 if [ $? -ne 0 ]; then
452 echo "Failed to build managed components."
456 if [ $__SkipCrossgen == 1 ]; then
457 echo "Skipping generating native image"
461 # The cross build generates a crossgen with the target architecture.
462 if [ $__CrossBuild == 0 ]; then
463 if [ $__SkipCoreCLR == 1 ]; then
467 # The architecture of host pc must be same architecture with target.
468 if [[ ( "$__HostArch" == "$__BuildArch" ) ]]; then
469 build_CoreLib_ni "$__BinDir/crossgen"
470 elif [[ ( "$__HostArch" == "x64" ) && ( "$__BuildArch" == "x86" ) ]]; then
471 build_CoreLib_ni "$__BinDir/crossgen"
472 elif [[ ( "$__HostArch" == "arm64" ) && ( "$__BuildArch" == "arm" ) ]]; then
473 build_CoreLib_ni "$__BinDir/crossgen"
478 if [[ ( "$__CrossArch" == "x86" ) && ( "$__BuildArch" == "arm" ) ]]; then
479 build_CoreLib_ni "$__CrossComponentBinDir/crossgen"
480 elif [[ ( "$__CrossArch" == "x64" ) && ( "$__BuildArch" == "arm" ) ]]; then
481 build_CoreLib_ni "$__CrossComponentBinDir/crossgen"
482 elif [[ ( "$__HostArch" == "x64" ) && ( "$__BuildArch" == "arm64" ) ]]; then
483 build_CoreLib_ni "$__CrossComponentBinDir/crossgen"
488 generate_NugetPackages()
490 # We can only generate nuget package if we also support building mscorlib as part of this build.
491 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
492 echo "Nuget package generation unsupported."
496 # Since we can build mscorlib for this OS, did we build the native components as well?
497 if [[ $__SkipCoreCLR == 1 && $__CrossgenOnly == 0 ]]; then
498 echo "Unable to generate nuget packages since native components were not built."
502 echo "Generating nuget packages for "$__BuildOS
503 echo "DistroRid is "$__DistroRid
504 echo "ROOTFS_DIR is "$ROOTFS_DIR
506 $__ProjectRoot/dotnet.sh msbuild /nologo /verbosity:minimal /clp:Summary \
507 /l:BinClashLogger,Tools/Microsoft.DotNet.Build.Tasks.dll\;LogFile=binclash.log \
508 /p:RestoreDefaultOptimizationDataPackage=false /p:PortableBuild=true \
509 /p:UsePartialNGENOptimization=false /maxcpucount \
510 $__SourceDir/.nuget/packages.builds \
511 /flp:Verbosity=normal\;LogFile=$__LogsDir/Nuget_$__BuildOS__$__BuildArch__$__BuildType.log \
512 /p:__IntermediatesDir=$__IntermediatesDir /p:__RootBinDir=$__RootBinDir /p:BuildNugetPackages=false /p:__DoCrossArchBuild=$__CrossBuild \
513 $__CommonMSBuildArgs $__UnprocessedBuildArgs
515 if [ $? -ne 0 ]; then
516 echo "Failed to generate Nuget packages."
521 echo "Commencing CoreCLR Repo build"
523 # Argument types supported by this script:
525 # Build architecture - valid values are: x64, ARM.
526 # Build Type - valid values are: Debug, Checked, Release
528 # Set the default arguments for build
530 # Obtain the location of the bash script to figure out where the root of the repo is.
531 __ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
533 # Use uname to determine what the CPU is.
535 # Some Linux platforms report unknown for platform, but the arch for machine.
536 if [ "$CPUName" == "unknown" ]; then
542 echo "Unsupported CPU $CPUName detected, build might not succeed!"
553 echo "Unsupported CPU $CPUName detected, build might not succeed!"
568 echo "Unknown CPU $CPUName detected, configuring as if for x64"
574 # Use uname to determine what the OS is.
608 echo "Unsupported OS $OSName detected, configuring as if for Linux"
618 # Set the various build properties here so that CMake and MSBuild can pick them up
619 __ProjectDir="$__ProjectRoot"
620 __SourceDir="$__ProjectDir/src"
621 __PackagesDir="${DotNetRestorePackagesPath:-${__ProjectDir}/packages}"
622 __RootBinDir="$__ProjectDir/bin"
623 __UnprocessedBuildArgs=
637 __SkipCrossArchNative=0
639 __SkipRestoreOptData=0
645 __ClangMajorVersion=0
646 __ClangMinorVersion=0
650 __NuGetPath="$__PackagesDir/NuGet.exe"
653 __SkipGenerateVersion=0
655 __msbuildonunsupportedplatform=0
656 __PgoOptDataVersion=""
657 __IbcOptDataVersion=""
658 __BuildManagedTools=1
661 __OfficialBuildIdArg=""
664 # Get the number of processors available to the scheduler
665 # Other techniques such as `nproc` only get the number of
666 # processors available to a single process.
667 if [ `uname` = "FreeBSD" ]; then
668 __NumProc=`sysctl hw.ncpu | awk '{ print $2+1 }'`
669 elif [ `uname` = "NetBSD" ]; then
670 __NumProc=$(($(getconf NPROCESSORS_ONLN)+1))
671 elif [ `uname` = "Darwin" ]; then
672 __NumProc=$(($(getconf _NPROCESSORS_ONLN)+1))
674 __NumProc=$(nproc --all)
678 if [ $# -le 0 ]; then
682 lowerI="$(echo $1 | awk '{print tolower($0)}')"
722 __CodeCoverage=Coverage
729 -portablebuild=false)
737 stripsymbols|-stripsymbols)
738 __cmakeargs="$__cmakeargs -DSTRIP_SYMBOLS=true"
742 __ClangMajorVersion=3
743 __ClangMinorVersion=5
747 __ClangMajorVersion=3
748 __ClangMinorVersion=6
752 __ClangMajorVersion=3
753 __ClangMinorVersion=7
757 __ClangMajorVersion=3
758 __ClangMinorVersion=8
762 __ClangMajorVersion=3
763 __ClangMinorVersion=9
767 __ClangMajorVersion=4
768 __ClangMinorVersion=0
772 __ClangMajorVersion=5
773 __ClangMinorVersion=0
777 __ClangMajorVersion=6
778 __ClangMinorVersion=0
782 __ClangMajorVersion=7
820 pgoinstrument|-pgoinstrument)
824 nopgooptimize|-nopgooptimize)
826 __SkipRestoreOptData=1
829 ibcinstrument|-ibcinstrument)
830 __IbcTuning="/Tuning"
833 configureonly|-configureonly)
839 skipconfigure|-skipconfigure)
843 skipnative|-skipnative)
844 # Use "skipnative" to use the same option name as build.cmd.
848 skipcoreclr|-skipcoreclr)
849 # Accept "skipcoreclr" for backwards-compatibility.
853 skipcrossarchnative|-skipcrossarchnative)
854 __SkipCrossArchNative=1
857 skipmanaged|-skipmanaged)
861 skipmscorlib|-skipmscorlib)
865 skipgenerateversion|-skipgenerateversion)
866 __SkipGenerateVersion=1
869 skiprestoreoptdata|-skiprestoreoptdata)
870 __SkipRestoreOptData=1
873 skipcrossgen|-skipcrossgen)
877 crossgenonly|-crossgenonly)
882 partialngen|-partialngen)
886 skiptests|-skiptests)
890 skipnuget|-skipnuget|skipbuildpackages|-skipbuildpackages)
894 ignorewarnings|-ignorewarnings)
896 __cmakeargs="$__cmakeargs -DCLR_CMAKE_WARNINGS_ARE_ERRORS=OFF"
899 cmakeargs|-cmakeargs)
901 __cmakeargs="$__cmakeargs $2"
904 echo "ERROR: 'cmakeargs' requires a non-empty option argument"
912 if [ ! -d $__RootBinDir ]; then
915 __RootBinParent=$(dirname $__RootBinDir)
916 __RootBinName=${__RootBinDir##*/}
917 __RootBinDir="$(cd $__RootBinParent &>/dev/null && printf %s/%s $PWD $__RootBinName)"
920 echo "ERROR: 'bindir' requires a non-empty option argument"
924 msbuildonunsupportedplatform|-msbuildonunsupportedplatform)
925 __msbuildonunsupportedplatform=1
932 echo "ERROR: 'numproc' requires a non-empty option argument"
941 echo "ERROR: 'osgroup' requires a non-empty option argument"
946 echo "ERROR: 'Rebuild' is not supported. Please remove it."
951 __SkipRestoreArg="/p:RestoreDuringBuild=false"
955 __SignTypeArg="/p:SignType=real"
959 __Id=$(echo $1| cut -d'=' -f 2)
960 __OfficialBuildIdArg="/p:OfficialBuildId=$__Id"
968 # Skip -Option=Value style argument passing
972 __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1"
979 __CommonMSBuildArgs="/p:__BuildArch=$__BuildArch /p:__BuildType=$__BuildType /p:__BuildOS=$__BuildOS $__OfficialBuildIdArg $__SignTypeArg $__SkipRestoreArg"
981 # Configure environment if we are doing a verbose build
982 if [ $__VerboseBuild == 1 ]; then
984 __CommonMSBuildArgs="$__CommonMSBuildArgs /v:detailed"
987 # Set default clang version
988 if [[ $__ClangMajorVersion == 0 && $__ClangMinorVersion == 0 ]]; then
989 if [[ "$__BuildArch" == "arm" || "$__BuildArch" == "armel" ]]; then
990 __ClangMajorVersion=5
991 __ClangMinorVersion=0
993 __ClangMajorVersion=3
994 __ClangMinorVersion=9
998 if [[ "$__BuildArch" == "armel" ]]; then
999 # Armel cross build is Tizen specific and does not support Portable RID build
1003 if [ $__PortableBuild == 0 ]; then
1004 __CommonMSBuildArgs="$__CommonMSBuildArgs /p:PortableBuild=false"
1007 # Set dependent variables
1008 __LogsDir="$__RootBinDir/Logs"
1009 __MsbuildDebugLogsDir="$__LogsDir/MsbuildDebugLogs"
1011 # Set the remaining variables based upon the determined build configuration
1012 __BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType"
1013 __PackagesBinDir="$__BinDir/.nuget"
1014 __ToolsDir="$__RootBinDir/tools"
1015 __TestWorkingDir="$__RootBinDir/tests/$__BuildOS.$__BuildArch.$__BuildType"
1016 export __IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType"
1017 __TestIntermediatesDir="$__RootBinDir/tests/obj/$__BuildOS.$__BuildArch.$__BuildType"
1018 __isMSBuildOnNETCoreSupported=0
1019 __CrossComponentBinDir="$__BinDir"
1021 __CrossArch="$__HostArch"
1022 if [ $__CrossBuild == 1 ]; then
1023 __CrossComponentBinDir="$__CrossComponentBinDir/$__CrossArch"
1025 __CrossGenCoreLibLog="$__LogsDir/CrossgenCoreLib_$__BuildOS.$__BuildArch.$__BuildType.log"
1027 # init the target distro name
1030 # Init if MSBuild for .NET Core is supported for this platform
1031 isMSBuildOnNETCoreSupported
1033 # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set.
1034 # This is needed by CLI to function.
1035 if [ -z "$HOME" ]; then
1036 if [ ! -d "$__ProjectDir/temp_home" ]; then
1039 export HOME=$__ProjectDir/temp_home
1040 echo "HOME not defined; setting it to $HOME"
1043 # Specify path to be set for CMAKE_INSTALL_PREFIX.
1044 # This is where all built CoreClr libraries will copied to.
1045 export __CMakeBinDir="$__BinDir"
1047 # Configure environment if we are doing a cross compile.
1048 if [ $__CrossBuild == 1 ]; then
1049 export CROSSCOMPILE=1
1050 if ! [[ -n "$ROOTFS_DIR" ]]; then
1051 export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__BuildArch"
1055 # Make the directories necessary for build if they don't exist
1058 # Set up the directory for MSBuild debug logs.
1059 export MSBUILDDEBUGPATH="${__MsbuildDebugLogsDir}"
1064 # Restore the package containing profile counts for profile-guided optimizations
1067 # Generate event logging infrastructure sources
1068 generate_event_logging
1070 # Build the coreclr (native) components.
1071 __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"
1073 # [TODO] Remove this when the `build-test.sh` script properly builds and deploys test assets.
1074 if [ $__SkipTests != 1 ]; then
1075 echo "Adding CMake flags to build native tests for $__BuildOS.$__BuildArch.$__BuildType"
1076 __ExtraCmakeArgs="$__ExtraCmakeArgs -DCLR_CMAKE_BUILD_TESTS=ON"
1079 build_native $__SkipCoreCLR "$__BuildArch" "$__IntermediatesDir" "$__ExtraCmakeArgs" "CoreCLR component"
1081 # Build cross-architecture components
1082 if [ $__SkipCrossArchNative != 1 ]; then
1083 if [[ $__CrossBuild == 1 ]]; then
1084 build_cross_architecture_components
1088 # Build System.Private.CoreLib.
1092 if [ $__CrossgenOnly == 1 ]; then
1093 build_CoreLib_ni "$__BinDir/crossgen"
1096 # Generate nuget packages
1097 if [ $__SkipNuget != 1 ]; then
1098 generate_NugetPackages
1104 echo "Repo successfully built."
1105 echo "Product binaries are available at $__BinDir"