3 # resolve python-version to use
4 if [ "$PYTHON" == "" ] ; then
5 if ! PYTHON=$(command -v python || command -v python2 || command -v python 2.7)
7 echo "Unable to locate build-dependency python2.x!" 1>&2
12 # validate python-dependency
13 # useful in case of explicitly set option.
14 if ! command -v $PYTHON > /dev/null
16 echo "Unable to locate build-dependency python2.x ($PYTHON)!" 1>&2
22 echo "Usage: $0 [BuildArch] [BuildType] [verbose] [coverage] [cross] [clangx.y] [ninja] [configureonly] [skipconfigure] [skipnative] [skipmscorlib] [skiptests] [cmakeargs] [bindir]"
23 echo "BuildArch can be: x64, x86, arm, armel, arm64"
24 echo "BuildType can be: debug, checked, release"
25 echo "coverage - optional argument to enable code coverage build (currently supported only for Linux and OSX)."
26 echo "ninja - target ninja instead of GNU make"
27 echo "clangx.y - optional argument to build using clang version x.y."
28 echo "cross - optional argument to signify cross compilation,"
29 echo " - will use ROOTFS_DIR environment variable if set."
30 echo "crosscomponent - optional argument to build cross-architecture component,"
31 echo " - will use CAC_ROOTFS_DIR environment variable if set."
32 echo "pgoinstrument - generate instrumented code for profile guided optimization enabled binaries."
33 echo "configureonly - do not perform any builds; just configure the build."
34 echo "skipconfigure - skip build configuration."
35 echo "skipnative - do not build native components."
36 echo "skipmscorlib - do not build mscorlib.dll."
37 echo "skiptests - skip the tests in the 'tests' subdirectory."
38 echo "skipnuget - skip building nuget packages."
39 echo "portableLinux - build for Portable Linux Distribution"
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 [ "$__HostOS" == "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 __HostDistroRid="$ID.$VERSION_ID-$__HostArch"
69 if [ $__CrossBuild == 1 ]; then
70 if [ "$__BuildOS" == "Linux" ]; then
71 if [ ! -e $ROOTFS_DIR/etc/os-release ]; then
72 echo "WARNING: Can not determine runtime id for current distro."
75 source $ROOTFS_DIR/etc/os-release
76 export __DistroRid="$ID.$VERSION_ID-$__BuildArch"
80 export __DistroRid="$__HostDistroRid"
83 # Portable builds target the base RID only for Linux based platforms
84 if [ $__PortableLinux == 1 ]; then
85 export __DistroRid="linux-$__BuildArch"
91 echo Setting up directories for build
93 mkdir -p "$__RootBinDir"
96 mkdir -p "$__IntermediatesDir"
98 if [ $__CrossBuild == 1 ]; then
99 mkdir -p "$__CrossComponentBinDir"
100 mkdir -p "$__CrossCompIntermediatesDir"
104 # Check the system to ensure the right prereqs are in place
108 echo "Checking prerequisites..."
110 # Check presence of CMake on the path
111 hash cmake 2>/dev/null || { echo >&2 "Please install cmake before running this script"; exit 1; }
114 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; }
119 generate_event_logging_sources()
121 if [ $__SkipCoreCLR == 1 ]; then
125 # Event Logging Infrastructure
126 __GeneratedIntermediate="$__IntermediatesDir/Generated"
127 __GeneratedIntermediateEventProvider="$__GeneratedIntermediate/eventprovider_new"
128 if [[ -d "$__GeneratedIntermediateEventProvider" ]]; then
129 rm -rf "$__GeneratedIntermediateEventProvider"
132 if [[ ! -d "$__GeneratedIntermediate/eventprovider" ]]; then
133 mkdir -p "$__GeneratedIntermediate/eventprovider"
136 mkdir -p "$__GeneratedIntermediateEventProvider"
137 if [[ $__SkipCoreCLR == 0 || $__ConfigureOnly == 1 ]]; then
138 echo "Laying out dynamically generated files consumed by the build system "
139 echo "Laying out dynamically generated Event Logging Test files"
140 $PYTHON -B -Wall -Werror "$__ProjectRoot/src/scripts/genXplatEventing.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --exc "$__ProjectRoot/src/vm/ClrEtwAllMeta.lst" --testdir "$__GeneratedIntermediateEventProvider/tests"
142 if [[ $? != 0 ]]; then
146 #determine the logging system
149 echo "Laying out dynamically generated Event Logging Implementation of Lttng"
150 $PYTHON -B -Wall -Werror "$__ProjectRoot/src/scripts/genXplatLttng.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__GeneratedIntermediateEventProvider"
151 if [[ $? != 0 ]]; then
160 echo "Cleaning the temp folder of dynamically generated Event Logging files"
161 $PYTHON -B -Wall -Werror -c "import sys;sys.path.insert(0,\"$__ProjectRoot/src/scripts\"); from Utilities import *;UpdateDirectory(\"$__GeneratedIntermediate/eventprovider\",\"$__GeneratedIntermediateEventProvider\")"
162 if [[ $? != 0 ]]; then
166 rm -rf "$__GeneratedIntermediateEventProvider"
173 intermediatesForBuild="$3"
174 extraCmakeArguments="$4"
177 if [ $skipCondition == 1 ]; then
178 echo "Skipping $message build."
182 # All set to commence the build
183 echo "Commencing build of $message for $__BuildOS.$__BuildArch.$__BuildType in $intermediatesForBuild"
188 if [ $__UseNinja == 1 ]; then
190 buildFile="build.ninja"
191 if ! buildTool=$(command -v ninja || command -v ninja-build); then
192 echo "Unable to locate ninja!" 1>&2
197 if [ $__SkipConfigure == 0 ]; then
198 # if msbuild is not supported, then set __SkipGenerateVersion to 1
199 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then __SkipGenerateVersion=1; fi
200 # Drop version.cpp file
201 __versionSourceFile="$intermediatesForBuild/version.cpp"
202 if [ $__SkipGenerateVersion == 0 ]; then
204 "$__ProjectRoot/run.sh" build -Project=$__ProjectDir/build.proj -generateHeaderUnix -NativeVersionSourceFile=$__versionSourceFile $__RunArgs $__UnprocessedBuildArgs
206 # Generate the dummy version.cpp, but only if it didn't exist to make sure we don't trigger unnecessary rebuild
207 __versionSourceLine="static char sccsid[] __attribute__((used)) = \"@(#)No version information produced\";"
208 if [ -e $__versionSourceFile ]; then
209 read existingVersionSourceLine < $__versionSourceFile
211 if [ "$__versionSourceLine" != "$existingVersionSourceLine" ]; then
212 echo $__versionSourceLine > $__versionSourceFile
216 pushd "$intermediatesForBuild"
217 # Regenerate the CMake solution
218 echo "Invoking \"$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh\" \"$__ProjectRoot\" $__ClangMajorVersion $__ClangMinorVersion $platformArch $__BuildType $__CodeCoverage $__IncludeTests $generator $extraCmakeArguments $__cmakeargs"
219 "$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh" "$__ProjectRoot" $__ClangMajorVersion $__ClangMinorVersion $platformArch $__BuildType $__CodeCoverage $__IncludeTests $generator "$extraCmakeArguments" "$__cmakeargs"
223 if [ ! -f "$intermediatesForBuild/$buildFile" ]; then
224 echo "Failed to generate $message build project!"
228 # Get the number of processors available to the scheduler
229 # Other techniques such as `nproc` only get the number of
230 # processors available to a single process.
231 if [ `uname` = "FreeBSD" ]; then
232 NumProc=`sysctl hw.ncpu | awk '{ print $2+1 }'`
233 elif [ `uname` = "NetBSD" ]; then
234 NumProc=$(($(getconf NPROCESSORS_ONLN)+1))
236 NumProc=$(($(getconf _NPROCESSORS_ONLN)+1))
240 if [ $__ConfigureOnly == 1 ]; then
241 echo "Finish configuration & skipping $message build."
245 # Check that the makefiles were created.
246 pushd "$intermediatesForBuild"
248 echo "Executing $buildTool install -j $NumProc"
250 $buildTool install -j $NumProc
252 echo "Failed to build $message."
259 build_cross_arch_component()
261 __SkipCrossArchBuild=1
263 # check supported cross-architecture components host(__HostArch)/target(__BuildArch) pair
264 if [[ "$__BuildArch" == "arm" && "$__CrossArch" == "x86" ]]; then
265 export CROSSCOMPILE=0
266 __SkipCrossArchBuild=0
268 # building x64-host/arm-target cross-architecture component need to use cross toolchain of x86
269 if [ "$__HostArch" == "x64" ]; then
270 export CROSSCOMPILE=1
277 export __CMakeBinDir="$__CrossComponentBinDir"
278 export CROSSCOMPONENT=1
279 if [ $CROSSCOMPILE == 1 ]; then
280 TARGET_ROOTFS="$ROOTFS_DIR"
281 if [ -n "$CAC_ROOTFS_DIR" ]; then
282 export ROOTFS_DIR="$CAC_ROOTFS_DIR"
284 export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__CrossArch"
288 __ExtraCmakeArgs="-DCLR_CMAKE_TARGET_ARCH=$__BuildArch -DCLR_CMAKE_TARGET_OS=$__BuildOS -DCLR_CMAKE_PACKAGES_DIR=$__PackagesDir -DCLR_CMAKE_PGO_INSTRUMENT=$__PgoInstrument"
289 build_native $__SkipCrossArchBuild "$__CrossArch" "$__CrossCompIntermediatesDir" "$__ExtraCmakeArgs" "cross-architecture component"
291 # restore ROOTFS_DIR, CROSSCOMPONENT, and CROSSCOMPILE
292 if [ -n "$TARGET_ROOTFS" ]; then
293 export ROOTFS_DIR="$TARGET_ROOTFS"
295 export CROSSCOMPONENT=
296 export CROSSCOMPILE=1
299 isMSBuildOnNETCoreSupported()
301 # This needs to be updated alongwith corresponding changes to netci.groovy.
302 __isMSBuildOnNETCoreSupported=0
304 if [ "$__HostArch" == "x64" ]; then
305 if [ "$__HostOS" == "Linux" ]; then
306 case "$__HostDistroRid" in
308 __isMSBuildOnNETCoreSupported=1
311 __isMSBuildOnNETCoreSupported=1
314 __isMSBuildOnNETCoreSupported=1
317 __isMSBuildOnNETCoreSupported=1
320 __isMSBuildOnNETCoreSupported=1
323 __isMSBuildOnNETCoreSupported=1
326 __isMSBuildOnNETCoreSupported=1
329 __isMSBuildOnNETCoreSupported=1
332 __isMSBuildOnNETCoreSupported=1
335 __isMSBuildOnNETCoreSupported=1
338 __isMSBuildOnNETCoreSupported=1
342 elif [ "$__HostOS" == "OSX" ]; then
343 __isMSBuildOnNETCoreSupported=1
350 if [ $__SkipCoreCLR == 0 -a -e $__BinDir/crossgen ]; then
351 echo "Generating native image for System.Private.CoreLib."
352 $__BinDir/crossgen $__BinDir/System.Private.CoreLib.dll
353 if [ $? -ne 0 ]; then
354 echo "Failed to generate native image for System.Private.CoreLib."
358 echo "Generating native image for MScorlib Facade."
359 $__BinDir/crossgen $__BinDir/mscorlib.dll
360 if [ $? -ne 0 ]; then
361 echo "Failed to generate native image for mscorlib facade."
365 if [ "$__BuildOS" == "Linux" ]; then
366 echo "Generating symbol file for System.Private.CoreLib."
367 $__BinDir/crossgen /CreatePerfMap $__BinDir $__BinDir/System.Private.CoreLib.ni.dll
368 if [ $? -ne 0 ]; then
369 echo "Failed to generate symbol file for System.Private.CoreLib."
379 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
380 echo "System.Private.CoreLib.dll build unsupported."
384 if [ $__SkipMSCorLib == 1 ]; then
385 echo "Skipping building System.Private.CoreLib."
389 echo "Commencing build of managed components for $__BuildOS.$__BuildArch.$__BuildType"
392 $__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
394 if [ $? -ne 0 ]; then
395 echo "Failed to build managed components."
399 # The cross build generates a crossgen with the target architecture.
400 if [ $__CrossBuild != 1 ]; then
401 # The architecture of host pc must be same architecture with target.
402 if [[ ( "$__HostArch" == "$__BuildArch" ) ]]; then
404 elif [[ ( "$__HostArch" == "x64" ) && ( "$__BuildArch" == "x86" ) ]]; then
406 elif [[ ( "$__HostArch" == "arm64" ) && ( "$__BuildArch" == "arm" ) ]]; then
414 generate_NugetPackages()
416 # We can only generate nuget package if we also support building mscorlib as part of this build.
417 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
418 echo "Nuget package generation unsupported."
422 # Since we can build mscorlib for this OS, did we build the native components as well?
423 if [ $__SkipCoreCLR == 1 ]; then
424 echo "Unable to generate nuget packages since native components were not built."
428 echo "Generating nuget packages for "$__BuildOS
431 $__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
433 if [ $? -ne 0 ]; then
434 echo "Failed to generate Nuget packages."
439 echo "Commencing CoreCLR Repo build"
441 # Argument types supported by this script:
443 # Build architecture - valid values are: x64, ARM.
444 # Build Type - valid values are: Debug, Checked, Release
446 # Set the default arguments for build
448 # Obtain the location of the bash script to figure out where the root of the repo is.
449 __ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
451 # Use uname to determine what the CPU is.
453 # Some Linux platforms report unknown for platform, but the arch for machine.
454 if [ "$CPUName" == "unknown" ]; then
460 echo "Unsupported CPU $CPUName detected, build might not succeed!"
471 echo "Unsupported CPU $CPUName detected, build might not succeed!"
477 echo "Unsupported CPU $CPUName detected, build might not succeed!"
483 echo "Unknown CPU $CPUName detected, configuring as if for x64"
489 # Use uname to determine what the OS is.
523 echo "Unsupported OS $OSName detected, configuring as if for Linux"
531 __IncludeTests=Include_Tests
533 # Set the various build properties here so that CMake and MSBuild can pick them up
534 __ProjectDir="$__ProjectRoot"
535 __SourceDir="$__ProjectDir/src"
536 __PackagesDir="$__ProjectDir/packages"
537 __RootBinDir="$__ProjectDir/bin"
538 __UnprocessedBuildArgs=
551 __ClangMajorVersion=0
552 __ClangMinorVersion=0
553 __NuGetPath="$__PackagesDir/NuGet.exe"
557 __SkipGenerateVersion=0
562 if [ $# -le 0 ]; then
566 lowerI="$(echo $1 | awk '{print tolower($0)}')"
606 __CodeCoverage=Coverage
614 if [ "$__BuildOS" == "Linux" ]; then
617 echo "ERROR: portableLinux not supported for non-Linux platforms."
627 __ClangMajorVersion=3
628 __ClangMinorVersion=5
632 __ClangMajorVersion=3
633 __ClangMinorVersion=6
637 __ClangMajorVersion=3
638 __ClangMinorVersion=7
642 __ClangMajorVersion=3
643 __ClangMinorVersion=8
647 __ClangMajorVersion=3
648 __ClangMinorVersion=9
670 # Use "skipnative" to use the same option name as build.cmd.
675 # Accept "skipcoreclr" for backwards-compatibility.
688 __SkipGenerateVersion=1
707 echo "ERROR: 'cmakeargs' requires a non-empty option argument"
715 if [ ! -d $__RootBinDir ]; then
718 __RootBinParent=$(dirname $__RootBinDir)
719 __RootBinName=${__RootBinDir##*/}
720 __RootBinDir="$(cd $__RootBinParent &>/dev/null && printf %s/%s $PWD $__RootBinName)"
723 echo "ERROR: 'bindir' requires a non-empty option argument"
729 __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1"
736 __RunArgs="-BuildArch=$__BuildArch -BuildType=$__BuildType -BuildOS=$__BuildOS"
738 # Configure environment if we are doing a verbose build
739 if [ $__VerboseBuild == 1 ]; then
741 __RunArgs="$__RunArgs -verbose"
744 # Set default clang version
745 if [[ $__ClangMajorVersion == 0 && $__ClangMinorVersion == 0 ]]; then
746 if [ $__CrossBuild == 1 ]; then
747 __ClangMajorVersion=3
748 __ClangMinorVersion=6
750 __ClangMajorVersion=3
751 __ClangMinorVersion=5
755 # Set dependent variables
756 __LogsDir="$__RootBinDir/Logs"
758 # init the host distro name
761 # Set the remaining variables based upon the determined build configuration
762 __BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType"
763 __PackagesBinDir="$__BinDir/.nuget"
764 __ToolsDir="$__RootBinDir/tools"
765 __TestWorkingDir="$__RootBinDir/tests/$__BuildOS.$__BuildArch.$__BuildType"
766 export __IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType"
767 __TestIntermediatesDir="$__RootBinDir/tests/obj/$__BuildOS.$__BuildArch.$__BuildType"
768 __isMSBuildOnNETCoreSupported=0
769 __CrossComponentBinDir="$__BinDir"
770 __CrossCompIntermediatesDir="$__IntermediatesDir/crossgen"
772 __CrossArch="$__HostArch"
773 if [[ "$__HostArch" == "x64" && "$__BuildArch" == "arm" ]]; then
776 if [ $__CrossBuild == 1 ]; then
777 __CrossComponentBinDir="$__CrossComponentBinDir/$__CrossArch"
779 __CrossgenCoreLibLog="$__LogsDir/CrossgenCoreLib_$__BuildOS.$BuildArch.$__BuildType.log"
780 __CrossgenExe="$__CrossComponentBinDir/crossgen"
782 # Init if MSBuild for .NET Core is supported for this platform
783 isMSBuildOnNETCoreSupported
785 # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set.
786 # This is needed by CLI to function.
787 if [ -z "$HOME" ]; then
788 if [ ! -d "$__ProjectDir/temp_home" ]; then
791 export HOME=$__ProjectDir/temp_home
792 echo "HOME not defined; setting it to $HOME"
795 # Specify path to be set for CMAKE_INSTALL_PREFIX.
796 # This is where all built CoreClr libraries will copied to.
797 export __CMakeBinDir="$__BinDir"
799 # Configure environment if we are doing a cross compile.
800 if [ $__CrossBuild == 1 ]; then
801 export CROSSCOMPILE=1
802 if ! [[ -n "$ROOTFS_DIR" ]]; then
803 export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__BuildArch"
807 # init the target distro name
810 # Make the directories necessary for build if they don't exist
816 # Generate event logging infrastructure sources
817 generate_event_logging_sources
819 # Build the coreclr (native) components.
820 __ExtraCmakeArgs="-DCLR_CMAKE_TARGET_OS=$__BuildOS -DCLR_CMAKE_PACKAGES_DIR=$__PackagesDir -DCLR_CMAKE_PGO_INSTRUMENT=$__PgoInstrument"
821 build_native $__SkipCoreCLR "$__BuildArch" "$__IntermediatesDir" "$__ExtraCmakeArgs" "CoreCLR component"
823 # Build cross-architecture components
824 if [[ $__CrossBuild == 1 && $__DoCrossArchBuild == 1 ]]; then
825 build_cross_arch_component
828 # Build System.Private.CoreLib.
832 # Generate nuget packages
833 if [ $__SkipNuget != 1 ]; then
834 generate_NugetPackages
840 echo "Repo successfully built."
841 echo "Product binaries are available at $__BinDir"