From 517e1d78b8a2daf7285ddf24f8642a922df02f89 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 20 Jul 2022 12:38:27 +0000 Subject: [PATCH 1/2] Add a scheme for always using the default toolchain, running clippy and fmt before running any other command --- .gitignore | 1 + CONTRIBUTING.md | 13 +++++++++++++ miri | 19 +++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/.gitignore b/.gitignore index dcefbc62c70b..185ff4f756c1 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ tex/*/out perf.data perf.data.old flamegraph.svg +.auto-* diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a57ef09e7db9..47864d822c4f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -28,6 +28,11 @@ install that exact version of rustc as a toolchain: This will set up a rustup toolchain called `miri` and set it as an override for the current directory. +You can also create a `.auto-everything` file (contents don't matter, can be empty), which +will cause any `./miri` command to automatically call `rustup-toolchain`, `clippy` and `rustfmt` +for you. If you don't want all of these to happen, you can add individual `.auto-toolchain`, +`.auto-clippy` and `.auto-fmt` files respectively. + [`rustup-toolchain-install-master`]: https://github.com/kennytm/rustup-toolchain-install-master ## Building and testing Miri @@ -244,6 +249,14 @@ rustup toolchain link stage2 build/x86_64-unknown-linux-gnu/stage2 rustup override set stage2 ``` +Note: When you are working with a locally built rustc or any other toolchain that +is not the same as the one in `rust-version`, you should not have `.auto-everything` or +`.auto-toolchain` as that will keep resetting your toolchain. + +``` +rm -f .auto-everything .auto-toolchain +``` + Important: You need to delete the Miri cache when you change the stdlib; otherwise the old, chached version will be used. On Linux, the cache is located at `~/.cache/miri`, and on Windows, it is located at `%LOCALAPPDATA%\rust-lang\miri\cache`; the exact diff --git a/miri b/miri index 04d441b60780..19925e14be63 100755 --- a/miri +++ b/miri @@ -48,6 +48,25 @@ Pass extra flags to all cargo invocations. EOF ) +## Run the subcommands that the user requested to always run first +if [ -z "$AUTO_OPS" ]; then + export AUTO_OPS=42 + + # Run this first, so that the toolchain doesn't change after + # other code has run. + if [ -f ".auto-everything" ] || [ -f ".auto-toolchain" ] ; then + "$MIRIDIR"/rustup-toolchain + fi + + if [ -f ".auto-everything" ] || [ -f ".auto-fmt" ] ; then + $0 fmt + fi + + if [ -f ".auto-everything" ] || [ -f ".auto-clippy" ] ; then + $0 clippy -- -D warnings + fi +fi + ## Preparation # macOS does not have a useful readlink/realpath so we have to use Python instead... MIRIDIR=$(python3 -c 'import os, sys; print(os.path.dirname(os.path.realpath(sys.argv[1])))' "$0") From 4d4eeca8a8da67c3dd6e27dd8665b4f11763fd87 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 20 Jul 2022 20:37:54 -0400 Subject: [PATCH 2/2] fix miri script --- miri | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/miri b/miri index 19925e14be63..2a9be1de3629 100755 --- a/miri +++ b/miri @@ -48,33 +48,34 @@ Pass extra flags to all cargo invocations. EOF ) -## Run the subcommands that the user requested to always run first +## We need to know where we are. +# macOS does not have a useful readlink/realpath so we have to use Python instead... +MIRIDIR=$(python3 -c 'import os, sys; print(os.path.dirname(os.path.realpath(sys.argv[1])))' "$0") + +## Run the auto-things. if [ -z "$AUTO_OPS" ]; then export AUTO_OPS=42 # Run this first, so that the toolchain doesn't change after # other code has run. - if [ -f ".auto-everything" ] || [ -f ".auto-toolchain" ] ; then + if [ -f "$MIRIDIR/.auto-everything" ] || [ -f "$MIRIDIR/.auto-toolchain" ] ; then "$MIRIDIR"/rustup-toolchain fi - if [ -f ".auto-everything" ] || [ -f ".auto-fmt" ] ; then + if [ -f "$MIRIDIR/.auto-everything" ] || [ -f "$MIRIDIR/.auto-fmt" ] ; then $0 fmt fi - if [ -f ".auto-everything" ] || [ -f ".auto-clippy" ] ; then + if [ -f "$MIRIDIR/.auto-everything" ] || [ -f "$MIRIDIR/.auto-clippy" ] ; then $0 clippy -- -D warnings fi fi -## Preparation -# macOS does not have a useful readlink/realpath so we have to use Python instead... -MIRIDIR=$(python3 -c 'import os, sys; print(os.path.dirname(os.path.realpath(sys.argv[1])))' "$0") -TOOLCHAIN=$(cd "$MIRIDIR"; rustup show active-toolchain | head -n 1 | cut -d ' ' -f 1) - -# Determine command. +## Determine command and toolchain. COMMAND="$1" [ $# -gt 0 ] && shift +# Doing this *after* auto-toolchain logic above, since that might change the toolchain. +TOOLCHAIN=$(cd "$MIRIDIR"; rustup show active-toolchain | head -n 1 | cut -d ' ' -f 1) ## Handle some commands early, since they should *not* alter the environment. case "$COMMAND" in