|
| 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. |
1 | 5 | name: Check binary size
|
2 | 6 |
|
3 | 7 | on:
|
4 | 8 | pull_request:
|
5 | 9 | branches:
|
6 |
| - - master |
| 10 | + - master |
7 | 11 |
|
8 | 12 | jobs:
|
9 | 13 | test:
|
10 | 14 | name: Check binary size
|
11 | 15 | runs-on: ubuntu-latest
|
| 16 | + permissions: |
| 17 | + pull-requests: write |
12 | 18 | steps:
|
13 |
| - - name: Print info |
14 |
| - run: | |
15 |
| - echo "Current SHA: ${{ github.sha }}" |
16 |
| - echo "Base SHA: ${{ github.event.pull_request.base.sha }}" |
17 |
| - - name: Clone Rustc |
18 |
| - run: git clone https://github.com/rust-lang/rust --depth=1 |
19 |
| - - name: Create hello world crate |
20 |
| - run: cargo new --bin /tmp/crate |
21 |
| - - name: Build reference binary |
22 |
| - run: | |
23 |
| - cd rust |
24 |
| - cp src/bootstrap/defaults/config.library.toml config.toml |
25 |
| - cd library/backtrace |
26 |
| - git fetch |
27 |
| - git checkout ${{ github.event.pull_request.base.sha }} |
28 |
| - cd ../.. |
29 |
| - python3 x.py build library --stage 0 |
30 |
| - ./build/x86_64-unknown-linux-gnu/stage0/bin/rustc -O /tmp/crate/src/main.rs -o binary-reference |
31 |
| - - name: Build current binary |
32 |
| - run: | |
33 |
| - cd library/backtrace |
34 |
| - git checkout ${{ github.sha }} |
35 |
| - cd ../.. |
36 |
| - python3 x.py build library --stage 0 |
37 |
| - ./build/x86_64-unknown-linux-gnu/stage0/bin/rustc -O /tmp/crate/src/main.rs -o binary-updated |
38 |
| - - name: Display binary size |
39 |
| - run: | |
40 |
| - ls -lha binary-* |
| 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 | + run: | |
| 25 | + git clone https://github.com/rust-lang/rust --depth=1 |
| 26 | + cd rust |
| 27 | + git submodule update --init library/backtrace |
| 28 | + - name: Create hello world crate |
| 29 | + run: cargo new --bin /tmp/hello |
| 30 | + - name: Build binary with base version of backtrace |
| 31 | + run: | |
| 32 | + cd rust |
| 33 | + printf "[llvm]\ndownload-ci-llvm = true\n\n[rust]\nincremental = false\n" > config.toml |
| 34 | + cd library/backtrace |
| 35 | + git remote add kobzol https://github.com/kobzol/backtrace-rs |
| 36 | + git fetch --all |
| 37 | + git checkout ${{ github.event.pull_request.base.sha }} |
| 38 | + cd ../.. |
| 39 | + git add library/backtrace |
| 40 | + python3 x.py build library --stage 0 |
| 41 | + ./build/x86_64-unknown-linux-gnu/stage0/bin/rustc \ |
| 42 | + --sysroot ./build/x86_64-unknown-linux-gnu/stage0 \ |
| 43 | + -O /tmp/hello/src/main.rs -o binary-reference |
| 44 | + - name: Build binary with PR version of backtrace |
| 45 | + run: | |
| 46 | + cd rust |
| 47 | + cd library/backtrace |
| 48 | + git checkout ${{ github.event.pull_request.head.sha }} |
| 49 | + cd ../.. |
| 50 | + git add library/backtrace |
| 51 | + rm -rf build/x86_64-unknown-linux-gnu/stage0-std |
| 52 | + python3 x.py build library --stage 0 |
| 53 | + ./build/x86_64-unknown-linux-gnu/stage0/bin/rustc \ |
| 54 | + --sysroot ./build/x86_64-unknown-linux-gnu/stage0 \ |
| 55 | + -O /tmp/hello/src/main.rs -o binary-updated |
| 56 | + - name: Display binary size |
| 57 | + run: | |
| 58 | + ls -la rust/binary-* |
| 59 | + echo "SIZE_REFERENCE=$(stat -c '%s' rust/binary-reference)" >> "$GITHUB_ENV" |
| 60 | + echo "SIZE_UPDATED=$(stat -c '%s' rust/binary-updated)" >> "$GITHUB_ENV" |
| 61 | + - name: Post a PR comment if the size has changed |
| 62 | + uses: actions/github-script@v6 |
| 63 | + with: |
| 64 | + script: | |
| 65 | + const reference = process.env.SIZE_REFERENCE; |
| 66 | + const updated = process.env.SIZE_UPDATED; |
| 67 | + const diff = updated - reference; |
| 68 | + let diff_str = `${diff}B`; |
| 69 | + if (diff > 0) { |
| 70 | + diff_str = `+${diff_str}`; |
| 71 | + } |
| 72 | +
|
| 73 | + if (diff !== 0) { |
| 74 | + github.rest.issues.createComment({ |
| 75 | + issue_number: context.issue.number, |
| 76 | + owner: context.repo.owner, |
| 77 | + repo: context.repo.repo, |
| 78 | + body: `Below is the size of a hello-world Rust program linked with libstd with backtrace. |
| 79 | +
|
| 80 | + Original binary size: **${reference}B** |
| 81 | + Updated binary size: **${updated}B** |
| 82 | + Difference: **${diff_str}**` |
| 83 | + }) |
| 84 | + } |
0 commit comments