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
--- 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.