rustdoc: forward -Z options to rustc

Currently rustdoc does not forward `-Z` options to rustc when building
test executables. This makes impossible to use rustdoc to run test
samples when crate under test is instrumented with one of sanitizers
`-Zsanitizer=...`, since the final linking step will not include
sanitizer runtime library.

Forward `-Z` options to rustc to solve the issue.

Helps with #43031.
This commit is contained in:
Tomasz Miąsko 2019-10-11 00:00:00 +00:00
parent 000d90b11f
commit 5db17335a1
6 changed files with 39 additions and 15 deletions

View file

@ -53,6 +53,8 @@ pub struct Options {
pub codegen_options_strs: Vec<String>, pub codegen_options_strs: Vec<String>,
/// Debugging (`-Z`) options to pass to the compiler. /// Debugging (`-Z`) options to pass to the compiler.
pub debugging_options: DebuggingOptions, pub debugging_options: DebuggingOptions,
/// Debugging (`-Z`) options strings to pass to the compiler.
pub debugging_options_strs: Vec<String>,
/// The target used to compile the crate against. /// The target used to compile the crate against.
pub target: TargetTriple, pub target: TargetTriple,
/// Edition used when reading the crate. Defaults to "2015". Also used by default when /// Edition used when reading the crate. Defaults to "2015". Also used by default when
@ -481,6 +483,7 @@ impl Options {
let generate_redirect_pages = matches.opt_present("generate-redirect-pages"); let generate_redirect_pages = matches.opt_present("generate-redirect-pages");
let test_builder = matches.opt_str("test-builder").map(PathBuf::from); let test_builder = matches.opt_str("test-builder").map(PathBuf::from);
let codegen_options_strs = matches.opt_strs("C"); let codegen_options_strs = matches.opt_strs("C");
let debugging_options_strs = matches.opt_strs("Z");
let lib_strs = matches.opt_strs("L"); let lib_strs = matches.opt_strs("L");
let extern_strs = matches.opt_strs("extern"); let extern_strs = matches.opt_strs("extern");
let runtool = matches.opt_str("runtool"); let runtool = matches.opt_str("runtool");
@ -502,6 +505,7 @@ impl Options {
codegen_options, codegen_options,
codegen_options_strs, codegen_options_strs,
debugging_options, debugging_options,
debugging_options_strs,
target, target,
edition, edition,
maybe_sysroot, maybe_sysroot,

View file

@ -279,6 +279,9 @@ fn run_test(
for codegen_options_str in &options.codegen_options_strs { for codegen_options_str in &options.codegen_options_strs {
compiler.arg("-C").arg(&codegen_options_str); compiler.arg("-C").arg(&codegen_options_str);
} }
for debugging_option_str in &options.debugging_options_strs {
compiler.arg("-Z").arg(&debugging_option_str);
}
if no_run { if no_run {
compiler.arg("--emit=metadata"); compiler.arg("--emit=metadata");
} }

View file

@ -8,7 +8,7 @@ failures:
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/failed-doctest-missing-codes.rs:9:13 --> $DIR/failed-doctest-missing-codes.rs:9:13
| |
3 | let x: () = 5i32; LL | let x: () = 5i32;
| ^^^^ expected (), found i32 | ^^^^ expected (), found i32
| |
= note: expected type `()` = note: expected type `()`

View file

@ -9,7 +9,7 @@ failures:
error[E0425]: cannot find value `no` in this scope error[E0425]: cannot find value `no` in this scope
--> $DIR/failed-doctest-output.rs:22:1 --> $DIR/failed-doctest-output.rs:22:1
| |
3 | no LL | no
| ^^ not found in this scope | ^^ not found in this scope
error: aborting due to previous error error: aborting due to previous error

View file

@ -8,7 +8,7 @@ failures:
error: unterminated double quote string error: unterminated double quote string
--> $DIR/unparseable-doc-test.rs:8:1 --> $DIR/unparseable-doc-test.rs:8:1
| |
2 | "unterminated LL | "unterminated
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^
error: aborting due to previous error error: aborting due to previous error

View file

@ -0,0 +1,17 @@
// needs-sanitizer-support
// compile-flags: --test -Z sanitizer=address
//
// #43031: Verify that rustdoc passes `-Z` options to rustc. Use an extern
// function that is provided by the sanitizer runtime, if flag is not passed
// correctly, then linking will fail.
/// ```
/// extern {
/// fn __sanitizer_print_stack_trace();
/// }
///
/// fn main() {
/// unsafe { __sanitizer_print_stack_trace() };
/// }
/// ```
pub fn z_flag_is_passed_to_rustc() {}