Skip to content

Commit 093b0a4

Browse files
committed
WIP
1 parent 916846c commit 093b0a4

File tree

3 files changed

+82
-30
lines changed

3 files changed

+82
-30
lines changed
Lines changed: 73 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,84 @@
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.
15
name: Check binary size
26

37
on:
48
pull_request:
59
branches:
6-
- master
10+
- master
711

812
jobs:
913
test:
1014
name: Check binary size
1115
runs-on: ubuntu-latest
16+
permissions:
17+
pull-requests: write
1218
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+
}

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "backtrace"
3-
version = "0.3.68"
3+
version = "0.3.69"
44
authors = ["The Rust Project Developers"]
55
build = "build.rs"
66
license = "MIT OR Apache-2.0"

src/capture.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use std::prelude::v1::*;
88
#[cfg(feature = "serde")]
99
use serde::{Deserialize, Serialize};
1010

11+
pub const SHAKESPEARE: &str = include_str!("shakespeare.txt");
12+
1113
/// Representation of an owned and self-contained backtrace.
1214
///
1315
/// This structure can be used to capture a backtrace at various points in a
@@ -108,6 +110,11 @@ pub struct BacktraceSymbol {
108110
colno: Option<u32>,
109111
}
110112

113+
#[allow(unused)]
114+
pub fn foo() {
115+
println!("FOO");
116+
}
117+
111118
impl Backtrace {
112119
/// Captures a backtrace at the callsite of this function, returning an
113120
/// owned representation.
@@ -137,6 +144,7 @@ impl Backtrace {
137144
/// enabled, and the `std` feature is enabled by default.
138145
#[inline(never)] // want to make sure there's a frame here to remove
139146
pub fn new() -> Backtrace {
147+
println!("FOO");
140148
let mut bt = Self::create(Self::new as usize);
141149
bt.resolve();
142150
bt

0 commit comments

Comments
 (0)