Bug 1324435 - mozboot: ensure win32 rust support. r?ted draft
authorRalph Giles <giles@mozilla.com>
Wed, 11 Jan 2017 11:30:47 -0800
changeset 463336 346dba5efaaab6d00e3145494947155a970f9c82
parent 463335 aaf2765c8146b0d720cff7b187d8715f36be73d3
child 542643 09c7095eb933ed1211b37460313c5e667a9b7463
push id42029
push userbmo:giles@thaumas.net
push dateWed, 18 Jan 2017 21:47:35 +0000
reviewersted
bugs1324435
milestone53.0a1
Bug 1324435 - mozboot: ensure win32 rust support. r?ted If we have rustup installed, use it to check the available target platforms and install 32-bit windows support if we're on the (default 64-bit) windows platform. This catches systems where the mozillabuild bootstrapper was run before it installed this, so rustup is available, but the i686 target library isn't. MozReview-Commit-ID: 9bE2OQnmvxs
python/mozboot/mozboot/base.py
--- a/python/mozboot/mozboot/base.py
+++ b/python/mozboot/mozboot/base.py
@@ -562,16 +562,17 @@ class BaseBootstrapper(object):
             'cmd': cmd,
         })
 
     def ensure_rust_modern(self):
         modern, version = self.is_rust_modern()
 
         if modern:
             print('Your version of Rust (%s) is new enough.' % version)
+            self.ensure_rust_targets(self.which('rustup'))
             return
 
         if not version:
             # Rust wasn't in PATH. Check the standard location.
             cargo_home, cargo_bin = self.cargo_home()
             try_rustc = os.path.join(cargo_bin, 'rustc' + rust.exe_suffix())
             try_cargo = os.path.join(cargo_bin, 'cargo' + rust.exe_suffix())
             have_rustc = os.path.exists(try_rustc)
@@ -596,16 +597,29 @@ class BaseBootstrapper(object):
             if not modern:
                 print(RUST_UPGRADE_FAILED % (MODERN_RUST_VERSION, after))
                 sys.exit(1)
         else:
             # No rustup. Download and run the installer.
             print('Will try to install Rust.')
             self.install_rust()
 
+    def ensure_rust_targets(self, rustup):
+        """Make sure appropriate cross target libraries are installed."""
+        target_list =  subprocess.check_output([rustup, 'target', 'list'])
+        targets = [line.split()[0] for line in target_list.splitlines()
+                if 'installed' in line or 'default' in line]
+        print('Rust supports %s targets.' % ', '.join(targets))
+
+        # Support 32-bit Windows on 64-bit Windows.
+        win32 = 'i686-pc-windows-msvc'
+        win64 = 'x86_64-pc-windows-msvc'
+        if rust.platform() == win64 and not win32 in targets:
+            subprocess.check_call([rustup, 'target', 'add', win32])
+
     def upgrade_rust(self, rustup):
         """Upgrade Rust.
 
         Invoke rustup from the given path to update the rust install."""
         subprocess.check_call([rustup, 'update'])
 
     def install_rust(self):
         """Download and run the rustup installer."""