]> git.proxmox.com Git - rustc.git/blame - src/ci/pgo.sh
Merge tag 'debian/1.52.1+dfsg1-1_exp2' into proxmox/buster
[rustc.git] / src / ci / pgo.sh
CommitLineData
fc512014
XL
1#!/bin/bash
2
3set -euxo pipefail
4
fc512014
XL
5rm -rf /tmp/rustc-pgo
6
7python2.7 ../x.py build --target=$PGO_HOST --host=$PGO_HOST \
8 --stage 2 library/std --rust-profile-generate=/tmp/rustc-pgo
9
6a06907d 10RUSTC_BOOTSTRAP=1 ./build/$PGO_HOST/stage2/bin/rustc --edition=2018 \
fc512014
XL
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.
14function 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
6a06907d
XL
19
20 RUSTC_BOOTSTRAP=1 ./build/$PGO_HOST/stage2/bin/rustc --edition=2018 \
21 --crate-type=lib /tmp/$name.rs
fc512014
XL
22}
23
24pgo_perf_benchmark externs
25pgo_perf_benchmark ctfe-stress-4
26
27cp -pri ../src/tools/cargo /tmp/cargo
28
5869c6ff
XL
29# The Cargo repository does not have a Cargo.lock in it, as it relies on the
30# lockfile already present in the rust-lang/rust monorepo. This decision breaks
31# down when Cargo is built outside the monorepo though (like in this case),
32# resulting in a build without any dependency locking.
33#
34# To ensure Cargo is built with locked dependencies even during PGO profiling
35# the following command copies the monorepo's lockfile into the Cargo temporary
36# directory. Cargo will *not* keep that lockfile intact, as it will remove all
37# the dependencies Cargo itself doesn't rely on. Still, it will prevent
38# building Cargo with arbitrary dependency versions.
39#
40# See #81378 for the bug that prompted adding this.
41cp -p ../Cargo.lock /tmp/cargo
42
fc512014
XL
43# Build cargo (with some flags)
44function pgo_cargo {
45 RUSTC=./build/$PGO_HOST/stage2/bin/rustc \
46 ./build/$PGO_HOST/stage0/bin/cargo $@ \
47 --manifest-path /tmp/cargo/Cargo.toml
48}
49
50# Build a couple different variants of Cargo
51CARGO_INCREMENTAL=1 pgo_cargo check
52echo 'pub fn barbarbar() {}' >> /tmp/cargo/src/cargo/lib.rs
53CARGO_INCREMENTAL=1 pgo_cargo check
54touch /tmp/cargo/src/cargo/lib.rs
55CARGO_INCREMENTAL=1 pgo_cargo check
56pgo_cargo build --release
57
58# Merge the profile data we gathered
59./build/$PGO_HOST/llvm/bin/llvm-profdata \
60 merge -o /tmp/rustc-pgo.profdata /tmp/rustc-pgo
61
62# This produces the actual final set of artifacts.
63$@ --rust-profile-use=/tmp/rustc-pgo.profdata