Skip to content

Commit 62d3a4f

Browse files
authored
Rollup merge of #78513 - jyn514:rustup-toolchain, r=Mark-Simulacrum
Infer the default host target from the host toolchain if possible - `beta-x86_64-unknown-linux-gnu` has beta stripped - `rustc2` is ignored This fixes ongoing issues where x.py will detect the wrong host triple between MSVC and GNU. I don't think this will break anyone's workflow - I'd be very surprised if you a) had no `[build]` section in `config.toml`, b) had rustc installed, and c) expected the default target to be something other than the default target used by `rustc`. But I could be wrong - I'm happy to hear user stories :) Fixes #78150. r? ``@Mark-Simulacrum`` cc ``@Lokathor``
2 parents 0aed74a + 3863dee commit 62d3a4f

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

src/bootstrap/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
88

99
- `x.py check` needs opt-in to check tests (--all-targets) [#77473](https://github.com/rust-lang/rust/pull/77473)
1010
- The default bootstrap profiles are now located at `bootstrap/defaults/config.$PROFILE.toml` (previously they were located at `bootstrap/defaults/config.toml.$PROFILE`) [#77558](https://github.com/rust-lang/rust/pull/77558)
11+
- If you have Rust already installed, `x.py` will now infer the host target
12+
from the default rust toolchain. [#78513](https://github.com/rust-lang/rust/pull/78513)
1113

1214

1315
## [Version 2] - 2020-09-25

src/bootstrap/bootstrap.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,23 @@ def format_build_time(duration):
187187
return str(datetime.timedelta(seconds=int(duration)))
188188

189189

190-
def default_build_triple():
190+
def default_build_triple(verbose):
191191
"""Build triple as in LLVM"""
192+
# If the user already has a host build triple with an existing `rustc`
193+
# install, use their preference. This fixes most issues with Windows builds
194+
# being detected as GNU instead of MSVC.
195+
try:
196+
version = subprocess.check_output(["rustc", "--version", "--verbose"])
197+
host = next(x for x in version.split('\n') if x.startswith("host: "))
198+
triple = host.split("host: ")[1]
199+
if verbose:
200+
print("detected default triple {}".format(triple))
201+
return triple
202+
except Exception as e:
203+
if verbose:
204+
print("rustup not detected: {}".format(e))
205+
print("falling back to auto-detect")
206+
192207
default_encoding = sys.getdefaultencoding()
193208
required = sys.platform != 'win32'
194209
ostype = require(["uname", "-s"], exit=required)
@@ -831,7 +846,7 @@ def build_triple(self):
831846
config = self.get_toml('build')
832847
if config:
833848
return config
834-
return default_build_triple()
849+
return default_build_triple(self.verbose)
835850

836851
def check_submodule(self, module, slow_submodules):
837852
if not slow_submodules:

src/bootstrap/configure.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def err(msg):
266266
def build():
267267
if 'build' in known_args:
268268
return known_args['build'][-1][1]
269-
return bootstrap.default_build_triple()
269+
return bootstrap.default_build_triple(verbose=False)
270270

271271

272272
def set(key, value):

0 commit comments

Comments
 (0)