From 353cef9654444799ed03576acbcc3af26f9899fd Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Fri, 8 Apr 2022 22:28:33 -0700 Subject: [PATCH] Use target exe_suffix for doctests This will use rust_out.exe for doctests on Windows, rust_out.wasm for doctests in the wasm case, and also handles cross-compiling or user-provided targets. --- src/librustdoc/doctest.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index cb50c3ae829..81d9c46447a 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -19,7 +19,7 @@ use rustc_span::source_map::SourceMap; use rustc_span::symbol::sym; use rustc_span::{BytePos, FileName, Pos, Span, DUMMY_SP}; -use rustc_target::spec::TargetTriple; +use rustc_target::spec::{Target, TargetTriple}; use tempfile::Builder as TempFileBuilder; use std::env; @@ -293,6 +293,16 @@ struct UnusedExterns { unused_extern_names: Vec, } +fn add_exe_suffix(input: String, target: &TargetTriple) -> String { + let exe_suffix = match target { + TargetTriple::TargetTriple(_) => Target::expect_builtin(target).options.exe_suffix, + TargetTriple::TargetJson { contents, .. } => { + Target::from_json(contents.parse().unwrap()).unwrap().0.options.exe_suffix + } + }; + input + &exe_suffix +} + fn run_test( test: &str, crate_name: &str, @@ -313,7 +323,9 @@ fn run_test( let (test, line_offset, supports_color) = make_test(test, Some(crate_name), lang_string.test_harness, opts, edition, Some(test_id)); - let output_file = outdir.path().join("rust_out"); + // Make sure we emit well-formed executable names for our target. + let rust_out = add_exe_suffix("rust_out".to_owned(), &target); + let output_file = outdir.path().join(rust_out); let rustc_binary = rustdoc_options .test_builder