@@ -15,55 +15,88 @@ jobs:
15
15
runs-on : ubuntu-latest
16
16
permissions :
17
17
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 }}
18
26
steps :
19
27
- name : Print info
20
28
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 }}
23
38
- name : Clone Rustc
24
39
uses : actions/checkout@v3
25
40
with :
26
41
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 }}
33
45
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
+
35
63
cd library/backtrace
36
64
git remote add head-pr https://github.com/${{ github.event.pull_request.head.repo.full_name }}
37
65
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
45
73
- 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
61
80
- name : Post a PR comment if the size has changed
62
81
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 }}
63
85
with :
64
86
script : |
65
87
const reference = process.env.SIZE_REFERENCE;
66
88
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
+
67
100
const diff = updated - reference;
68
101
const plus = diff > 0 ? "+" : "";
69
102
const diff_str = `${plus}${diff}B`;
0 commit comments