Skip to content

Instantly share code, notes, and snippets.

@nikomatsakis
Last active August 29, 2015 14:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikomatsakis/eafb2bbfae3817c66bd6 to your computer and use it in GitHub Desktop.
Save nikomatsakis/eafb2bbfae3817c66bd6 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# A script that identifies the root of the current rustc checkout.
# If the environment variable RUST_ROOT is not set, then it
# walks up from the current directory to find the right spot.
if [ -n "$RUST_ROOT" ]; then
echo "$RUST_ROOT"
exit 0
fi
DIR="$PWD"
while [[ "$DIR" != "/" && "$DIR" != "$HOME" ]]; do
if [[ -r "$DIR/src/librustc" ]]; then
echo "$DIR"
exit 0
fi
DIR=$(dirname "$DIR")
done
# Default to "rust-m" if we're not in a more specific Rust
# directory. This is where I keep my "plain vanilla" Rust build.
if [[ -r "$HOME/versioned/rust-m/src/librustc" ]]; then
echo "$HOME/versioned/rust-m/"
exit 0
fi
echo "/no/rust/root/found"
exit 1
#!/bin/bash
#
# A wrapper around `rustc` that will use the
# version of `rustc` appropriate to the current
# directory (if the current directory is a checkout
# of the rust repository), and otherwise fall back
# to `/usr/local/bin/rustc`. It will try to use the most
# advanced build it can find (i.e., stage2 in preference to
# stage1), or you can pass various arguments (e.g., `rustc --stage1`)
# to control what build it uses. You may also want
# `rustc --echo` (see what command it would run) or `rustc --gdb`
# (run rustc in gdb).
ARG=
if [ "$1" == "--stage0" ]
then
shift
ARG=stage0
fi
if [ "$1" == "--stage1" ]
then
shift
ARG=stage1
fi
if [ "$1" == "--stage2" ]
then
shift
ARG=stage2
fi
if [ "$1" == "--echo" ]
then
shift
ECHO=1
else
ECHO=0
fi
if [ "$1" == "--gdb" ]
then
shift
GDB="gdb --args"
else
GDB=""
fi
if [ "$1" == "--lldb" ]
then
shift
GDB="lldb --"
else
GDB=""
fi
R="$($(dirname $0)/rustc-path $ARG)"
D="$(dirname "$R")"
if [ "$(uname)" == "Darwin" ]
then
VAR=DYLD_LIBRARY_PATH
else
VAR=LD_LIBRARY_PATH
fi
if [[ -x "$R" ]]; then
if (($ECHO)); then
echo $VAR="$D/../lib:$LD_LIBRARY_PATH" $GDB "$R" "$@"
else
env $VAR="$D/../lib:$LD_LIBRARY_PATH" $GDB "$R" "$@"
fi
exit $?
fi
echo > /dev/stderr "ERROR: Could not find an appropriate rustc to execute from dir $PWD!"
exit 1
#!/bin/bash
#
# Script which finds an appropriate rustc to execute based on the current
# directory. We begin by walking up the set of directories until we find
# one that contains "src/comp/rustc.rc".
# Walk up directories looking for the main rust directory. Don't walk
# past the home directory of the current user, just seems unsanitary.
if [ -z "$1" ]; then
STAGES="stage2 stage1"
else
STAGES="$1"
fi
DIR=$(rust-root)
for stage in ${STAGES}; do
# Use glob to search through all architectures.
# But if some stage doesn't exist, then
# the glob will keep the "*" rather than return the
# empty set, so we have to check within the for loop
# too.
for rustc in "$DIR"/build/*/$stage/bin/rustc; do
if [[ -x "$rustc" ]]; then
echo "$rustc"
exit 0
fi
done
done
# Fallback to /usr/local/bin/rustc, if any:
echo /usr/local/bin/rustc
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment