@@ -226,13 +226,16 @@ def format_build_time(duration):
226
226
227
227
def default_build_triple (verbose ):
228
228
"""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.
233
232
default_encoding = sys .getdefaultencoding ()
234
233
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 :
236
239
try :
237
240
version = subprocess .check_output (["rustc" , "--version" , "--verbose" ],
238
241
stderr = subprocess .DEVNULL )
@@ -250,17 +253,19 @@ def default_build_triple(verbose):
250
253
print ("falling back to auto-detect" , file = sys .stderr )
251
254
252
255
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 )
254
258
255
259
# If we do not have `uname`, assume Windows.
256
- if uname is None :
260
+ if ostype is None or cputype is None :
257
261
return 'x86_64-pc-windows-msvc'
258
262
259
- kernel , cputype , processor = uname .decode (default_encoding ).split ()
263
+ ostype = ostype .decode (default_encoding )
264
+ cputype = cputype .decode (default_encoding )
260
265
261
266
# The goal here is to come up with the same triple as LLVM would,
262
267
# at least for the subset of platforms we're willing to target.
263
- kerneltype_mapper = {
268
+ ostype_mapper = {
264
269
'Darwin' : 'apple-darwin' ,
265
270
'DragonFly' : 'unknown-dragonfly' ,
266
271
'FreeBSD' : 'unknown-freebsd' ,
@@ -270,18 +275,17 @@ def default_build_triple(verbose):
270
275
}
271
276
272
277
# 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'
281
285
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'
285
289
# On Solaris, uname -m will return a machine classification instead
286
290
# of a cpu type, so uname -p is recommended instead. However, the
287
291
# output from that option is too generic for our purposes (it will
@@ -290,34 +294,34 @@ def default_build_triple(verbose):
290
294
cputype = require (['isainfo' , '-k' ]).decode (default_encoding )
291
295
# sparc cpus have sun as a target vendor
292
296
if 'sparc' in cputype :
293
- kernel = 'sun-solaris'
294
- elif kernel .startswith ('MINGW' ):
297
+ ostype = 'sun-solaris'
298
+ elif ostype .startswith ('MINGW' ):
295
299
# msys' `uname` does not print gcc configuration, but prints msys
296
300
# configuration. so we cannot believe `uname -m`:
297
301
# msys1 is always i686 and msys2 is always x86_64.
298
302
# instead, msys defines $MSYSTEM which is MINGW32 on i686 and
299
303
# MINGW64 on x86_64.
300
- kernel = 'pc-windows-gnu'
304
+ ostype = 'pc-windows-gnu'
301
305
cputype = 'i686'
302
306
if os .environ .get ('MSYSTEM' ) == 'MINGW64' :
303
307
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' ):
307
311
cputype = 'i686'
308
- if kernel .endswith ('WOW64' ):
312
+ if ostype .endswith ('WOW64' ):
309
313
cputype = 'x86_64'
310
- kernel = 'pc-windows-gnu'
311
- elif platform_is_win32 () :
314
+ ostype = 'pc-windows-gnu'
315
+ elif sys . platform == 'win32' :
312
316
# Some Windows platforms might have a `uname` command that returns a
313
317
# non-standard string (e.g. gnuwin32 tools returns `windows32`). In
314
318
# these cases, fall back to using sys.platform.
315
319
return 'x86_64-pc-windows-msvc'
316
320
else :
317
- err = "unknown OS type: {}" .format (kernel )
321
+ err = "unknown OS type: {}" .format (ostype )
318
322
sys .exit (err )
319
323
320
- if cputype in ['powerpc' , 'riscv' ] and kernel == 'unknown-freebsd' :
324
+ if cputype in ['powerpc' , 'riscv' ] and ostype == 'unknown-freebsd' :
321
325
cputype = subprocess .check_output (
322
326
['uname' , '-p' ]).strip ().decode (default_encoding )
323
327
cputype_mapper = {
@@ -351,23 +355,24 @@ def default_build_triple(verbose):
351
355
cputype = cputype_mapper [cputype ]
352
356
elif cputype in {'xscale' , 'arm' }:
353
357
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'
359
364
elif cputype == 'armv6l' :
360
365
cputype = 'arm'
361
- if kernel == 'linux-android' :
362
- kernel = 'linux-androideabi'
366
+ if ostype == 'linux-android' :
367
+ ostype = 'linux-androideabi'
363
368
else :
364
- kernel += 'eabihf'
369
+ ostype += 'eabihf'
365
370
elif cputype in {'armv7l' , 'armv8l' }:
366
371
cputype = 'armv7'
367
- if kernel == 'linux-android' :
368
- kernel = 'linux-androideabi'
372
+ if ostype == 'linux-android' :
373
+ ostype = 'linux-androideabi'
369
374
else :
370
- kernel += 'eabihf'
375
+ ostype += 'eabihf'
371
376
elif cputype == 'mips' :
372
377
if sys .byteorder == 'big' :
373
378
cputype = 'mips'
@@ -383,14 +388,14 @@ def default_build_triple(verbose):
383
388
else :
384
389
raise ValueError ('unknown byteorder: {}' .format (sys .byteorder ))
385
390
# only the n64 ABI is supported, indicate it
386
- kernel += 'abi64'
391
+ ostype += 'abi64'
387
392
elif cputype == 'sparc' or cputype == 'sparcv9' or cputype == 'sparc64' :
388
393
pass
389
394
else :
390
395
err = "unknown cpu type: {}" .format (cputype )
391
396
sys .exit (err )
392
397
393
- return "{}-{}" .format (cputype , kernel )
398
+ return "{}-{}" .format (cputype , ostype )
394
399
395
400
396
401
@contextlib .contextmanager
0 commit comments