5 source="${BASH_SOURCE[0]}"
7 # resolve $source until the file is no longer a symlink
8 while [[ -h "$source" ]]; do
9 scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
10 source="$(readlink "$source")"
11 # if $source was a relative symlink, we need to resolve it relative to the path where the
12 # symlink file was located
13 [[ $source != /* ]] && source="$scriptroot/$source"
15 scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
19 echo "Common settings:"
20 echo " --arch (-a) Target platform: x86, x64, arm, armel, arm64, s390x or wasm."
21 echo " [Default: Your machine's architecture.]"
22 echo " --binaryLog (-bl) Output binary log."
23 echo " --cross Optional argument to signify cross compilation."
24 echo " --configuration (-c) Build configuration: Debug, Release or Checked."
25 echo " Checked is exclusive to the CLR subset. It is the same as Debug, except code is"
26 echo " compiled with optimizations enabled."
27 echo " [Default: Debug]"
28 echo " --help (-h) Print help and exit."
29 echo " --librariesConfiguration (-lc) Libraries build configuration: Debug or Release."
30 echo " [Default: Debug]"
31 echo " --os Target operating system: windows, Linux, FreeBSD, OSX, MacCatalyst, tvOS,"
32 echo " tvOSSimulator, iOS, iOSSimulator, Android, Browser, NetBSD, illumos or Solaris."
33 echo " [Default: Your machine's OS.]"
34 echo " --projects <value> Project or solution file(s) to build."
35 echo " --runtimeConfiguration (-rc) Runtime build configuration: Debug, Release or Checked."
36 echo " Checked is exclusive to the CLR runtime. It is the same as Debug, except code is"
37 echo " compiled with optimizations enabled."
38 echo " [Default: Debug]"
39 echo " -runtimeFlavor (-rf) Runtime flavor: CoreCLR or Mono."
40 echo " [Default: CoreCLR]"
41 echo " --subset (-s) Build a subset, print available subsets with -subset help."
42 echo " '--subset' can be omitted if the subset is given as the first argument."
43 echo " [Default: Builds the entire repo.]"
44 echo " --verbosity (-v) MSBuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]."
45 echo " [Default: Minimal]"
48 echo "Actions (defaults to --restore --build):"
49 echo " --build (-b) Build all source projects."
50 echo " This assumes --restore has been run already."
51 echo " --clean Clean the solution."
52 echo " --pack Package build outputs into NuGet packages."
53 echo " --publish Publish artifacts (e.g. symbols)."
54 echo " This assumes --build has been run already."
55 echo " --rebuild Rebuild all source projects."
56 echo " --restore (-r) Restore dependencies."
57 echo " --sign Sign build outputs."
58 echo " --test (-t) Incrementally builds and runs tests."
59 echo " Use in conjuction with --testnobuild to only run tests."
62 echo "Libraries settings:"
63 echo " --allconfigurations Build packages for all build configurations."
64 echo " --coverage Collect code coverage when testing."
65 echo " --framework (-f) Build framework: net6.0 or net48."
66 echo " [Default: net6.0]"
67 echo " --testnobuild Skip building tests when invoking -test."
68 echo " --testscope Test scope, allowed values: innerloop, outerloop, all."
71 echo "Native build settings:"
72 echo " --clang Optional argument to build using clang in PATH (default)."
73 echo " --clangx Optional argument to build using clang version x (used for Clang 7 and newer)."
74 echo " --clangx.y Optional argument to build using clang version x.y (used for Clang 6 and older)."
75 echo " --cmakeargs User-settable additional arguments passed to CMake."
76 echo " --gcc Optional argument to build using gcc in PATH (default)."
77 echo " --gccx.y Optional argument to build using gcc version x.y."
78 echo " --portablebuild Optional argument: set to false to force a non-portable build."
79 echo " --keepnativesymbols Optional argument: set to true to keep native symbols/debuginfo in generated binaries."
80 echo " --ninja Optional argument: set to true to use Ninja instead of Make to run the native build."
81 echo " --pgoinstrument Optional argument: build PGO-instrumented runtime"
82 echo " --nopgooptimize Optional argument: build without PGO optimization"
85 echo "Command line arguments starting with '/p:' are passed through to MSBuild."
86 echo "Arguments can also be passed in with a single hyphen."
89 echo "Here are some quick examples. These assume you are on a Linux x64 machine:"
91 echo "* Build CoreCLR for Linux x64 on Release configuration:"
92 echo "./build.sh clr -c release"
94 echo "* Build Debug libraries with a Release runtime for Linux x64."
95 echo "./build.sh clr+libs -rc release"
97 echo "* Build Release libraries and their tests with a Checked runtime for Linux x64, and run the tests."
98 echo "./build.sh clr+libs+libs.tests -rc checked -lc release -test"
100 echo "* Build CoreCLR for Linux x64 on Debug configuration using Clang 9."
101 echo "./build.sh clr -clang9"
103 echo "* Build CoreCLR for Linux x64 on Debug configuration using GCC 8.4."
104 echo "./build.sh clr -gcc8.4"
106 echo "* Build CoreCLR for Linux x64 using extra compiler flags (-fstack-clash-protection)."
107 echo "EXTRA_CFLAGS=-fstack-clash-protection EXTRA_CXXFLAGS=-fstack-clash-protection ./build.sh clr"
109 echo "* Cross-compile CoreCLR runtime for Linux ARM64 on Release configuration."
110 echo "./build.sh clr.runtime -arch arm64 -c release -cross"
112 echo "However, for this example, you need to already have ROOTFS_DIR set up."
113 echo "Further information on this can be found here:"
114 echo "https://github.com/dotnet/runtime/blob/main/docs/workflow/building/coreclr/linux-instructions.md"
116 echo "* Build Mono runtime for Linux x64 on Release configuration."
117 echo "./build.sh mono -c release"
119 echo "* Build Release coreclr corelib, crossgen corelib and update Debug libraries testhost to run test on an updated corelib."
120 echo "./build.sh clr.corelib+clr.nativecorelib+libs.pretest -rc release"
122 echo "* Build Debug mono corelib and update Release libraries testhost to run test on an updated corelib."
123 echo "./build.sh mono.corelib+libs.pretest -rc debug -c release"
126 echo "For more general information, check out https://github.com/dotnet/runtime/blob/main/docs/workflow/README.md"
131 source "$scriptroot"/native/init-distro-rid.sh
133 local passedRootfsDir=""
136 local isCrossBuild="$3"
137 local isPortableBuild="$4"
139 # Only pass ROOTFS_DIR if __DoCrossArchBuild is specified and the current platform is not OSX that doesn't use rootfs
140 if [[ $isCrossBuild == 1 && "$targetOs" != "OSX" ]]; then
141 passedRootfsDir=${ROOTFS_DIR}
143 initDistroRidGlobal ${targetOs} ${buildArch} ${isPortableBuild} ${passedRootfsDir}
148 "$scriptroot/common/build.sh" "-restore" "-build" "/p:Subset=help" "/clp:nosummary"
157 source $scriptroot/native/init-os-and-arch.sh
161 # Check if an action is passed in
162 declare -a actions=("b" "build" "r" "restore" "rebuild" "testnobuild" "sign" "publish" "clean")
163 actInt=($(comm -12 <(printf '%s\n' "${actions[@]/#/-}" | sort) <(printf '%s\n' "${@/#--/-}" | sort)))
164 firstArgumentChecked=0
166 while [[ $# > 0 ]]; do
167 opt="$(echo "${1/#--/-}" | tr "[:upper:]" "[:lower:]")"
169 if [[ $firstArgumentChecked -eq 0 && $opt =~ ^[a-zA-Z.+]+$ ]]; then
170 if [ $opt == "help" ]; then
175 arguments="$arguments /p:Subset=$1"
180 firstArgumentChecked=1
189 if [ -z ${2+x} ]; then
193 passedSubset="$(echo "$2" | tr "[:upper:]" "[:lower:]")"
194 if [ $passedSubset == "help" ]; then
198 arguments="$arguments /p:Subset=$2"
204 if [ -z ${2+x} ]; then
205 echo "No architecture supplied. See help (--help) for supported architectures." 1>&2
208 passedArch="$(echo "$2" | tr "[:upper:]" "[:lower:]")"
209 case "$passedArch" in
210 x64|x86|arm|armel|arm64|s390x|wasm)
214 echo "Unsupported target architecture '$2'."
215 echo "The allowed values are x86, x64, arm, armel, arm64, s390x, and wasm."
223 if [ -z ${2+x} ]; then
224 echo "No configuration supplied. See help (--help) for supported configurations." 1>&2
227 passedConfig="$(echo "$2" | tr "[:upper:]" "[:lower:]")"
228 case "$passedConfig" in
229 debug|release|checked)
230 val="$(tr '[:lower:]' '[:upper:]' <<< ${passedConfig:0:1})${passedConfig:1}"
233 echo "Unsupported target configuration '$2'."
234 echo "The allowed values are Debug, Release, and Checked."
238 arguments="$arguments -configuration $val"
243 if [ -z ${2+x} ]; then
244 echo "No framework supplied. See help (--help) for supported frameworks." 1>&2
247 val="$(echo "$2" | tr "[:upper:]" "[:lower:]")"
248 arguments="$arguments /p:BuildTargetFramework=$val"
253 if [ -z ${2+x} ]; then
254 echo "No target operating system supplied. See help (--help) for supported target operating systems." 1>&2
257 passedOS="$(echo "$2" | tr "[:upper:]" "[:lower:]")"
272 os="tvOSSimulator" ;;
286 echo "Unsupported target OS '$2'."
287 echo "The allowed values are windows, Linux, FreeBSD, OSX, MacCatalyst, tvOS, tvOSSimulator, iOS, iOSSimulator, Android, Browser, illumos and Solaris."
291 arguments="$arguments /p:TargetOS=$os"
296 arguments="$arguments /p:BuildAllConfigurations=true"
301 if [ -z ${2+x} ]; then
302 echo "No test scope supplied. See help (--help) for supported test scope values." 1>&2
305 arguments="$arguments /p:TestScope=$2"
310 arguments="$arguments /p:TestNoBuild=true"
315 arguments="$arguments /p:Coverage=true"
319 -runtimeconfiguration|-rc)
320 if [ -z ${2+x} ]; then
321 echo "No runtime configuration supplied. See help (--help) for supported runtime configurations." 1>&2
324 passedRuntimeConf="$(echo "$2" | tr "[:upper:]" "[:lower:]")"
325 case "$passedRuntimeConf" in
326 debug|release|checked)
327 val="$(tr '[:lower:]' '[:upper:]' <<< ${passedRuntimeConf:0:1})${passedRuntimeConf:1}"
330 echo "Unsupported runtime configuration '$2'."
331 echo "The allowed values are Debug, Release, and Checked."
335 arguments="$arguments /p:RuntimeConfiguration=$val"
340 if [ -z ${2+x} ]; then
341 echo "No runtime flavor supplied. See help (--help) for supported runtime flavors." 1>&2
344 passedRuntimeFlav="$(echo "$2" | tr "[:upper:]" "[:lower:]")"
345 case "$passedRuntimeFlav" in
347 val="$(tr '[:lower:]' '[:upper:]' <<< ${passedRuntimeFlav:0:1})${passedRuntimeFlav:1}"
350 echo "Unsupported runtime flavor '$2'."
351 echo "The allowed values are CoreCLR and Mono."
355 arguments="$arguments /p:RuntimeFlavor=$val"
359 -librariesconfiguration|-lc)
360 if [ -z ${2+x} ]; then
361 echo "No libraries configuration supplied. See help (--help) for supported libraries configurations." 1>&2
364 passedLibConf="$(echo "$2" | tr "[:upper:]" "[:lower:]")"
365 case "$passedLibConf" in
367 val="$(tr '[:lower:]' '[:upper:]' <<< ${passedLibConf:0:1})${passedLibConf:1}"
370 echo "Unsupported libraries configuration '$2'."
371 echo "The allowed values are Debug and Release."
375 arguments="$arguments /p:LibrariesConfiguration=$val"
381 arguments="$arguments /p:CrossBuild=True"
386 arguments="$arguments /p:Compiler=$opt"
391 if [ -z ${2+x} ]; then
392 echo "No cmake args supplied." 1>&2
395 cmakeargs="${cmakeargs} ${opt} $2"
400 arguments="$arguments /p:Compiler=$opt"
405 if [ -z ${2+x} ]; then
406 echo "No value for portablebuild is supplied. See help (--help) for supported values." 1>&2
409 passedPortable="$(echo "$2" | tr "[:upper:]" "[:lower:]")"
410 if [ "$passedPortable" = false ]; then
412 arguments="$arguments /p:PortableBuild=false"
418 if [ -z ${2+x} ]; then
419 echo "No value for keepNativeSymbols is supplied. See help (--help) for supported values." 1>&2
422 passedKeepNativeSymbols="$(echo "$2" | tr "[:upper:]" "[:lower:]")"
423 if [ "$passedKeepNativeSymbols" = true ]; then
424 arguments="$arguments /p:KeepNativeSymbols=true"
431 if [ -z ${2+x} ]; then
432 arguments="$arguments /p:Ninja=true"
435 ninja="$(echo "$2" | tr "[:upper:]" "[:lower:]")"
436 if [ "$ninja" = true ]; then
437 arguments="$arguments /p:Ninja=true"
439 elif [ "$ninja" = false ]; then
440 arguments="$arguments /p:Ninja=false"
443 arguments="$arguments /p:Ninja=true"
450 arguments="$arguments /p:PgoInstrument=true"
455 arguments="$arguments /p:NoPgoOptimize=true"
460 extraargs="$extraargs $1"
466 if [ ${#actInt[@]} -eq 0 ]; then
467 arguments="-restore -build $arguments"
470 if [ "$os" = "Browser" ] && [ "$arch" != "wasm" ]; then
471 # override default arch for Browser, we only support wasm
475 initDistroRid $os $arch $crossBuild $portableBuild
477 # Disable targeting pack caching as we reference a partially constructed targeting pack and update it later.
478 # The later changes are ignored when using the cache.
479 export DOTNETSDK_ALLOW_TARGETING_PACK_CACHING=0
481 # URL-encode space (%20) to avoid quoting issues until the msbuild call in /eng/common/tools.sh.
482 # In *proj files (XML docs), URL-encoded string are rendered in their decoded form.
483 cmakeargs="${cmakeargs// /%20}"
484 arguments="$arguments /p:TargetArchitecture=$arch /p:BuildArchitecture=$hostArch"
485 arguments="$arguments /p:CMakeArgs=\"$cmakeargs\" $extraargs"
486 "$scriptroot/common/build.sh" $arguments