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 local OptDataProjectFilePath="$__ProjectRoot/src/.nuget/optdata/optdata.csproj"
140 if [[ ( $__SkipRestoreOptData == 0 ) && ( $__isMSBuildOnNETCoreSupported == 1 ) ]]; then
141 echo "Restoring the OptimizationData package"
142 "$__ProjectRoot/dotnet.sh" restore /nologo /verbosity:minimal /clp:Summary /m \
143 $OptDataProjectFilePath \
144 $__CommonMSBuildArgs $__UnprocessedBuildArgs
146 echo "Failed to restore the optimization data package."
151 if [ $__isMSBuildOnNETCoreSupported == 1 ]; then
152 # Parse the optdata package versions out of msbuild so that we can pass them on to CMake
153 local DotNetCli="$__ProjectRoot/.dotnet/dotnet"
154 if [ ! -f $DotNetCli ]; then
155 source "$__ProjectRoot/init-dotnet.sh"
157 echo "Failed to install dotnet."
161 __PgoOptDataVersion=$(DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 $DotNetCli msbuild $OptDataProjectFilePath /t:DumpPgoDataPackageVersion /nologo)
163 echo "Failed to get PGO data package version."
166 __PgoOptDataVersion=$(echo $__PgoOptDataVersion | sed 's/^\s*//')
167 __IbcOptDataVersion=$(DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 $DotNetCli msbuild $OptDataProjectFilePath /t:DumpIbcDataPackageVersion /nologo)
169 echo "Failed to get IBC data package version."
172 __IbcOptDataVersion=$(echo $__IbcOptDataVersion | sed 's/^[[:blank:]]*//')
176 generate_event_logging_sources()
179 __OutputEventingDir="$__OutputDir/Eventing"
181 __PythonWarningFlags="-Wall"
182 if [[ $__IgnoreWarnings == 0 ]]; then
183 __PythonWarningFlags="$__PythonWarningFlags -Werror"
186 echo "Laying out dynamically generated EventSource classes"
187 $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genRuntimeEventSources.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventingDir"
190 generate_event_logging()
192 # Event Logging Infrastructure
193 if [[ $__SkipMSCorLib == 0 ]]; then
194 generate_event_logging_sources "$__IntermediatesDir"
202 intermediatesForBuild="$3"
203 extraCmakeArguments="$4"
206 if [ $skipCondition == 1 ]; then
207 echo "Skipping $message build."
211 # All set to commence the build
212 echo "Commencing build of $message for $__BuildOS.$__BuildArch.$__BuildType in $intermediatesForBuild"
217 if [ $__UseNinja == 1 ]; then
219 buildFile="build.ninja"
220 if ! buildTool=$(command -v ninja || command -v ninja-build); then
221 echo "Unable to locate ninja!" 1>&2
226 if [ $__SkipConfigure == 0 ]; then
227 # if msbuild is not supported, then set __SkipGenerateVersion to 1
228 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then __SkipGenerateVersion=1; fi
229 # Drop version.c file
230 __versionSourceFile="$intermediatesForBuild/version.c"
231 if [ $__SkipGenerateVersion == 0 ]; then
233 "$__ProjectRoot/eng/common/msbuild.sh" $__ProjectRoot/eng/empty.csproj \
234 /p:NativeVersionFile=$__versionSourceFile \
235 /p:ArcadeBuild=true /t:GenerateNativeVersionFile /restore \
236 $__CommonMSBuildArgs $__UnprocessedBuildArgs
237 if [ $? -ne 0 ]; then
238 echo "Failed to generate native version file."
242 # Generate the dummy version.c, but only if it didn't exist to make sure we don't trigger unnecessary rebuild
243 __versionSourceLine="static char sccsid[] __attribute__((used)) = \"@(#)No version information produced\";"
244 if [ -e $__versionSourceFile ]; then
245 read existingVersionSourceLine < $__versionSourceFile
247 if [ "$__versionSourceLine" != "$existingVersionSourceLine" ]; then
248 echo $__versionSourceLine > $__versionSourceFile
253 pushd "$intermediatesForBuild"
254 # Regenerate the CMake solution
256 scriptDir="$__ProjectRoot/src/pal/tools"
257 if [[ $__GccBuild == 0 ]]; then
259 if [[ $__StaticAnalyzer == 1 ]]; then
260 scan_build=scan-build
262 echo "Invoking \"$scriptDir/gen-buildsys-clang.sh\" \"$__ProjectRoot\" $__ClangMajorVersion \"$__ClangMinorVersion\" $platformArch "$scriptDir" $__BuildType $__CodeCoverage $scan_build $generator $extraCmakeArguments $__cmakeargs"
263 source "$scriptDir/gen-buildsys-clang.sh" "$__ProjectRoot" $__ClangMajorVersion "$__ClangMinorVersion" $platformArch "$scriptDir" $__BuildType $__CodeCoverage $scan_build $generator "$extraCmakeArguments" "$__cmakeargs"
265 echo "Invoking \"$scriptDir/gen-buildsys-gcc.sh\" \"$__ProjectRoot\" $__GccMajorVersion \"$__GccMinorVersion\" $platformArch "$scriptDir" $__BuildType $__CodeCoverage $generator $extraCmakeArguments $__cmakeargs"
266 source "$scriptDir/gen-buildsys-gcc.sh" "$__ProjectRoot" "$__GccMajorVersion" "$__CGccMinorVersion" $platformArch "$scriptDir" $__BuildType $__CodeCoverage $generator "$extraCmakeArguments" "$__cmakeargs"
271 if [ ! -f "$intermediatesForBuild/$buildFile" ]; then
272 echo "Failed to generate $message build project!"
277 if [ $__ConfigureOnly == 1 ]; then
278 echo "Finish configuration & skipping $message build."
282 # Check that the makefiles were created.
283 pushd "$intermediatesForBuild"
285 if [ $__StaticAnalyzer == 1 ]; then
286 buildTool="$SCAN_BUILD_COMMAND $buildTool"
289 echo "Executing $buildTool install -j $__NumProc"
291 $buildTool install -j $__NumProc
293 echo "Failed to build $message."
300 build_cross_architecture_components()
302 local intermediatesForBuild="$__IntermediatesDir/Host$__CrossArch/crossgen"
303 local crossArchBinDir="$__BinDir/$__CrossArch"
305 mkdir -p "$intermediatesForBuild"
306 mkdir -p "$crossArchBinDir"
308 generate_event_logging_sources "$intermediatesForBuild" "the crossarch build system"
310 __SkipCrossArchBuild=1
311 # check supported cross-architecture components host(__HostArch)/target(__BuildArch) pair
312 if [[ ("$__BuildArch" == "arm" || "$__BuildArch" == "armel") && ("$__CrossArch" == "x86" || "$__CrossArch" == "x64") ]]; then
313 __SkipCrossArchBuild=0
314 elif [[ "$__BuildArch" == "arm64" && "$__CrossArch" == "x64" ]]; then
315 __SkipCrossArchBuild=0
321 export __CMakeBinDir="$crossArchBinDir"
322 export CROSSCOMPILE=0
324 __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"
325 build_native $__SkipCrossArchBuild "$__CrossArch" "$intermediatesForBuild" "$__ExtraCmakeArgs" "cross-architecture components"
327 export CROSSCOMPILE=1
330 isMSBuildOnNETCoreSupported()
332 __isMSBuildOnNETCoreSupported=$__msbuildonunsupportedplatform
334 if [ $__isMSBuildOnNETCoreSupported == 1 ]; then
338 if [ $__SkipManaged == 1 ]; then
339 __isMSBuildOnNETCoreSupported=0
343 if [ "$__HostArch" == "x64" ]; then
344 if [ "$__HostOS" == "Linux" ]; then
345 __isMSBuildOnNETCoreSupported=1
346 # note: the RIDs below can use globbing patterns
347 UNSUPPORTED_RIDS=("ubuntu.17.04-x64")
348 for UNSUPPORTED_RID in "${UNSUPPORTED_RIDS[@]}"
350 if [[ ${__DistroRid} == $UNSUPPORTED_RID ]]; then
351 __isMSBuildOnNETCoreSupported=0
355 elif [ "$__HostOS" == "OSX" ]; then
356 __isMSBuildOnNETCoreSupported=1
357 elif [ "$__HostOS" == "FreeBSD" ]; then
358 __isMSBuildOnNETCoreSupported=1
366 local __CrossGenExec=$1
367 local __CoreLibILDir=$2
369 if [ $__PartialNgen == 1 ]; then
370 export COMPlus_PartialNGen=1
373 if [ -e $__CrossGenCoreLibLog ]; then
374 rm $__CrossGenCoreLibLog
376 echo "Generating native image of System.Private.CoreLib.dll for $__BuildOS.$__BuildArch.$__BuildType. Logging to \"$__CrossGenCoreLibLog\"."
377 echo "$__CrossGenExec /Platform_Assemblies_Paths $__CoreLibILDir $__IbcTuning /out $__BinDir/System.Private.CoreLib.dll $__CoreLibILDir/System.Private.CoreLib.dll"
378 $__CrossGenExec /Platform_Assemblies_Paths $__CoreLibILDir $__IbcTuning /out $__BinDir/System.Private.CoreLib.dll $__CoreLibILDir/System.Private.CoreLib.dll >> $__CrossGenCoreLibLog 2>&1
379 if [ $? -ne 0 ]; then
380 echo "Failed to generate native image for System.Private.CoreLib. Refer to $__CrossGenCoreLibLog"
384 if [ "$__BuildOS" == "Linux" ]; then
385 echo "Generating symbol file for System.Private.CoreLib.dll"
386 echo "$__CrossGenExec /Platform_Assemblies_Paths $__BinDir /CreatePerfMap $__BinDir $__BinDir/System.Private.CoreLib.dll"
387 $__CrossGenExec /Platform_Assemblies_Paths $__BinDir /CreatePerfMap $__BinDir $__BinDir/System.Private.CoreLib.dll >> $__CrossGenCoreLibLog 2>&1
388 if [ $? -ne 0 ]; then
389 echo "Failed to generate symbol file for System.Private.CoreLib. Refer to $__CrossGenCoreLibLog"
397 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
398 echo "System.Private.CoreLib.dll build unsupported."
402 if [ $__SkipMSCorLib == 1 ]; then
403 echo "Skipping building System.Private.CoreLib."
407 echo "Commencing build of managed components for $__BuildOS.$__BuildArch.$__BuildType"
411 if [[ "$__IbcTuning" == "" ]]; then
412 __ExtraBuildArgs="$__ExtraBuildArgs /p:OptimizationDataDir=\"$__PackagesDir/optimization.$__BuildOS-$__BuildArch.IBC.CoreCLR/$__IbcOptDataVersion/data\""
413 __ExtraBuildArgs="$__ExtraBuildArgs /p:EnableProfileGuidedOptimization=true"
416 if [[ "$__BuildManagedTools" -eq "1" ]]; then
417 __ExtraBuildArgs="$__ExtraBuildArgs /p:BuildManagedTools=true"
420 $__ProjectRoot/dotnet.sh restore /nologo /verbosity:minimal /clp:Summary \
421 /p:PortableBuild=true /maxcpucount /p:IncludeRestoreOnlyProjects=true /p:ArcadeBuild=true\
422 $__ProjectDir/src/build.proj \
423 /flp:Verbosity=normal\;LogFile=$__LogsDir/System.Private.CoreLib_$__BuildOS__$__BuildArch__$__BuildType.log \
424 /p:__IntermediatesDir=$__IntermediatesDir /p:__RootBinDir=$__RootBinDir \
425 $__CommonMSBuildArgs $__ExtraBuildArgs $__UnprocessedBuildArgs
427 if [ $? -ne 0 ]; then
428 echo "Failed to restore managed components."
432 $__ProjectRoot/dotnet.sh msbuild /nologo /verbosity:minimal /clp:Summary \
433 /p:PortableBuild=true /maxcpucount /p:ArcadeBuild=true\
434 $__ProjectDir/src/build.proj \
435 /flp:Verbosity=normal\;LogFile=$__LogsDir/System.Private.CoreLib_$__BuildOS__$__BuildArch__$__BuildType.log \
436 /p:__IntermediatesDir=$__IntermediatesDir /p:__RootBinDir=$__RootBinDir \
437 $__CommonMSBuildArgs $__ExtraBuildArgs $__UnprocessedBuildArgs
439 if [ $? -ne 0 ]; then
440 echo "Failed to build managed components."
444 local __CoreLibILDir=$__BinDir/IL
446 if [ $__SkipCrossgen == 1 ]; then
447 echo "Skipping generating native image"
449 if [ $__CrossBuild == 1 ]; then
450 # Crossgen not performed, so treat the IL version as the final version
451 cp $__CoreLibILDir/System.Private.CoreLib.dll $__BinDir/System.Private.CoreLib.dll
457 # The cross build generates a crossgen with the target architecture.
458 if [ $__CrossBuild == 0 ]; then
459 if [ $__SkipCoreCLR == 1 ]; then
463 # The architecture of host pc must be same architecture with target.
464 if [[ ( "$__HostArch" == "$__BuildArch" ) ]]; then
465 build_CoreLib_ni "$__BinDir/crossgen" $__CoreLibILDir
466 elif [[ ( "$__HostArch" == "x64" ) && ( "$__BuildArch" == "x86" ) ]]; then
467 build_CoreLib_ni "$__BinDir/crossgen" $__CoreLibILDir
468 elif [[ ( "$__HostArch" == "arm64" ) && ( "$__BuildArch" == "arm" ) ]]; then
469 build_CoreLib_ni "$__BinDir/crossgen" $__CoreLibILDir
474 if [[ ( "$__CrossArch" == "x86" ) && ( "$__BuildArch" == "arm" ) ]]; then
475 build_CoreLib_ni "$__CrossComponentBinDir/crossgen" $__CoreLibILDir
476 elif [[ ( "$__CrossArch" == "x64" ) && ( "$__BuildArch" == "arm" ) ]]; then
477 build_CoreLib_ni "$__CrossComponentBinDir/crossgen" $__CoreLibILDir
478 elif [[ ( "$__HostArch" == "x64" ) && ( "$__BuildArch" == "arm64" ) ]]; then
479 build_CoreLib_ni "$__CrossComponentBinDir/crossgen" $__CoreLibILDir
481 # Crossgen not performed, so treat the IL version as the final version
482 cp $__CoreLibILDir/System.Private.CoreLib.dll $__BinDir/System.Private.CoreLib.dll
487 generate_NugetPackages()
489 # We can only generate nuget package if we also support building mscorlib as part of this build.
490 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
491 echo "Nuget package generation unsupported."
495 # Since we can build mscorlib for this OS, did we build the native components as well?
496 if [[ $__SkipCoreCLR == 1 && $__CrossgenOnly == 0 ]]; then
497 echo "Unable to generate nuget packages since native components were not built."
501 echo "Generating nuget packages for "$__BuildOS
502 echo "DistroRid is "$__DistroRid
503 echo "ROOTFS_DIR is "$ROOTFS_DIR
505 # Package build uses the Arcade system and scripts, relying on it to restore required toolsets as part of build
506 $__ProjectRoot/eng/common/build.sh -r -b -projects $__SourceDir/.nuget/packages.builds \
507 -verbosity minimal -bl:$__LogsDir/Nuget_$__BuildOS__$__BuildArch__$__BuildType.binlog \
508 /p:PortableBuild=true /p:ArcadeBuild=true \
509 /p:__IntermediatesDir=$__IntermediatesDir /p:__RootBinDir=$__RootBinDir /p:__DoCrossArchBuild=$__CrossBuild \
510 $__CommonMSBuildArgs $__UnprocessedBuildArgs
512 if [ $? -ne 0 ]; then
513 echo "Failed to generate Nuget packages."
518 echo "Commencing CoreCLR Repo build"
520 # Argument types supported by this script:
522 # Build architecture - valid values are: x64, ARM.
523 # Build Type - valid values are: Debug, Checked, Release
525 # Set the default arguments for build
527 # Obtain the location of the bash script to figure out where the root of the repo is.
528 __ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
530 # Use uname to determine what the CPU is.
532 # Some Linux platforms report unknown for platform, but the arch for machine.
533 if [ "$CPUName" == "unknown" ]; then
539 echo "Unsupported CPU $CPUName detected, build might not succeed!"
550 echo "Unsupported CPU $CPUName detected, build might not succeed!"
565 echo "Unknown CPU $CPUName detected, configuring as if for x64"
571 # Use uname to determine what the OS is.
605 echo "Unsupported OS $OSName detected, configuring as if for Linux"
615 # Set the various build properties here so that CMake and MSBuild can pick them up
616 __ProjectDir="$__ProjectRoot"
617 __SourceDir="$__ProjectDir/src"
618 __PackagesDir="${DotNetRestorePackagesPath:-${__ProjectDir}/.packages}"
619 __RootBinDir="$__ProjectDir/bin"
620 __UnprocessedBuildArgs=
634 __SkipCrossArchNative=0
636 __SkipRestoreOptData=0
642 __ClangMajorVersion=0
643 __ClangMinorVersion=0
647 __NuGetPath="$__PackagesDir/NuGet.exe"
650 __SkipGenerateVersion=0
652 __msbuildonunsupportedplatform=0
653 __PgoOptDataVersion=""
654 __IbcOptDataVersion=""
655 __BuildManagedTools=1
656 __SkipRestoreArg="/p:RestoreDuringBuild=true"
658 __OfficialBuildIdArg=""
661 # Get the number of processors available to the scheduler
662 # Other techniques such as `nproc` only get the number of
663 # processors available to a single process.
664 if [ `uname` = "FreeBSD" ]; then
665 __NumProc=`sysctl hw.ncpu | awk '{ print $2+1 }'`
666 elif [ `uname` = "NetBSD" ]; then
667 __NumProc=$(($(getconf NPROCESSORS_ONLN)+1))
668 elif [ `uname` = "Darwin" ]; then
669 __NumProc=$(($(getconf _NPROCESSORS_ONLN)+1))
671 __NumProc=$(nproc --all)
675 if [ $# -le 0 ]; then
679 lowerI="$(echo $1 | awk '{print tolower($0)}')"
719 __CodeCoverage=Coverage
726 -portablebuild=false)
734 stripsymbols|-stripsymbols)
735 __cmakeargs="$__cmakeargs -DSTRIP_SYMBOLS=true"
739 __ClangMajorVersion=3
740 __ClangMinorVersion=5
744 __ClangMajorVersion=3
745 __ClangMinorVersion=6
749 __ClangMajorVersion=3
750 __ClangMinorVersion=7
754 __ClangMajorVersion=3
755 __ClangMinorVersion=8
759 __ClangMajorVersion=3
760 __ClangMinorVersion=9
764 __ClangMajorVersion=4
765 __ClangMinorVersion=0
769 __ClangMajorVersion=5
770 __ClangMinorVersion=0
774 __ClangMajorVersion=6
775 __ClangMinorVersion=0
779 __ClangMajorVersion=7
817 pgoinstrument|-pgoinstrument)
821 nopgooptimize|-nopgooptimize)
823 __SkipRestoreOptData=1
826 ibcinstrument|-ibcinstrument)
827 __IbcTuning="/Tuning"
830 configureonly|-configureonly)
836 skipconfigure|-skipconfigure)
840 skipnative|-skipnative)
841 # Use "skipnative" to use the same option name as build.cmd.
845 skipcoreclr|-skipcoreclr)
846 # Accept "skipcoreclr" for backwards-compatibility.
850 skipcrossarchnative|-skipcrossarchnative)
851 __SkipCrossArchNative=1
854 skipmanaged|-skipmanaged)
858 skipmscorlib|-skipmscorlib)
862 skipgenerateversion|-skipgenerateversion)
863 __SkipGenerateVersion=1
866 skiprestoreoptdata|-skiprestoreoptdata)
867 __SkipRestoreOptData=1
870 skipcrossgen|-skipcrossgen)
874 crossgenonly|-crossgenonly)
879 partialngen|-partialngen)
883 skiptests|-skiptests)
887 skipnuget|-skipnuget|skipbuildpackages|-skipbuildpackages)
891 ignorewarnings|-ignorewarnings)
893 __cmakeargs="$__cmakeargs -DCLR_CMAKE_WARNINGS_ARE_ERRORS=OFF"
896 cmakeargs|-cmakeargs)
898 __cmakeargs="$__cmakeargs $2"
901 echo "ERROR: 'cmakeargs' requires a non-empty option argument"
909 if [ ! -d $__RootBinDir ]; then
912 __RootBinParent=$(dirname $__RootBinDir)
913 __RootBinName=${__RootBinDir##*/}
914 __RootBinDir="$(cd $__RootBinParent &>/dev/null && printf %s/%s $PWD $__RootBinName)"
917 echo "ERROR: 'bindir' requires a non-empty option argument"
921 msbuildonunsupportedplatform|-msbuildonunsupportedplatform)
922 __msbuildonunsupportedplatform=1
929 echo "ERROR: 'numproc' requires a non-empty option argument"
938 echo "ERROR: 'osgroup' requires a non-empty option argument"
943 echo "ERROR: 'Rebuild' is not supported. Please remove it."
948 __SkipRestoreArg="/p:RestoreDuringBuild=false"
952 __SignTypeArg="/p:SignType=real"
956 __Id=$(echo $1| cut -d'=' -f 2)
957 __OfficialBuildIdArg="/p:OfficialBuildId=$__Id"
965 # Skip -Option=Value style argument passing
969 __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1"
976 __CommonMSBuildArgs="/p:__BuildArch=$__BuildArch /p:__BuildType=$__BuildType /p:__BuildOS=$__BuildOS $__OfficialBuildIdArg $__SignTypeArg $__SkipRestoreArg"
978 # Configure environment if we are doing a verbose build
979 if [ $__VerboseBuild == 1 ]; then
981 __CommonMSBuildArgs="$__CommonMSBuildArgs /v:detailed"
984 # Set default clang version
985 if [[ $__ClangMajorVersion == 0 && $__ClangMinorVersion == 0 ]]; then
986 if [[ "$__BuildArch" == "arm" || "$__BuildArch" == "armel" ]]; then
987 __ClangMajorVersion=5
988 __ClangMinorVersion=0
990 __ClangMajorVersion=3
991 __ClangMinorVersion=9
995 # Set dependent variables
996 __LogsDir="$__RootBinDir/Logs"
997 __MsbuildDebugLogsDir="$__LogsDir/MsbuildDebugLogs"
999 # Set the remaining variables based upon the determined build configuration
1000 __BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType"
1001 __PackagesBinDir="$__BinDir/.nuget"
1002 export __IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType"
1003 __isMSBuildOnNETCoreSupported=0
1004 __CrossComponentBinDir="$__BinDir"
1006 __CrossArch="$__HostArch"
1007 if [ $__CrossBuild == 1 ]; then
1008 __CrossComponentBinDir="$__CrossComponentBinDir/$__CrossArch"
1010 __CrossGenCoreLibLog="$__LogsDir/CrossgenCoreLib_$__BuildOS.$__BuildArch.$__BuildType.log"
1012 # Configure environment if we are doing a cross compile.
1013 if [ $__CrossBuild == 1 ]; then
1014 export CROSSCOMPILE=1
1015 if ! [[ -n "$ROOTFS_DIR" ]]; then
1016 export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__BuildArch"
1020 # init the target distro name
1023 if [ $__PortableBuild == 0 ]; then
1024 __CommonMSBuildArgs="$__CommonMSBuildArgs /p:PortableBuild=false"
1027 # Init if MSBuild for .NET Core is supported for this platform
1028 isMSBuildOnNETCoreSupported
1030 # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set.
1031 # This is needed by CLI to function.
1032 if [ -z "$HOME" ]; then
1033 if [ ! -d "$__ProjectDir/temp_home" ]; then
1036 export HOME=$__ProjectDir/temp_home
1037 echo "HOME not defined; setting it to $HOME"
1040 # Specify path to be set for CMAKE_INSTALL_PREFIX.
1041 # This is where all built CoreClr libraries will copied to.
1042 export __CMakeBinDir="$__BinDir"
1044 # Make the directories necessary for build if they don't exist
1047 # Set up the directory for MSBuild debug logs.
1048 export MSBUILDDEBUGPATH="${__MsbuildDebugLogsDir}"
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"