3 # resolve python-version to use
4 if [ "$PYTHON" == "" ]; then
5 if hash python 2>/dev/null; then
7 elif hash python2 2>/dev/null; then
9 elif hash python2.7 2>/dev/null; then
12 echo "Unable to locate build-dependency python2.x!" 1>&2
17 # validate python-dependency
18 # useful in case of explicitly set option.
19 if ! hash $PYTHON 2>/dev/null; then
20 echo "Unable to locate build-dependency python2.x ($PYTHON)!" 1>&2
26 echo "Usage: $0 [BuildArch] [BuildType] [verbose] [coverage] [cross] [clangx.y] [ninja] [configureonly] [skipconfigure] [skipnative] [skipmscorlib] [skiptests] [cmakeargs] [bindir]"
27 echo "BuildArch can be: x64, x86, arm, arm-softfp, arm64"
28 echo "BuildType can be: debug, checked, release"
29 echo "coverage - optional argument to enable code coverage build (currently supported only for Linux and OSX)."
30 echo "ninja - target ninja instead of GNU make"
31 echo "clangx.y - optional argument to build using clang version x.y."
32 echo "cross - optional argument to signify cross compilation,"
33 echo " - will use ROOTFS_DIR environment variable if set."
34 echo "configureonly - do not perform any builds; just configure the build."
35 echo "skipconfigure - skip build configuration."
36 echo "skipnative - do not build native components."
37 echo "skipmscorlib - do not build mscorlib.dll."
38 echo "skiptests - skip the tests in the 'tests' subdirectory."
39 echo "skipnuget - skip building nuget packages."
40 echo "verbose - optional argument to enable verbose build output."
41 echo "-skiprestore: skip restoring packages ^(default: packages are restored during build^)."
42 echo "-disableoss: Disable Open Source Signing for System.Private.CoreLib."
43 echo "-sequential: force a non-parallel build ^(default is to build in parallel"
44 echo " using all processors^)."
45 echo "-officialbuildid=^<ID^>: specify the official build ID to be used by this build."
46 echo "-Rebuild: passes /t:rebuild to the build projects."
47 echo "skipgenerateversion - disable version generation even if MSBuild is supported."
48 echo "cmakeargs - user-settable additional arguments passed to CMake."
49 echo "bindir - output directory (defaults to $__ProjectRoot/bin)"
56 if [ "$__BuildOS" == "Linux" ]; then
57 if [ ! -e /etc/os-release ]; then
58 echo "WARNING: Can not determine runtime id for current distro."
61 source /etc/os-release
62 export __DistroRid="$ID.$VERSION_ID-$__HostArch"
69 echo Setting up directories for build
71 mkdir -p "$__RootBinDir"
74 mkdir -p "$__IntermediatesDir"
77 # Check the system to ensure the right prereqs are in place
81 echo "Checking prerequisites..."
83 # Check presence of CMake on the path
84 hash cmake 2>/dev/null || { echo >&2 "Please install cmake before running this script"; exit 1; }
87 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; }
94 if [ $__SkipCoreCLR == 1 ]; then
95 echo "Skipping CoreCLR build."
99 # Event Logging Infrastructure
100 __GeneratedIntermediate="$__IntermediatesDir/Generated"
101 __GeneratedIntermediateEventProvider="$__GeneratedIntermediate/eventprovider_new"
102 if [[ -d "$__GeneratedIntermediateEventProvider" ]]; then
103 rm -rf "$__GeneratedIntermediateEventProvider"
106 if [[ ! -d "$__GeneratedIntermediate/eventprovider" ]]; then
107 mkdir -p "$__GeneratedIntermediate/eventprovider"
110 mkdir -p "$__GeneratedIntermediateEventProvider"
111 if [[ $__SkipCoreCLR == 0 || $__ConfigureOnly == 1 ]]; then
112 echo "Laying out dynamically generated files consumed by the build system "
113 echo "Laying out dynamically generated Event Logging Test files"
114 $PYTHON -B -Wall -Werror "$__ProjectRoot/src/scripts/genXplatEventing.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --exc "$__ProjectRoot/src/vm/ClrEtwAllMeta.lst" --testdir "$__GeneratedIntermediateEventProvider/tests"
116 if [[ $? != 0 ]]; then
120 #determine the logging system
123 echo "Laying out dynamically generated Event Logging Implementation of Lttng"
124 $PYTHON -B -Wall -Werror "$__ProjectRoot/src/scripts/genXplatLttng.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__GeneratedIntermediateEventProvider"
125 if [[ $? != 0 ]]; then
134 echo "Cleaning the temp folder of dynamically generated Event Logging files"
135 $PYTHON -B -Wall -Werror -c "import sys;sys.path.insert(0,\"$__ProjectRoot/src/scripts\"); from Utilities import *;UpdateDirectory(\"$__GeneratedIntermediate/eventprovider\",\"$__GeneratedIntermediateEventProvider\")"
136 if [[ $? != 0 ]]; then
140 rm -rf "$__GeneratedIntermediateEventProvider"
142 # All set to commence the build
144 echo "Commencing build of native components for $__BuildOS.$__BuildArch.$__BuildType in $__IntermediatesDir"
149 if [ $__UseNinja == 1 ]; then
151 buildFile="build.ninja"
152 if hash ninja 2>/dev/null; then
154 elif hash ninja-build 2>/dev/null; then
155 buildTool="ninja-build"
157 echo "Unable to locate ninja!" 1>&2
162 if [ $__SkipConfigure == 0 ]; then
163 # if msbuild is not supported, then set __SkipGenerateVersion to 1
164 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then __SkipGenerateVersion=1; fi
165 # Drop version.c file
166 __versionSourceFile=$__IntermediatesDir/version.cpp
167 if [ $__SkipGenerateVersion == 0 ]; then
168 "$__ProjectRoot/run.sh" build -Project=$__ProjectDir/build.proj -generateHeaderUnix -NativeVersionSourceFile=$__versionSourceFile $__RunArgs $__UnprocessedBuildArgs
170 __versionSourceLine="static char sccsid[] __attribute__((used)) = \"@(#)No version information produced\";"
171 echo $__versionSourceLine > $__versionSourceFile
174 pushd "$__IntermediatesDir"
175 # Regenerate the CMake solution
176 echo "Invoking \"$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh\" \"$__ProjectRoot\" $__ClangMajorVersion $__ClangMinorVersion $__BuildArch $__BuildType $__CodeCoverage $__IncludeTests $generator $__cmakeargs"
177 "$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh" "$__ProjectRoot" $__ClangMajorVersion $__ClangMinorVersion $__BuildArch $__BuildType $__CodeCoverage $__IncludeTests $generator "$__cmakeargs"
181 # Check that the makefiles were created.
182 pushd "$__IntermediatesDir"
184 if [ ! -f "$__IntermediatesDir/$buildFile" ]; then
185 echo "Failed to generate native component build project!"
189 # Get the number of processors available to the scheduler
190 # Other techniques such as `nproc` only get the number of
191 # processors available to a single process.
192 if [ `uname` = "FreeBSD" ]; then
193 NumProc=`sysctl hw.ncpu | awk '{ print $2+1 }'`
194 elif [ `uname` = "NetBSD" ]; then
195 NumProc=$(($(getconf NPROCESSORS_ONLN)+1))
197 NumProc=$(($(getconf _NPROCESSORS_ONLN)+1))
202 if [ $__ConfigureOnly == 1 ]; then
203 echo "Skipping CoreCLR build."
207 echo "Executing $buildTool install -j $NumProc"
209 $buildTool install -j $NumProc
211 echo "Failed to build coreclr components."
217 isMSBuildOnNETCoreSupported()
219 # This needs to be updated alongwith corresponding changes to netci.groovy.
220 __isMSBuildOnNETCoreSupported=0
222 if [ "$__HostArch" == "x64" ]; then
223 if [ "$__HostOS" == "Linux" ]; then
224 case "$__DistroRid" in
226 __isMSBuildOnNETCoreSupported=1
229 __isMSBuildOnNETCoreSupported=1
232 __isMSBuildOnNETCoreSupported=1
235 __isMSBuildOnNETCoreSupported=1
238 __isMSBuildOnNETCoreSupported=1
241 __isMSBuildOnNETCoreSupported=1
244 __isMSBuildOnNETCoreSupported=1
247 __isMSBuildOnNETCoreSupported=1
250 __isMSBuildOnNETCoreSupported=1
254 elif [ "$__HostOS" == "OSX" ]; then
255 __isMSBuildOnNETCoreSupported=1
262 if [ $__SkipCoreCLR == 0 -a -e $__BinDir/crossgen ]; then
263 echo "Generating native image for System.Private.CoreLib."
264 $__BinDir/crossgen $__BinDir/System.Private.CoreLib.dll
265 if [ $? -ne 0 ]; then
266 echo "Failed to generate native image for System.Private.CoreLib."
270 echo "Generating native image for MScorlib Facade."
271 $__BinDir/crossgen $__BinDir/mscorlib.dll
272 if [ $? -ne 0 ]; then
273 echo "Failed to generate native image for mscorlib facade."
277 if [ "$__BuildOS" == "Linux" ]; then
278 echo "Generating symbol file for System.Private.CoreLib."
279 $__BinDir/crossgen /CreatePerfMap $__BinDir $__BinDir/System.Private.CoreLib.ni.dll
280 if [ $? -ne 0 ]; then
281 echo "Failed to generate symbol file for System.Private.CoreLib."
291 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
292 echo "System.Private.CoreLib.dll build unsupported."
296 if [ $__SkipMSCorLib == 1 ]; then
297 echo "Skipping building System.Private.CoreLib."
301 echo "Commencing build of managed components for $__BuildOS.$__BuildArch.$__BuildType"
304 $__ProjectRoot/run.sh build -Project=$__ProjectDir/build.proj -MsBuildLog="/flp:Verbosity=normal;LogFile=$__LogsDir/System.Private.CoreLib_$__BuildOS__$__BuildArch__$__BuildType.log" -BuildTarget -__IntermediatesDir=$__IntermediatesDir -__RootBinDir=$__RootBinDir -BuildNugetPackage=false -UseSharedCompilation=false $__RunArgs $__UnprocessedBuildArgs
306 if [ $? -ne 0 ]; then
307 echo "Failed to build managed components."
311 # The cross build generates a crossgen with the target architecture.
312 if [ $__CrossBuild != 1 ]; then
313 # The architecture of host pc must be same architecture with target.
314 if [[ ( "$__HostArch" == "$__BuildArch" ) ]]; then
316 elif [[ ( "$__HostArch" == "x64" ) && ( "$__BuildArch" == "x86" ) ]]; then
318 elif [[ ( "$__HostArch" == "arm64" ) && ( "$__BuildArch" == "arm" ) ]]; then
326 generate_NugetPackages()
328 # We can only generate nuget package if we also support building mscorlib as part of this build.
329 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
330 echo "Nuget package generation unsupported."
334 # Since we can build mscorlib for this OS, did we build the native components as well?
335 if [ $__SkipCoreCLR == 1 ]; then
336 echo "Unable to generate nuget packages since native components were not built."
340 echo "Generating nuget packages for "$__BuildOS
343 $__ProjectRoot/run.sh build -Project=$__SourceDir/.nuget/packages.builds -MsBuildLog="/flp:Verbosity=normal;LogFile=$__LogsDir/Nuget_$__BuildOS__$__BuildArch__$__BuildType.log" -BuildTarget -__IntermediatesDir=$__IntermediatesDir -__RootBinDir=$__RootBinDir -BuildNugetPackage=false -UseSharedCompilation=false $__RunArgs $__UnprocessedBuildArgs
345 if [ $? -ne 0 ]; then
346 echo "Failed to generate Nuget packages."
351 echo "Commencing CoreCLR Repo build"
353 # Argument types supported by this script:
355 # Build architecture - valid values are: x64, ARM.
356 # Build Type - valid values are: Debug, Checked, Release
358 # Set the default arguments for build
360 # Obtain the location of the bash script to figure out where the root of the repo is.
361 __ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
363 # Use uname to determine what the CPU is.
365 # Some Linux platforms report unknown for platform, but the arch for machine.
366 if [ "$CPUName" == "unknown" ]; then
372 echo "Unsupported CPU $CPUName detected, build might not succeed!"
383 echo "Unsupported CPU $CPUName detected, build might not succeed!"
389 echo "Unsupported CPU $CPUName detected, build might not succeed!"
395 echo "Unknown CPU $CPUName detected, configuring as if for x64"
401 # Use uname to determine what the OS is.
435 echo "Unsupported OS $OSName detected, configuring as if for Linux"
443 __IncludeTests=Include_Tests
445 # Set the various build properties here so that CMake and MSBuild can pick them up
446 __ProjectDir="$__ProjectRoot"
447 __SourceDir="$__ProjectDir/src"
448 __PackagesDir="$__ProjectDir/packages"
449 __RootBinDir="$__ProjectDir/bin"
450 __UnprocessedBuildArgs=
462 __ClangMajorVersion=0
463 __ClangMinorVersion=0
464 __NuGetPath="$__PackagesDir/NuGet.exe"
467 __SkipGenerateVersion=0
470 if [ $# -le 0 ]; then
474 lowerI="$(echo $1 | awk '{print tolower($0)}')"
494 __BuildArch=arm-softfp
514 __CodeCoverage=Coverage
526 __ClangMajorVersion=3
527 __ClangMinorVersion=5
531 __ClangMajorVersion=3
532 __ClangMinorVersion=6
536 __ClangMajorVersion=3
537 __ClangMinorVersion=7
541 __ClangMajorVersion=3
542 __ClangMinorVersion=8
546 __ClangMajorVersion=3
547 __ClangMinorVersion=9
566 # Use "skipnative" to use the same option name as build.cmd.
571 # Accept "skipcoreclr" for backwards-compatibility.
580 __SkipGenerateVersion=1
599 echo "ERROR: 'cmakeargs' requires a non-empty option argument"
607 if [ ! -d $__RootBinDir ]; then
610 __RootBinParent=$(dirname $__RootBinDir)
611 __RootBinName=${__RootBinDir##*/}
612 __RootBinDir="$(cd $__RootBinParent &>/dev/null && printf %s/%s $PWD $__RootBinName)"
615 echo "ERROR: 'bindir' requires a non-empty option argument"
621 __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1"
628 __RunArgs="-BuildArch=$__BuildArch -BuildType=$__BuildType -BuildOS=$__BuildOS"
630 # Configure environment if we are doing a verbose build
631 if [ $__VerboseBuild == 1 ]; then
633 __RunArgs="$__RunArgs -verbose"
636 # Set default clang version
637 if [[ $__ClangMajorVersion == 0 && $__ClangMinorVersion == 0 ]]; then
638 if [ $__CrossBuild == 1 ]; then
639 __ClangMajorVersion=3
640 __ClangMinorVersion=6
642 __ClangMajorVersion=3
643 __ClangMinorVersion=5
647 # Set dependent variables
648 __LogsDir="$__RootBinDir/Logs"
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 cross compile.
680 if [ $__CrossBuild == 1 ]; then
681 export CROSSCOMPILE=1
682 if ! [[ -n "$ROOTFS_DIR" ]]; then
683 export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__BuildArch"
687 # Make the directories necessary for build if they don't exist
695 # Build the coreclr (native) components.
699 # Build System.Private.CoreLib.
703 # Generate nuget packages
704 if [ $__SkipNuget != 1 ]; then
705 generate_NugetPackages
711 echo "Repo successfully built."
712 echo "Product binaries are available at $__BinDir"