@@ -159,6 +159,17 @@ get_bitness() {
159
159
fi
160
160
}
161
161
162
+ is_host_amd64_elf () {
163
+ need_cmd head
164
+ need_cmd tail
165
+ # ELF e_machine detection without dependencies beyond coreutils.
166
+ # Two-byte field at offset 0x12 indicates the CPU,
167
+ # but we're interested in it being 0x3E to indicate amd64, or not that.
168
+ local _current_exe_machine
169
+ _current_exe_machine=$( head -c 19 /proc/self/exe | tail -c 1)
170
+ [ " $_current_exe_machine " = " $( printf ' \076' ) " ]
171
+ }
172
+
162
173
get_endianness () {
163
174
local cputype=$1
164
175
local suffix_eb=$2
@@ -338,7 +349,24 @@ get_architecture() {
338
349
if [ " ${_ostype} " = unknown-linux-gnu ] && [ " ${_bitness} " -eq 32 ]; then
339
350
case $_cputype in
340
351
x86_64)
341
- _cputype=i686
352
+ if [ -n " ${RUSTUP_CPUTYPE:- } " ]; then
353
+ _cputype=" $RUSTUP_CPUTYPE "
354
+ else {
355
+ # 32-bit executable for amd64 = x32
356
+ if is_host_amd64_elf; then {
357
+ echo " This host is running an x32 userland; as it stands, x32 support is poor," 1>&2
358
+ echo " and there isn't a native toolchain -- you will have to install" 1>&2
359
+ echo " multiarch compatibility with i686 and/or amd64, then select one" 1>&2
360
+ echo " by re-running this script with the RUSTUP_CPUTYPE environment variable" 1>&2
361
+ echo " set to i686 or x86_64, respectively." 1>&2
362
+ echo 1>&2
363
+ echo " You will be able to add an x32 target after installation by running" 1>&2
364
+ echo " rustup target add x86_64-unknown-linux-gnux32" 1>&2
365
+ exit 1
366
+ }; else
367
+ _cputype=i686
368
+ fi
369
+ }; fi
342
370
;;
343
371
mips64)
344
372
_cputype=$( get_endianness mips ' ' el)
0 commit comments