]> git.lizzy.rs Git - rust.git/blob - src/ci/pgo.sh
Rollup merge of #79849 - Digital-Chaos:sleep-zero, r=m-ou-se
[rust.git] / src / ci / pgo.sh
1 #!/bin/bash
2
3 set -euxo pipefail
4
5 rm -rf /tmp/rustc-pgo
6
7 python2.7 ../x.py build --target=$PGO_HOST --host=$PGO_HOST \
8     --stage 2 library/std --rust-profile-generate=/tmp/rustc-pgo
9
10 ./build/$PGO_HOST/stage2/bin/rustc --edition=2018 \
11     --crate-type=lib ../library/core/src/lib.rs
12
13 # Download and build a single-file stress test benchmark on perf.rust-lang.org.
14 function pgo_perf_benchmark {
15     local PERF=e095f5021bf01cf3800f50b3a9f14a9683eb3e4e
16     local github_prefix=https://raw.githubusercontent.com/rust-lang/rustc-perf/$PERF
17     local name=$1
18     curl -o /tmp/$name.rs $github_prefix/collector/benchmarks/$name/src/lib.rs
19     ./build/$PGO_HOST/stage2/bin/rustc --edition=2018 --crate-type=lib /tmp/$name.rs
20 }
21
22 pgo_perf_benchmark externs
23 pgo_perf_benchmark ctfe-stress-4
24
25 cp -pri ../src/tools/cargo /tmp/cargo
26
27 # The Cargo repository does not have a Cargo.lock in it, as it relies on the
28 # lockfile already present in the rust-lang/rust monorepo. This decision breaks
29 # down when Cargo is built outside the monorepo though (like in this case),
30 # resulting in a build without any dependency locking.
31 #
32 # To ensure Cargo is built with locked dependencies even during PGO profiling
33 # the following command copies the monorepo's lockfile into the Cargo temporary
34 # directory. Cargo will *not* keep that lockfile intact, as it will remove all
35 # the dependencies Cargo itself doesn't rely on. Still, it will prevent
36 # building Cargo with arbitrary dependency versions.
37 #
38 # See #81378 for the bug that prompted adding this.
39 cp -p ../Cargo.lock /tmp/cargo
40
41 # Build cargo (with some flags)
42 function pgo_cargo {
43     RUSTC=./build/$PGO_HOST/stage2/bin/rustc \
44         ./build/$PGO_HOST/stage0/bin/cargo $@ \
45         --manifest-path /tmp/cargo/Cargo.toml
46 }
47
48 # Build a couple different variants of Cargo
49 CARGO_INCREMENTAL=1 pgo_cargo check
50 echo 'pub fn barbarbar() {}' >> /tmp/cargo/src/cargo/lib.rs
51 CARGO_INCREMENTAL=1 pgo_cargo check
52 touch /tmp/cargo/src/cargo/lib.rs
53 CARGO_INCREMENTAL=1 pgo_cargo check
54 pgo_cargo build --release
55
56 # Merge the profile data we gathered
57 ./build/$PGO_HOST/llvm/bin/llvm-profdata \
58     merge -o /tmp/rustc-pgo.profdata /tmp/rustc-pgo
59
60 # This produces the actual final set of artifacts.
61 $@ --rust-profile-use=/tmp/rustc-pgo.profdata