Skip to content

Commit

Permalink
Rollup merge of #78513 - jyn514:rustup-toolchain, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
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``
  • Loading branch information
Dylan-DPC committed Nov 9, 2020
2 parents 0aed74a + 3863dee commit 62d3a4f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/bootstrap/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

- `x.py check` needs opt-in to check tests (--all-targets) [#77473](https://github.com/rust-lang/rust/pull/77473)
- 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)
- If you have Rust already installed, `x.py` will now infer the host target
from the default rust toolchain. [#78513](https://github.com/rust-lang/rust/pull/78513)


## [Version 2] - 2020-09-25
Expand Down
19 changes: 17 additions & 2 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,23 @@ def format_build_time(duration):
return str(datetime.timedelta(seconds=int(duration)))


def default_build_triple():
def default_build_triple(verbose):
"""Build triple as in LLVM"""
# If the user already has a host build triple with an existing `rustc`
# install, use their preference. This fixes most issues with Windows builds
# being detected as GNU instead of MSVC.
try:
version = subprocess.check_output(["rustc", "--version", "--verbose"])
host = next(x for x in version.split('\n') if x.startswith("host: "))
triple = host.split("host: ")[1]
if verbose:
print("detected default triple {}".format(triple))
return triple
except Exception as e:
if verbose:
print("rustup not detected: {}".format(e))
print("falling back to auto-detect")

default_encoding = sys.getdefaultencoding()
required = sys.platform != 'win32'
ostype = require(["uname", "-s"], exit=required)
Expand Down Expand Up @@ -831,7 +846,7 @@ def build_triple(self):
config = self.get_toml('build')
if config:
return config
return default_build_triple()
return default_build_triple(self.verbose)

def check_submodule(self, module, slow_submodules):
if not slow_submodules:
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def err(msg):
def build():
if 'build' in known_args:
return known_args['build'][-1][1]
return bootstrap.default_build_triple()
return bootstrap.default_build_triple(verbose=False)


def set(key, value):
Expand Down

0 comments on commit 62d3a4f

Please sign in to comment.