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
36 if [ "$(cat /etc/*-release | grep -cim1 ubuntu)" -eq 1 ]; then
37 export __DistroName=ubuntu
38 elif [ "$(cat /etc/*-release | grep -cim1 centos)" -eq 1 ]; then
39 export __DistroName=rhel
40 elif [ "$(cat /etc/*-release | grep -cim1 rhel)" -eq 1 ]; then
41 export __DistroName=rhel
42 elif [ "$(cat /etc/*-release | grep -cim1 debian)" -eq 1 ]; then
43 export __DistroName=debian
45 export __DistroName=""
52 echo Setting up directories for build
54 mkdir -p "$__RootBinDir"
57 mkdir -p "$__IntermediatesDir"
60 # Performs "clean build" type actions (deleting and remaking directories)
64 echo Cleaning previous output for the selected configuration
66 rm -rf "$__IntermediatesDir"
68 rm -rf "$__TestWorkingDir"
69 rm -rf "$__TestIntermediatesDir"
71 rm -rf "$__LogsDir/*_$__BuildOS__$__BuildArch__$__BuildType.*"
72 rm -rf "$__ProjectRoot/Tools"
75 # Check the system to ensure the right prereqs are in place
79 echo "Checking prerequisites..."
81 # Check presence of CMake on the path
82 hash cmake 2>/dev/null || { echo >&2 "Please install cmake before running this script"; exit 1; }
85 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; }
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 if [ $__SkipCoreCLR == 1 ]; then
169 echo "Skipping CoreCLR build."
173 # Check that the makefiles were created.
175 if [ ! -f "$__IntermediatesDir/$buildFile" ]; then
176 echo "Failed to generate native component build project!"
180 # Get the number of processors available to the scheduler
181 # Other techniques such as `nproc` only get the number of
182 # processors available to a single process.
183 if [ `uname` = "FreeBSD" ]; then
184 NumProc=`sysctl hw.ncpu | awk '{ print $2+1 }'`
185 elif [ `uname` = "NetBSD" ]; then
186 NumProc=$(($(getconf NPROCESSORS_ONLN)+1))
188 NumProc=$(($(getconf _NPROCESSORS_ONLN)+1))
193 echo "Executing $buildTool install -j $NumProc $__UnprocessedBuildArgs"
195 $buildTool install -j $NumProc $__UnprocessedBuildArgs
197 echo "Failed to build coreclr components."
204 echo "Restoring BuildTools..."
205 $__ProjectRoot/init-tools.sh
206 if [ $? -ne 0 ]; then
207 echo "Failed to restore BuildTools."
212 isMSBuildOnNETCoreSupported()
214 # This needs to be updated alongwith corresponding changes to netci.groovy.
215 __isMSBuildOnNETCoreSupported=0
217 if [ "$__BuildArch" == "x64" ]; then
218 if [ "$__BuildOS" == "Linux" ]; then
219 if [ "$__DistroName" == "ubuntu" ]; then
220 __OSVersion=$(lsb_release -rs)
221 if [ "$__OSVersion" == "14.04" ]; then
222 __isMSBuildOnNETCoreSupported=1
223 elif [ "$(cat /etc/*-release | grep -cim1 14.04)" -eq 1 ]; then
224 # Linux Mint based on Ubuntu 14.04
225 __isMSBuildOnNETCoreSupported=1
227 elif [ "$__DistroName" == "rhel" ]; then
228 __isMSBuildOnNETCoreSupported=1
229 elif [ "$__DistroName" == "debian" ]; then
230 __isMSBuildOnNETCoreSupported=1
232 elif [ "$__BuildOS" == "OSX" ]; then
233 __isMSBuildOnNETCoreSupported=1
235 elif [ "$__BuildArch" == "arm" ] || [ "$__BuildArch" == "arm64" ] ; then
236 if [ "$__BuildOS" == "Linux" ]; then
237 if [ "$__DistroName" == "ubuntu" ]; then
238 __isMSBuildOnNETCoreSupported=1
247 if [ $__SkipCoreCLR == 0 -a -e $__BinDir/crossgen ]; then
248 echo "Generating native image for System.Private.CoreLib."
249 $__BinDir/crossgen $__BinDir/System.Private.CoreLib.dll
250 if [ $? -ne 0 ]; then
251 echo "Failed to generate native image for System.Private.CoreLib."
255 echo "Generating native image for MScorlib Facade."
256 $__BinDir/crossgen $__BinDir/mscorlib.dll
257 if [ $? -ne 0 ]; then
258 echo "Failed to generate native image for mscorlib facade."
267 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
268 echo "System.Private.CoreLib.dll build unsupported."
272 if [ $__SkipMSCorLib == 1 ]; then
273 echo "Skipping building System.Private.CoreLib."
281 echo "Commencing build of managed components for $__BuildOS.$__BuildArch.$__BuildType"
284 $__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}
286 if [ $? -ne 0 ]; then
287 echo "Failed to build managed components."
291 # The cross build generates a crossgen with the target architecture.
292 if [ $__CrossBuild != 1 ]; then
293 # The architecture of host pc must be same architecture with target.
294 if [[ ( "$__HostArch" == "$__BuildArch" ) ]]; then
296 elif [[ ( "$__HostArch" == "x64" ) && ( "$__BuildArch" == "x86" ) ]]; then
298 elif [[ ( "$__HostArch" == "arm64" ) && ( "$__BuildArch" == "arm" ) ]]; then
306 generate_NugetPackages()
308 # We can only generate nuget package if we also support building mscorlib as part of this build.
309 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
310 echo "Nuget package generation unsupported."
314 # Since we can build mscorlib for this OS, did we build the native components as well?
315 if [ $__SkipCoreCLR == 1 ]; then
316 echo "Unable to generate nuget packages since native components were not built."
320 echo "Generating nuget packages for "$__BuildOS
322 if [ $__SkipMSCorLib == 1 ]; then
323 # Restore buildTools, since we skipped doing so with the mscorlib build.
327 echo "Unable to generate Microsoft.NETCore.Runtime.CoreCLR nuget package since mscorlib was not built."
329 # Build the CoreCLR packages
330 $__ProjectRoot/Tools/corerun "$__MSBuildPath" /nologo "$__ProjectRoot/src/.nuget/Microsoft.NETCore.Runtime.CoreCLR/Microsoft.NETCore.Runtime.CoreCLR.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
332 if [ $? -ne 0 ]; then
333 echo "Failed to generate Nuget packages."
338 # Build the JIT packages
339 $__ProjectRoot/Tools/corerun "$__MSBuildPath" /nologo "$__ProjectRoot/src/.nuget/Microsoft.NETCore.Jit/Microsoft.NETCore.Jit.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:BuildNugetPackage=false /p:__RootBinDir=$__RootBinDir /p:UseSharedCompilation=false
341 if [ $? -ne 0 ]; then
342 echo "Failed to generate Nuget packages."
347 echo "Commencing CoreCLR Repo build"
349 # Argument types supported by this script:
351 # Build architecture - valid values are: x64, ARM.
352 # Build Type - valid values are: Debug, Checked, Release
354 # Set the default arguments for build
356 # Obtain the location of the bash script to figure out where the root of the repo is.
357 __ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
359 # Use uname to determine what the CPU is.
361 # Some Linux platforms report unknown for platform, but the arch for machine.
362 if [ $CPUName == "unknown" ]; then
368 echo "Unsupported CPU $CPUName detected, build might not succeed!"
379 echo "Unsupported CPU $CPUName detected, build might not succeed!"
385 echo "Unsupported CPU $CPUName detected, build might not succeed!"
391 echo "Unknown CPU $CPUName detected, configuring as if for x64"
397 # Use uname to determine what the OS is.
425 echo "Unsupported OS $OSName detected, configuring as if for Linux"
432 __IncludeTests=Include_Tests
434 # Set the various build properties here so that CMake and MSBuild can pick them up
435 __ProjectDir="$__ProjectRoot"
436 __SourceDir="$__ProjectDir/src"
437 __PackagesDir="$__ProjectDir/packages"
438 __RootBinDir="$__ProjectDir/bin"
439 __UnprocessedBuildArgs=
452 __ClangMajorVersion=0
453 __ClangMinorVersion=0
454 __MSBuildPath=$__ProjectRoot/Tools/MSBuild.exe
455 __NuGetPath="$__PackagesDir/NuGet.exe"
458 __OfficialBuildIdArg=
459 __SkipGenerateVersion=0
462 if [ $# -le 0 ]; then
466 lowerI="$(echo $1 | awk '{print tolower($0)}')"
486 __BuildArch=arm-softfp
506 __CodeCoverage=Coverage
522 __ClangMajorVersion=3
523 __ClangMinorVersion=5
527 __ClangMajorVersion=3
528 __ClangMinorVersion=6
532 __ClangMajorVersion=3
533 __ClangMinorVersion=7
537 __ClangMajorVersion=3
538 __ClangMinorVersion=8
557 # Use "skipnative" to use the same option name as build.cmd.
562 # Accept "skipcoreclr" for backwards-compatibility.
571 __SkipGenerateVersion=1
582 __SkipRestore="/p:RestoreDuringBuild=true"
590 __SignTypeReal="/p:SignType=real"
598 echo "ERROR: 'cmakeargs' requires a non-empty option argument"
606 if [ ! -d $__RootBinDir ]; then
609 __RootBinParent=$(dirname $__RootBinDir)
610 __RootBinName=${__RootBinDir##*/}
611 __RootBinDir="$(cd $__RootBinParent &>/dev/null && printf %s/%s $PWD $__RootBinName)"
614 echo "ERROR: 'bindir' requires a non-empty option argument"
620 if [[ $1 == "/p:OfficialBuildId="* ]]; then
621 __OfficialBuildIdArg=$1
623 __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1"
631 # Set default clang version
632 if [[ $__ClangMajorVersion == 0 && $__ClangMinorVersion == 0 ]]; then
633 if [ $__CrossBuild == 1 ]; then
634 __ClangMajorVersion=3
635 __ClangMinorVersion=6
637 __ClangMajorVersion=3
638 __ClangMinorVersion=5
642 # Set dependent variables
643 __LogsDir="$__RootBinDir/Logs"
645 if [[ $__ConfigureOnly == 1 && $__SkipConfigure == 1 ]]; then
646 echo "configureonly and skipconfigure are mutually exclusive!"
650 # init the distro name
653 # Set the remaining variables based upon the determined build configuration
654 __BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType"
655 __PackagesBinDir="$__BinDir/.nuget"
656 __ToolsDir="$__RootBinDir/tools"
657 __TestWorkingDir="$__RootBinDir/tests/$__BuildOS.$__BuildArch.$__BuildType"
658 export __IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType"
659 __TestIntermediatesDir="$__RootBinDir/tests/obj/$__BuildOS.$__BuildArch.$__BuildType"
660 __isMSBuildOnNETCoreSupported=0
662 # Init if MSBuild for .NET Core is supported for this platform
663 isMSBuildOnNETCoreSupported
665 # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set.
666 # This is needed by CLI to function.
667 if [ -z "$HOME" ]; then
668 if [ ! -d "$__ProjectDir/temp_home" ]; then
671 export HOME=$__ProjectDir/temp_home
672 echo "HOME not defined; setting it to $HOME"
675 # Specify path to be set for CMAKE_INSTALL_PREFIX.
676 # This is where all built CoreClr libraries will copied to.
677 export __CMakeBinDir="$__BinDir"
679 # Configure environment if we are doing a clean build.
680 if [ $__CleanBuild == 1 ]; then
684 # Configure environment if we are doing a verbose build
685 if [ $__VerboseBuild == 1 ]; then
689 # Configure environment if we are doing a cross compile.
690 if [ $__CrossBuild == 1 ]; then
691 export CROSSCOMPILE=1
692 if ! [[ -n "$ROOTFS_DIR" ]]; then
693 export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__BuildArch"
697 # Make the directories necessary for build if they don't exist
705 # Build the coreclr (native) components.
709 # Build System.Private.CoreLib.
713 # Generate nuget packages
714 if [ $__SkipNuget != 1 ]; then
715 generate_NugetPackages
721 echo "Repo successfully built."
722 echo "Product binaries are available at $__BinDir"