Skip to content

Commit 6922b50

Browse files
bsilver8192illicitonionUebelAndre
authored
rustdoc_test: fix and test OUT_DIR (#1779)
It needs the same treatment as SYSROOT. Co-authored-by: Daniel Wagner-Hall <[email protected]> Co-authored-by: UebelAndre <[email protected]>
1 parent ad01d1b commit 6922b50

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

rust/private/rustdoc.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ def rustdoc_compile_action(
132132
if is_test:
133133
if "SYSROOT" in env:
134134
env.update({"SYSROOT": "${{pwd}}/{}".format(toolchain.sysroot_short_path)})
135+
if "OUT_DIR" in env:
136+
env.update({"OUT_DIR": "${{pwd}}/{}".format(build_info.out_dir.short_path)})
135137

136138
# `rustdoc` does not support the SYSROOT environment variable. To account
137139
# for this, the flag must be explicitly passed to the `rustdoc` binary.

test/out_dir_in_tests/BUILD.bazel

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
load("//cargo:defs.bzl", "cargo_build_script")
2-
load("//rust:defs.bzl", "rust_library", "rust_test", "rust_test_suite")
2+
load("//rust:defs.bzl", "rust_doc_test", "rust_library", "rust_test", "rust_test_suite")
33

44
cargo_build_script(
55
name = "build_script",
@@ -22,6 +22,11 @@ rust_test(
2222
edition = "2018",
2323
)
2424

25+
rust_doc_test(
26+
name = "demo_lib_doc_test",
27+
crate = ":demo_lib",
28+
)
29+
2530
rust_test_suite(
2631
name = "suite",
2732
srcs = glob(["tests/**"]),

test/out_dir_in_tests/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
//! ```
2+
//! let contents = include_str!(concat!(env!("OUT_DIR"), "/test_content.txt"));
3+
//! assert_eq!("Test content", contents);
4+
//! ```
5+
16
#[cfg(test)]
27
mod tests {
38
use std::env;

0 commit comments

Comments
 (0)