2 # Copyright 2014 The Rust Project Developers. See the COPYRIGHT
3 # file at the top-level directory of this distribution and at
4 # http://rust-lang.org/COPYRIGHT.
6 # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
7 # http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
8 # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
9 # option. This file may not be copied, modified, or distributed
10 # except according to those terms.
24 echo "rustup: WARNING: $1"
28 echo "rustup: error: $1"
46 printf "rustup: %-20s := %.35s ...\n" $1 "$T"
48 printf "rustup: %-20s := %s %s\n" $1 "$T" "$2"
62 VER0=$($P --version 2>/dev/null | head -1 \
63 | sed -e 's/[^0-9]*\([vV]\?[0-9.]\+[^ ]*\).*/\1/' )
64 if [ $? -eq 0 -a "x${VER0}" != "x" ]
86 err "needed, but unable to find any of: $*"
92 VAL_OPTIONS="$VAL_OPTIONS $1"
101 local UOP=$(echo $OP | tr '[:lower:]' '[:upper:]' | tr '\-' '\_')
106 if echo "$arg" | grep -q -- "--$OP="
108 val=$(echo "$arg" | cut -f2 -d=)
118 OP="${OP}=[${DEFAULT}]"
119 printf " --%-30s %s\n" "$OP" "$DOC"
124 BOOL_OPTIONS="$BOOL_OPTIONS $1"
133 if [ $DEFAULT -eq 0 ]
145 if [ "$arg" = "--${FLAG}-${OP}" ]
147 OP=$(echo $OP | tr 'a-z-' 'A-Z_')
148 FLAG=$(echo $FLAG | tr 'a-z' 'A-Z')
149 local V="CFG_${FLAG}_${OP}"
159 printf " --%-30s %s\n" "$FLAG-$OP" "$DOC"
164 BOOL_OPTIONS="$BOOL_OPTIONS $1"
174 if [ "$arg" = "--${OP}" ]
176 OP=$(echo $OP | tr 'a-z-' 'A-Z_')
187 printf " --%-30s %s\n" "$OP" "$DOC"
195 for option in $BOOL_OPTIONS
197 if test --disable-$option = $arg
201 if test --enable-$option = $arg
205 if test --$option = $arg
210 for option in $VAL_OPTIONS
212 if echo "$arg" | grep -q -- "--$option="
217 if [ "$arg" = "--help" ]
220 echo "No more help available for Configure options,"
221 echo "check the Wiki or join our IRC channel"
224 if test $isArgValid -eq 0
226 err "Option '$arg' is not recognized"
233 local TMP_DIR=./rustup-tmp-install
236 need_ok "failed to remove temporary installation directory"
238 mkdir -p "${TMP_DIR}"
239 need_ok "failed to create create temporary installation directory"
244 probe_need CFG_CURL curl
245 probe_need CFG_TAR tar
246 probe_need CFG_FILE file
248 CFG_SRC_DIR="$(cd $(dirname $0) && pwd)/"
253 if [ "$1" = "--help" ]
258 echo "Usage: $CFG_SELF [options]"
263 step_msg "processing $CFG_SELF args"
270 flag uninstall "only uninstall from the installation prefix"
271 valopt prefix "" "set installation prefix"
272 opt cargo 1 "install cargo with rust"
280 step_msg "validating $CFG_SELF args"
284 # Platform detection copied from `configure`
286 CFG_OSTYPE=$(uname -s)
287 CFG_CPUTYPE=$(uname -m)
289 if [ $CFG_OSTYPE = Darwin -a $CFG_CPUTYPE = i386 ]
291 # Darwin's `uname -s` lies and always returns i386. We have to use sysctl
293 if sysctl hw.optional.x86_64 | grep -q ': 1'
299 # The goal here is to come up with the same triple as LLVM would,
300 # at least for the subset of platforms we're willing to target.
305 CFG_OSTYPE=unknown-linux-gnu
309 CFG_OSTYPE=unknown-freebsd
313 CFG_OSTYPE=apple-darwin
317 CFG_OSTYPE=pc-mingw32
319 # Thad's Cygwin identifers below
323 CFG_OSTYPE=pc-mingw32
329 CFG_OSTYPE=w64-mingw32
335 CFG_OSTYPE=pc-mingw32
341 CFG_OSTYPE=w64-mingw32
345 # We do not detect other OS such as XP/2003 using 64 bit using uname.
346 # If we want to in the future, we will need to use Cygwin
347 # Chuck's csih helper in /usr/lib/csih/winProductName.exe or alternative.
349 err "unknown OS type: $CFG_OSTYPE"
356 i386 | i486 | i686 | i786 | x86)
364 x86_64 | x86-64 | x64 | amd64)
369 err "unknown CPU type: $CFG_CPUTYPE"
372 # Detect 64 bit linux systems with 32 bit userland and force 32 bit compilation
373 if [ $CFG_OSTYPE = unknown-linux-gnu -a $CFG_CPUTYPE = x86_64 ]
375 "${CFG_FILE}" -L "$SHELL" | grep -q "x86[_-]64"
381 HOST_TRIPLE="${CFG_CPUTYPE}-${CFG_OSTYPE}"
383 # Is this a triple we have nightlies for?
386 x86_64-unknown-linux-gnu)
389 i686-unknown-linux-gnu)
399 err "rustup.sh doesn't work for host $HOST_TRIPLE"
403 msg "host triple: ${HOST_TRIPLE}"
406 if [ -n "${CFG_UNINSTALL}" ]
408 CFG_INSTALL_FLAGS="${CFG_INSTALL_FLAGS} --uninstall"
411 if [ -n "${CFG_PREFIX}" ]
413 CFG_INSTALL_FLAGS="${CFG_INSTALL_FLAGS} --prefix=${CFG_PREFIX}"
416 CFG_TMP_DIR=$(mktemp -d 2>/dev/null \
417 || mktemp -d -t 'rustup-tmp-install' 2>/dev/null \
420 RUST_URL="https://static.rust-lang.org/dist"
421 RUST_PACKAGE_NAME=rust-nightly
422 RUST_PACKAGE_NAME_AND_TRIPLE="${RUST_PACKAGE_NAME}-${HOST_TRIPLE}"
423 RUST_TARBALL_NAME="${RUST_PACKAGE_NAME_AND_TRIPLE}.tar.gz"
424 RUST_LOCAL_INSTALL_DIR="${CFG_TMP_DIR}/${RUST_PACKAGE_NAME_AND_TRIPLE}"
425 RUST_LOCAL_INSTALL_SCRIPT="${RUST_LOCAL_INSTALL_DIR}/install.sh"
427 CARGO_URL="https://static.rust-lang.org/cargo-dist"
428 CARGO_PACKAGE_NAME=cargo-nightly
429 CARGO_PACKAGE_NAME_AND_TRIPLE="${CARGO_PACKAGE_NAME}-${HOST_TRIPLE}"
430 CARGO_TARBALL_NAME="${CARGO_PACKAGE_NAME_AND_TRIPLE}.tar.gz"
431 CARGO_LOCAL_INSTALL_DIR="${CFG_TMP_DIR}/${CARGO_PACKAGE_NAME_AND_TRIPLE}"
432 CARGO_LOCAL_INSTALL_SCRIPT="${CARGO_LOCAL_INSTALL_DIR}/install.sh"
439 msg "Downloading ${remote_tarball} to ${local_tarball}"
441 "${CFG_CURL}" -f -o "${local_tarball}" "${remote_tarball}"
444 rm -Rf "${CFG_TMP_DIR}"
445 err "failed to download installer"
449 # Wrap all the commands needed to install a package.
454 msg "Extracting ${tarball_name}"
455 (cd "${CFG_TMP_DIR}" && "${CFG_TAR}" -xzf "${tarball_name}")
456 if [ $? -ne 0 ]; then
457 rm -Rf "${CFG_TMP_DIR}"
458 err "failed to unpack installer"
461 sh "${install_script}" "${CFG_INSTALL_FLAGS}"
464 rm -Rf "${CFG_TMP_DIR}"
465 err "failed to install Rust"
469 # It's possible that curl could be interrupted partway though downloading
470 # `rustup.sh`, truncating the file. This could be especially bad if we were in
471 # the middle of a line that would run "rm -rf ". To protect against this, we
472 # wrap up the `rustup.sh` destructive functionality in this helper function,
473 # which we call as the last thing we do. This means we will not do anything
474 # unless we have the entire file downloaded.
476 rm -Rf "${CFG_TMP_DIR}"
477 need_ok "failed to remove temporary installation directory"
479 mkdir -p "${CFG_TMP_DIR}"
480 need_ok "failed to create create temporary installation directory"
482 RUST_LOCAL_TARBALL="${CFG_TMP_DIR}/${RUST_TARBALL_NAME}"
483 CARGO_LOCAL_TARBALL="${CFG_TMP_DIR}/${CARGO_TARBALL_NAME}"
486 "${RUST_URL}/${RUST_TARBALL_NAME}" \
487 "${RUST_LOCAL_TARBALL}"
489 if [ -z "${CFG_DISABLE_CARGO}" ]; then
491 "${CARGO_URL}/${CARGO_TARBALL_NAME}" \
492 "${CARGO_LOCAL_TARBALL}"
496 "${RUST_TARBALL_NAME}" \
497 "${RUST_LOCAL_INSTALL_SCRIPT}"
499 if [ -z "${CFG_DISABLE_CARGO}" ]; then
501 "${CARGO_TARBALL_NAME}" \
502 "${CARGO_LOCAL_INSTALL_SCRIPT}"
505 rm -Rf "${CFG_TMP_DIR}"
506 need_ok "couldn't rm temporary installation directory"