Skip to content

Commit f80c6ae

Browse files
authored
Rollup merge of #79845 - jyn514:python3, r=Mark-Simulacrum
Fix rustup support in default_build_triple for python3 bootstrap completely ignores all errors when detecting a rustup version, so this wasn't noticed before. Fixes the following error: ``` rustup not detected: a bytes-like object is required, not 'str' falling back to auto-detect ``` This also takes the opportunity to only call rustup and other external commands only once during startup. Follow-up to #78513.
2 parents 89051d8 + 8909c4d commit f80c6ae

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/bootstrap/bootstrap.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,10 @@ def default_build_triple(verbose):
192192
# If the user already has a host build triple with an existing `rustc`
193193
# install, use their preference. This fixes most issues with Windows builds
194194
# being detected as GNU instead of MSVC.
195+
default_encoding = sys.getdefaultencoding()
195196
try:
196197
version = subprocess.check_output(["rustc", "--version", "--verbose"])
198+
version = version.decode(default_encoding)
197199
host = next(x for x in version.split('\n') if x.startswith("host: "))
198200
triple = host.split("host: ")[1]
199201
if verbose:
@@ -204,7 +206,6 @@ def default_build_triple(verbose):
204206
print("rustup not detected: {}".format(e))
205207
print("falling back to auto-detect")
206208

207-
default_encoding = sys.getdefaultencoding()
208209
required = sys.platform != 'win32'
209210
ostype = require(["uname", "-s"], exit=required)
210211
cputype = require(['uname', '-m'], exit=required)
@@ -794,7 +795,7 @@ def build_bootstrap(self):
794795
env.setdefault("RUSTFLAGS", "")
795796
env["RUSTFLAGS"] += " -Cdebuginfo=2"
796797

797-
build_section = "target.{}".format(self.build_triple())
798+
build_section = "target.{}".format(self.build)
798799
target_features = []
799800
if self.get_toml("crt-static", build_section) == "true":
800801
target_features += ["+crt-static"]
@@ -825,7 +826,11 @@ def build_bootstrap(self):
825826
run(args, env=env, verbose=self.verbose)
826827

827828
def build_triple(self):
828-
"""Build triple as in LLVM"""
829+
"""Build triple as in LLVM
830+
831+
Note that `default_build_triple` is moderately expensive,
832+
so use `self.build` where possible.
833+
"""
829834
config = self.get_toml('build')
830835
if config:
831836
return config

0 commit comments

Comments
 (0)