Skip to content

Commit edc37d2

Browse files
committed
revert rust-lang#111562 changes
1 parent ed33437 commit edc37d2

File tree

1 file changed

+49
-44
lines changed

1 file changed

+49
-44
lines changed

src/bootstrap/bootstrap.py

+49-44
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,16 @@ def format_build_time(duration):
226226

227227
def default_build_triple(verbose):
228228
"""Build triple as in LLVM"""
229-
# If we're on Windows and have an existing `rustc` toolchain, use `rustc --version --verbose`
230-
# to find our host target triple. This fixes an issue with Windows builds being detected
231-
# as GNU instead of MSVC.
232-
# Otherwise, detect it via `uname`
229+
# If the user already has a host build triple with an existing `rustc`
230+
# install, use their preference. This fixes most issues with Windows builds
231+
# being detected as GNU instead of MSVC.
233232
default_encoding = sys.getdefaultencoding()
234233

235-
if platform_is_win32():
234+
if sys.platform == 'darwin':
235+
if verbose:
236+
print("not using rustc detection as it is unreliable on macOS", file=sys.stderr)
237+
print("falling back to auto-detect", file=sys.stderr)
238+
else:
236239
try:
237240
version = subprocess.check_output(["rustc", "--version", "--verbose"],
238241
stderr=subprocess.DEVNULL)
@@ -250,17 +253,19 @@ def default_build_triple(verbose):
250253
print("falling back to auto-detect", file=sys.stderr)
251254

252255
required = not platform_is_win32()
253-
uname = require(["uname", "-smp"], exit=required)
256+
ostype = require(["uname", "-s"], exit=required)
257+
cputype = require(['uname', '-m'], exit=required)
254258

255259
# If we do not have `uname`, assume Windows.
256-
if uname is None:
260+
if ostype is None or cputype is None:
257261
return 'x86_64-pc-windows-msvc'
258262

259-
kernel, cputype, processor = uname.decode(default_encoding).split()
263+
ostype = ostype.decode(default_encoding)
264+
cputype = cputype.decode(default_encoding)
260265

261266
# The goal here is to come up with the same triple as LLVM would,
262267
# at least for the subset of platforms we're willing to target.
263-
kerneltype_mapper = {
268+
ostype_mapper = {
264269
'Darwin': 'apple-darwin',
265270
'DragonFly': 'unknown-dragonfly',
266271
'FreeBSD': 'unknown-freebsd',
@@ -270,18 +275,17 @@ def default_build_triple(verbose):
270275
}
271276

272277
# Consider the direct transformation first and then the special cases
273-
if kernel in kerneltype_mapper:
274-
kernel = kerneltype_mapper[kernel]
275-
elif kernel == 'Linux':
276-
# Apple doesn't support `-o` so this can't be used in the combined
277-
# uname invocation above
278-
ostype = require(["uname", "-o"], exit=required).decode(default_encoding)
279-
if ostype == 'Android':
280-
kernel = 'linux-android'
278+
if ostype in ostype_mapper:
279+
ostype = ostype_mapper[ostype]
280+
elif ostype == 'Linux':
281+
os_from_sp = subprocess.check_output(
282+
['uname', '-o']).strip().decode(default_encoding)
283+
if os_from_sp == 'Android':
284+
ostype = 'linux-android'
281285
else:
282-
kernel = 'unknown-linux-gnu'
283-
elif kernel == 'SunOS':
284-
kernel = 'pc-solaris'
286+
ostype = 'unknown-linux-gnu'
287+
elif ostype == 'SunOS':
288+
ostype = 'pc-solaris'
285289
# On Solaris, uname -m will return a machine classification instead
286290
# of a cpu type, so uname -p is recommended instead. However, the
287291
# output from that option is too generic for our purposes (it will
@@ -290,34 +294,34 @@ def default_build_triple(verbose):
290294
cputype = require(['isainfo', '-k']).decode(default_encoding)
291295
# sparc cpus have sun as a target vendor
292296
if 'sparc' in cputype:
293-
kernel = 'sun-solaris'
294-
elif kernel.startswith('MINGW'):
297+
ostype = 'sun-solaris'
298+
elif ostype.startswith('MINGW'):
295299
# msys' `uname` does not print gcc configuration, but prints msys
296300
# configuration. so we cannot believe `uname -m`:
297301
# msys1 is always i686 and msys2 is always x86_64.
298302
# instead, msys defines $MSYSTEM which is MINGW32 on i686 and
299303
# MINGW64 on x86_64.
300-
kernel = 'pc-windows-gnu'
304+
ostype = 'pc-windows-gnu'
301305
cputype = 'i686'
302306
if os.environ.get('MSYSTEM') == 'MINGW64':
303307
cputype = 'x86_64'
304-
elif kernel.startswith('MSYS'):
305-
kernel = 'pc-windows-gnu'
306-
elif kernel.startswith('CYGWIN_NT'):
308+
elif ostype.startswith('MSYS'):
309+
ostype = 'pc-windows-gnu'
310+
elif ostype.startswith('CYGWIN_NT'):
307311
cputype = 'i686'
308-
if kernel.endswith('WOW64'):
312+
if ostype.endswith('WOW64'):
309313
cputype = 'x86_64'
310-
kernel = 'pc-windows-gnu'
311-
elif platform_is_win32():
314+
ostype = 'pc-windows-gnu'
315+
elif sys.platform == 'win32':
312316
# Some Windows platforms might have a `uname` command that returns a
313317
# non-standard string (e.g. gnuwin32 tools returns `windows32`). In
314318
# these cases, fall back to using sys.platform.
315319
return 'x86_64-pc-windows-msvc'
316320
else:
317-
err = "unknown OS type: {}".format(kernel)
321+
err = "unknown OS type: {}".format(ostype)
318322
sys.exit(err)
319323

320-
if cputype in ['powerpc', 'riscv'] and kernel == 'unknown-freebsd':
324+
if cputype in ['powerpc', 'riscv'] and ostype == 'unknown-freebsd':
321325
cputype = subprocess.check_output(
322326
['uname', '-p']).strip().decode(default_encoding)
323327
cputype_mapper = {
@@ -351,23 +355,24 @@ def default_build_triple(verbose):
351355
cputype = cputype_mapper[cputype]
352356
elif cputype in {'xscale', 'arm'}:
353357
cputype = 'arm'
354-
if kernel == 'linux-android':
355-
kernel = 'linux-androideabi'
356-
elif kernel == 'unknown-freebsd':
357-
cputype = processor
358-
kernel = 'unknown-freebsd'
358+
if ostype == 'linux-android':
359+
ostype = 'linux-androideabi'
360+
elif ostype == 'unknown-freebsd':
361+
cputype = subprocess.check_output(
362+
['uname', '-p']).strip().decode(default_encoding)
363+
ostype = 'unknown-freebsd'
359364
elif cputype == 'armv6l':
360365
cputype = 'arm'
361-
if kernel == 'linux-android':
362-
kernel = 'linux-androideabi'
366+
if ostype == 'linux-android':
367+
ostype = 'linux-androideabi'
363368
else:
364-
kernel += 'eabihf'
369+
ostype += 'eabihf'
365370
elif cputype in {'armv7l', 'armv8l'}:
366371
cputype = 'armv7'
367-
if kernel == 'linux-android':
368-
kernel = 'linux-androideabi'
372+
if ostype == 'linux-android':
373+
ostype = 'linux-androideabi'
369374
else:
370-
kernel += 'eabihf'
375+
ostype += 'eabihf'
371376
elif cputype == 'mips':
372377
if sys.byteorder == 'big':
373378
cputype = 'mips'
@@ -383,14 +388,14 @@ def default_build_triple(verbose):
383388
else:
384389
raise ValueError('unknown byteorder: {}'.format(sys.byteorder))
385390
# only the n64 ABI is supported, indicate it
386-
kernel += 'abi64'
391+
ostype += 'abi64'
387392
elif cputype == 'sparc' or cputype == 'sparcv9' or cputype == 'sparc64':
388393
pass
389394
else:
390395
err = "unknown cpu type: {}".format(cputype)
391396
sys.exit(err)
392397

393-
return "{}-{}".format(cputype, kernel)
398+
return "{}-{}".format(cputype, ostype)
394399

395400

396401
@contextlib.contextmanager

0 commit comments

Comments
 (0)