Fix Cairo issue on macOS Big Sur
[mono-project.git] / netcore / build.sh
bloba57401e8195dfeea6f16608f3a6a5bf7d7c0bd28
1 #!/usr/bin/env bash
3 # Stop script if unbound variable found (use ${var:-} if intentional)
4 set -u
6 # Stop script if command returns non-zero exit code.
7 # Prevents hidden errors caused by missing error code propagation.
8 set -e
10 # Handle being in the "wrong" directory
11 cd "${BASH_SOURCE%/*}/"
13 # Include VSTS logging helpers
14 . ../eng/common/pipeline-logging-functions.sh
16 usage()
18 echo "Common settings:"
19 echo " --configuration <value> Build configuration: 'Debug' or 'Release' (short: -c)"
20 echo " --help Print help and exit (short: -h)"
21 echo ""
23 echo "Actions:"
24 echo " --pack Package build outputs into NuGet packages"
25 echo " --test Run all unit tests in the solution (short: -t)"
26 echo " --interpreter Run tests with interpreter"
27 echo " --rebuild Run ../.autogen.sh"
28 echo " --llvm Enable LLVM support"
29 echo " --skipnative Do not build runtime"
30 echo " --skipmscorlib Do not build System.Private.CoreLib"
31 echo " --ci Enable Azure DevOps telemetry decoration"
32 echo ""
34 echo "Command line arguments starting with '/p:' are passed through to MSBuild."
35 echo "Arguments can also be passed in with a single hyphen."
38 pack=false
39 configuration='Debug'
40 test_mono_flags=''
41 test_xunit_flags=''
42 properties=''
43 force_rebuild=false
44 test=false
45 skipmscorlib=false
46 skipnative=false
47 llvm=false
48 autogen_params=''
49 ci=false
51 while [[ $# > 0 ]]; do
52 opt="$(echo "${1/#--/-}" | awk '{print tolower($0)}')"
53 case "$opt" in
54 -help|-h)
55 usage
56 exit 0
58 -configuration|-c)
59 properties="$properties $1 $2"
60 configuration=$2
61 shift
63 -pack)
64 pack=true
66 -test|-t)
67 test=true
69 -interpreter)
70 test_mono_flags="$test_mono_flags --interpreter"
71 test_xunit_flags="$test_xunit_flags @../../../../CoreFX.issues_interpreter.rsp -parallel none"
73 -rebuild)
74 force_rebuild=true
76 -skipmscorlib)
77 skipmscorlib=true
79 -skipnative)
80 skipnative=true
82 -llvm)
83 llvm=true
84 test_mono_flags="$test_mono_flags --llvm"
86 -ci)
87 ci=true
89 -p:*|/p:*)
90 properties="$properties $1"
92 -m:*|/m:*)
93 properties="$properties $1"
95 -bl:*|/bl:*)
96 properties="$properties $1"
98 -dl:*|/dl:*)
99 properties="$properties $1"
102 echo "Invalid argument: $1"
103 usage
104 exit 1
106 esac
108 shift
109 done
111 CPU_COUNT=$(getconf _NPROCESSORS_ONLN || echo 4)
113 if [[ "$configuration" == "Debug" ]]; then
114 EXTRA_CFLAGS="-O0 -ggdb3 -fno-omit-frame-pointer"
115 EXTRA_CXXFLAGS="-O0 -ggdb3 -fno-omit-frame-pointer"
116 elif [[ "$configuration" == "Release" ]]; then
117 EXTRA_CFLAGS="-O2 -g"
118 EXTRA_CXXFLAGS="-O2 -g"
121 if [ "$llvm" = "true" ]; then
122 git submodule update --init -- ../external/llvm-project || (Write-PipelineTelemetryError -c "git" -e 1 "Error fetching LLVM submodule" && exit 1)
123 autogen_params="$autogen_params --enable-llvm"
126 if [[ "$configuration" == "Debug" ]]; then
127 autogen_params="$autogen_params --enable-checked-build=private_types"
130 # run .././autogen.sh only once or if "--rebuild" argument is provided
131 if [[ "$force_rebuild" == "true" || ! -f .configured ]]; then
132 (cd .. && ./autogen.sh --with-core=only $autogen_params CFLAGS="$EXTRA_CFLAGS" CXXFLAGS="$EXTRA_CXXFLAGS") || (Write-PipelineTelemetryError -c "configure" -e 1 "Error running autogen" && exit 1)
133 touch .configured
136 # build mono runtime
137 if [ "$skipnative" = "false" ]; then
138 make runtime -j$CPU_COUNT || (Write-PipelineTelemetryError -c "runtime" -e 1 "Error building unmanaged runtime" && exit 1)
141 # build System.Private.CoreLib (../mcs/class/System.Private.CoreLib)
142 if [ "$skipmscorlib" = "false" ]; then
143 make bcl CORLIB_BUILD_FLAGS="$properties" || (Write-PipelineTelemetryError -c "bcl" -e 1 "Error building System.Private.CoreLib" && exit 1)
146 # create a nupkg with runtime and System.Private.CoreLib
147 if [ "$pack" = "true" ]; then
148 if [ "$llvm" = "true" ]; then
149 make nupkg-llvm || (Write-PipelineTelemetryError -c "nupkg" -e 1 "Error packing NuGet package" && exit 1)
150 else
151 make nupkg || (Write-PipelineTelemetryError -c "nupkg" -e 1 "Error packing NuGet package" && exit 1)
155 # run all xunit tests
156 if [ "$test" = "true" ]; then
157 make update-tests-corefx || (Write-PipelineTelemetryError -c "tests-download" -e 1 "Error downloading tests" && exit 1)
158 if [ "$ci" = "true" ]; then
159 make run-tests-corefx XUNIT_MONO_ENV_OPTIONS="$test_mono_flags" XUNIT_ARGS="$test_xunit_flags" USE_TIMEOUT=1 || (Write-PipelineTelemetryError -c "tests" -e 1 "Error running tests" && exit 1)
160 else
161 make run-tests-corefx XUNIT_MONO_ENV_OPTIONS="$test_mono_flags" XUNIT_ARGS="$test_xunit_flags"