Bug 1320741 - Recommend `rustup target add`. r=chmanchester
authorRalph Giles <giles@mozilla.com>
Mon, 28 Nov 2016 10:51:59 -0800
changeset 325038 cd6aa4390d359320b0eeed1e1a6823a01516f115
parent 325037 16a80745ac452861923c6e3482b0d1f4842b5e45
child 325039 a3d8baec7db04cb05102fee3fd6ecb8bd6cd5dd3
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewerschmanchester
bugs1320741
milestone53.0a1
Bug 1320741 - Recommend `rustup target add`. r=chmanchester Provide some guidance on how to resolve the common error: can't find crate for `std` when cross-compiling rust code. This most commonly comes up with the Android build. MozReview-Commit-ID: 8PKKt7tf1KS
build/moz.configure/rust.configure
--- a/build/moz.configure/rust.configure
+++ b/build/moz.configure/rust.configure
@@ -80,16 +80,17 @@ def rust_triple_alias(host_or_target):
     assert host_or_target in (host, target)
 
     @depends(rustc, host_or_target, when=rust_compiler)
     @imports('os')
     @imports('subprocess')
     @imports(_from='mozbuild.configure.util', _import='LineIO')
     @imports(_from='mozbuild.shellutil', _import='quote')
     @imports(_from='tempfile', _import='mkstemp')
+    @imports(_from='textwrap', _import='dedent')
     def rust_target(rustc, host_or_target):
         # Rust's --target options are similar to, but not exactly the same
         # as, the autoconf-derived targets we use.  An example would be that
         # Rust uses distinct target triples for targetting the GNU C++ ABI
         # and the MSVC C++ ABI on Win32, whereas autoconf has a single
         # triple and relies on the user to ensure that everything is
         # compiled for the appropriate ABI.  We need to perform appropriate
         # munging to get the correct option to rustc.
@@ -150,17 +151,23 @@ def rust_triple_alias(host_or_target):
             cmd = [
                 rustc,
                 '--crate-type', 'staticlib',
                 target_arg,
                 '-o', out_path,
                 in_path,
             ]
             def failed():
-                die('Cannot compile for {} with {}'.format(host_or_target.alias, rustc))
+                die(dedent('''\
+                Cannot compile for {} with {}
+                The target may be unsupported, or you may not have
+                a rust std library for that target installed. Try:
+
+                  rustup target add {}
+                '''.format(host_or_target.alias, rustc, rustc_target)))
             check_cmd_output(*cmd, onerror=failed)
             if not os.path.exists(out_path) or os.path.getsize(out_path) == 0:
                 failed()
         finally:
             os.remove(in_path)
             os.remove(out_path)
 
         # This target is usable.