# HG changeset patch
# User Xidorn Quan <me@upsuper.org>
# Date 1525255324 -36000
# Node ID 4340083e6691e1d2aaec806461fd8d355fcf451b
# Parent  12c4ce3c0ac903e917c168ea527dff9d768d2019
Bug 1457524 part 3 - Check rustdoc for rust tests. r=froydnj

MozReview-Commit-ID: 4qRccUcXq6O

diff --git a/build/moz.configure/rust.configure b/build/moz.configure/rust.configure
--- a/build/moz.configure/rust.configure
+++ b/build/moz.configure/rust.configure
@@ -256,22 +256,33 @@ set_config('RUST_TARGET_ENV_NAME', rust_
 set_config('RUSTC_COMMIT', depends(rustc_info)(lambda i: i.commit))
 
 set_config('RUSTC_VERSION', depends(rustc_info)(lambda i: str(i.version)))
 
 # Until we remove all the other Rust checks in old-configure.
 add_old_configure_assignment('RUSTC', rustc)
 add_old_configure_assignment('RUST_TARGET', rust_target_triple)
 
+# Rustdoc is required by Rust tests below.
+rustdoc = check_prog('RUSTDOC', add_rustup_path('rustdoc'), allow_missing=True)
+
 # This option is separate from --enable-tests because Rust tests are particularly
 # expensive in terms of compile time (especially for code in libxul).
 option('--enable-rust-tests',
        help='Enable building of Rust tests, and build-time execution of them')
 
-set_config('MOZ_RUST_TESTS', depends('--enable-rust-tests')(lambda v: bool(v)))
+
+@depends('--enable-rust-tests', rustdoc)
+def rust_tests(enable_rust_tests, rustdoc):
+    if enable_rust_tests and not rustdoc:
+        die('--enable-rust-tests requires rustdoc')
+    return bool(enable_rust_tests)
+
+
+set_config('MOZ_RUST_TESTS', rust_tests)
 
 option(env='WIN64_LINK', nargs=1, help='Path to link.exe that targets win64')
 option(env='WIN64_LIB', nargs=1, help='Paths to libraries for the win64 linker')
 
 set_config('WIN64_LINK', depends('WIN64_LINK')(lambda x: x))
 set_config('WIN64_LIB', depends('WIN64_LIB')(lambda x: x))
 
 
diff --git a/build/mozconfig.rust b/build/mozconfig.rust
--- a/build/mozconfig.rust
+++ b/build/mozconfig.rust
@@ -1,9 +1,10 @@
 # Options to enable rust in automation builds.
 
 TOOLTOOL_DIR=${TOOLTOOL_DIR:-$topsrcdir}
 
 # Tell configure to use the tooltool rustc.
 RUSTC="$TOOLTOOL_DIR/rustc/bin/rustc"
 CARGO="$TOOLTOOL_DIR/rustc/bin/cargo"
+RUSTDOC="$TOOLTOOL_DIR/rustc/bin/rustdoc"
 
 ac_add_options --enable-rust-simd
diff --git a/config/rules.mk b/config/rules.mk
--- a/config/rules.mk
+++ b/config/rules.mk
@@ -893,16 +893,17 @@ endif
 
 # We use the + prefix to pass down the jobserver fds to cargo, but we
 # don't use the prefix when make -n is used, so that cargo doesn't run
 # in that case)
 define RUN_CARGO
 $(if $(findstring n,$(filter-out --%, $(MAKEFLAGS))),,+)env $(environment_cleaner) $(rust_unlock_unstable) $(rustflags_override) $(sccache_wrap) \
 	CARGO_TARGET_DIR=$(CARGO_TARGET_DIR) \
 	RUSTC=$(RUSTC) \
+	RUSTDOC=$(RUSTDOC) \
 	MOZ_SRC=$(topsrcdir) \
 	MOZ_DIST=$(ABS_DIST) \
 	LIBCLANG_PATH="$(MOZ_LIBCLANG_PATH)" \
 	CLANG_PATH="$(MOZ_CLANG_PATH)" \
 	PKG_CONFIG_ALLOW_CROSS=1 \
 	RUST_BACKTRACE=full \
 	MOZ_TOPOBJDIR=$(topobjdir) \
 	$(cargo_incremental) \
