X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Ftools%2Fmiri%2Fmiri;h=b09897c294cd17f3bf539b6a74420510f44e3d18;hb=43fa2918d1e4dfd90f83ce46aac8373ae8120068;hp=e492308a62eb5f9930c4aafe708f2d9ae6ef18f6;hpb=5b82ea74b705799665b5a676b162f30d26f5108c;p=rust.git diff --git a/src/tools/miri/miri b/src/tools/miri/miri index e492308a62e..b09897c294c 100755 --- a/src/tools/miri/miri +++ b/src/tools/miri/miri @@ -42,6 +42,22 @@ many different seeds. Runs the benchmarks from bench-cargo-miri in hyperfine. hyperfine needs to be installed. can explicitly list the benchmarks to run; by default, all of them are run. +./miri toolchain : +Update and activate the rustup toolchain 'miri' to the commit given in the +`rust-version` file. +`rustup-toolchain-install-master` must be installed for this to work. Any extra +flags are passed to `rustup-toolchain-install-master`. + +./miri rustc-pull: +Pull and merge Miri changes from the rustc repo. The fetched commit is stored in +the `rust-version` file, so the next `./miri toolchain` will install the rustc +we just pulled. + +./miri rustc-push : +Push Miri changes back to the rustc repo. This will pull a copy of the rustc +history into the Miri repo, unless you set the RUSTC_GIT env var to an existing +clone of the rustc repo. + ENVIRONMENT VARIABLES MIRI_SYSROOT: @@ -52,37 +68,101 @@ Pass extra flags to all cargo invocations. (Ignored by `./miri cargo`.) EOF ) -## We need to know where we are. +## We need to know which command to run and some global constants. +COMMAND="$1" +if [ -z "$COMMAND" ]; then + echo "$USAGE" + exit 1 +fi +shift # 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") +# Used for rustc syncs. +JOSH_FILTER=":rev(75dd959a3a40eb5b4574f8d2e23aa6efbeb33573:prefix=src/tools/miri):/src/tools/miri" +# Needed for `./miri bench`. +TOOLCHAIN=$(cd "$MIRIDIR"; rustup show active-toolchain | head -n 1 | cut -d ' ' -f 1) -## Run the auto-things. -if [ -z "$MIRI_AUTO_OPS" ]; then - export MIRI_AUTO_OPS=42 - - # Run this first, so that the toolchain doesn't change after - # other code has run. - if [ -f "$MIRIDIR/.auto-everything" ] || [ -f "$MIRIDIR/.auto-toolchain" ] ; then - (cd "$MIRIDIR" && ./rustup-toolchain) +## Early commands, that don't do auto-things and don't want the environment-altering things happening below. +case "$COMMAND" in +toolchain) + cd "$MIRIDIR" + NEW_COMMIT=$(cat rust-version) + # Make sure rustup-toolchain-install-master is installed. + if ! which rustup-toolchain-install-master >/dev/null; then + echo "Please install rustup-toolchain-install-master by running 'cargo install rustup-toolchain-install-master'" + exit 1 fi - - if [ -f "$MIRIDIR/.auto-everything" ] || [ -f "$MIRIDIR/.auto-fmt" ] ; then - $0 fmt + # Check if we already are at that commit. + CUR_COMMIT=$(rustc +miri --version -v 2>/dev/null | grep "^commit-hash: " | cut -d " " -f 2) + if [[ "$CUR_COMMIT" == "$NEW_COMMIT" ]]; then + echo "miri toolchain is already at commit $CUR_COMMIT." + rustup override set miri + exit 0 fi - - if [ -f "$MIRIDIR/.auto-everything" ] || [ -f "$MIRIDIR/.auto-clippy" ] ; then - $0 clippy -- -D warnings + # Install and setup new toolchain. + rustup toolchain uninstall miri + rustup-toolchain-install-master -n miri -c cargo -c rust-src -c rustc-dev -c llvm-tools -c rustfmt -c clippy "$@" -- "$NEW_COMMIT" + rustup override set miri + # Cleanup. + cargo clean + # Call 'cargo metadata' on the sources in case that changes the lockfile + # (which fails under some setups when it is done from inside vscode). + cargo metadata --format-version 1 --manifest-path "$(rustc --print sysroot)/lib/rustlib/rustc-src/rust/compiler/rustc/Cargo.toml" >/dev/null + # Done! + exit 0 + ;; +rustc-pull) + cd "$MIRIDIR" + FETCH_COMMIT=$(git ls-remote https://github.com/rust-lang/rust/ HEAD | cut -f 1) + # We can't pull from a commit with josh + # (https://github.com/josh-project/josh/issues/1034), so we just hope that + # nothing gets merged into rustc *during* this pull. + git fetch http://localhost:8000/rust-lang/rust.git$JOSH_FILTER.git master + # Just verify that `master` didn't move. + if [[ $FETCH_COMMIT != $(git ls-remote https://github.com/rust-lang/rust/ HEAD | cut -f 1) ]]; then + echo "Looks like something got merged into Rust *while we were pulling*. Aborting. Please try again." fi -fi - -## 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 + echo "$FETCH_COMMIT" > rust-version # do this *before* merging as merging will fail in case of conflicts + git merge FETCH_HEAD --no-ff -m "Merge from rustc" + git commit rust-version --amend -m "Merge from rustc" + exit 0 + ;; +rustc-push) + USER="$1" + BRANCH="$2" + if [ -z "$USER" ] || [ -z "$BRANCH" ]; then + echo "Usage: $0 rustc-push " + exit 1 + fi + if [ -n "$RUSTC_GIT" ]; then + # Use an existing fork for the branch updates. + cd "$RUSTC_GIT" + else + # Do this in the local Miri repo. + echo "This will pull a copy of the rust-lang/rust history into this Miri checkout, growing it by about 1GB." + read -r -p "To avoid that, abort now and set the RUSTC_GIT environment variable to an existing rustc checkout. Proceed? [y/N] " + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + exit 1 + fi + cd "$MIRIDIR" + fi + # Prepare the branch. Pushing works much better if we use as base exactly + # the commit that we pulled from last time, so we use the `rust-version` + # file as a good approximation of that. + BASE=$(cat "$MIRIDIR/rust-version") + echo "Preparing $USER/rust (base: $BASE)..." + if git fetch "https://github.com/$USER/rust" "$BRANCH" &>/dev/null; then + echo "The branch '$BRANCH' seems to already exist in 'https://github.com/$USER/rust'. Please delete it and try again." + exit 1 + fi + git fetch https://github.com/rust-lang/rust $BASE + git push https://github.com/$USER/rust $BASE:refs/heads/$BRANCH -f + # Do the actual push. + cd "$MIRIDIR" + echo "Pushing Miri changes..." + git push http://localhost:8000/$USER/rust.git$JOSH_FILTER.git HEAD:$BRANCH + exit 0 + ;; many-seeds) for SEED in $({ echo obase=16; seq 0 255; } | bc); do echo "Trying seed: $SEED" @@ -106,9 +186,29 @@ bench) ;; esac +## Run the auto-things. +if [ -z "$MIRI_AUTO_OPS" ]; then + export MIRI_AUTO_OPS=42 + + # Run this first, so that the toolchain doesn't change after + # other code has run. + if [ -f "$MIRIDIR/.auto-everything" ] || [ -f "$MIRIDIR/.auto-toolchain" ] ; then + $0 toolchain + # Let's make sure to actually use that toolchain, too. + TOOLCHAIN=miri + fi + + if [ -f "$MIRIDIR/.auto-everything" ] || [ -f "$MIRIDIR/.auto-fmt" ] ; then + $0 fmt + fi + + if [ -f "$MIRIDIR/.auto-everything" ] || [ -f "$MIRIDIR/.auto-clippy" ] ; then + $0 clippy -- -D warnings + fi +fi + ## Prepare the environment # Determine some toolchain properties -# export the target so its available in miri TARGET=$(rustc +$TOOLCHAIN --version --verbose | grep "^host:" | cut -d ' ' -f 2) SYSROOT=$(rustc +$TOOLCHAIN --print sysroot) LIBDIR=$SYSROOT/lib/rustlib/$TARGET/lib @@ -227,10 +327,7 @@ cargo) $CARGO "$@" ;; *) - if [ -n "$COMMAND" ]; then - echo "Unknown command: $COMMAND" - echo - fi - echo "$USAGE" + echo "Unknown command: $COMMAND" exit 1 + ;; esac