diff --git a/rust/private/rustdoc_test.bzl b/rust/private/rustdoc_test.bzl index 07fef51f54..10be63eb6b 100644 --- a/rust/private/rustdoc_test.bzl +++ b/rust/private/rustdoc_test.bzl @@ -64,6 +64,9 @@ def _construct_writer_arguments(ctx, test_runner, opt_test_params, action, crate # Collect and dedupe all of the file roots in a list before appending # them to args to prevent generating a large amount of identical args roots = [] + root = crate_info.output.root.path + if not root in roots: + roots.append(root) for dep in crate_info.deps.to_list(): dep_crate_info = getattr(dep, "crate_info", None) dep_dep_info = getattr(dep, "dep_info", None) diff --git a/test/unit/rustdoc/rustdoc_build.rs b/test/unit/rustdoc/rustdoc_build.rs new file mode 100644 index 0000000000..651ed52989 --- /dev/null +++ b/test/unit/rustdoc/rustdoc_build.rs @@ -0,0 +1,3 @@ +fn main() { + println!("cargo:rustc-env=CONST=xyz"); +} diff --git a/test/unit/rustdoc/rustdoc_lib.rs b/test/unit/rustdoc/rustdoc_lib.rs index 6ab32347ba..4bff6575f0 100644 --- a/test/unit/rustdoc/rustdoc_lib.rs +++ b/test/unit/rustdoc/rustdoc_lib.rs @@ -4,6 +4,9 @@ use rustdoc_proc_macro::make_answer; #[cfg(feature = "with_proc_macro")] make_answer!(); +#[cfg(feature = "with_build_script")] +pub const CONST: &str = env!("CONST"); + /// The answer to the ultimate question /// ``` /// fn answer() -> u32 { 42 } diff --git a/test/unit/rustdoc/rustdoc_nodep_lib.rs b/test/unit/rustdoc/rustdoc_nodep_lib.rs new file mode 100644 index 0000000000..e737daf3b9 --- /dev/null +++ b/test/unit/rustdoc/rustdoc_nodep_lib.rs @@ -0,0 +1,28 @@ +#[cfg(feature = "with_proc_macro")] +use rustdoc_proc_macro::make_answer; + +#[cfg(feature = "with_proc_macro")] +make_answer!(); + +#[cfg(feature = "with_build_script")] +pub const CONST: &str = env!("CONST"); + +/// The answer to the ultimate question +/// ``` +/// fn answer() -> u32 { 42 } +/// assert_eq!(answer(), 42); +/// ``` +#[cfg(not(feature = "with_proc_macro"))] +pub fn answer() -> u32 { + 42 +} + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn test_answer() { + assert_eq!(answer(), 42); + } +} diff --git a/test/unit/rustdoc/rustdoc_unit_test.bzl b/test/unit/rustdoc/rustdoc_unit_test.bzl index e6a122ac0a..e3bc548fb3 100644 --- a/test/unit/rustdoc/rustdoc_unit_test.bzl +++ b/test/unit/rustdoc/rustdoc_unit_test.bzl @@ -2,6 +2,7 @@ load("@bazel_skylib//lib:unittest.bzl", "analysistest") load("@rules_cc//cc:defs.bzl", "cc_library") +load("//cargo:defs.bzl", "cargo_build_script") load("//rust:defs.bzl", "rust_binary", "rust_doc", "rust_doc_test", "rust_library", "rust_proc_macro", "rust_test") load( "//test/unit:common.bzl", @@ -118,6 +119,12 @@ def _define_targets(): rustdoc_deps = [":adder"], ) + _target_maker( + rust_library, + name = "nodep_lib", + srcs = ["rustdoc_nodep_lib.rs"], + ) + _target_maker( rust_proc_macro, name = "rustdoc_proc_macro", @@ -133,6 +140,14 @@ def _define_targets(): crate_features = ["with_proc_macro"], ) + _target_maker( + rust_library, + name = "lib_nodep_with_proc_macro", + srcs = ["rustdoc_nodep_lib.rs"], + proc_macro_deps = [":rustdoc_proc_macro"], + crate_features = ["with_proc_macro"], + ) + _target_maker( rust_binary, name = "bin_with_transitive_proc_macro", @@ -157,6 +172,37 @@ def _define_targets(): deps = [":cc_lib"], ) + _target_maker( + rust_library, + name = "lib_nodep_with_cc", + srcs = ["rustdoc_nodep_lib.rs"], + crate_features = ["with_cc"], + deps = [":cc_lib"], + ) + + cargo_build_script( + name = "lib_build_script", + srcs = ["rustdoc_build.rs"], + edition = "2018", + ) + + _target_maker( + rust_library, + name = "lib_with_build_script", + srcs = ["rustdoc_lib.rs"], + rustdoc_deps = [":adder"], + crate_features = ["with_build_script"], + deps = [":lib_build_script"], + ) + + _target_maker( + rust_library, + name = "lib_nodep_with_build_script", + srcs = ["rustdoc_nodep_lib.rs"], + crate_features = ["with_build_script"], + deps = [":lib_build_script"], + ) + def rustdoc_test_suite(name): """Entry-point macro called from the BUILD file.