Bug 1320741 - Recommend `rustup target add`. r=chmanchester draft
authorRalph Giles <giles@mozilla.com>
Mon, 28 Nov 2016 10:51:59 -0800
changeset 446672 d8b71af6e3ba421b8e4d5a41c09f077e1a400771
parent 446527 3853c539a1b7c803f1075d2c3ecefbdd314af1d8
child 538841 e771821292c805e1d1b6679b37cb504549fad78b
push id37854
push userbmo:giles@thaumas.net
push dateThu, 01 Dec 2016 18:51:45 +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.