3 PYTHON=${PYTHON:-python}
7 echo "Usage: $0 [BuildArch] [BuildType] [clean] [verbose] [coverage] [cross] [clangx.y] [ninja] [configureonly] [skipconfigure] [skipnative] [skipmscorlib] [skiptests] [cmakeargs] [bindir]"
8 echo "BuildArch can be: x64, x86, arm, arm-softfp, arm64"
9 echo "BuildType can be: debug, checked, release"
10 echo "clean - optional argument to force a clean build."
11 echo "verbose - optional argument to enable verbose build output."
12 echo "coverage - optional argument to enable code coverage build (currently supported only for Linux and OSX)."
13 echo "ninja - target ninja instead of GNU make"
14 echo "clangx.y - optional argument to build using clang version x.y."
15 echo "cross - optional argument to signify cross compilation,"
16 echo " - will use ROOTFS_DIR environment variable if set."
17 echo "configureonly - do not perform any builds; just configure the build."
18 echo "skipconfigure - skip build configuration."
19 echo "skipnative - do not build native components."
20 echo "skipmscorlib - do not build mscorlib.dll."
21 echo "skiptests - skip the tests in the 'tests' subdirectory."
22 echo "skiprestore - skip restoring nuget packages."
23 echo "skipnuget - skip building nuget packages."
24 echo "disableoss - Disable Open Source Signing for mscorlib."
25 echo "skipgenerateversion - disable version generation even if MSBuild is supported."
26 echo "cmakeargs - user-settable additional arguments passed to CMake."
27 echo "bindir - output directory (defaults to $__ProjectRoot/bin)"
34 if [ "$__BuildOS" == "Linux" ]; then
35 if [ ! -e /etc/os-release ]; then
36 echo "WARNING: Can not determine runtime id for current distro."
39 source /etc/os-release
40 export __DistroRid="$ID.$VERSION_ID-$__HostArch"
47 echo Setting up directories for build
49 mkdir -p "$__RootBinDir"
52 mkdir -p "$__IntermediatesDir"
55 # Performs "clean build" type actions (deleting and remaking directories)
59 echo Cleaning previous output for the selected configuration
61 rm -rf "$__IntermediatesDir"
63 rm -rf "$__TestWorkingDir"
64 rm -rf "$__TestIntermediatesDir"
66 rm -rf "$__LogsDir/*_$__BuildOS__$__BuildArch__$__BuildType.*"
67 rm -rf "$__ProjectRoot/Tools"
70 # Check the system to ensure the right prereqs are in place
74 echo "Checking prerequisites..."
76 # Check presence of CMake on the path
77 hash cmake 2>/dev/null || { echo >&2 "Please install cmake before running this script"; exit 1; }
80 hash clang-$__ClangMajorVersion.$__ClangMinorVersion 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; }
87 if [ $__SkipCoreCLR == 1 ]; then
88 echo "Skipping CoreCLR build."
92 # Event Logging Infrastructure
93 __GeneratedIntermediate="$__IntermediatesDir/Generated"
94 __GeneratedIntermediateEventProvider="$__GeneratedIntermediate/eventprovider_new"
95 if [[ -d "$__GeneratedIntermediateEventProvider" ]]; then
96 rm -rf "$__GeneratedIntermediateEventProvider"
99 if [[ ! -d "$__GeneratedIntermediate/eventprovider" ]]; then
100 mkdir -p "$__GeneratedIntermediate/eventprovider"
103 mkdir -p "$__GeneratedIntermediateEventProvider"
104 if [[ $__SkipCoreCLR == 0 || $__ConfigureOnly == 1 ]]; then
105 echo "Laying out dynamically generated files consumed by the build system "
106 echo "Laying out dynamically generated Event Logging Test files"
107 $PYTHON -B -Wall -Werror "$__ProjectRoot/src/scripts/genXplatEventing.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --exc "$__ProjectRoot/src/vm/ClrEtwAllMeta.lst" --testdir "$__GeneratedIntermediateEventProvider/tests"
109 if [[ $? != 0 ]]; then
113 #determine the logging system
116 echo "Laying out dynamically generated Event Logging Implementation of Lttng"
117 $PYTHON -B -Wall -Werror "$__ProjectRoot/src/scripts/genXplatLttng.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__GeneratedIntermediateEventProvider"
118 if [[ $? != 0 ]]; then
127 echo "Cleaning the temp folder of dynamically generated Event Logging files"
128 $PYTHON -B -Wall -Werror -c "import sys;sys.path.insert(0,\"$__ProjectRoot/src/scripts\"); from Utilities import *;UpdateDirectory(\"$__GeneratedIntermediate/eventprovider\",\"$__GeneratedIntermediateEventProvider\")"
129 if [[ $? != 0 ]]; then
133 rm -rf "$__GeneratedIntermediateEventProvider"
135 # All set to commence the build
137 echo "Commencing build of native components for $__BuildOS.$__BuildArch.$__BuildType in $__IntermediatesDir"
139 cd "$__IntermediatesDir"
144 if [ $__UseNinja == 1 ]; then
146 buildFile="build.ninja"
150 if [ $__SkipConfigure == 0 ]; then
151 # if msbuild is not supported, then set __SkipGenerateVersion to 1
152 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then __SkipGenerateVersion=1; fi
153 # Drop version.c file
154 __versionSourceFile=$__IntermediatesDir/version.cpp
155 if [ $__SkipGenerateVersion == 0 ]; then
156 "$__ProjectRoot/init-tools.sh" > "$__ProjectRoot/init-tools.log"
157 echo "Running: \"$__ProjectRoot/Tools/corerun\" \"$__ProjectRoot/Tools/MSBuild.exe\" \"$__ProjectRoot/build.proj\" /v:minimal /t:GenerateVersionSourceFile /p:NativeVersionSourceFile=$__versionSourceFile /p:GenerateVersionSourceFile=true /v:minimal $__OfficialBuildIdArg"
158 "$__ProjectRoot/Tools/corerun" "$__ProjectRoot/Tools/MSBuild.exe" "$__ProjectRoot/build.proj" /v:minimal /t:GenerateVersionSourceFile /p:NativeVersionSourceFile=$__versionSourceFile /p:GenerateVersionSourceFile=true /v:minimal $__OfficialBuildIdArg
160 __versionSourceLine="static char sccsid[] __attribute__((used)) = \"@(#)No version information produced\";"
161 echo $__versionSourceLine > $__versionSourceFile
163 # Regenerate the CMake solution
164 echo "Invoking \"$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh\" \"$__ProjectRoot\" $__ClangMajorVersion $__ClangMinorVersion $__BuildArch $__BuildType $__CodeCoverage $__IncludeTests $generator $__cmakeargs"
165 "$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh" "$__ProjectRoot" $__ClangMajorVersion $__ClangMinorVersion $__BuildArch $__BuildType $__CodeCoverage $__IncludeTests $generator "$__cmakeargs"
168 # Check that the makefiles were created.
170 if [ ! -f "$__IntermediatesDir/$buildFile" ]; then
171 echo "Failed to generate native component build project!"
175 # Get the number of processors available to the scheduler
176 # Other techniques such as `nproc` only get the number of
177 # processors available to a single process.
178 if [ `uname` = "FreeBSD" ]; then
179 NumProc=`sysctl hw.ncpu | awk '{ print $2+1 }'`
180 elif [ `uname` = "NetBSD" ]; then
181 NumProc=$(($(getconf NPROCESSORS_ONLN)+1))
183 NumProc=$(($(getconf _NPROCESSORS_ONLN)+1))
188 echo "Executing $buildTool install -j $NumProc $__UnprocessedBuildArgs"
190 $buildTool install -j $NumProc $__UnprocessedBuildArgs
192 echo "Failed to build coreclr components."
199 echo "Restoring BuildTools..."
200 $__ProjectRoot/init-tools.sh
201 if [ $? -ne 0 ]; then
202 echo "Failed to restore BuildTools."
207 isMSBuildOnNETCoreSupported()
209 # This needs to be updated alongwith corresponding changes to netci.groovy.
210 __isMSBuildOnNETCoreSupported=0
212 if [ "$__HostArch" == "x64" ]; then
213 if [ "$__HostOS" == "Linux" ]; then
214 case "$__DistroRid" in
216 __isMSBuildOnNETCoreSupported=1
219 __isMSBuildOnNETCoreSupported=1
222 __isMSBuildOnNETCoreSupported=1
225 __isMSBuildOnNETCoreSupported=1
228 __isMSBuildOnNETCoreSupported=1
231 __isMSBuildOnNETCoreSupported=1
234 __isMSBuildOnNETCoreSupported=1
238 elif [ "$__HostOS" == "OSX" ]; then
239 __isMSBuildOnNETCoreSupported=1
246 if [ $__SkipCoreCLR == 0 -a -e $__BinDir/crossgen ]; then
247 echo "Generating native image for System.Private.CoreLib."
248 $__BinDir/crossgen $__BinDir/System.Private.CoreLib.dll
249 if [ $? -ne 0 ]; then
250 echo "Failed to generate native image for System.Private.CoreLib."
254 echo "Generating native image for MScorlib Facade."
255 $__BinDir/crossgen $__BinDir/mscorlib.dll
256 if [ $? -ne 0 ]; then
257 echo "Failed to generate native image for mscorlib facade."
261 if [ "$__BuildOS" == "Linux" ]; then
262 echo "Generating symbol file for System.Private.CoreLib."
263 $__BinDir/crossgen /CreatePerfMap $__BinDir $__BinDir/System.Private.CoreLib.ni.dll
264 if [ $? -ne 0 ]; then
265 echo "Failed to generate symbol file for System.Private.CoreLib."
275 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
276 echo "System.Private.CoreLib.dll build unsupported."
280 if [ $__SkipMSCorLib == 1 ]; then
281 echo "Skipping building System.Private.CoreLib."
289 echo "Commencing build of managed components for $__BuildOS.$__BuildArch.$__BuildType"
292 $__ProjectRoot/Tools/corerun "$__MSBuildPath" /nologo "$__ProjectRoot/build.proj" /verbosity:minimal "/fileloggerparameters:Verbosity=normal;LogFile=$__LogsDir/System.Private.CoreLib_$__BuildOS__$__BuildArch__$__BuildType.log" /t:Build /p:__BuildOS=$__BuildOS /p:__BuildArch=$__BuildArch /p:__BuildType=$__BuildType /p:__IntermediatesDir=$__IntermediatesDir /p:__RootBinDir=$__RootBinDir /p:BuildNugetPackage=false /p:UseSharedCompilation=false ${__SignTypeReal}
294 if [ $? -ne 0 ]; then
295 echo "Failed to build managed components."
299 # The cross build generates a crossgen with the target architecture.
300 if [ $__CrossBuild != 1 ]; then
301 # The architecture of host pc must be same architecture with target.
302 if [[ ( "$__HostArch" == "$__BuildArch" ) ]]; then
304 elif [[ ( "$__HostArch" == "x64" ) && ( "$__BuildArch" == "x86" ) ]]; then
306 elif [[ ( "$__HostArch" == "arm64" ) && ( "$__BuildArch" == "arm" ) ]]; then
314 generate_NugetPackages()
316 # We can only generate nuget package if we also support building mscorlib as part of this build.
317 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
318 echo "Nuget package generation unsupported."
322 # Since we can build mscorlib for this OS, did we build the native components as well?
323 if [ $__SkipCoreCLR == 1 ]; then
324 echo "Unable to generate nuget packages since native components were not built."
328 if [ $__SkipMSCorLib == 1 ]; then
329 # Restore buildTools, since we skipped doing so with the mscorlib build.
332 echo "Unable to generate Microsoft.NETCore.Runtime.CoreCLR nuget package since mscorlib was not built."
335 echo "Generating nuget packages for "$__BuildOS
338 $__ProjectRoot/Tools/corerun "$__MSBuildPath" /nologo "$__ProjectRoot/src/.nuget/packages.builds" /verbosity:minimal "/fileloggerparameters:Verbosity=normal;LogFile=$__LogsDir/Nuget_$__BuildOS__$__BuildArch__$__BuildType.log" /t:Build /p:__BuildOS=$__BuildOS /p:__BuildArch=$__BuildArch /p:__BuildType=$__BuildType /p:__IntermediatesDir=$__IntermediatesDir /p:__RootBinDir=$__RootBinDir /p:BuildNugetPackage=false /p:UseSharedCompilation=false
340 if [ $? -ne 0 ]; then
341 echo "Failed to generate Nuget packages."
346 echo "Commencing CoreCLR Repo build"
348 # Argument types supported by this script:
350 # Build architecture - valid values are: x64, ARM.
351 # Build Type - valid values are: Debug, Checked, Release
353 # Set the default arguments for build
355 # Obtain the location of the bash script to figure out where the root of the repo is.
356 __ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
358 # Use uname to determine what the CPU is.
360 # Some Linux platforms report unknown for platform, but the arch for machine.
361 if [ "$CPUName" == "unknown" ]; then
367 echo "Unsupported CPU $CPUName detected, build might not succeed!"
378 echo "Unsupported CPU $CPUName detected, build might not succeed!"
384 echo "Unsupported CPU $CPUName detected, build might not succeed!"
390 echo "Unknown CPU $CPUName detected, configuring as if for x64"
396 # Use uname to determine what the OS is.
430 echo "Unsupported OS $OSName detected, configuring as if for Linux"
438 __IncludeTests=Include_Tests
440 # Set the various build properties here so that CMake and MSBuild can pick them up
441 __ProjectDir="$__ProjectRoot"
442 __SourceDir="$__ProjectDir/src"
443 __PackagesDir="$__ProjectDir/packages"
444 __RootBinDir="$__ProjectDir/bin"
445 __UnprocessedBuildArgs=
458 __ClangMajorVersion=0
459 __ClangMinorVersion=0
460 __MSBuildPath=$__ProjectRoot/Tools/MSBuild.exe
461 __NuGetPath="$__PackagesDir/NuGet.exe"
464 __OfficialBuildIdArg=
465 __SkipGenerateVersion=0
468 if [ $# -le 0 ]; then
472 lowerI="$(echo $1 | awk '{print tolower($0)}')"
492 __BuildArch=arm-softfp
512 __CodeCoverage=Coverage
528 __ClangMajorVersion=3
529 __ClangMinorVersion=5
533 __ClangMajorVersion=3
534 __ClangMinorVersion=6
538 __ClangMajorVersion=3
539 __ClangMinorVersion=7
543 __ClangMajorVersion=3
544 __ClangMinorVersion=8
563 # Use "skipnative" to use the same option name as build.cmd.
568 # Accept "skipcoreclr" for backwards-compatibility.
577 __SkipGenerateVersion=1
588 __SkipRestore="/p:RestoreDuringBuild=true"
596 __SignTypeReal="/p:SignType=real"
604 echo "ERROR: 'cmakeargs' requires a non-empty option argument"
612 if [ ! -d $__RootBinDir ]; then
615 __RootBinParent=$(dirname $__RootBinDir)
616 __RootBinName=${__RootBinDir##*/}
617 __RootBinDir="$(cd $__RootBinParent &>/dev/null && printf %s/%s $PWD $__RootBinName)"
620 echo "ERROR: 'bindir' requires a non-empty option argument"
626 if [[ $1 == "/p:OfficialBuildId="* ]]; then
627 __OfficialBuildIdArg=$1
629 __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1"
637 # Set default clang version
638 if [[ $__ClangMajorVersion == 0 && $__ClangMinorVersion == 0 ]]; then
639 if [ $__CrossBuild == 1 ]; then
640 __ClangMajorVersion=3
641 __ClangMinorVersion=6
643 __ClangMajorVersion=3
644 __ClangMinorVersion=5
648 # Set dependent variables
649 __LogsDir="$__RootBinDir/Logs"
651 if [[ $__ConfigureOnly == 1 && $__SkipConfigure == 1 ]]; then
652 echo "configureonly and skipconfigure are mutually exclusive!"
656 # init the distro name
659 # Set the remaining variables based upon the determined build configuration
660 __BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType"
661 __PackagesBinDir="$__BinDir/.nuget"
662 __ToolsDir="$__RootBinDir/tools"
663 __TestWorkingDir="$__RootBinDir/tests/$__BuildOS.$__BuildArch.$__BuildType"
664 export __IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType"
665 __TestIntermediatesDir="$__RootBinDir/tests/obj/$__BuildOS.$__BuildArch.$__BuildType"
666 __isMSBuildOnNETCoreSupported=0
668 # Init if MSBuild for .NET Core is supported for this platform
669 isMSBuildOnNETCoreSupported
671 # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set.
672 # This is needed by CLI to function.
673 if [ -z "$HOME" ]; then
674 if [ ! -d "$__ProjectDir/temp_home" ]; then
677 export HOME=$__ProjectDir/temp_home
678 echo "HOME not defined; setting it to $HOME"
681 # Specify path to be set for CMAKE_INSTALL_PREFIX.
682 # This is where all built CoreClr libraries will copied to.
683 export __CMakeBinDir="$__BinDir"
685 # Configure environment if we are doing a clean build.
686 if [ $__CleanBuild == 1 ]; then
690 # Configure environment if we are doing a verbose build
691 if [ $__VerboseBuild == 1 ]; then
695 # Configure environment if we are doing a cross compile.
696 if [ $__CrossBuild == 1 ]; then
697 export CROSSCOMPILE=1
698 if ! [[ -n "$ROOTFS_DIR" ]]; then
699 export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__BuildArch"
703 # Make the directories necessary for build if they don't exist
711 # Build the coreclr (native) components.
715 # Build System.Private.CoreLib.
719 # Generate nuget packages
720 if [ $__SkipNuget != 1 ]; then
721 generate_NugetPackages
727 echo "Repo successfully built."
728 echo "Product binaries are available at $__BinDir"