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 "configureonly - do not perform any builds; just configure the build."
39 echo "skipconfigure - skip build configuration."
40 echo "skipnative - do not build native components."
41 echo "skipmscorlib - do not build mscorlib.dll."
42 echo "skiptests - skip the tests in the 'tests' subdirectory."
43 echo "skipnuget - skip building nuget packages."
44 echo "verbose - optional argument to enable verbose build output."
45 echo "-skiprestore: skip restoring packages ^(default: packages are restored during build^)."
46 echo "-disableoss: Disable Open Source Signing for System.Private.CoreLib."
47 echo "-sequential: force a non-parallel build ^(default is to build in parallel"
48 echo " using all processors^)."
49 echo "-officialbuildid=^<ID^>: specify the official build ID to be used by this build."
50 echo "-Rebuild: passes /t:rebuild to the build projects."
51 echo "skipgenerateversion - disable version generation even if MSBuild is supported."
52 echo "cmakeargs - user-settable additional arguments passed to CMake."
53 echo "bindir - output directory (defaults to $__ProjectRoot/bin)"
60 if [ "$__BuildOS" == "Linux" ]; then
61 if [ ! -e /etc/os-release ]; then
62 echo "WARNING: Can not determine runtime id for current distro."
65 source /etc/os-release
66 export __DistroRid="$ID.$VERSION_ID-$__HostArch"
73 echo Setting up directories for build
75 mkdir -p "$__RootBinDir"
78 mkdir -p "$__IntermediatesDir"
81 # Check the system to ensure the right prereqs are in place
85 echo "Checking prerequisites..."
87 # Check presence of CMake on the path
88 hash cmake 2>/dev/null || { echo >&2 "Please install cmake before running this script"; exit 1; }
91 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; }
98 if [ $__SkipCoreCLR == 1 ]; then
99 echo "Skipping CoreCLR build."
103 # Event Logging Infrastructure
104 __GeneratedIntermediate="$__IntermediatesDir/Generated"
105 __GeneratedIntermediateEventProvider="$__GeneratedIntermediate/eventprovider_new"
106 if [[ -d "$__GeneratedIntermediateEventProvider" ]]; then
107 rm -rf "$__GeneratedIntermediateEventProvider"
110 if [[ ! -d "$__GeneratedIntermediate/eventprovider" ]]; then
111 mkdir -p "$__GeneratedIntermediate/eventprovider"
114 mkdir -p "$__GeneratedIntermediateEventProvider"
115 if [[ $__SkipCoreCLR == 0 || $__ConfigureOnly == 1 ]]; then
116 echo "Laying out dynamically generated files consumed by the build system "
117 echo "Laying out dynamically generated Event Logging Test files"
118 $PYTHON -B -Wall -Werror "$__ProjectRoot/src/scripts/genXplatEventing.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --exc "$__ProjectRoot/src/vm/ClrEtwAllMeta.lst" --testdir "$__GeneratedIntermediateEventProvider/tests"
120 if [[ $? != 0 ]]; then
124 #determine the logging system
127 echo "Laying out dynamically generated Event Logging Implementation of Lttng"
128 $PYTHON -B -Wall -Werror "$__ProjectRoot/src/scripts/genXplatLttng.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__GeneratedIntermediateEventProvider"
129 if [[ $? != 0 ]]; then
138 echo "Cleaning the temp folder of dynamically generated Event Logging files"
139 $PYTHON -B -Wall -Werror -c "import sys;sys.path.insert(0,\"$__ProjectRoot/src/scripts\"); from Utilities import *;UpdateDirectory(\"$__GeneratedIntermediate/eventprovider\",\"$__GeneratedIntermediateEventProvider\")"
140 if [[ $? != 0 ]]; then
144 rm -rf "$__GeneratedIntermediateEventProvider"
146 # All set to commence the build
148 echo "Commencing build of native components for $__BuildOS.$__BuildArch.$__BuildType in $__IntermediatesDir"
153 if [ $__UseNinja == 1 ]; then
155 buildFile="build.ninja"
156 if which ninja >/dev/null 2>&1; then
158 elif which ninja-build >/dev/null 2>&1; then
159 buildTool="ninja-build"
161 echo "Unable to locate ninja!" 1>&2
166 if [ $__SkipConfigure == 0 ]; then
167 # if msbuild is not supported, then set __SkipGenerateVersion to 1
168 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then __SkipGenerateVersion=1; fi
169 # Drop version.c file
170 __versionSourceFile=$__IntermediatesDir/version.cpp
171 if [ $__SkipGenerateVersion == 0 ]; then
172 "$__ProjectRoot/run.sh" build -Project=$__ProjectDir/build.proj -generateHeaderUnix -NativeVersionSourceFile=$__versionSourceFile $__RunArgs $__UnprocessedBuildArgs
174 __versionSourceLine="static char sccsid[] __attribute__((used)) = \"@(#)No version information produced\";"
175 echo $__versionSourceLine > $__versionSourceFile
178 pushd "$__IntermediatesDir"
179 # Regenerate the CMake solution
180 echo "Invoking \"$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh\" \"$__ProjectRoot\" $__ClangMajorVersion $__ClangMinorVersion $__BuildArch $__BuildType $__CodeCoverage $__IncludeTests $generator $__cmakeargs"
181 "$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh" "$__ProjectRoot" $__ClangMajorVersion $__ClangMinorVersion $__BuildArch $__BuildType $__CodeCoverage $__IncludeTests $generator "$__cmakeargs"
185 # Check that the makefiles were created.
186 pushd "$__IntermediatesDir"
188 if [ ! -f "$__IntermediatesDir/$buildFile" ]; then
189 echo "Failed to generate native component build project!"
193 # Get the number of processors available to the scheduler
194 # Other techniques such as `nproc` only get the number of
195 # processors available to a single process.
196 if [ `uname` = "FreeBSD" ]; then
197 NumProc=`sysctl hw.ncpu | awk '{ print $2+1 }'`
198 elif [ `uname` = "NetBSD" ]; then
199 NumProc=$(($(getconf NPROCESSORS_ONLN)+1))
201 NumProc=$(($(getconf _NPROCESSORS_ONLN)+1))
206 if [ $__ConfigureOnly == 1 ]; then
207 echo "Skipping CoreCLR build."
211 echo "Executing $buildTool install -j $NumProc"
213 $buildTool install -j $NumProc
215 echo "Failed to build coreclr components."
221 isMSBuildOnNETCoreSupported()
223 # This needs to be updated alongwith corresponding changes to netci.groovy.
224 __isMSBuildOnNETCoreSupported=0
226 if [ "$__HostArch" == "x64" ]; then
227 if [ "$__HostOS" == "Linux" ]; then
228 case "$__DistroRid" in
230 __isMSBuildOnNETCoreSupported=1
233 __isMSBuildOnNETCoreSupported=1
236 __isMSBuildOnNETCoreSupported=1
239 __isMSBuildOnNETCoreSupported=1
242 __isMSBuildOnNETCoreSupported=1
245 __isMSBuildOnNETCoreSupported=1
248 __isMSBuildOnNETCoreSupported=1
251 __isMSBuildOnNETCoreSupported=1
254 __isMSBuildOnNETCoreSupported=1
258 elif [ "$__HostOS" == "OSX" ]; then
259 __isMSBuildOnNETCoreSupported=1
266 if [ $__SkipCoreCLR == 0 -a -e $__BinDir/crossgen ]; then
267 echo "Generating native image for System.Private.CoreLib."
268 $__BinDir/crossgen $__BinDir/System.Private.CoreLib.dll
269 if [ $? -ne 0 ]; then
270 echo "Failed to generate native image for System.Private.CoreLib."
274 echo "Generating native image for MScorlib Facade."
275 $__BinDir/crossgen $__BinDir/mscorlib.dll
276 if [ $? -ne 0 ]; then
277 echo "Failed to generate native image for mscorlib facade."
281 if [ "$__BuildOS" == "Linux" ]; then
282 echo "Generating symbol file for System.Private.CoreLib."
283 $__BinDir/crossgen /CreatePerfMap $__BinDir $__BinDir/System.Private.CoreLib.ni.dll
284 if [ $? -ne 0 ]; then
285 echo "Failed to generate symbol file for System.Private.CoreLib."
295 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
296 echo "System.Private.CoreLib.dll build unsupported."
300 if [ $__SkipMSCorLib == 1 ]; then
301 echo "Skipping building System.Private.CoreLib."
305 echo "Commencing build of managed components for $__BuildOS.$__BuildArch.$__BuildType"
308 $__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
310 if [ $? -ne 0 ]; then
311 echo "Failed to build managed components."
315 # The cross build generates a crossgen with the target architecture.
316 if [ $__CrossBuild != 1 ]; then
317 # The architecture of host pc must be same architecture with target.
318 if [[ ( "$__HostArch" == "$__BuildArch" ) ]]; then
320 elif [[ ( "$__HostArch" == "x64" ) && ( "$__BuildArch" == "x86" ) ]]; then
322 elif [[ ( "$__HostArch" == "arm64" ) && ( "$__BuildArch" == "arm" ) ]]; then
330 generate_NugetPackages()
332 # We can only generate nuget package if we also support building mscorlib as part of this build.
333 if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
334 echo "Nuget package generation unsupported."
338 # Since we can build mscorlib for this OS, did we build the native components as well?
339 if [ $__SkipCoreCLR == 1 ]; then
340 echo "Unable to generate nuget packages since native components were not built."
344 echo "Generating nuget packages for "$__BuildOS
347 $__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
349 if [ $? -ne 0 ]; then
350 echo "Failed to generate Nuget packages."
355 echo "Commencing CoreCLR Repo build"
357 # Argument types supported by this script:
359 # Build architecture - valid values are: x64, ARM.
360 # Build Type - valid values are: Debug, Checked, Release
362 # Set the default arguments for build
364 # Obtain the location of the bash script to figure out where the root of the repo is.
365 __ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
367 # Use uname to determine what the CPU is.
369 # Some Linux platforms report unknown for platform, but the arch for machine.
370 if [ "$CPUName" == "unknown" ]; then
376 echo "Unsupported CPU $CPUName detected, build might not succeed!"
387 echo "Unsupported CPU $CPUName detected, build might not succeed!"
393 echo "Unsupported CPU $CPUName detected, build might not succeed!"
399 echo "Unknown CPU $CPUName detected, configuring as if for x64"
405 # Use uname to determine what the OS is.
439 echo "Unsupported OS $OSName detected, configuring as if for Linux"
447 __IncludeTests=Include_Tests
449 # Set the various build properties here so that CMake and MSBuild can pick them up
450 __ProjectDir="$__ProjectRoot"
451 __SourceDir="$__ProjectDir/src"
452 __PackagesDir="$__ProjectDir/packages"
453 __RootBinDir="$__ProjectDir/bin"
454 __UnprocessedBuildArgs=
466 __ClangMajorVersion=0
467 __ClangMinorVersion=0
468 __NuGetPath="$__PackagesDir/NuGet.exe"
471 __SkipGenerateVersion=0
474 if [ $# -le 0 ]; then
478 lowerI="$(echo $1 | awk '{print tolower($0)}')"
498 __BuildArch=arm-softfp
518 __CodeCoverage=Coverage
530 __ClangMajorVersion=3
531 __ClangMinorVersion=5
535 __ClangMajorVersion=3
536 __ClangMinorVersion=6
540 __ClangMajorVersion=3
541 __ClangMinorVersion=7
545 __ClangMajorVersion=3
546 __ClangMinorVersion=8
550 __ClangMajorVersion=3
551 __ClangMinorVersion=9
570 # Use "skipnative" to use the same option name as build.cmd.
575 # Accept "skipcoreclr" for backwards-compatibility.
584 __SkipGenerateVersion=1
603 echo "ERROR: 'cmakeargs' requires a non-empty option argument"
611 if [ ! -d $__RootBinDir ]; then
614 __RootBinParent=$(dirname $__RootBinDir)
615 __RootBinName=${__RootBinDir##*/}
616 __RootBinDir="$(cd $__RootBinParent &>/dev/null && printf %s/%s $PWD $__RootBinName)"
619 echo "ERROR: 'bindir' requires a non-empty option argument"
625 __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1"
632 __RunArgs="-BuildArch=$__BuildArch -BuildType=$__BuildType -BuildOS=$__BuildOS"
634 # Configure environment if we are doing a verbose build
635 if [ $__VerboseBuild == 1 ]; then
637 __RunArgs="$__RunArgs -verbose"
640 # Set default clang version
641 if [[ $__ClangMajorVersion == 0 && $__ClangMinorVersion == 0 ]]; then
642 if [ $__CrossBuild == 1 ]; then
643 __ClangMajorVersion=3
644 __ClangMinorVersion=6
646 __ClangMajorVersion=3
647 __ClangMinorVersion=5
651 # Set dependent variables
652 __LogsDir="$__RootBinDir/Logs"
654 # init the distro name
657 # Set the remaining variables based upon the determined build configuration
658 __BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType"
659 __PackagesBinDir="$__BinDir/.nuget"
660 __ToolsDir="$__RootBinDir/tools"
661 __TestWorkingDir="$__RootBinDir/tests/$__BuildOS.$__BuildArch.$__BuildType"
662 export __IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType"
663 __TestIntermediatesDir="$__RootBinDir/tests/obj/$__BuildOS.$__BuildArch.$__BuildType"
664 __isMSBuildOnNETCoreSupported=0
666 # Init if MSBuild for .NET Core is supported for this platform
667 isMSBuildOnNETCoreSupported
669 # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set.
670 # This is needed by CLI to function.
671 if [ -z "$HOME" ]; then
672 if [ ! -d "$__ProjectDir/temp_home" ]; then
675 export HOME=$__ProjectDir/temp_home
676 echo "HOME not defined; setting it to $HOME"
679 # Specify path to be set for CMAKE_INSTALL_PREFIX.
680 # This is where all built CoreClr libraries will copied to.
681 export __CMakeBinDir="$__BinDir"
683 # Configure environment if we are doing a cross compile.
684 if [ $__CrossBuild == 1 ]; then
685 export CROSSCOMPILE=1
686 if ! [[ -n "$ROOTFS_DIR" ]]; then
687 export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__BuildArch"
691 # Make the directories necessary for build if they don't exist
699 # Build the coreclr (native) components.
703 # Build System.Private.CoreLib.
707 # Generate nuget packages
708 if [ $__SkipNuget != 1 ]; then
709 generate_NugetPackages
715 echo "Repo successfully built."
716 echo "Product binaries are available at $__BinDir"