]>
Commit | Line | Data |
---|---|---|
781aab86 FG |
1 | # This workflow checks if a PR commit has changed the size of a hello world Rust program. |
2 | # It downloads Rustc and compiles two versions of a stage0 compiler - one using the base commit | |
3 | # of the PR, and one using the latest commit in the PR. | |
4 | # If the size of the hello world program has changed, it posts a comment to the PR. | |
5 | name: Check binary size | |
6 | ||
7 | on: | |
8 | pull_request_target: | |
9 | branches: | |
10 | - master | |
11 | ||
12 | jobs: | |
13 | test: | |
14 | name: Check binary size | |
15 | runs-on: ubuntu-latest | |
16 | permissions: | |
17 | pull-requests: write | |
18 | steps: | |
19 | - name: Print info | |
20 | run: | | |
21 | echo "Current SHA: ${{ github.event.pull_request.head.sha }}" | |
22 | echo "Base SHA: ${{ github.event.pull_request.base.sha }}" | |
23 | - name: Clone Rustc | |
24 | uses: actions/checkout@v3 | |
25 | with: | |
26 | repository: rust-lang/rust | |
27 | fetch-depth: 1 | |
28 | - name: Fetch backtrace | |
29 | run: git submodule update --init library/backtrace | |
30 | - name: Create hello world program that uses backtrace | |
31 | run: printf "fn main() { panic!(); }" > foo.rs | |
32 | - name: Build binary with base version of backtrace | |
33 | run: | | |
34 | printf "[llvm]\ndownload-ci-llvm = true\n\n[rust]\nincremental = false\n" > config.toml | |
35 | cd library/backtrace | |
36 | git remote add head-pr https://github.com/${{ github.event.pull_request.head.repo.full_name }} | |
37 | git fetch --all | |
38 | git checkout ${{ github.event.pull_request.base.sha }} | |
39 | cd ../.. | |
40 | git add library/backtrace | |
41 | python3 x.py build library --stage 0 | |
42 | ./build/x86_64-unknown-linux-gnu/stage0-sysroot/bin/rustc -O foo.rs -o binary-reference | |
43 | - name: Build binary with PR version of backtrace | |
44 | run: | | |
45 | cd library/backtrace | |
46 | git checkout ${{ github.event.pull_request.head.sha }} | |
47 | cd ../.. | |
48 | git add library/backtrace | |
49 | rm -rf build/x86_64-unknown-linux-gnu/stage0-std | |
50 | python3 x.py build library --stage 0 | |
51 | ./build/x86_64-unknown-linux-gnu/stage0-sysroot/bin/rustc -O foo.rs -o binary-updated | |
52 | - name: Display binary size | |
53 | run: | | |
54 | ls -la binary-* | |
55 | echo "SIZE_REFERENCE=$(stat -c '%s' binary-reference)" >> "$GITHUB_ENV" | |
56 | echo "SIZE_UPDATED=$(stat -c '%s' binary-updated)" >> "$GITHUB_ENV" | |
57 | - name: Post a PR comment if the size has changed | |
58 | uses: actions/github-script@v6 | |
59 | with: | |
60 | script: | | |
61 | const reference = process.env.SIZE_REFERENCE; | |
62 | const updated = process.env.SIZE_UPDATED; | |
63 | const diff = updated - reference; | |
64 | const plus = diff > 0 ? "+" : ""; | |
65 | const diff_str = `${plus}${diff}B`; | |
66 | ||
67 | if (diff !== 0) { | |
68 | const percent = (((updated / reference) - 1) * 100).toFixed(2); | |
69 | // The body is created here and wrapped so "weirdly" to avoid whitespace at the start of the lines, | |
70 | // which is interpreted as a code block by Markdown. | |
71 | const body = `Below is the size of a hello-world Rust program linked with libstd with backtrace. | |
72 | ||
73 | Original binary size: **${reference}B** | |
74 | Updated binary size: **${updated}B** | |
75 | Difference: **${diff_str}** (${percent}%)`; | |
76 | ||
77 | github.rest.issues.createComment({ | |
78 | issue_number: context.issue.number, | |
79 | owner: context.repo.owner, | |
80 | repo: context.repo.repo, | |
81 | body | |
82 | }) | |
83 | } |