Skip to content

Commit

Permalink
Merge pull request #825 from xen0n/mips-up-rustup-init-sh
Browse files Browse the repository at this point in the history
Support MIPS architectures in rustup-init.sh
  • Loading branch information
brson authored Nov 21, 2016
2 parents d5e96c4 + a3b1250 commit f5eb14c
Showing 1 changed file with 58 additions and 9 deletions.
67 changes: 58 additions & 9 deletions rustup-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down Expand Up @@ -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
;;
Expand All @@ -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
Expand Down

0 comments on commit f5eb14c

Please sign in to comment.