]>
Commit | Line | Data |
---|---|---|
abe05a73 | 1 | #!/usr/bin/env bash |
476ff2be SL |
2 | |
3 | set -e | |
4 | ||
83c7162d XL |
5 | if [ -n "$CI_JOB_NAME" ]; then |
6 | echo "[CI_JOB_NAME=$CI_JOB_NAME]" | |
7 | fi | |
8 | ||
8bb4bdeb XL |
9 | if [ "$NO_CHANGE_USER" = "" ]; then |
10 | if [ "$LOCAL_USER_ID" != "" ]; then | |
add651ee | 11 | id -u user &>/dev/null || useradd --shell /bin/bash -u $LOCAL_USER_ID -o -c "" -m user |
8bb4bdeb XL |
12 | export HOME=/home/user |
13 | unset LOCAL_USER_ID | |
f2b60f7d FG |
14 | |
15 | # Ensure that runners are able to execute git commands in the worktree, | |
16 | # overriding the typical git protections. In our docker container we're running | |
17 | # as root, while the user owning the checkout is not root. | |
18 | # This is only necessary when we change the user, otherwise we should | |
19 | # already be running with the right user. | |
20 | # | |
21 | # For NO_CHANGE_USER done in the small number of Dockerfiles affected. | |
22 | echo -e '[safe]\n\tdirectory = *' > /home/user/gitconfig | |
23 | ||
8bb4bdeb XL |
24 | exec su --preserve-environment -c "env PATH=$PATH \"$0\"" user |
25 | fi | |
476ff2be SL |
26 | fi |
27 | ||
8faf50e0 XL |
28 | # only enable core dump on Linux |
29 | if [ -f /proc/sys/kernel/core_pattern ]; then | |
30 | ulimit -c unlimited | |
31 | fi | |
32 | ||
3dfed10e XL |
33 | # There was a bad interaction between "old" 32-bit binaries on current 64-bit |
34 | # kernels with selinux enabled, where ASLR mmap would sometimes choose a low | |
35 | # address and then block it for being below `vm.mmap_min_addr` -> `EACCES`. | |
36 | # This is probably a kernel bug, but setting `ulimit -Hs` works around it. | |
37 | # See also `dist-i686-linux` where this setting is enabled. | |
38 | if [ "$SET_HARD_RLIMIT_STACK" = "1" ]; then | |
39 | rlimit_stack=$(ulimit -Ss) | |
40 | if [ "$rlimit_stack" != "" ]; then | |
41 | ulimit -Hs "$rlimit_stack" | |
42 | fi | |
43 | fi | |
44 | ||
8bb4bdeb XL |
45 | ci_dir=`cd $(dirname $0) && pwd` |
46 | source "$ci_dir/shared.sh" | |
47 | ||
9ffffee4 FG |
48 | export CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse |
49 | ||
c0240ec0 FG |
50 | # suppress change-tracker warnings on CI |
51 | if [ "$CI" != "" ]; then | |
52 | RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set change-id=99999999" | |
53 | fi | |
54 | ||
ed00b5ec FG |
55 | if ! isCI || isCiBranch auto || isCiBranch beta || isCiBranch try || isCiBranch try-perf || \ |
56 | isCiBranch automation/bors/try; then | |
94b46f34 | 57 | RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set build.print-step-timings --enable-verbose-tests" |
923072b8 | 58 | RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set build.metrics" |
9c376795 | 59 | HAS_METRICS=1 |
7cac9316 XL |
60 | fi |
61 | ||
fe692bf9 | 62 | RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-verbose-configure" |
32a655c1 | 63 | RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-sccache" |
32a655c1 | 64 | RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --disable-manage-submodules" |
8bb4bdeb | 65 | RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-locked-deps" |
0bf4aa26 | 66 | RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-cargo-native-static" |
a1dfa0c6 | 67 | RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.codegen-units-std=1" |
353b0b11 FG |
68 | # rust-lang/promote-release will recompress CI artifacts, and while we care |
69 | # about the per-commit artifact sizes, it's not as important that they're | |
70 | # highly compressed as it is that the process is fast. Best compression | |
71 | # generally implies single-threaded compression which results in wasting most | |
72 | # of our CPU resources. | |
73 | RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set dist.compression-profile=balanced" | |
8bb4bdeb | 74 | |
9ffffee4 FG |
75 | # When building for mingw, limit the number of parallel linker jobs during |
76 | # the LLVM build, as not to run out of memory. | |
77 | # This is an attempt to fix the spurious build error tracked by | |
78 | # https://github.com/rust-lang/rust/issues/108227. | |
c620b35d | 79 | if isKnownToBeMingwBuild; then |
9ffffee4 FG |
80 | RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set llvm.link-jobs=1" |
81 | fi | |
82 | ||
5869c6ff XL |
83 | # Only produce xz tarballs on CI. gz tarballs will be generated by the release |
84 | # process by recompressing the existing xz ones. This decreases the storage | |
85 | # space required for CI artifacts. | |
86 | RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --dist-compression-formats=xz" | |
87 | ||
c0240ec0 FG |
88 | # Enable the `c` feature for compiler_builtins, but only when the `compiler-rt` source is available |
89 | # (to avoid spending a lot of time cloning llvm) | |
90 | if [ "$EXTERNAL_LLVM" = "" ]; then | |
91 | RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set build.optimized-compiler-builtins" | |
31ef2f64 FG |
92 | # Likewise, only demand we test all LLVM components if we know we built LLVM with them |
93 | export COMPILETEST_REQUIRE_ALL_LLVM_COMPONENTS=1 | |
c0240ec0 FG |
94 | elif [ "$DEPLOY$DEPLOY_ALT" = "1" ]; then |
95 | echo "error: dist builds should always use optimized compiler-rt!" >&2 | |
96 | exit 1 | |
97 | fi | |
98 | ||
8bb4bdeb XL |
99 | if [ "$DIST_SRC" = "" ]; then |
100 | RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --disable-dist-src" | |
101 | fi | |
32a655c1 | 102 | |
dfeec247 XL |
103 | # Always set the release channel for bootstrap; this is normally not important (i.e., only dist |
104 | # builds would seem to matter) but in practice bootstrap wants to know whether we're targeting | |
105 | # master, beta, or stable with a build to determine whether to run some checks (notably toolstate). | |
17df50a5 | 106 | export RUST_RELEASE_CHANNEL=$(releaseChannel) |
dfeec247 XL |
107 | RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --release-channel=$RUST_RELEASE_CHANNEL" |
108 | ||
dc9dc135 | 109 | if [ "$DEPLOY$DEPLOY_ALT" = "1" ]; then |
32a655c1 | 110 | RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-llvm-static-stdcpp" |
b7449926 | 111 | RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.remap-debuginfo" |
dc9dc135 | 112 | RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --debuginfo-level-std=1" |
32a655c1 SL |
113 | |
114 | if [ "$NO_LLVM_ASSERTIONS" = "1" ]; then | |
115 | RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --disable-llvm-assertions" | |
8bb4bdeb | 116 | elif [ "$DEPLOY_ALT" != "" ]; then |
ed00b5ec FG |
117 | if [ "$ALT_PARALLEL_COMPILER" = "" ]; then |
118 | RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.parallel-compiler=false" | |
e74abb32 | 119 | fi |
abe05a73 | 120 | RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-llvm-assertions" |
0bf4aa26 | 121 | RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.verify-llvm-ir" |
32a655c1 | 122 | fi |
ed00b5ec | 123 | |
c0240ec0 FG |
124 | CODEGEN_BACKENDS="${CODEGEN_BACKENDS:-llvm}" |
125 | RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.codegen-backends=$CODEGEN_BACKENDS" | |
32a655c1 | 126 | else |
ea8adc8c XL |
127 | # We almost always want debug assertions enabled, but sometimes this takes too |
128 | # long for too little benefit, so we just turn them off. | |
129 | if [ "$NO_DEBUG_ASSERTIONS" = "" ]; then | |
130 | RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-debug-assertions" | |
131 | fi | |
32a655c1 | 132 | |
3c0e092e XL |
133 | # Same for overflow checks |
134 | if [ "$NO_OVERFLOW_CHECKS" = "" ]; then | |
135 | RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-overflow-checks" | |
136 | fi | |
137 | ||
32a655c1 SL |
138 | # In general we always want to run tests with LLVM assertions enabled, but not |
139 | # all platforms currently support that, so we have an option to disable. | |
140 | if [ "$NO_LLVM_ASSERTIONS" = "" ]; then | |
141 | RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-llvm-assertions" | |
142 | fi | |
0bf4aa26 XL |
143 | |
144 | RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.verify-llvm-ir" | |
f2b60f7d | 145 | |
ed00b5ec FG |
146 | # When running gcc backend tests, we need to install `libgccjit` and to not run llvm codegen |
147 | # tests as it will fail them. | |
148 | if [[ "${ENABLE_GCC_CODEGEN}" == "1" ]]; then | |
149 | # Test the Cranelift and GCC backends in CI. Bootstrap knows which targets to run tests on. | |
c0240ec0 | 150 | CODEGEN_BACKENDS="${CODEGEN_BACKENDS:-llvm,cranelift,gcc}" |
ed00b5ec FG |
151 | else |
152 | # Test the Cranelift backend in CI. Bootstrap knows which targets to run tests on. | |
c0240ec0 | 153 | CODEGEN_BACKENDS="${CODEGEN_BACKENDS:-llvm,cranelift}" |
ed00b5ec | 154 | fi |
c0240ec0 | 155 | RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.codegen-backends=$CODEGEN_BACKENDS" |
781aab86 | 156 | |
f2b60f7d FG |
157 | # We enable this for non-dist builders, since those aren't trying to produce |
158 | # fresh binaries. We currently don't entirely support distributing a fresh | |
159 | # copy of the compiler (including llvm tools, etc.) if we haven't actually | |
160 | # built LLVM, since not everything necessary is copied into the | |
161 | # local-usage-only LLVM artifacts. If that changes, this could maybe be made | |
162 | # true for all builds. In practice it's probably a good idea to keep building | |
163 | # LLVM continuously on at least some builders to ensure it works, though. | |
164 | # (And PGO is its own can of worms). | |
165 | if [ "$NO_DOWNLOAD_CI_LLVM" = "" ]; then | |
4b012472 | 166 | RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set llvm.download-ci-llvm=if-unchanged" |
487cf647 FG |
167 | else |
168 | # When building for CI we want to use the static C++ Standard library | |
169 | # included with LLVM, since a dynamic libstdcpp may not be available. | |
170 | RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set llvm.static-libstdcpp" | |
f2b60f7d | 171 | fi |
0bf4aa26 XL |
172 | fi |
173 | ||
4b012472 FG |
174 | if [ "$ENABLE_GCC_CODEGEN" = "1" ]; then |
175 | # If `ENABLE_GCC_CODEGEN` is set and not empty, we add the `--enable-new-symbol-mangling` | |
176 | # argument to `RUST_CONFIGURE_ARGS` and set the `GCC_EXEC_PREFIX` environment variable. | |
177 | # `cg_gcc` doesn't support the legacy mangling so we need to enforce the new one | |
178 | # if we run `cg_gcc` tests. | |
179 | RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-new-symbol-mangling" | |
180 | fi | |
181 | ||
e1599b0c XL |
182 | # Print the date from the local machine and the date from an external source to |
183 | # check for clock drifts. An HTTP URL is used instead of HTTPS since on Azure | |
184 | # Pipelines it happened that the certificates were marked as expired. | |
185 | datecheck() { | |
add651ee FG |
186 | # If an error has happened, we do not want to start a new group, because that will collapse |
187 | # a previous group that might have contained the error log. | |
188 | exit_code=$? | |
189 | ||
190 | if [ $exit_code -eq 0 ] | |
191 | then | |
192 | echo "::group::Clock drift check" | |
193 | fi | |
194 | ||
e1599b0c XL |
195 | echo -n " local time: " |
196 | date | |
197 | echo -n " network time: " | |
3c0e092e | 198 | curl -fs --head http://ci-caches.rust-lang.org | grep ^Date: \ |
e1599b0c | 199 | | sed 's/Date: //g' || true |
add651ee FG |
200 | |
201 | if [ $exit_code -eq 0 ] | |
202 | then | |
203 | echo "::endgroup::" | |
204 | fi | |
e1599b0c XL |
205 | } |
206 | datecheck | |
207 | trap datecheck EXIT | |
208 | ||
0531ce1d XL |
209 | # We've had problems in the past of shell scripts leaking fds into the sccache |
210 | # server (#48192) which causes Cargo to erroneously think that a build script | |
211 | # hasn't finished yet. Try to solve that problem by starting a very long-lived | |
212 | # sccache server at the start of the build, but no need to worry if this fails. | |
213 | SCCACHE_IDLE_TIMEOUT=10800 sccache --start-server || true | |
214 | ||
add651ee FG |
215 | # Our build may overwrite config.toml, so we remove it here |
216 | rm -f config.toml | |
217 | ||
32a655c1 | 218 | $SRC/configure $RUST_CONFIGURE_ARGS |
7cac9316 | 219 | |
8bb4bdeb | 220 | retry make prepare |
476ff2be | 221 | |
0531ce1d XL |
222 | # Display the CPU and memory information. This helps us know why the CI timing |
223 | # is fluctuating. | |
add651ee | 224 | echo "::group::Display CPU and Memory information" |
e74abb32 | 225 | if isMacOS; then |
0531ce1d XL |
226 | system_profiler SPHardwareDataType || true |
227 | sysctl hw || true | |
476ff2be SL |
228 | ncpus=$(sysctl -n hw.ncpu) |
229 | else | |
0531ce1d XL |
230 | cat /proc/cpuinfo || true |
231 | cat /proc/meminfo || true | |
32a655c1 | 232 | ncpus=$(grep processor /proc/cpuinfo | wc -l) |
476ff2be | 233 | fi |
add651ee | 234 | echo "::endgroup::" |
476ff2be | 235 | |
32a655c1 | 236 | if [ ! -z "$SCRIPT" ]; then |
fe692bf9 | 237 | echo "Executing ${SCRIPT}" |
32a655c1 | 238 | sh -x -c "$SCRIPT" |
476ff2be | 239 | else |
7cac9316 | 240 | do_make() { |
7cac9316 | 241 | echo "make -j $ncpus $1" |
0531ce1d | 242 | make -j $ncpus $1 |
7cac9316 | 243 | local retval=$? |
7cac9316 XL |
244 | return $retval |
245 | } | |
246 | ||
7cac9316 | 247 | do_make "$RUST_CHECK_TARGET" |
476ff2be | 248 | fi |
dc9dc135 | 249 | |
9c376795 FG |
250 | if [ "$RUN_CHECK_WITH_PARALLEL_QUERIES" != "" ]; then |
251 | rm -f config.toml | |
c0240ec0 | 252 | $SRC/configure --set change-id=99999999 --set rust.parallel-compiler |
9c376795 FG |
253 | |
254 | # Save the build metrics before we wipe the directory | |
255 | if [ "$HAS_METRICS" = 1 ]; then | |
256 | mv build/metrics.json . | |
257 | fi | |
258 | rm -rf build | |
259 | if [ "$HAS_METRICS" = 1 ]; then | |
260 | mkdir build | |
261 | mv metrics.json build | |
262 | fi | |
263 | ||
264 | CARGO_INCREMENTAL=0 ../x check | |
265 | fi | |
266 | ||
add651ee | 267 | echo "::group::sccache stats" |
dc9dc135 | 268 | sccache --show-stats || true |
add651ee | 269 | echo "::endgroup::" |