Hello,

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.


Niko

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

DIR="$PWD"
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 $?
                fi
            done
        done
        break
    fi
    DIR=$(dirname "$DIR")
done

# 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 $?
fi

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

_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to