@@ -15,51 +15,92 @@ jobs:
1515 runs-on : ubuntu-latest
1616 permissions :
1717 pull-requests : write
18+ env :
19+ # This cannot be used as a context variable in the 'uses' key later. If it
20+ # changes, update those steps too.
21+ BACKTRACE_DIR : backtrace
22+ RUSTC_DIR : rustc
23+ TEST_MAIN_RS : foo.rs
24+ BASE_COMMIT : ${{ github.event.pull_request.base.sha }}
25+ HEAD_COMMIT : ${{ github.event.pull_request.head.sha }}
1826 steps :
1927 - name : Print info
28+ shell : bash
2029 run : |
21- echo "Current SHA: ${{ github.event.pull_request.head.sha }}"
22- echo "Base SHA: ${{ github.event.pull_request.base.sha }}"
30+ echo "Current SHA: $HEAD_COMMIT"
31+ echo "Base SHA: $BASE_COMMIT"
32+ # Note: the backtrace source that's cloned here is NOT the version to be
33+ # patched in to std. It's cloned here to access the Github action for
34+ # building the test binary and measuring its size.
35+ - name : Clone backtrace to access Github action
36+ uses : actions/checkout@v3
37+ with :
38+ path : ${{ env.BACKTRACE_DIR }}
2339 - name : Clone Rustc
2440 uses : actions/checkout@v3
2541 with :
2642 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
43+ path : ${{ env.RUSTC_DIR }}
44+ - name : Set up std repository and backtrace submodule for size test
45+ shell : bash
46+ working-directory : ${{ env.RUSTC_DIR }}
47+ env :
48+ PR_SOURCE_REPO : ${{ github.event.pull_request.head.repo.full_name }}
3349 run : |
34- printf "[llvm]\ndownload-ci-llvm = true\n\n[rust]\nincremental = false\n" > config.toml
50+ # Bootstrap config
51+ cat <<EOF > config.toml
52+ [llvm]
53+ download-ci-llvm = true
54+ [rust]
55+ incremental = false
56+ EOF
57+
58+ # Test program source
59+ cat <<EOF > $TEST_MAIN_RS
60+ fn main() {
61+ panic!();
62+ }
63+ EOF
64+
65+ git submodule update --init library/backtrace
66+
3567 cd library/backtrace
36- git remote add head-pr https://github.com/${{ github.event.pull_request.head.repo.full_name }}
68+ git remote add head-pr " https://github.com/$PR_SOURCE_REPO"
3769 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
70+ - name : Build binary with base version of backtrace
71+ uses : ./backtrace/.github/actions/build-with-patched-std
72+ with :
73+ backtrace-commit : ${{ env.BASE_COMMIT }}
74+ main-rs : ${{ env.TEST_MAIN_RS }}
75+ rustc-dir : ${{ env.RUSTC_DIR }}
76+ id : size-reference
4377 - 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"
78+ uses : ./backtrace/.github/actions/build-with-patched-std
79+ with :
80+ backtrace-commit : ${{ env.HEAD_COMMIT }}
81+ main-rs : ${{ env.TEST_MAIN_RS }}
82+ rustc-dir : ${{ env.RUSTC_DIR }}
83+ id : size-updated
5784 - name : Post a PR comment if the size has changed
5885 uses : actions/github-script@v6
86+ env :
87+ SIZE_REFERENCE : ${{ steps.size-reference.outputs.test-binary-size }}
88+ SIZE_UPDATED : ${{ steps.size-updated.outputs.test-binary-size }}
5989 with :
6090 script : |
6191 const reference = process.env.SIZE_REFERENCE;
6292 const updated = process.env.SIZE_UPDATED;
93+
94+ if (!(reference > 0)) {
95+ core.setFailed(`Reference size invalid: ${reference}`);
96+ return;
97+ }
98+
99+ if (!(updated > 0)) {
100+ core.setFailed(`Updated size invalid: ${updated}`);
101+ return;
102+ }
103+
63104 const diff = updated - reference;
64105 const plus = diff > 0 ? "+" : "";
65106 const diff_str = `${plus}${diff}B`;
0 commit comments