@@ -15,55 +15,88 @@ 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
2028 run : |
21- echo "Current SHA: ${{ github.event.pull_request.head.sha }}"
22- echo "Base SHA: ${{ github.event.pull_request.base.sha }}"
29+ echo "Current SHA: $HEAD_COMMIT"
30+ echo "Base SHA: $BASE_COMMIT"
31+ # Note: the backtrace source that's cloned here is NOT the version to be
32+ # patched in to std. It's cloned here to access the Github action for
33+ # building the test binary and measuring its size.
34+ - name : Clone backtrace to access Github action
35+ uses : actions/checkout@v3
36+ with :
37+ path : ${{ env.BACKTRACE_DIR }}
2338 - name : Clone Rustc
2439 uses : actions/checkout@v3
2540 with :
2641 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
42+ path : ${{ env.RUSTC_DIR }}
43+ - name : Set up std repository and backtrace submodule for size test
44+ working-directory : ${{ env.RUSTC_DIR }}
3345 run : |
34- printf "[llvm]\ndownload-ci-llvm = true\n\n[rust]\nincremental = false\n" > config.toml
46+ # Bootstrap config
47+ cat <<EOF > config.toml
48+ [llvm]
49+ download-ci-llvm = true
50+ [rust]
51+ incremental = false
52+ EOF
53+
54+ # Test program source
55+ cat <<EOF > $TEST_MAIN_RS
56+ fn main() {
57+ panic!();
58+ }
59+ EOF
60+
61+ git submodule update --init library/backtrace
62+
3563 cd library/backtrace
3664 git remote add head-pr https://github.com/${{ github.event.pull_request.head.repo.full_name }}
3765 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- cp -r ./build/x86_64-unknown-linux-gnu/stage0/bin ./build/x86_64-unknown-linux-gnu/stage0-sysroot/bin
43- cp -r ./build/x86_64-unknown-linux-gnu/stage0/lib/*.so ./build/x86_64-unknown-linux-gnu/stage0-sysroot/lib
44- ./build/x86_64-unknown-linux-gnu/stage0-sysroot/bin/rustc -O foo.rs -o binary -reference
66+ - name : Build binary with base version of backtrace
67+ uses : ./backtrace/.github/actions/build-with-patched-std
68+ with :
69+ backtrace-commit : $BASE_COMMIT
70+ main-rs : ${{ env.TEST_MAIN_RS }}
71+ rustc-dir : ${{ env.RUSTC_DIR }}
72+ id : size -reference
4573 - name : Build binary with PR version of backtrace
46- run : |
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- cp -r ./build/x86_64-unknown-linux-gnu/stage0/bin ./build/x86_64-unknown-linux-gnu/stage0-sysroot/bin
54- cp -r ./build/x86_64-unknown-linux-gnu/stage0/lib/*.so ./build/x86_64-unknown-linux-gnu/stage0-sysroot/lib
55- ./build/x86_64-unknown-linux-gnu/stage0-sysroot/bin/rustc -O foo.rs -o binary-updated
56- - name : Display binary size
57- run : |
58- ls -la binary-*
59- echo "SIZE_REFERENCE=$(stat -c '%s' binary-reference)" >> "$GITHUB_ENV"
60- echo "SIZE_UPDATED=$(stat -c '%s' binary-updated)" >> "$GITHUB_ENV"
74+ uses : ./backtrace/.github/actions/build-with-patched-std
75+ with :
76+ backtrace-commit : $HEAD_COMMIT
77+ main-rs : ${{ env.TEST_MAIN_RS }}
78+ rustc-dir : ${{ env.RUSTC_DIR }}
79+ id : size-updated
6180 - name : Post a PR comment if the size has changed
6281 uses : actions/github-script@v6
82+ env :
83+ SIZE_REFERENCE : ${{ steps.size-reference.outputs.test-binary-size }}
84+ SIZE_UPDATED : ${{ steps.size-updated.outputs.test-binary-size }}
6385 with :
6486 script : |
6587 const reference = process.env.SIZE_REFERENCE;
6688 const updated = process.env.SIZE_UPDATED;
89+
90+ if (!(reference > 0)) {
91+ core.setFailed(`Reference size invalid: ${reference}`);
92+ return;
93+ }
94+
95+ if (!(updated > 0)) {
96+ core.setFailed(`Updated size invalid: ${updated}`);
97+ return;
98+ }
99+
67100 const diff = updated - reference;
68101 const plus = diff > 0 ? "+" : "";
69102 const diff_str = `${plus}${diff}B`;
0 commit comments