Skip to content

Commit 4f3a988

Browse files
committed
teach ./miri how to do Josh syncs
1 parent a0fbf0d commit 4f3a988

File tree

2 files changed

+89
-44
lines changed

2 files changed

+89
-44
lines changed

src/tools/miri/CONTRIBUTING.md

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -290,14 +290,12 @@ cargo run --release -p josh-proxy -- --local=$(pwd)/local --remote=https://githu
290290

291291
### Importing changes from the rustc repo
292292

293+
Josh needs to be running, as described above.
293294
We assume we start on an up-to-date master branch in the Miri repo.
294295

295296
```sh
296-
# Fetch rustc side of the history. Takes ca 5 min the first time.
297-
# Do NOT change that commit ID, it needs to be exactly this!
298-
git fetch http://localhost:8000/rust-lang/rust.git:at_commit=75dd959a3a40eb5b4574f8d2e23aa6efbeb33573[:prefix=src/tools/miri]:/src/tools/miri.git master
299-
# Include that history into ours.
300-
git merge FETCH_HEAD -m "merge rustc history"
297+
# Fetch and merge rustc side of the history. Takes ca 5 min the first time.
298+
./miri rustc-pull
301299
# Update toolchain reference and apply formatting.
302300
./rustup-toolchain HEAD && ./miri fmt
303301
git commit -am "rustup"
@@ -310,16 +308,15 @@ needed.
310308

311309
### Exporting changes to the rustc repo
312310

313-
We will use the josh proxy to push to your fork of rustc. You need to make sure
314-
that the master branch of your fork is up-to-date. Also make sure that there
315-
exists no branch called `miri` in your fork. Then run the following in the Miri
316-
repo, assuming we are on an up-to-date master branch:
311+
Josh needs to be running, as described above. We will use the josh proxy to push
312+
to your fork of rustc. Run the following in the Miri repo, assuming we are on an
313+
up-to-date master branch:
317314

318315
```sh
319316
# Push the Miri changes to your rustc fork (substitute your github handle for YOUR_NAME).
320-
# Do NOT change that commit ID, it needs to be exactly this!
321-
git push http://localhost:8000/YOUR_NAME/rust.git:at_commit=75dd959a3a40eb5b4574f8d2e23aa6efbeb33573[:prefix=src/tools/miri]:/src/tools/miri.git -o base=master HEAD:miri
317+
./miri rustc-push YOUR_NAME miri
322318
```
323319

324-
This will create a new branch in your fork, and the output should include a link
325-
to create a rustc PR that will integrate those changes into the main repository.
320+
This will create a new branch called 'miri' in your fork, and the output should
321+
include a link to create a rustc PR that will integrate those changes into the
322+
main repository.

src/tools/miri/miri

Lines changed: 79 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ many different seeds.
4242
Runs the benchmarks from bench-cargo-miri in hyperfine. hyperfine needs to be installed.
4343
<benches> can explicitly list the benchmarks to run; by default, all of them are run.
4444
45+
./miri rustc-pull:
46+
Pull and merge Miri changes from the rustc repo.
47+
48+
./miri rustc-push <github user> <branch>:
49+
Push Miri changes back to the rustc repo. This will update the 'master' branch
50+
in the Rust fork of the given user to upstream. It will also pull a copy of the
51+
rustc history into the Miri repo, unless you set the RUSTC_GIT env var to an
52+
existing clone of the rustc repo.
53+
4554
ENVIRONMENT VARIABLES
4655
4756
MIRI_SYSROOT:
@@ -52,37 +61,60 @@ Pass extra flags to all cargo invocations. (Ignored by `./miri cargo`.)
5261
EOF
5362
)
5463

55-
## We need to know where we are.
64+
## We need to know which command to run and some global constants.
65+
COMMAND="$1"
66+
if [ -z "$COMMAND" ]; then
67+
echo "$USAGE"
68+
exit 1
69+
fi
70+
shift
5671
# macOS does not have a useful readlink/realpath so we have to use Python instead...
5772
MIRIDIR=$(python3 -c 'import os, sys; print(os.path.dirname(os.path.realpath(sys.argv[1])))' "$0")
73+
# Used for rustc syncs.
74+
JOSH_FILTER=":at_commit=75dd959a3a40eb5b4574f8d2e23aa6efbeb33573[:prefix=src/tools/miri]:/src/tools/miri"
5875

59-
## Run the auto-things.
60-
if [ -z "$MIRI_AUTO_OPS" ]; then
61-
export MIRI_AUTO_OPS=42
62-
63-
# Run this first, so that the toolchain doesn't change after
64-
# other code has run.
65-
if [ -f "$MIRIDIR/.auto-everything" ] || [ -f "$MIRIDIR/.auto-toolchain" ] ; then
66-
(cd "$MIRIDIR" && ./rustup-toolchain)
76+
## Early commands, that don't do auto-things and don't want the environment-altering things happening below.
77+
case "$COMMAND" in
78+
rustc-pull)
79+
cd "$MIRIDIR"
80+
git fetch http://localhost:8000/rust-lang/rust.git$JOSH_FILTER.git master
81+
git merge FETCH_HEAD
82+
exit 0
83+
;;
84+
rustc-push)
85+
USER="$1"
86+
BRANCH="$2"
87+
if [ -z "$USER" ] || [ -z "$BRANCH" ]; then
88+
echo "Usage: $0 rustc-push <github user> <branch>"
89+
exit 1
6790
fi
68-
69-
if [ -f "$MIRIDIR/.auto-everything" ] || [ -f "$MIRIDIR/.auto-fmt" ] ; then
70-
$0 fmt
91+
if [ -n "$RUSTC_GIT" ]; then
92+
# Use an existing fork for the branch updates.
93+
cd "$RUSTC_GIT"
94+
else
95+
# Do this in the local Miri repo.
96+
echo "This will pull a copy of the rust-lang/rust history into this Miri checkout, growing it by about 1GB."
97+
read -r -p "To avoid that, abort now and set the RUSTC_GIT environment variable to an existing rustc checkout. Proceed? [y/N] "
98+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
99+
exit 1
100+
fi
101+
cd "$MIRIDIR"
71102
fi
72-
73-
if [ -f "$MIRIDIR/.auto-everything" ] || [ -f "$MIRIDIR/.auto-clippy" ] ; then
74-
$0 clippy -- -D warnings
103+
# Prepare the branches. For reliable pushing we need to push to a non-existent branch
104+
# and set `-o base` to a branch that holds current rustc master.
105+
echo "Preparing $USER/rust..."
106+
if git fetch https://github.com/$USER/rust $BRANCH &>/dev/null; then
107+
echo "The '$BRANCH' seems to already exist in $USER/rust. Please delete it and try again."
108+
exit 1
75109
fi
76-
fi
77-
78-
## Determine command and toolchain.
79-
COMMAND="$1"
80-
[ $# -gt 0 ] && shift
81-
# Doing this *after* auto-toolchain logic above, since that might change the toolchain.
82-
TOOLCHAIN=$(cd "$MIRIDIR"; rustup show active-toolchain | head -n 1 | cut -d ' ' -f 1)
83-
84-
## Handle some commands early, since they should *not* alter the environment.
85-
case "$COMMAND" in
110+
git fetch https://github.com/rust-lang/rust master
111+
git push https://github.com/$USER/rust FETCH_HEAD:master
112+
# Do the actual push.
113+
cd "$MIRIDIR"
114+
echo "Pushing Miri changes..."
115+
git push http://localhost:8000/$USER/rust.git$JOSH_FILTER.git HEAD:$BRANCH -o base=master
116+
exit 0
117+
;;
86118
many-seeds)
87119
for SEED in $({ echo obase=16; seq 0 255; } | bc); do
88120
echo "Trying seed: $SEED"
@@ -106,9 +138,28 @@ bench)
106138
;;
107139
esac
108140

141+
## Run the auto-things.
142+
if [ -z "$MIRI_AUTO_OPS" ]; then
143+
export MIRI_AUTO_OPS=42
144+
145+
# Run this first, so that the toolchain doesn't change after
146+
# other code has run.
147+
if [ -f "$MIRIDIR/.auto-everything" ] || [ -f "$MIRIDIR/.auto-toolchain" ] ; then
148+
(cd "$MIRIDIR" && ./rustup-toolchain)
149+
fi
150+
151+
if [ -f "$MIRIDIR/.auto-everything" ] || [ -f "$MIRIDIR/.auto-fmt" ] ; then
152+
$0 fmt
153+
fi
154+
155+
if [ -f "$MIRIDIR/.auto-everything" ] || [ -f "$MIRIDIR/.auto-clippy" ] ; then
156+
$0 clippy -- -D warnings
157+
fi
158+
fi
159+
109160
## Prepare the environment
110161
# Determine some toolchain properties
111-
# export the target so its available in miri
162+
TOOLCHAIN=$(cd "$MIRIDIR"; rustup show active-toolchain | head -n 1 | cut -d ' ' -f 1)
112163
TARGET=$(rustc +$TOOLCHAIN --version --verbose | grep "^host:" | cut -d ' ' -f 2)
113164
SYSROOT=$(rustc +$TOOLCHAIN --print sysroot)
114165
LIBDIR=$SYSROOT/lib/rustlib/$TARGET/lib
@@ -227,10 +278,7 @@ cargo)
227278
$CARGO "$@"
228279
;;
229280
*)
230-
if [ -n "$COMMAND" ]; then
231-
echo "Unknown command: $COMMAND"
232-
echo
233-
fi
234-
echo "$USAGE"
281+
echo "Unknown command: $COMMAND"
235282
exit 1
283+
;;
236284
esac

0 commit comments

Comments
 (0)