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] [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 "coverage - optional argument to enable code coverage build (currently supported only for Linux and OSX)."
34 echo "ninja - target ninja instead of GNU make"
35 echo "clangx.y - optional argument to build using clang version x.y."
36 echo "cross - optional argument to signify cross compilation,"
37 echo " - will use ROOTFS_DIR environment variable if set."
38 echo "pgoinstrument - generate instrumented code for profile guided optimization enabled binaries."
39 echo "configureonly - do not perform any builds; just configure the build."
40 echo "skipconfigure - skip build configuration."
41 echo "skipnative - do not build native components."
42 echo "skipmscorlib - do not build mscorlib.dll."
43 echo "skiptests - skip the tests in the 'tests' subdirectory."
44 echo "skipnuget - skip building nuget packages."
45 echo "portableLinux - build for Portable Linux Distribution"
46 echo "verbose - optional argument to enable verbose build output."
47 echo "-skiprestore: skip restoring packages ^(default: packages are restored during build^)."
48 echo "-disableoss: Disable Open Source Signing for System.Private.CoreLib."
49 echo "-sequential: force a non-parallel build ^(default is to build in parallel"
50 echo " using all processors^)."
51 echo "-officialbuildid=^<ID^>: specify the official build ID to be used by this build."
52 echo "-Rebuild: passes /t:rebuild to the build projects."
53 echo "skipgenerateversion - disable version generation even if MSBuild is supported."
54 echo "cmakeargs - user-settable additional arguments passed to CMake."
55 echo "bindir - output directory (defaults to $__ProjectRoot/bin)"
62 if [ "$__HostOS" == "Linux" ]; then
63 if [ ! -e /etc/os-release ]; then
64 echo "WARNING: Can not determine runtime id for current distro."
67 source /etc/os-release
68 __HostDistroRid="$ID.$VERSION_ID-$__HostArch"
75 if [ $__CrossBuild == 1 ]; then
76 if [ "$__BuildOS" == "Linux" ]; then
77 if [ ! -e $ROOTFS_DIR/etc/os-release ]; then
78 echo "WARNING: Can not determine runtime id for current distro."
81 source $ROOTFS_DIR/etc/os-release
82 export __DistroRid="$ID.$VERSION_ID-$__BuildArch"
86 export __DistroRid="$__HostDistroRid"
89 # Portable builds target the base RID only for Linux based platforms
90 if [ $__PortableLinux == 1 ]; then
91 export __DistroRid="linux-$__BuildArch"
97 echo Setting up directories for build
99 mkdir -p "$__RootBinDir"
101 mkdir -p "$__LogsDir"
102 mkdir -p "$__IntermediatesDir"
104 if [ $__CrossBuild == 1 ]; then
105 mkdir -p "$__CrossComponentBinDir"
106 mkdir -p "$__CrossCompIntermediatesDir"
110 # Check the system to ensure the right prereqs are in place
114 echo "Checking prerequisites..."
116 # Check presence of CMake on the path
117 hash cmake 2>/dev/null || { echo >&2 "Please install cmake before running this script"; exit 1; }
120 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; }
125 generate_event_logging_sources()
127 if [ $__SkipCoreCLR == 1 ]; then
131 # Event Logging Infrastructure
132 __GeneratedIntermediate="$__IntermediatesDir/Generated"
133 __GeneratedIntermediateEventProvider="$__GeneratedIntermediate/eventprovider_new"
134 if [[ -d "$__GeneratedIntermediateEventProvider" ]]; then
135 rm -rf "$__GeneratedIntermediateEventProvider"
138 if [[ ! -d "$__GeneratedIntermediate/eventprovider" ]]; then
139 mkdir -p "$__GeneratedIntermediate/eventprovider"
142 mkdir -p "$__GeneratedIntermediateEventProvider"
143 if [[ $__SkipCoreCLR == 0 || $__ConfigureOnly == 1 ]]; then
144 echo "Laying out dynamically generated files consumed by the build system "
145 echo "Laying out dynamically generated Event Logging Test files"
146 $PYTHON -B -Wall -Werror "$__ProjectRoot/src/scripts/genXplatEventing.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --exc "$__ProjectRoot/src/vm/ClrEtwAllMeta.lst" --testdir "$__GeneratedIntermediateEventProvider/tests"
148 if [[ $? != 0 ]]; then
152 #determine the logging system
155 echo "Laying out dynamically generated Event Logging Implementation of Lttng"
156 $PYTHON -B -Wall -Werror "$__ProjectRoot/src/scripts/genXplatLttng.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__GeneratedIntermediateEventProvider"
157 if [[ $? != 0 ]]; then
166 echo "Cleaning the temp folder of dynamically generated Event Logging files"
167 $PYTHON -B -Wall -Werror -c "import sys;sys.path.insert(0,\"$__ProjectRoot/src/scripts\"); from Utilities import *;UpdateDirectory(\"$__GeneratedIntermediate/eventprovider\",\"$__GeneratedIntermediateEventProvider\")"
168 if [[ $? != 0 ]]; then
172 rm -rf "$__GeneratedIntermediateEventProvider"
179 intermediatesForBuild="$3"
180 extraCmakeArguments="$4"
183 if [ $skipCondition == 1 ]; then
184 echo "Skipping $message build."
188 # All set to commence the build
189 echo "Commencing build of $message for $__BuildOS.$__BuildArch.$__BuildType in $intermediatesForBuild"
194 if [ $__UseNinja == 1 ]; then
196 buildFile="build.ninja"
197 if which ninja >/dev/null 2>&1; then
199 elif which ninja-build >/dev/null 2>&1; then
200 buildTool="ninja-build"
202 echo "Unable to locate ninja!" 1>&2
207 if [ $__SkipConfigure == 0 ]; then
208 # if msbuild is not supported, then set __SkipGenerateVersion to 1
209 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then __SkipGenerateVersion=1; fi
210 # Drop version.cpp file
211 __versionSourceFile="$intermediatesForBuild/version.cpp"
212 if [ $__SkipGenerateVersion == 0 ]; then
214 "$__ProjectRoot/run.sh" build -Project=$__ProjectDir/build.proj -generateHeaderUnix -NativeVersionSourceFile=$__versionSourceFile $__RunArgs $__UnprocessedBuildArgs
216 # Generate the dummy version.cpp, but only if it didn't exist to make sure we don't trigger unnecessary rebuild
217 __versionSourceLine="static char sccsid[] __attribute__((used)) = \"@(#)No version information produced\";"
218 if [ -e $__versionSourceFile ]; then
219 read existingVersionSourceLine < $__versionSourceFile
221 if [ "$__versionSourceLine" != "$existingVersionSourceLine" ]; then
222 echo $__versionSourceLine > $__versionSourceFile
226 pushd "$intermediatesForBuild"
227 # Regenerate the CMake solution
228 echo "Invoking \"$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh\" \"$__ProjectRoot\" $__ClangMajorVersion $__ClangMinorVersion $platformArch $__BuildType $__CodeCoverage $__IncludeTests $generator $extraCmakeArguments $__cmakeargs"
229 "$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh" "$__ProjectRoot" $__ClangMajorVersion $__ClangMinorVersion $platformArch $__BuildType $__CodeCoverage $__IncludeTests $generator "$extraCmakeArguments" "$__cmakeargs"
233 if [ ! -f "$intermediatesForBuild/$buildFile" ]; then
234 echo "Failed to generate $message build project!"
238 # Get the number of processors available to the scheduler
239 # Other techniques such as `nproc` only get the number of
240 # processors available to a single process.
241 if [ `uname` = "FreeBSD" ]; then
242 NumProc=`sysctl hw.ncpu | awk '{ print $2+1 }'`
243 elif [ `uname` = "NetBSD" ]; then
244 NumProc=$(($(getconf NPROCESSORS_ONLN)+1))
246 NumProc=$(($(getconf _NPROCESSORS_ONLN)+1))
250 if [ $__ConfigureOnly == 1 ]; then
251 echo "Finish configuration & skipping $message build."
255 # Check that the makefiles were created.
256 pushd "$intermediatesForBuild"
258 echo "Executing $buildTool install -j $NumProc"
260 $buildTool install -j $NumProc
262 echo "Failed to build $message."
269 isMSBuildOnNETCoreSupported()
271 # This needs to be updated alongwith corresponding changes to netci.groovy.
272 __isMSBuildOnNETCoreSupported=0
274 if [ "$__HostArch" == "x64" ]; then
275 if [ "$__HostOS" == "Linux" ]; then
276 case "$__HostDistroRid" in
278 __isMSBuildOnNETCoreSupported=1
281 __isMSBuildOnNETCoreSupported=1
284 __isMSBuildOnNETCoreSupported=1
287 __isMSBuildOnNETCoreSupported=1
290 __isMSBuildOnNETCoreSupported=1
293 __isMSBuildOnNETCoreSupported=1
296 __isMSBuildOnNETCoreSupported=1
299 __isMSBuildOnNETCoreSupported=1
302 __isMSBuildOnNETCoreSupported=1
305 __isMSBuildOnNETCoreSupported=1
308 __isMSBuildOnNETCoreSupported=1
312 elif [ "$__HostOS" == "OSX" ]; then
313 __isMSBuildOnNETCoreSupported=1
320 if [ $__SkipCoreCLR == 0 -a -e $__BinDir/crossgen ]; then
321 echo "Generating native image for System.Private.CoreLib."
322 $__BinDir/crossgen $__BinDir/System.Private.CoreLib.dll
323 if [ $? -ne 0 ]; then
324 echo "Failed to generate native image for System.Private.CoreLib."
328 echo "Generating native image for MScorlib Facade."
329 $__BinDir/crossgen $__BinDir/mscorlib.dll
330 if [ $? -ne 0 ]; then
331 echo "Failed to generate native image for mscorlib facade."
335 if [ "$__BuildOS" == "Linux" ]; then
336 echo "Generating symbol file for System.Private.CoreLib."
337 $__BinDir/crossgen /CreatePerfMap $__BinDir $__BinDir/System.Private.CoreLib.ni.dll
338 if [ $? -ne 0 ]; then
339 echo "Failed to generate symbol file for System.Private.CoreLib."
349 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
350 echo "System.Private.CoreLib.dll build unsupported."
354 if [ $__SkipMSCorLib == 1 ]; then
355 echo "Skipping building System.Private.CoreLib."
359 echo "Commencing build of managed components for $__BuildOS.$__BuildArch.$__BuildType"
362 $__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
364 if [ $? -ne 0 ]; then
365 echo "Failed to build managed components."
369 # The cross build generates a crossgen with the target architecture.
370 if [ $__CrossBuild != 1 ]; then
371 # The architecture of host pc must be same architecture with target.
372 if [[ ( "$__HostArch" == "$__BuildArch" ) ]]; then
374 elif [[ ( "$__HostArch" == "x64" ) && ( "$__BuildArch" == "x86" ) ]]; then
376 elif [[ ( "$__HostArch" == "arm64" ) && ( "$__BuildArch" == "arm" ) ]]; then
384 generate_NugetPackages()
386 # We can only generate nuget package if we also support building mscorlib as part of this build.
387 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
388 echo "Nuget package generation unsupported."
392 # Since we can build mscorlib for this OS, did we build the native components as well?
393 if [ $__SkipCoreCLR == 1 ]; then
394 echo "Unable to generate nuget packages since native components were not built."
398 echo "Generating nuget packages for "$__BuildOS
401 $__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
403 if [ $? -ne 0 ]; then
404 echo "Failed to generate Nuget packages."
409 echo "Commencing CoreCLR Repo build"
411 # Argument types supported by this script:
413 # Build architecture - valid values are: x64, ARM.
414 # Build Type - valid values are: Debug, Checked, Release
416 # Set the default arguments for build
418 # Obtain the location of the bash script to figure out where the root of the repo is.
419 __ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
421 # Use uname to determine what the CPU is.
423 # Some Linux platforms report unknown for platform, but the arch for machine.
424 if [ "$CPUName" == "unknown" ]; then
430 echo "Unsupported CPU $CPUName detected, build might not succeed!"
441 echo "Unsupported CPU $CPUName detected, build might not succeed!"
447 echo "Unsupported CPU $CPUName detected, build might not succeed!"
453 echo "Unknown CPU $CPUName detected, configuring as if for x64"
459 # Use uname to determine what the OS is.
493 echo "Unsupported OS $OSName detected, configuring as if for Linux"
501 __IncludeTests=Include_Tests
503 # Set the various build properties here so that CMake and MSBuild can pick them up
504 __ProjectDir="$__ProjectRoot"
505 __SourceDir="$__ProjectDir/src"
506 __PackagesDir="$__ProjectDir/packages"
507 __RootBinDir="$__ProjectDir/bin"
508 __UnprocessedBuildArgs=
521 __ClangMajorVersion=0
522 __ClangMinorVersion=0
523 __NuGetPath="$__PackagesDir/NuGet.exe"
527 __SkipGenerateVersion=0
532 if [ $# -le 0 ]; then
536 lowerI="$(echo $1 | awk '{print tolower($0)}')"
556 __BuildArch=arm-softfp
576 __CodeCoverage=Coverage
584 if [ "$__BuildOS" == "Linux" ]; then
587 echo "ERROR: portableLinux not supported for non-Linux platforms."
597 __ClangMajorVersion=3
598 __ClangMinorVersion=5
602 __ClangMajorVersion=3
603 __ClangMinorVersion=6
607 __ClangMajorVersion=3
608 __ClangMinorVersion=7
612 __ClangMajorVersion=3
613 __ClangMinorVersion=8
617 __ClangMajorVersion=3
618 __ClangMinorVersion=9
640 # Use "skipnative" to use the same option name as build.cmd.
645 # Accept "skipcoreclr" for backwards-compatibility.
658 __SkipGenerateVersion=1
677 echo "ERROR: 'cmakeargs' requires a non-empty option argument"
685 if [ ! -d $__RootBinDir ]; then
688 __RootBinParent=$(dirname $__RootBinDir)
689 __RootBinName=${__RootBinDir##*/}
690 __RootBinDir="$(cd $__RootBinParent &>/dev/null && printf %s/%s $PWD $__RootBinName)"
693 echo "ERROR: 'bindir' requires a non-empty option argument"
699 __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1"
706 __RunArgs="-BuildArch=$__BuildArch -BuildType=$__BuildType -BuildOS=$__BuildOS"
708 # Configure environment if we are doing a verbose build
709 if [ $__VerboseBuild == 1 ]; then
711 __RunArgs="$__RunArgs -verbose"
714 # Set default clang version
715 if [[ $__ClangMajorVersion == 0 && $__ClangMinorVersion == 0 ]]; then
716 if [ $__CrossBuild == 1 ]; then
717 __ClangMajorVersion=3
718 __ClangMinorVersion=6
720 __ClangMajorVersion=3
721 __ClangMinorVersion=5
725 # Set dependent variables
726 __LogsDir="$__RootBinDir/Logs"
728 # init the host distro name
731 # Set the remaining variables based upon the determined build configuration
732 __BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType"
733 __PackagesBinDir="$__BinDir/.nuget"
734 __ToolsDir="$__RootBinDir/tools"
735 __TestWorkingDir="$__RootBinDir/tests/$__BuildOS.$__BuildArch.$__BuildType"
736 export __IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType"
737 __TestIntermediatesDir="$__RootBinDir/tests/obj/$__BuildOS.$__BuildArch.$__BuildType"
738 __isMSBuildOnNETCoreSupported=0
739 __CrossComponentBinDir="$__BinDir"
740 __CrossCompIntermediatesDir="$__IntermediatesDir/crossgen"
742 __CrossArch="$__HostArch"
743 if [[ "$__HostArch" == "x64" && "$__BuildArch" == "arm" ]]; then
746 if [ $__CrossBuild == 1 ]; then
747 __CrossComponentBinDir="$__CrossComponentBinDir/$__CrossArch"
749 __CrossgenCoreLibLog="$__LogsDir/CrossgenCoreLib_$__BuildOS.$BuildArch.$__BuildType.log"
750 __CrossgenExe="$__CrossComponentBinDir/crossgen"
752 # Init if MSBuild for .NET Core is supported for this platform
753 isMSBuildOnNETCoreSupported
755 # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set.
756 # This is needed by CLI to function.
757 if [ -z "$HOME" ]; then
758 if [ ! -d "$__ProjectDir/temp_home" ]; then
761 export HOME=$__ProjectDir/temp_home
762 echo "HOME not defined; setting it to $HOME"
765 # Specify path to be set for CMAKE_INSTALL_PREFIX.
766 # This is where all built CoreClr libraries will copied to.
767 export __CMakeBinDir="$__BinDir"
769 # Configure environment if we are doing a cross compile.
770 if [ $__CrossBuild == 1 ]; then
771 export CROSSCOMPILE=1
772 if ! [[ -n "$ROOTFS_DIR" ]]; then
773 export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__BuildArch"
777 # init the target distro name
780 # Make the directories necessary for build if they don't exist
786 # Generate event logging infrastructure sources
787 generate_event_logging_sources
789 # Build the coreclr (native) components.
790 __ExtraCmakeArgs="-DCLR_CMAKE_TARGET_OS=$__BuildOS -DCLR_CMAKE_PACKAGES_DIR=$__PackagesDir -DCLR_CMAKE_PGO_INSTRUMENT=$__PgoInstrument"
791 build_native $__SkipCoreCLR "$__BuildArch" "$__IntermediatesDir" "$__ExtraCmakeArgs" "CoreCLR component"
793 # Build cross-architecture components
794 if [ $__CrossBuild == 1 ]; then
795 __SkipCrossArchBuild=1
796 if [ $__DoCrossArchBuild == 1 ]; then
797 # build cross-architecture components for x86-host/arm-target
798 if [[ "$__BuildArch" == "arm" && "$__CrossArch" == "x86" ]]; then
799 __SkipCrossArchBuild=0
803 export __CMakeBinDir="$__CrossComponentBinDir"
804 export CROSSCOMPONENT=1
805 __ExtraCmakeArgs="-DCLR_CMAKE_TARGET_ARCH=$__BuildArch -DCLR_CMAKE_TARGET_OS=$__BuildOS -DCLR_CMAKE_PACKAGES_DIR=$__PackagesDir -DCLR_CMAKE_PGO_INSTRUMENT=$__PgoInstrument"
806 build_native $__SkipCrossArchBuild "$__CrossArch" "$__CrossCompIntermediatesDir" "$__ExtraCmakeArgs" "cross-architecture component"
809 # Build System.Private.CoreLib.
813 # Generate nuget packages
814 if [ $__SkipNuget != 1 ]; then
815 generate_NugetPackages
821 echo "Repo successfully built."
822 echo "Product binaries are available at $__BinDir"