diff --git a/rustup-init.sh b/rustup-init.sh index a7853c0d36..7c46294c96 100755 --- a/rustup-init.sh +++ b/rustup-init.sh @@ -104,6 +104,43 @@ main() { return "$_retval" } +get_bitness() { + need_cmd head + # Architecture detection without dependencies beyond coreutils. + # ELF files start out "\x7fELF", and the following byte is + # 0x01 for 32-bit and + # 0x02 for 64-bit. + # The printf builtin on some shells like dash only supports octal + # escape sequences, so we use those. + local _current_exe_head=$(head -c 5 /proc/self/exe ) + if [ "$_current_exe_head" = "$(printf '\177ELF\001')" ]; then + echo 32 + elif [ "$_current_exe_head" = "$(printf '\177ELF\002')" ]; then + echo 64 + else + err "unknown platform bitness" + fi +} + +get_endianness() { + local cputype=$1 + local suffix_eb=$2 + local suffix_el=$3 + + # detect endianness without od/hexdump, like get_bitness() does. + need_cmd head + need_cmd tail + + local _current_exe_endianness="$(head -c 6 /proc/self/exe | tail -c 1)" + if [ "$_current_exe_endianness" = "$(printf '\001')" ]; then + echo "${cputype}${suffix_el}" + elif [ "$_current_exe_endianness" = "$(printf '\002')" ]; then + echo "${cputype}${suffix_eb}" + else + err "unknown platform endianness" + fi +} + get_architecture() { local _ostype="$(uname -s)" @@ -172,6 +209,26 @@ get_architecture() { local _cputype=x86_64 ;; + mips) + local _cputype="$(get_endianness $_cputype "" 'el')" + ;; + + mips64) + local _bitness="$(get_bitness)" + if [ $_bitness = "32" ]; then + if [ $_ostype = "unknown-linux-gnu" ]; then + # 64-bit kernel with 32-bit userland + # endianness suffix is appended later + local _cputype=mips + fi + else + # only n64 ABI is supported for now + local _ostype="${_ostype}abi64" + fi + + local _cputype="$(get_endianness $_cputype "" 'el')" + ;; + ppc) local _cputype=powerpc ;; @@ -191,15 +248,7 @@ get_architecture() { # Detect 64-bit linux with 32-bit userland if [ $_ostype = unknown-linux-gnu -a $_cputype = x86_64 ]; then - need_cmd head - # Architecture detection without dependencies beyond coreutils. - # ELF files start out "\x7fELF", and the following byte is - # 0x01 for 32-bit and - # 0x02 for 64-bit. - # The printf builtin on some shells like dash only supports octal - # escape sequences, so we use those. - local _current_exe_head=$(head -c 5 /proc/self/exe ) - if [ "$_current_exe_head" = "$(printf '\177ELF\001')" ]; then + if [ "$(get_bitness)" = "32" ]; then local _cputype=i686 fi fi