@@ -42,6 +42,22 @@ many different seeds.
42
42
Runs the benchmarks from bench-cargo-miri in hyperfine. hyperfine needs to be installed.
43
43
<benches> can explicitly list the benchmarks to run; by default, all of them are run.
44
44
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
+
54
+ ./miri toolchain <commit> <flags>:
55
+ Update and activate the rustup toolchain 'miri'. If no commit is given, updates
56
+ to the commit given in the `rust-version` file. If the commit is `HEAD`, updates
57
+ to the latest upstream rustc commit.
58
+ `rustup-toolchain-install-master` must be installed for this to work. Any extra
59
+ flags are passed to `rustup-toolchain-install-master`.
60
+
45
61
ENVIRONMENT VARIABLES
46
62
47
63
MIRI_SYSROOT:
@@ -52,37 +68,98 @@ Pass extra flags to all cargo invocations. (Ignored by `./miri cargo`.)
52
68
EOF
53
69
)
54
70
55
- # # We need to know where we are.
71
+ # # We need to know which command to run and some global constants.
72
+ COMMAND=" $1 "
73
+ if [ -z " $COMMAND " ]; then
74
+ echo " $USAGE "
75
+ exit 1
76
+ fi
77
+ shift
56
78
# macOS does not have a useful readlink/realpath so we have to use Python instead...
57
79
MIRIDIR=$( python3 -c ' import os, sys; print(os.path.dirname(os.path.realpath(sys.argv[1])))' " $0 " )
80
+ # Used for rustc syncs.
81
+ JOSH_FILTER=" :at_commit=75dd959a3a40eb5b4574f8d2e23aa6efbeb33573[:prefix=src/tools/miri]:/src/tools/miri"
82
+ # Needed for `./miri bench`.
83
+ TOOLCHAIN=$( cd " $MIRIDIR " ; rustup show active-toolchain | head -n 1 | cut -d ' ' -f 1)
58
84
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)
85
+ # # Early commands, that don't do auto-things and don't want the environment-altering things happening below .
86
+ case " $COMMAND " in
87
+ toolchain)
88
+ cd " $MIRIDIR "
89
+ # Make sure rustup- toolchain-install-master is installed.
90
+ if ! which rustup-toolchain-install-master > /dev/null ; then
91
+ echo " Please install rustup-toolchain-install-master by running 'cargo install rustup -toolchain-install-master' "
92
+ exit 1
67
93
fi
68
-
69
- if [ -f " $MIRIDIR /.auto-everything" ] || [ -f " $MIRIDIR /.auto-fmt" ] ; then
70
- $0 fmt
94
+ # Determine new commit.
95
+ if [[ " $1 " == " " ]]; then
96
+ NEW_COMMIT=$( cat rust-version)
97
+ elif [[ " $1 " == " HEAD" ]]; then
98
+ NEW_COMMIT=$( git ls-remote https://github.com/rust-lang/rust/ HEAD | cut -f 1)
99
+ else
100
+ NEW_COMMIT=" $1 "
71
101
fi
72
-
73
- if [ -f " $MIRIDIR /.auto-everything" ] || [ -f " $MIRIDIR /.auto-clippy" ] ; then
74
- $0 clippy -- -D warnings
102
+ echo " $NEW_COMMIT " > rust-version
103
+ shift || true # don't fail if shifting fails because no commit was given
104
+ # Check if we already are at that commit.
105
+ CUR_COMMIT=$( rustc +miri --version -v 2> /dev/null | grep " ^commit-hash: " | cut -d " " -f 2)
106
+ if [[ " $CUR_COMMIT " == " $NEW_COMMIT " ]]; then
107
+ echo " miri toolchain is already at commit $CUR_COMMIT ."
108
+ rustup override set miri
109
+ exit 0
75
110
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
111
+ # Install and setup new toolchain.
112
+ rustup toolchain uninstall miri
113
+ rustup-toolchain-install-master -n miri -c cargo -c rust-src -c rustc-dev -c llvm-tools -c rustfmt -c clippy " $@ " -- " $NEW_COMMIT "
114
+ rustup override set miri
115
+ # Cleanup.
116
+ cargo clean
117
+ # Call 'cargo metadata' on the sources in case that changes the lockfile
118
+ # (which fails under some setups when it is done from inside vscode).
119
+ cargo metadata --format-version 1 --manifest-path " $( rustc --print sysroot) /lib/rustlib/rustc-src/rust/compiler/rustc/Cargo.toml" > /dev/null
120
+ # Done!
121
+ exit 0
122
+ ;;
123
+ rustc-pull)
124
+ cd " $MIRIDIR "
125
+ git fetch http://localhost:8000/rust-lang/rust.git$JOSH_FILTER .git master
126
+ git merge FETCH_HEAD --no-ff -m " Merge from rustc"
127
+ exit 0
128
+ ;;
129
+ rustc-push)
130
+ USER=" $1 "
131
+ BRANCH=" $2 "
132
+ if [ -z " $USER " ] || [ -z " $BRANCH " ]; then
133
+ echo " Usage: $0 rustc-push <github user> <branch>"
134
+ exit 1
135
+ fi
136
+ if [ -n " $RUSTC_GIT " ]; then
137
+ # Use an existing fork for the branch updates.
138
+ cd " $RUSTC_GIT "
139
+ else
140
+ # Do this in the local Miri repo.
141
+ echo " This will pull a copy of the rust-lang/rust history into this Miri checkout, growing it by about 1GB."
142
+ read -r -p " To avoid that, abort now and set the RUSTC_GIT environment variable to an existing rustc checkout. Proceed? [y/N] "
143
+ if [[ ! $REPLY =~ ^[Yy]$ ]]; then
144
+ exit 1
145
+ fi
146
+ cd " $MIRIDIR "
147
+ fi
148
+ # Prepare the branches. For reliable pushing we need to push to a non-existent branch
149
+ # and set `-o base` to a branch that holds current rustc master.
150
+ echo " Preparing $USER /rust..."
151
+ if git fetch https://github.com/$USER /rust $BRANCH & > /dev/null; then
152
+ echo " The '$BRANCH ' seems to already exist in $USER /rust. Please delete it and try again."
153
+ exit 1
154
+ fi
155
+ git fetch https://github.com/rust-lang/rust master
156
+ git push https://github.com/$USER /rust FETCH_HEAD:master
157
+ # Do the actual push.
158
+ cd " $MIRIDIR "
159
+ echo " Pushing Miri changes..."
160
+ git push http://localhost:8000/$USER /rust.git$JOSH_FILTER .git HEAD:$BRANCH -o base=master
161
+ exit 0
162
+ ;;
86
163
many-seeds)
87
164
for SEED in $( { echo obase=16; seq 0 255; } | bc) ; do
88
165
echo " Trying seed: $SEED "
@@ -106,9 +183,29 @@ bench)
106
183
;;
107
184
esac
108
185
186
+ # # Run the auto-things.
187
+ if [ -z " $MIRI_AUTO_OPS " ]; then
188
+ export MIRI_AUTO_OPS=42
189
+
190
+ # Run this first, so that the toolchain doesn't change after
191
+ # other code has run.
192
+ if [ -f " $MIRIDIR /.auto-everything" ] || [ -f " $MIRIDIR /.auto-toolchain" ] ; then
193
+ $0 toolchain
194
+ # Let's make sure to actually use that toolchain, too.
195
+ TOOLCHAIN=miri
196
+ fi
197
+
198
+ if [ -f " $MIRIDIR /.auto-everything" ] || [ -f " $MIRIDIR /.auto-fmt" ] ; then
199
+ $0 fmt
200
+ fi
201
+
202
+ if [ -f " $MIRIDIR /.auto-everything" ] || [ -f " $MIRIDIR /.auto-clippy" ] ; then
203
+ $0 clippy -- -D warnings
204
+ fi
205
+ fi
206
+
109
207
# # Prepare the environment
110
208
# Determine some toolchain properties
111
- # export the target so its available in miri
112
209
TARGET=$( rustc +$TOOLCHAIN --version --verbose | grep " ^host:" | cut -d ' ' -f 2)
113
210
SYSROOT=$( rustc +$TOOLCHAIN --print sysroot)
114
211
LIBDIR=$SYSROOT /lib/rustlib/$TARGET /lib
@@ -227,10 +324,7 @@ cargo)
227
324
$CARGO " $@ "
228
325
;;
229
326
* )
230
- if [ -n " $COMMAND " ]; then
231
- echo " Unknown command: $COMMAND "
232
- echo
233
- fi
234
- echo " $USAGE "
327
+ echo " Unknown command: $COMMAND "
235
328
exit 1
329
+ ;;
236
330
esac
0 commit comments