]> git.lizzy.rs Git - rust.git/blob - src/ci/run.sh
Make timer hierarchical
[rust.git] / src / ci / run.sh
1 #!/usr/bin/env bash
2
3 set -e
4
5 if [ -n "$CI_JOB_NAME" ]; then
6   echo "[CI_JOB_NAME=$CI_JOB_NAME]"
7 fi
8
9 if [ "$NO_CHANGE_USER" = "" ]; then
10   if [ "$LOCAL_USER_ID" != "" ]; then
11     useradd --shell /bin/bash -u $LOCAL_USER_ID -o -c "" -m user
12     export HOME=/home/user
13     unset LOCAL_USER_ID
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
24     exec su --preserve-environment -c "env PATH=$PATH \"$0\"" user
25   fi
26 fi
27
28 # only enable core dump on Linux
29 if [ -f /proc/sys/kernel/core_pattern ]; then
30   ulimit -c unlimited
31 fi
32
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
45 ci_dir=`cd $(dirname $0) && pwd`
46 source "$ci_dir/shared.sh"
47
48 if ! isCI || isCiBranch auto || isCiBranch beta || isCiBranch try || isCiBranch try-perf; then
49     RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set build.print-step-timings --enable-verbose-tests"
50     RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set build.metrics"
51     HAS_METRICS=1
52 fi
53
54 RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-sccache"
55 RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --disable-manage-submodules"
56 RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-locked-deps"
57 RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-cargo-native-static"
58 RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.codegen-units-std=1"
59
60 # Only produce xz tarballs on CI. gz tarballs will be generated by the release
61 # process by recompressing the existing xz ones. This decreases the storage
62 # space required for CI artifacts.
63 RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --dist-compression-formats=xz"
64
65 if [ "$DIST_SRC" = "" ]; then
66   RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --disable-dist-src"
67 fi
68
69 # Always set the release channel for bootstrap; this is normally not important (i.e., only dist
70 # builds would seem to matter) but in practice bootstrap wants to know whether we're targeting
71 # master, beta, or stable with a build to determine whether to run some checks (notably toolstate).
72 export RUST_RELEASE_CHANNEL=$(releaseChannel)
73 RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --release-channel=$RUST_RELEASE_CHANNEL"
74
75 if [ "$DEPLOY$DEPLOY_ALT" = "1" ]; then
76   RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-llvm-static-stdcpp"
77   RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.remap-debuginfo"
78   RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --debuginfo-level-std=1"
79
80   if [ "$NO_LLVM_ASSERTIONS" = "1" ]; then
81     RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --disable-llvm-assertions"
82   elif [ "$DEPLOY_ALT" != "" ]; then
83     if [ "$NO_PARALLEL_COMPILER" = "" ]; then
84       RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.parallel-compiler"
85     fi
86     RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-llvm-assertions"
87     RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.verify-llvm-ir"
88   fi
89 else
90   # We almost always want debug assertions enabled, but sometimes this takes too
91   # long for too little benefit, so we just turn them off.
92   if [ "$NO_DEBUG_ASSERTIONS" = "" ]; then
93     RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-debug-assertions"
94   fi
95
96   # Same for overflow checks
97   if [ "$NO_OVERFLOW_CHECKS" = "" ]; then
98     RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-overflow-checks"
99   fi
100
101   # In general we always want to run tests with LLVM assertions enabled, but not
102   # all platforms currently support that, so we have an option to disable.
103   if [ "$NO_LLVM_ASSERTIONS" = "" ]; then
104     RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-llvm-assertions"
105   fi
106
107   RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.verify-llvm-ir"
108
109   # We enable this for non-dist builders, since those aren't trying to produce
110   # fresh binaries. We currently don't entirely support distributing a fresh
111   # copy of the compiler (including llvm tools, etc.) if we haven't actually
112   # built LLVM, since not everything necessary is copied into the
113   # local-usage-only LLVM artifacts. If that changes, this could maybe be made
114   # true for all builds. In practice it's probably a good idea to keep building
115   # LLVM continuously on at least some builders to ensure it works, though.
116   # (And PGO is its own can of worms).
117   if [ "$NO_DOWNLOAD_CI_LLVM" = "" ]; then
118     RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set llvm.download-ci-llvm=if-available"
119   else
120     # When building for CI we want to use the static C++ Standard library
121     # included with LLVM, since a dynamic libstdcpp may not be available.
122     RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set llvm.static-libstdcpp"
123   fi
124 fi
125
126 if [ "$RUST_RELEASE_CHANNEL" = "nightly" ] || [ "$DIST_REQUIRE_ALL_TOOLS" = "" ]; then
127     RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-missing-tools"
128 fi
129
130 export COMPILETEST_NEEDS_ALL_LLVM_COMPONENTS=1
131
132 # Print the date from the local machine and the date from an external source to
133 # check for clock drifts. An HTTP URL is used instead of HTTPS since on Azure
134 # Pipelines it happened that the certificates were marked as expired.
135 datecheck() {
136   echo "== clock drift check =="
137   echo -n "  local time: "
138   date
139   echo -n "  network time: "
140   curl -fs --head http://ci-caches.rust-lang.org | grep ^Date: \
141       | sed 's/Date: //g' || true
142   echo "== end clock drift check =="
143 }
144 datecheck
145 trap datecheck EXIT
146
147 # We've had problems in the past of shell scripts leaking fds into the sccache
148 # server (#48192) which causes Cargo to erroneously think that a build script
149 # hasn't finished yet. Try to solve that problem by starting a very long-lived
150 # sccache server at the start of the build, but no need to worry if this fails.
151 SCCACHE_IDLE_TIMEOUT=10800 sccache --start-server || true
152
153 $SRC/configure $RUST_CONFIGURE_ARGS
154
155 retry make prepare
156
157 # Display the CPU and memory information. This helps us know why the CI timing
158 # is fluctuating.
159 if isMacOS; then
160     system_profiler SPHardwareDataType || true
161     sysctl hw || true
162     ncpus=$(sysctl -n hw.ncpu)
163 else
164     cat /proc/cpuinfo || true
165     cat /proc/meminfo || true
166     ncpus=$(grep processor /proc/cpuinfo | wc -l)
167 fi
168
169 if [ ! -z "$SCRIPT" ]; then
170   sh -x -c "$SCRIPT"
171 else
172   do_make() {
173     echo "make -j $ncpus $1"
174     make -j $ncpus $1
175     local retval=$?
176     return $retval
177   }
178
179   do_make "$RUST_CHECK_TARGET"
180 fi
181
182 if [ "$RUN_CHECK_WITH_PARALLEL_QUERIES" != "" ]; then
183   rm -f config.toml
184   $SRC/configure --set rust.parallel-compiler
185
186   # Save the build metrics before we wipe the directory
187   if [ "$HAS_METRICS" = 1 ]; then
188     mv build/metrics.json .
189   fi
190   rm -rf build
191   if [ "$HAS_METRICS" = 1 ]; then
192     mkdir build
193     mv metrics.json build
194   fi
195
196   CARGO_INCREMENTAL=0 ../x check
197 fi
198
199 sccache --show-stats || true