Skip to content

Commit 8401ee4

Browse files
committed
Clarify pure-rust-build cc1 wrapping
This adds comments, and also refactors, to make these steps of the `pure-rust-build` CI job more readable, and to make clearer what the wrapping does and how it works: - "Wrap cc1 (and cc1plus if present) to record calls" - "Build max-pure with limited dev tools and log cc1" The logic clarified here was introduced in GitoxideLabs#1682. The clarification is mainly through these two changes: - Document each of the scripts the steps create and use with an explanatory comment above the "stanza" of code that creates it. - Extract the command to create the `~/display` symlink to such a script, which also has such a comment to explain the effect of writing to that symlink, why it is needed, and why it has to be set in the same GitHub Actions step as the related `cargo` command. Two other less significant clarifcations are made, which arguably are not refactorings in that they could change the behavior (for the better) in some hypothetical situations, but the goal is clarity rather than a behavioral change: - In the scripts that had more than one non-shebang line, take `-e` out of the shebangs and use a `set -e` commmand. This makes no difference in how the scripts are used, since they are always executed directoy. But may make them easier to read, as readers need not check that they are only run in this way to verify their understanding of what they do. - Set `noclobber` in the step that uses `>` to create the script files in `/usr/local`, so that if they somehow clash with files already there, we get an error rather than proceeding and maybe having them called in unantiicpated ways. The likelihood this would happen on a GHA runner is very low, so the real impact of this change is to make immediately clear to readers that the scripts and their names do not have a pre-defined meaning but are instead simply helpers for these GHA steps.
1 parent b856ad9 commit 8401ee4

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

.github/workflows/ci.yml

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,31 +68,56 @@ jobs:
6868
! grep -qP '(?<!\blinux-raw)-sys\b' tree.txt
6969
- name: Wrap cc1 (and cc1plus if present) to record calls
7070
run: |
71+
set -o noclobber # Catch any collisions with existing entries in /usr/local.
72+
73+
# Define the wrapper script for a compiler driver (for cc1 or cc1plus). This wrapper
74+
# records calls, then delegates to the executable it wraps. When recording calls, writes
75+
# to the log are synchronized so fragments of separate log entries aren't interleaved,
76+
# even in concurrent runs. This wrapper knows what executable it is wrapping because,
77+
# when deployed, this wrapper (or a symlink) replaces that executable, which will itself
78+
# have been moved aside by being renamed with a `.orig` suffix, so this can call it.
7179
cat >/usr/local/bin/wrapper1 <<'EOF'
72-
#!/bin/sh -e
80+
#!/bin/sh
81+
set -e
7382
printf '%s\n' "$0 $*" |
7483
flock /run/lock/wrapper1.fbd136bd-9b1b-448d-84a9-e18be53ae63c.lock \
7584
tee -a -- /var/log/wrapper1.log ~/display >/dev/null # We'll link ~/display later.
7685
exec "$0.orig" "$@"
7786
EOF
7887
88+
# Define the script that performs the wrapping. This script shall be run once for each
89+
# executable to be wrapped, renaming it with a `.orig` suffix and replacing it with a
90+
# symlink to the wrapper script, defined above.
7991
cat >/usr/local/bin/wrap1 <<'EOF'
80-
#!/bin/sh -e
92+
#!/bin/sh
93+
set -e
8194
dir="$(dirname -- "$1")"
8295
base="$(basename -- "$1")"
8396
cd -- "$dir"
8497
mv -- "$base" "$base.orig"
8598
ln -s -- /usr/local/bin/wrapper1 "$base"
8699
EOF
87100
88-
chmod +x /usr/local/bin/wrap1 /usr/local/bin/wrapper1
101+
# Define a script that wires up the `~/display` symlink that `wrapper1` uses to report
102+
# calls as GitHub Actions step output (in addition to writing them to a log file). This
103+
# is needed because stdout and stderr are both redirected elsewhere when the wrapper
104+
# actually runs, and `/dev/tty` is not usable. This script must be run in the same step
105+
# as the `cargo` command that causes wrapped executables to be run, because different
106+
# steps write to different pipe objects. (As implemented, this also needs the calling
107+
# shell to remain running, but that is not the cause of the underlying limitation.)
108+
cat >/usr/local/bin/set-display <<'EOF'
109+
#!/bin/sh
110+
ln -s -- "/proc/$$/fd/1" ~/display
111+
EOF
112+
113+
chmod +x /usr/local/bin/wrapper1 /usr/local/bin/wrap1 /usr/local/bin/set-display
89114
mkdir /run/lock/wrapper1.fbd136bd-9b1b-448d-84a9-e18be53ae63c.lock
90115
91116
find /usr/lib/gcc \( -name cc1 -o -name cc1plus \) \
92117
-print -exec /usr/local/bin/wrap1 {} \;
93118
- name: Build max-pure with limited dev tools and log cc1
94119
run: |
95-
ln -s -- "/proc/$$/fd/1" ~/display # Bypass `cc1` redirection.
120+
/usr/local/bin/set-display
96121
cargo install --debug --locked --no-default-features --features max-pure --path .
97122
- name: Show logged C and C++ compilations (should be none)
98123
run: |

0 commit comments

Comments
 (0)