Skip to content

Instantly share code, notes, and snippets.

@Nadrieril
Last active January 8, 2021 19:59
Show Gist options
  • Save Nadrieril/349f646b76dfa622e9a36c3430ad570a to your computer and use it in GitHub Desktop.
Save Nadrieril/349f646b76dfa622e9a36c3430ad570a to your computer and use it in GitHub Desktop.
My `x.py` for rustc development
#!/usr/bin/env bash
# Wrapper around `x.py`. Assumes it's being run from the root of the rustc repo.
RUSTC_REPO="$(realpath "$PWD")"
RUSTC_PERF_REPO="$RUSTC_REPO/../rustc-perf"
X_PY="$RUSTC_REPO/x.py"
RUSTC="$RUSTC_REPO/build/x86_64-unknown-linux-gnu/stage1/bin/rustc"
RUSTFMT="$RUSTC_REPO/build/x86_64-unknown-linux-gnu/stage0/bin/rustfmt"
cd $RUSTC_REPO || exit
case $1 in
fmt)
if [ "$#" -eq 1 ] && [ "$1" -eq '-u' ]; then
$RUSTFMT compiler/rustc_mir_build/src/thir/pattern/*.rs
else
$X_PY fmt
fi
;;
tidy)
$X_PY test tidy --bless
;;
check)
$X_PY check
;;
check-cat)
$X_PY check 2>&1 | cat
;;
build)
$X_PY build --stage 1
;;
perf)
shift
# Benchmark local rustc build. This assumes it's run from the root of the rustc
# repo, and that the rustc-perf repo is at `../rustc-perf` and has been built.
# This compares perf relative to the `base` commit, which is a branch I move
# around for this purpose. This stores the list of commits encountered in
# `../rustc-perf/commits`.
run_site=0
test_args=('test' 'src/test/ui' '--test-args' 'pattern')
for i in "$@"; do
case $i in
-s|--run-site)
run_site=1
;;
-k|--keep)
test_args+=('--keep-stage' '1')
;;
*)
echo "Unknown option: $i" >&2
exit 1
;;
esac
done
$X_PY "${test_args[@]}" || exit
BASE=base
BASE_HASH="$(git show "$BASE" -s --format="%h")"
COMMIT_HASH="$(git show -s --format="%h")"
COMMIT_MSG="$(git show -s --format="%s")"
COUNT_SINCE_BASE="$(git rev-list --count $BASE..HEAD)"
DIRTY="$(git diff-index --quiet HEAD -- compiler || date +"-dirty-%m%dT%H%M%S")"
BASE_NAME="b0-$BASE_HASH"
NAME="b$COUNT_SINCE_BASE-$COMMIT_HASH$DIRTY"
cd $RUSTC_PERF_REPO || exit
$RUSTC_PERF_REPO/target/release/collector bench_local \
--builds Check \
--runs Full \
--include unicode_normalization,match-stress-enum,encoding,match-stress-exhaustive_patterns \
$RUSTC \
"$NAME"
echo
echo "Measured $NAME" >&2
echo "$NAME $COMMIT_MSG" >> $RUSTC_PERF_REPO/commits
xdg-open "http://localhost:2346/compare.html?start=${BASE_NAME}&end=${NAME}&stat=instructions:u"
if [[ "$run_site" == "1" ]]; then
$RUSTC_PERF_REPO/target/release/site
fi
;;
test)
shift
args=('test' '--bless' 'src/test/ui')
case $1 in
-k|--keep)
shift
args+=('--keep-stage' '1')
;;
esac
if [ "$#" -eq 1 ]; then
args+=('--test-args' "$1")
shift
fi
echo $X_PY "${args[@]}" "$@"
$X_PY "${args[@]}" "$@"
;;
*)
$X_PY "$@"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment