3 # resolve python-version to use
4 if [ "$PYTHON" == "" ] ; then
5 if which python >/dev/null 2>&1
8 elif which python2 >/dev/null 2>&1
11 elif which python2.7 >/dev/null 2>&1
15 echo "Unable to locate build-dependency python2.x!" 1>&2
20 # validate python-dependency
21 # useful in case of explicitly set option.
22 if ! which $PYTHON > /dev/null 2>&1
24 echo "Unable to locate build-dependency python2.x ($PYTHON)!" 1>&2
30 echo "Usage: $0 [BuildArch] [BuildType] [clean] [verbose] [coverage] [cross] [clangx.y] [ninja] [configureonly] [skipconfigure] [skipnative] [skipmscorlib] [skiptests] [cmakeargs] [bindir]"
31 echo "BuildArch can be: x64, x86, arm, arm-softfp, arm64"
32 echo "BuildType can be: debug, checked, release"
33 echo "clean - optional argument to force a clean build."
34 echo "verbose - optional argument to enable verbose build output."
35 echo "coverage - optional argument to enable code coverage build (currently supported only for Linux and OSX)."
36 echo "ninja - target ninja instead of GNU make"
37 echo "clangx.y - optional argument to build using clang version x.y."
38 echo "cross - optional argument to signify cross compilation,"
39 echo " - will use ROOTFS_DIR environment variable if set."
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 "skipmscorlib - do not build mscorlib.dll."
44 echo "skiptests - skip the tests in the 'tests' subdirectory."
45 echo "skiprestore - skip restoring nuget packages."
46 echo "skipnuget - skip building nuget packages."
47 echo "disableoss - Disable Open Source Signing for mscorlib."
48 echo "skipgenerateversion - disable version generation even if MSBuild is supported."
49 echo "cmakeargs - user-settable additional arguments passed to CMake."
50 echo "bindir - output directory (defaults to $__ProjectRoot/bin)"
57 if [ "$__BuildOS" == "Linux" ]; then
58 if [ ! -e /etc/os-release ]; then
59 echo "WARNING: Can not determine runtime id for current distro."
62 source /etc/os-release
63 export __DistroRid="$ID.$VERSION_ID-$__HostArch"
70 echo Setting up directories for build
72 mkdir -p "$__RootBinDir"
75 mkdir -p "$__IntermediatesDir"
78 # Performs "clean build" type actions (deleting and remaking directories)
82 echo Cleaning previous output for the selected configuration
84 rm -rf "$__IntermediatesDir"
86 rm -rf "$__TestWorkingDir"
87 rm -rf "$__TestIntermediatesDir"
89 rm -rf "$__LogsDir/*_$__BuildOS__$__BuildArch__$__BuildType.*"
90 rm -rf "$__ProjectRoot/Tools"
93 # Check the system to ensure the right prereqs are in place
97 echo "Checking prerequisites..."
99 # Check presence of CMake on the path
100 hash cmake 2>/dev/null || { echo >&2 "Please install cmake before running this script"; exit 1; }
103 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; }
110 if [ $__SkipCoreCLR == 1 ]; then
111 echo "Skipping CoreCLR build."
115 # Event Logging Infrastructure
116 __GeneratedIntermediate="$__IntermediatesDir/Generated"
117 __GeneratedIntermediateEventProvider="$__GeneratedIntermediate/eventprovider_new"
118 if [[ -d "$__GeneratedIntermediateEventProvider" ]]; then
119 rm -rf "$__GeneratedIntermediateEventProvider"
122 if [[ ! -d "$__GeneratedIntermediate/eventprovider" ]]; then
123 mkdir -p "$__GeneratedIntermediate/eventprovider"
126 mkdir -p "$__GeneratedIntermediateEventProvider"
127 if [[ $__SkipCoreCLR == 0 || $__ConfigureOnly == 1 ]]; then
128 echo "Laying out dynamically generated files consumed by the build system "
129 echo "Laying out dynamically generated Event Logging Test files"
130 $PYTHON -B -Wall -Werror "$__ProjectRoot/src/scripts/genXplatEventing.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --exc "$__ProjectRoot/src/vm/ClrEtwAllMeta.lst" --testdir "$__GeneratedIntermediateEventProvider/tests"
132 if [[ $? != 0 ]]; then
136 #determine the logging system
139 echo "Laying out dynamically generated Event Logging Implementation of Lttng"
140 $PYTHON -B -Wall -Werror "$__ProjectRoot/src/scripts/genXplatLttng.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__GeneratedIntermediateEventProvider"
141 if [[ $? != 0 ]]; then
150 echo "Cleaning the temp folder of dynamically generated Event Logging files"
151 $PYTHON -B -Wall -Werror -c "import sys;sys.path.insert(0,\"$__ProjectRoot/src/scripts\"); from Utilities import *;UpdateDirectory(\"$__GeneratedIntermediate/eventprovider\",\"$__GeneratedIntermediateEventProvider\")"
152 if [[ $? != 0 ]]; then
156 rm -rf "$__GeneratedIntermediateEventProvider"
158 # All set to commence the build
160 echo "Commencing build of native components for $__BuildOS.$__BuildArch.$__BuildType in $__IntermediatesDir"
162 cd "$__IntermediatesDir"
167 if [ $__UseNinja == 1 ]; then
169 buildFile="build.ninja"
173 if [ $__SkipConfigure == 0 ]; then
174 # if msbuild is not supported, then set __SkipGenerateVersion to 1
175 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then __SkipGenerateVersion=1; fi
176 # Drop version.c file
177 __versionSourceFile=$__IntermediatesDir/version.cpp
178 if [ $__SkipGenerateVersion == 0 ]; then
179 "$__ProjectRoot/init-tools.sh" > "$__ProjectRoot/init-tools.log"
180 echo "Running: \"$__ProjectRoot/Tools/dotnetcli/dotnet\" \"$__ProjectRoot/Tools/MSBuild.exe\" \"$__ProjectRoot/build.proj\" /v:minimal /t:GenerateVersionSourceFile /p:NativeVersionSourceFile=$__versionSourceFile /p:GenerateVersionSourceFile=true /v:minimal $__OfficialBuildIdArg"
181 "$__ProjectRoot/Tools/dotnetcli/dotnet" "$__ProjectRoot/Tools/MSBuild.exe" "$__ProjectRoot/build.proj" /v:minimal /t:GenerateVersionSourceFile /p:NativeVersionSourceFile=$__versionSourceFile /p:GenerateVersionSourceFile=true /v:minimal $__OfficialBuildIdArg
183 __versionSourceLine="static char sccsid[] __attribute__((used)) = \"@(#)No version information produced\";"
184 echo $__versionSourceLine > $__versionSourceFile
186 # Regenerate the CMake solution
187 echo "Invoking \"$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh\" \"$__ProjectRoot\" $__ClangMajorVersion $__ClangMinorVersion $__BuildArch $__BuildType $__CodeCoverage $__IncludeTests $generator $__cmakeargs"
188 "$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh" "$__ProjectRoot" $__ClangMajorVersion $__ClangMinorVersion $__BuildArch $__BuildType $__CodeCoverage $__IncludeTests $generator "$__cmakeargs"
191 # Check that the makefiles were created.
193 if [ ! -f "$__IntermediatesDir/$buildFile" ]; then
194 echo "Failed to generate native component build project!"
198 # Get the number of processors available to the scheduler
199 # Other techniques such as `nproc` only get the number of
200 # processors available to a single process.
201 if [ `uname` = "FreeBSD" ]; then
202 NumProc=`sysctl hw.ncpu | awk '{ print $2+1 }'`
203 elif [ `uname` = "NetBSD" ]; then
204 NumProc=$(($(getconf NPROCESSORS_ONLN)+1))
206 NumProc=$(($(getconf _NPROCESSORS_ONLN)+1))
211 echo "Executing $buildTool install -j $NumProc $__UnprocessedBuildArgs"
213 $buildTool install -j $NumProc $__UnprocessedBuildArgs
215 echo "Failed to build coreclr components."
222 echo "Restoring BuildTools..."
223 $__ProjectRoot/init-tools.sh
224 if [ $? -ne 0 ]; then
225 echo "Failed to restore BuildTools."
230 isMSBuildOnNETCoreSupported()
232 # This needs to be updated alongwith corresponding changes to netci.groovy.
233 __isMSBuildOnNETCoreSupported=0
235 if [ "$__HostArch" == "x64" ]; then
236 if [ "$__HostOS" == "Linux" ]; then
237 case "$__DistroRid" in
239 __isMSBuildOnNETCoreSupported=1
242 __isMSBuildOnNETCoreSupported=1
245 __isMSBuildOnNETCoreSupported=1
248 __isMSBuildOnNETCoreSupported=1
251 __isMSBuildOnNETCoreSupported=1
254 __isMSBuildOnNETCoreSupported=1
257 __isMSBuildOnNETCoreSupported=1
261 elif [ "$__HostOS" == "OSX" ]; then
262 __isMSBuildOnNETCoreSupported=1
269 if [ $__SkipCoreCLR == 0 -a -e $__BinDir/crossgen ]; then
270 echo "Generating native image for System.Private.CoreLib."
271 $__BinDir/crossgen $__BinDir/System.Private.CoreLib.dll
272 if [ $? -ne 0 ]; then
273 echo "Failed to generate native image for System.Private.CoreLib."
277 echo "Generating native image for MScorlib Facade."
278 $__BinDir/crossgen $__BinDir/mscorlib.dll
279 if [ $? -ne 0 ]; then
280 echo "Failed to generate native image for mscorlib facade."
284 if [ "$__BuildOS" == "Linux" ]; then
285 echo "Generating symbol file for System.Private.CoreLib."
286 $__BinDir/crossgen /CreatePerfMap $__BinDir $__BinDir/System.Private.CoreLib.ni.dll
287 if [ $? -ne 0 ]; then
288 echo "Failed to generate symbol file for System.Private.CoreLib."
298 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
299 echo "System.Private.CoreLib.dll build unsupported."
303 if [ $__SkipMSCorLib == 1 ]; then
304 echo "Skipping building System.Private.CoreLib."
312 echo "Commencing build of managed components for $__BuildOS.$__BuildArch.$__BuildType"
315 $__ProjectRoot/Tools/dotnetcli/dotnet "$__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}
317 if [ $? -ne 0 ]; then
318 echo "Failed to build managed components."
322 # The cross build generates a crossgen with the target architecture.
323 if [ $__CrossBuild != 1 ]; then
324 # The architecture of host pc must be same architecture with target.
325 if [[ ( "$__HostArch" == "$__BuildArch" ) ]]; then
327 elif [[ ( "$__HostArch" == "x64" ) && ( "$__BuildArch" == "x86" ) ]]; then
329 elif [[ ( "$__HostArch" == "arm64" ) && ( "$__BuildArch" == "arm" ) ]]; then
337 generate_NugetPackages()
339 # We can only generate nuget package if we also support building mscorlib as part of this build.
340 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
341 echo "Nuget package generation unsupported."
345 # Since we can build mscorlib for this OS, did we build the native components as well?
346 if [ $__SkipCoreCLR == 1 ]; then
347 echo "Unable to generate nuget packages since native components were not built."
351 if [ $__SkipMSCorLib == 1 ]; then
352 # Restore buildTools, since we skipped doing so with the mscorlib build.
355 echo "Unable to generate Microsoft.NETCore.Runtime.CoreCLR nuget package since mscorlib was not built."
358 echo "Generating nuget packages for "$__BuildOS
361 $__ProjectRoot/Tools/dotnetcli/dotnet "$__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
363 if [ $? -ne 0 ]; then
364 echo "Failed to generate Nuget packages."
369 echo "Commencing CoreCLR Repo build"
371 # Argument types supported by this script:
373 # Build architecture - valid values are: x64, ARM.
374 # Build Type - valid values are: Debug, Checked, Release
376 # Set the default arguments for build
378 # Obtain the location of the bash script to figure out where the root of the repo is.
379 __ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
381 # Use uname to determine what the CPU is.
383 # Some Linux platforms report unknown for platform, but the arch for machine.
384 if [ "$CPUName" == "unknown" ]; then
390 echo "Unsupported CPU $CPUName detected, build might not succeed!"
401 echo "Unsupported CPU $CPUName detected, build might not succeed!"
407 echo "Unsupported CPU $CPUName detected, build might not succeed!"
413 echo "Unknown CPU $CPUName detected, configuring as if for x64"
419 # Use uname to determine what the OS is.
453 echo "Unsupported OS $OSName detected, configuring as if for Linux"
461 __IncludeTests=Include_Tests
463 # Set the various build properties here so that CMake and MSBuild can pick them up
464 __ProjectDir="$__ProjectRoot"
465 __SourceDir="$__ProjectDir/src"
466 __PackagesDir="$__ProjectDir/packages"
467 __RootBinDir="$__ProjectDir/bin"
468 __UnprocessedBuildArgs=
481 __ClangMajorVersion=0
482 __ClangMinorVersion=0
483 __MSBuildPath=$__ProjectRoot/Tools/MSBuild.exe
484 __NuGetPath="$__PackagesDir/NuGet.exe"
487 __OfficialBuildIdArg=
488 __SkipGenerateVersion=0
491 if [ $# -le 0 ]; then
495 lowerI="$(echo $1 | awk '{print tolower($0)}')"
515 __BuildArch=arm-softfp
535 __CodeCoverage=Coverage
551 __ClangMajorVersion=3
552 __ClangMinorVersion=5
556 __ClangMajorVersion=3
557 __ClangMinorVersion=6
561 __ClangMajorVersion=3
562 __ClangMinorVersion=7
566 __ClangMajorVersion=3
567 __ClangMinorVersion=8
586 # Use "skipnative" to use the same option name as build.cmd.
591 # Accept "skipcoreclr" for backwards-compatibility.
600 __SkipGenerateVersion=1
611 __SkipRestore="/p:RestoreDuringBuild=true"
619 __SignTypeReal="/p:SignType=real"
627 echo "ERROR: 'cmakeargs' requires a non-empty option argument"
635 if [ ! -d $__RootBinDir ]; then
638 __RootBinParent=$(dirname $__RootBinDir)
639 __RootBinName=${__RootBinDir##*/}
640 __RootBinDir="$(cd $__RootBinParent &>/dev/null && printf %s/%s $PWD $__RootBinName)"
643 echo "ERROR: 'bindir' requires a non-empty option argument"
649 if [[ $1 == "/p:OfficialBuildId="* ]]; then
650 __OfficialBuildIdArg=$1
652 __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1"
660 # Set default clang version
661 if [[ $__ClangMajorVersion == 0 && $__ClangMinorVersion == 0 ]]; then
662 if [ $__CrossBuild == 1 ]; then
663 __ClangMajorVersion=3
664 __ClangMinorVersion=6
666 __ClangMajorVersion=3
667 __ClangMinorVersion=5
671 # Set dependent variables
672 __LogsDir="$__RootBinDir/Logs"
674 if [[ $__ConfigureOnly == 1 && $__SkipConfigure == 1 ]]; then
675 echo "configureonly and skipconfigure are mutually exclusive!"
679 # init the distro name
682 # Set the remaining variables based upon the determined build configuration
683 __BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType"
684 __PackagesBinDir="$__BinDir/.nuget"
685 __ToolsDir="$__RootBinDir/tools"
686 __TestWorkingDir="$__RootBinDir/tests/$__BuildOS.$__BuildArch.$__BuildType"
687 export __IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType"
688 __TestIntermediatesDir="$__RootBinDir/tests/obj/$__BuildOS.$__BuildArch.$__BuildType"
689 __isMSBuildOnNETCoreSupported=0
691 # Init if MSBuild for .NET Core is supported for this platform
692 isMSBuildOnNETCoreSupported
694 # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set.
695 # This is needed by CLI to function.
696 if [ -z "$HOME" ]; then
697 if [ ! -d "$__ProjectDir/temp_home" ]; then
700 export HOME=$__ProjectDir/temp_home
701 echo "HOME not defined; setting it to $HOME"
704 # Specify path to be set for CMAKE_INSTALL_PREFIX.
705 # This is where all built CoreClr libraries will copied to.
706 export __CMakeBinDir="$__BinDir"
708 # Configure environment if we are doing a clean build.
709 if [ $__CleanBuild == 1 ]; then
713 # Configure environment if we are doing a verbose build
714 if [ $__VerboseBuild == 1 ]; then
718 # Configure environment if we are doing a cross compile.
719 if [ $__CrossBuild == 1 ]; then
720 export CROSSCOMPILE=1
721 if ! [[ -n "$ROOTFS_DIR" ]]; then
722 export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__BuildArch"
726 # Make the directories necessary for build if they don't exist
734 # Build the coreclr (native) components.
738 # Build System.Private.CoreLib.
742 # Generate nuget packages
743 if [ $__SkipNuget != 1 ]; then
744 generate_NugetPackages
750 echo "Repo successfully built."
751 echo "Product binaries are available at $__BinDir"