forked from rust-lang/backtrace-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
87 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,88 @@ | ||
# This workflow checks if a PR commit has changed the size of a hello world Rust program. | ||
# It downloads Rustc and compiles two versions of a stage0 compiler - one using the base commit | ||
# of the PR, and one using the latest commit in the PR. | ||
# If the size of the hello world program has changed, it posts a comment to the PR. | ||
name: Check binary size | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- master | ||
- master | ||
|
||
jobs: | ||
test: | ||
name: Check binary size | ||
runs-on: ubuntu-latest | ||
permissions: | ||
pull-requests: write | ||
steps: | ||
- name: Print info | ||
run: | | ||
echo "Current SHA: ${{ github.sha }}" | ||
echo "Base SHA: ${{ github.event.pull_request.base.sha }}" | ||
- name: Clone Rustc | ||
run: git clone https://github.com/rust-lang/rust --depth=1 | ||
- name: Create hello world crate | ||
run: cargo new --bin /tmp/crate | ||
- name: Build reference binary | ||
run: | | ||
cd rust | ||
cp src/bootstrap/defaults/config.library.toml config.toml | ||
cd library/backtrace | ||
git fetch | ||
git checkout ${{ github.event.pull_request.base.sha }} | ||
cd ../.. | ||
python3 x.py build library --stage 0 | ||
./build/x86_64-unknown-linux-gnu/stage0/bin/rustc -O /tmp/crate/src/main.rs -o binary-reference | ||
- name: Build current binary | ||
run: | | ||
cd library/backtrace | ||
git checkout ${{ github.sha }} | ||
cd ../.. | ||
python3 x.py build library --stage 0 | ||
./build/x86_64-unknown-linux-gnu/stage0/bin/rustc -O /tmp/crate/src/main.rs -o binary-updated | ||
- name: Display binary size | ||
run: | | ||
ls -lha binary-* | ||
- name: Print info | ||
run: | | ||
echo "Current SHA: ${{ github.event.pull_request.head.sha }}" | ||
echo "Base SHA: ${{ github.event.pull_request.base.sha }}" | ||
- name: Clone Rustc | ||
uses: actions/checkout@v3 | ||
with: | ||
repository: rust-lang/rust | ||
fetch-depth: 1 | ||
- name: Fetch backtrace | ||
run: git submodule update --init library/backtrace | ||
- name: Create hello world crate | ||
run: printf "fn main() { panic!(); }" > foo.rs | ||
- name: Build binary with base version of backtrace | ||
run: | | ||
printf "[llvm]\ndownload-ci-llvm = true\n\n[rust]\nincremental = false\n" > config.toml | ||
cd library/backtrace | ||
git remote add kobzol https://github.com/kobzol/backtrace-rs | ||
git fetch --all | ||
git checkout ${{ github.event.pull_request.base.sha }} | ||
cd ../.. | ||
git add library/backtrace | ||
python3 x.py build library --stage 0 | ||
cp -r ./build/x86_64-unknown-linux-gnu/stage0/bin ./build/x86_64-unknown-linux-gnu/stage0-sysroot/bin | ||
cp -r ./build/x86_64-unknown-linux-gnu/stage0/lib/*.so ./build/x86_64-unknown-linux-gnu/stage0-sysroot/lib | ||
./build/x86_64-unknown-linux-gnu/stage0-sysroot/bin/rustc -O foo.rs -o binary-reference | ||
- name: Build binary with PR version of backtrace | ||
run: | | ||
cd library/backtrace | ||
git checkout ${{ github.event.pull_request.head.sha }} | ||
cd ../.. | ||
git add library/backtrace | ||
rm -rf build/x86_64-unknown-linux-gnu/stage0-std | ||
python3 x.py build library --stage 0 | ||
cp -r ./build/x86_64-unknown-linux-gnu/stage0/bin ./build/x86_64-unknown-linux-gnu/stage0-sysroot/bin | ||
cp -r ./build/x86_64-unknown-linux-gnu/stage0/lib/*.so ./build/x86_64-unknown-linux-gnu/stage0-sysroot/lib | ||
./build/x86_64-unknown-linux-gnu/stage0-sysroot/bin/rustc -O foo.rs -o binary-updated | ||
- name: Display binary size | ||
run: | | ||
ls -la binary-* | ||
echo "SIZE_REFERENCE=$(stat -c '%s' binary-reference)" >> "$GITHUB_ENV" | ||
echo "SIZE_UPDATED=$(stat -c '%s' binary-updated)" >> "$GITHUB_ENV" | ||
- name: Post a PR comment if the size has changed | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
const reference = process.env.SIZE_REFERENCE; | ||
const updated = process.env.SIZE_UPDATED; | ||
const diff = updated - reference; | ||
let diff_str = `${diff}B`; | ||
if (diff > 0) { | ||
diff_str = `+${diff_str}`; | ||
} | ||
if (diff !== 0) { | ||
// The body is created here and wrapped so "weirdly" to avoid whitespace at the start of the lines, | ||
// which is interpreted as a code block by Markdown. | ||
const body = `Below is the size of a hello-world Rust program linked with libstd with backtrace. | ||
Original binary size: **${reference}B** | ||
Updated binary size: **${updated}B** | ||
Difference: **${diff_str}**`; | ||
github.rest.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters