about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJoshua Nelson <jyn514@gmail.com>2020-10-28 23:09:41 -0400
committerJoshua Nelson <jyn514@gmail.com>2020-11-05 17:44:22 -0500
commit3863dee15988d8e2b8b33ff6ba8759342e8dd98f (patch)
tree306b043506c8f9a5d939c6cd09e7e1cabe959ec2
parent07e968b640e8ff76fa8be4b48b70ab80ea577800 (diff)
Infer the default host target from the host toolchain if possible
This fixes ongoing issues where x.py will detect the wrong host triple
between MSVC and GNU.

- Add line to changelog
-rw-r--r--src/bootstrap/CHANGELOG.md2
-rw-r--r--src/bootstrap/bootstrap.py19
-rwxr-xr-xsrc/bootstrap/configure.py2
3 files changed, 20 insertions, 3 deletions
diff --git a/src/bootstrap/CHANGELOG.md b/src/bootstrap/CHANGELOG.md
index 7bb4e504275..a103c9fb0b7 100644
--- a/src/bootstrap/CHANGELOG.md
+++ b/src/bootstrap/CHANGELOG.md
@@ -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
diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py
index 87e15363818..54d0a23dec5 100644
--- a/src/bootstrap/bootstrap.py
+++ b/src/bootstrap/bootstrap.py
@@ -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)
@@ -831,7 +846,7 @@ class RustBuild(object):
         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:
diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py
index e156952d56f..322e9d69232 100755
--- a/src/bootstrap/configure.py
+++ b/src/bootstrap/configure.py
@@ -266,7 +266,7 @@ config = {}
 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):