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)"
50 echo "buildstandalonegc - builds the GC in a standalone mode. Can't be used with \"cmakeargs\"."
51 echo "msbuildonunsupportedplatform - build managed binaries even if distro is not officially supported."
57 if [ "$__HostOS" == "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 __HostDistroRid="$ID.$VERSION_ID-$__HostArch"
70 if [ $__CrossBuild == 1 ]; then
71 if [ "$__BuildOS" == "Linux" ]; then
72 if [ ! -e $ROOTFS_DIR/etc/os-release ]; then
73 echo "WARNING: Can not determine runtime id for current distro."
76 source $ROOTFS_DIR/etc/os-release
77 export __DistroRid="$ID.$VERSION_ID-$__BuildArch"
81 export __DistroRid="$__HostDistroRid"
84 # Portable builds target the base RID only for Linux based platforms
85 if [ $__PortableLinux == 1 ]; then
86 export __DistroRid="linux-$__BuildArch"
92 echo Setting up directories for build
94 mkdir -p "$__RootBinDir"
97 mkdir -p "$__IntermediatesDir"
99 if [ $__CrossBuild == 1 ]; then
100 mkdir -p "$__CrossComponentBinDir"
101 mkdir -p "$__CrossCompIntermediatesDir"
105 # Check the system to ensure the right prereqs are in place
109 echo "Checking prerequisites..."
111 # Check presence of CMake on the path
112 hash cmake 2>/dev/null || { echo >&2 "Please install cmake before running this script"; exit 1; }
115 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; }
120 generate_event_logging_sources()
122 if [ $__SkipCoreCLR == 1 ]; then
126 # Event Logging Infrastructure
127 __GeneratedIntermediate="$__IntermediatesDir/Generated"
128 __GeneratedIntermediateEventProvider="$__GeneratedIntermediate/eventprovider_new"
129 if [[ -d "$__GeneratedIntermediateEventProvider" ]]; then
130 rm -rf "$__GeneratedIntermediateEventProvider"
133 if [[ ! -d "$__GeneratedIntermediate/eventprovider" ]]; then
134 mkdir -p "$__GeneratedIntermediate/eventprovider"
137 mkdir -p "$__GeneratedIntermediateEventProvider"
138 if [[ $__SkipCoreCLR == 0 || $__ConfigureOnly == 1 ]]; then
139 echo "Laying out dynamically generated files consumed by the build system "
140 echo "Laying out dynamically generated Event Logging Test files"
141 $PYTHON -B -Wall -Werror "$__ProjectRoot/src/scripts/genXplatEventing.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --exc "$__ProjectRoot/src/vm/ClrEtwAllMeta.lst" --testdir "$__GeneratedIntermediateEventProvider/tests"
143 if [[ $? != 0 ]]; then
147 #determine the logging system
150 echo "Laying out dynamically generated Event Logging Implementation of Lttng"
151 $PYTHON -B -Wall -Werror "$__ProjectRoot/src/scripts/genXplatLttng.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__GeneratedIntermediateEventProvider"
152 if [[ $? != 0 ]]; then
161 echo "Cleaning the temp folder of dynamically generated Event Logging files"
162 $PYTHON -B -Wall -Werror -c "import sys;sys.path.insert(0,\"$__ProjectRoot/src/scripts\"); from Utilities import *;UpdateDirectory(\"$__GeneratedIntermediate/eventprovider\",\"$__GeneratedIntermediateEventProvider\")"
163 if [[ $? != 0 ]]; then
167 rm -rf "$__GeneratedIntermediateEventProvider"
174 intermediatesForBuild="$3"
175 extraCmakeArguments="$4"
178 if [ $skipCondition == 1 ]; then
179 echo "Skipping $message build."
183 # All set to commence the build
184 echo "Commencing build of $message for $__BuildOS.$__BuildArch.$__BuildType in $intermediatesForBuild"
189 if [ $__UseNinja == 1 ]; then
191 buildFile="build.ninja"
192 if ! buildTool=$(command -v ninja || command -v ninja-build); then
193 echo "Unable to locate ninja!" 1>&2
198 if [ $__SkipConfigure == 0 ]; then
199 # if msbuild is not supported, then set __SkipGenerateVersion to 1
200 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then __SkipGenerateVersion=1; fi
201 # Drop version.cpp file
202 __versionSourceFile="$intermediatesForBuild/version.cpp"
203 if [ $__SkipGenerateVersion == 0 ]; then
205 "$__ProjectRoot/run.sh" build -Project=$__ProjectDir/build.proj -generateHeaderUnix -NativeVersionSourceFile=$__versionSourceFile $__RunArgs $__UnprocessedBuildArgs
207 # Generate the dummy version.cpp, but only if it didn't exist to make sure we don't trigger unnecessary rebuild
208 __versionSourceLine="static char sccsid[] __attribute__((used)) = \"@(#)No version information produced\";"
209 if [ -e $__versionSourceFile ]; then
210 read existingVersionSourceLine < $__versionSourceFile
212 if [ "$__versionSourceLine" != "$existingVersionSourceLine" ]; then
213 echo $__versionSourceLine > $__versionSourceFile
217 pushd "$intermediatesForBuild"
218 # Regenerate the CMake solution
219 echo "Invoking \"$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh\" \"$__ProjectRoot\" $__ClangMajorVersion $__ClangMinorVersion $platformArch $__BuildType $__CodeCoverage $__IncludeTests $generator $extraCmakeArguments $__cmakeargs"
220 "$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh" "$__ProjectRoot" $__ClangMajorVersion $__ClangMinorVersion $platformArch $__BuildType $__CodeCoverage $__IncludeTests $generator "$extraCmakeArguments" "$__cmakeargs"
224 if [ ! -f "$intermediatesForBuild/$buildFile" ]; then
225 echo "Failed to generate $message build project!"
229 # Get the number of processors available to the scheduler
230 # Other techniques such as `nproc` only get the number of
231 # processors available to a single process.
232 if [ `uname` = "FreeBSD" ]; then
233 NumProc=`sysctl hw.ncpu | awk '{ print $2+1 }'`
234 elif [ `uname` = "NetBSD" ]; then
235 NumProc=$(($(getconf NPROCESSORS_ONLN)+1))
237 NumProc=$(($(getconf _NPROCESSORS_ONLN)+1))
241 if [ $__ConfigureOnly == 1 ]; then
242 echo "Finish configuration & skipping $message build."
246 # Check that the makefiles were created.
247 pushd "$intermediatesForBuild"
249 echo "Executing $buildTool install -j $NumProc"
251 $buildTool install -j $NumProc
253 echo "Failed to build $message."
260 build_cross_arch_component()
262 __SkipCrossArchBuild=1
264 # check supported cross-architecture components host(__HostArch)/target(__BuildArch) pair
265 if [[ "$__BuildArch" == "arm" && "$__CrossArch" == "x86" ]]; then
266 export CROSSCOMPILE=0
267 __SkipCrossArchBuild=0
269 # building x64-host/arm-target cross-architecture component need to use cross toolchain of x86
270 if [ "$__HostArch" == "x64" ]; then
271 export CROSSCOMPILE=1
278 export __CMakeBinDir="$__CrossComponentBinDir"
279 export CROSSCOMPONENT=1
282 if [ $CROSSCOMPILE == 1 ]; then
283 TARGET_ROOTFS="$ROOTFS_DIR"
284 if [ -n "$CAC_ROOTFS_DIR" ]; then
285 export ROOTFS_DIR="$CAC_ROOTFS_DIR"
287 export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__CrossArch"
291 __ExtraCmakeArgs="-DCLR_CMAKE_TARGET_ARCH=$__BuildArch -DCLR_CMAKE_TARGET_OS=$__BuildOS -DCLR_CMAKE_PACKAGES_DIR=$__PackagesDir -DCLR_CMAKE_PGO_INSTRUMENT=$__PgoInstrument"
292 build_native $__SkipCrossArchBuild "$__CrossArch" "$__CrossCompIntermediatesDir" "$__ExtraCmakeArgs" "cross-architecture component"
294 # restore ROOTFS_DIR, CROSSCOMPONENT, and CROSSCOMPILE
295 if [ -n "$TARGET_ROOTFS" ]; then
296 export ROOTFS_DIR="$TARGET_ROOTFS"
298 export CROSSCOMPONENT=
299 export CROSSCOMPILE=1
302 isMSBuildOnNETCoreSupported()
304 # This needs to be updated alongwith corresponding changes to netci.groovy.
305 __isMSBuildOnNETCoreSupported=0
307 if [ "$__HostArch" == "x64" ]; then
308 if [ "$__HostOS" == "Linux" ]; then
309 case "$__HostDistroRid" in
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
341 __isMSBuildOnNETCoreSupported=$__msbuildonunsupportedplatform
343 elif [ "$__HostOS" == "OSX" ]; then
344 __isMSBuildOnNETCoreSupported=1
351 if [ $__SkipCoreCLR == 0 -a -e $__BinDir/crossgen ]; then
352 echo "Generating native image for System.Private.CoreLib."
353 $__BinDir/crossgen $__BinDir/System.Private.CoreLib.dll
354 if [ $? -ne 0 ]; then
355 echo "Failed to generate native image for System.Private.CoreLib."
359 echo "Generating native image for MScorlib Facade."
360 $__BinDir/crossgen $__BinDir/mscorlib.dll
361 if [ $? -ne 0 ]; then
362 echo "Failed to generate native image for mscorlib facade."
366 if [ "$__BuildOS" == "Linux" ]; then
367 echo "Generating symbol file for System.Private.CoreLib."
368 $__BinDir/crossgen /CreatePerfMap $__BinDir $__BinDir/System.Private.CoreLib.ni.dll
369 if [ $? -ne 0 ]; then
370 echo "Failed to generate symbol file for System.Private.CoreLib."
380 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
381 echo "System.Private.CoreLib.dll build unsupported."
385 if [ $__SkipMSCorLib == 1 ]; then
386 echo "Skipping building System.Private.CoreLib."
390 echo "Commencing build of managed components for $__BuildOS.$__BuildArch.$__BuildType"
393 $__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
395 if [ $? -ne 0 ]; then
396 echo "Failed to build managed components."
400 # The cross build generates a crossgen with the target architecture.
401 if [ $__CrossBuild != 1 ]; then
402 # The architecture of host pc must be same architecture with target.
403 if [[ ( "$__HostArch" == "$__BuildArch" ) ]]; then
405 elif [[ ( "$__HostArch" == "x64" ) && ( "$__BuildArch" == "x86" ) ]]; then
407 elif [[ ( "$__HostArch" == "arm64" ) && ( "$__BuildArch" == "arm" ) ]]; then
415 generate_NugetPackages()
417 # We can only generate nuget package if we also support building mscorlib as part of this build.
418 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
419 echo "Nuget package generation unsupported."
423 # Since we can build mscorlib for this OS, did we build the native components as well?
424 if [ $__SkipCoreCLR == 1 ]; then
425 echo "Unable to generate nuget packages since native components were not built."
429 echo "Generating nuget packages for "$__BuildOS
432 $__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
434 if [ $? -ne 0 ]; then
435 echo "Failed to generate Nuget packages."
440 echo "Commencing CoreCLR Repo build"
442 # Argument types supported by this script:
444 # Build architecture - valid values are: x64, ARM.
445 # Build Type - valid values are: Debug, Checked, Release
447 # Set the default arguments for build
449 # Obtain the location of the bash script to figure out where the root of the repo is.
450 __ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
452 # Use uname to determine what the CPU is.
454 # Some Linux platforms report unknown for platform, but the arch for machine.
455 if [ "$CPUName" == "unknown" ]; then
461 echo "Unsupported CPU $CPUName detected, build might not succeed!"
472 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
560 __msbuildonunsupportedplatform=0
563 if [ $# -le 0 ]; then
567 lowerI="$(echo $1 | awk '{print tolower($0)}')"
607 __CodeCoverage=Coverage
615 if [ "$__BuildOS" == "Linux" ]; then
618 echo "ERROR: portableLinux not supported for non-Linux platforms."
628 __ClangMajorVersion=3
629 __ClangMinorVersion=5
633 __ClangMajorVersion=3
634 __ClangMinorVersion=6
638 __ClangMajorVersion=3
639 __ClangMinorVersion=7
643 __ClangMajorVersion=3
644 __ClangMinorVersion=8
648 __ClangMajorVersion=3
649 __ClangMinorVersion=9
671 # Use "skipnative" to use the same option name as build.cmd.
676 # Accept "skipcoreclr" for backwards-compatibility.
689 __SkipGenerateVersion=1
708 echo "ERROR: 'cmakeargs' requires a non-empty option argument"
716 if [ ! -d $__RootBinDir ]; then
719 __RootBinParent=$(dirname $__RootBinDir)
720 __RootBinName=${__RootBinDir##*/}
721 __RootBinDir="$(cd $__RootBinParent &>/dev/null && printf %s/%s $PWD $__RootBinName)"
724 echo "ERROR: 'bindir' requires a non-empty option argument"
729 __cmakeargs="-DFEATURE_STANDALONE_GC=1"
731 msbuildonunsupportedplatform)
732 __msbuildonunsupportedplatform=1
735 __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1"
742 __RunArgs="-BuildArch=$__BuildArch -BuildType=$__BuildType -BuildOS=$__BuildOS"
744 # Configure environment if we are doing a verbose build
745 if [ $__VerboseBuild == 1 ]; then
747 __RunArgs="$__RunArgs -verbose"
750 # Set default clang version
751 if [[ $__ClangMajorVersion == 0 && $__ClangMinorVersion == 0 ]]; then
752 if [ $__CrossBuild == 1 ]; then
753 __ClangMajorVersion=3
754 __ClangMinorVersion=6
756 __ClangMajorVersion=3
757 __ClangMinorVersion=5
761 # Set dependent variables
762 __LogsDir="$__RootBinDir/Logs"
764 # init the host distro name
767 # Set the remaining variables based upon the determined build configuration
768 __BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType"
769 __PackagesBinDir="$__BinDir/.nuget"
770 __ToolsDir="$__RootBinDir/tools"
771 __TestWorkingDir="$__RootBinDir/tests/$__BuildOS.$__BuildArch.$__BuildType"
772 export __IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType"
773 __TestIntermediatesDir="$__RootBinDir/tests/obj/$__BuildOS.$__BuildArch.$__BuildType"
774 __isMSBuildOnNETCoreSupported=0
775 __CrossComponentBinDir="$__BinDir"
776 __CrossCompIntermediatesDir="$__IntermediatesDir/crossgen"
778 __CrossArch="$__HostArch"
779 if [[ "$__HostArch" == "x64" && "$__BuildArch" == "arm" ]]; then
782 if [ $__CrossBuild == 1 ]; then
783 __CrossComponentBinDir="$__CrossComponentBinDir/$__CrossArch"
785 __CrossgenCoreLibLog="$__LogsDir/CrossgenCoreLib_$__BuildOS.$BuildArch.$__BuildType.log"
786 __CrossgenExe="$__CrossComponentBinDir/crossgen"
788 # Init if MSBuild for .NET Core is supported for this platform
789 isMSBuildOnNETCoreSupported
791 # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set.
792 # This is needed by CLI to function.
793 if [ -z "$HOME" ]; then
794 if [ ! -d "$__ProjectDir/temp_home" ]; then
797 export HOME=$__ProjectDir/temp_home
798 echo "HOME not defined; setting it to $HOME"
801 # Specify path to be set for CMAKE_INSTALL_PREFIX.
802 # This is where all built CoreClr libraries will copied to.
803 export __CMakeBinDir="$__BinDir"
805 # Configure environment if we are doing a cross compile.
806 if [ $__CrossBuild == 1 ]; then
807 export CROSSCOMPILE=1
808 if ! [[ -n "$ROOTFS_DIR" ]]; then
809 export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__BuildArch"
813 # init the target distro name
816 # Make the directories necessary for build if they don't exist
822 # Generate event logging infrastructure sources
823 generate_event_logging_sources
825 # Build the coreclr (native) components.
826 __ExtraCmakeArgs="-DCLR_CMAKE_TARGET_OS=$__BuildOS -DCLR_CMAKE_PACKAGES_DIR=$__PackagesDir -DCLR_CMAKE_PGO_INSTRUMENT=$__PgoInstrument"
827 build_native $__SkipCoreCLR "$__BuildArch" "$__IntermediatesDir" "$__ExtraCmakeArgs" "CoreCLR component"
829 # Build cross-architecture components
830 if [[ $__CrossBuild == 1 && $__DoCrossArchBuild == 1 ]]; then
831 build_cross_arch_component
834 # Build System.Private.CoreLib.
838 # Generate nuget packages
839 if [ $__SkipNuget != 1 ]; then
840 generate_NugetPackages
846 echo "Repo successfully built."
847 echo "Product binaries are available at $__BinDir"