[rust-dev] handy script

Niko Matsakis niko at alum.mit.edu
Wed Jan 4 14:14:12 PST 2012


I thought some of you might find this script handy.  It searches your 
current working directory to try and find an appropriate rustc to run.  
This way you can just put this script on your path and type "rustc foo" 
from within a rust checkout and it will do the right thing.


# 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.

while [[ "$DIR" != "/" && "$DIR" != "$HOME" ]]; do
     if [[ -r "$DIR/src/comp/rustc.rc" ]]; then
         for stage in stage3 stage2 stage1; 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 Running "$rustc":
                     "$rustc" "$@"
                     exit $?
     DIR=$(dirname "$DIR")

# Fallback to /usr/local/bin/rustc, if any:
if [[ -x /usr/local/bin/rustc ]]; then
     echo Running /usr/local/bin/rustc:
     /usr/local/bin/rustc "$@"
     exit $?

echo "ERROR: Could not find an appropriate rustc to execute from dir $PWD!"
exit 1

More information about the Rust-dev mailing list