diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:03 +0000 |
commit | 64d98f8ee037282c35007b64c2649055c56af1db (patch) | |
tree | 5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/run-make-fulldeps/issue-19371 | |
parent | Adding debian version 1.67.1+dfsg1-1. (diff) | |
download | rustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip |
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/run-make-fulldeps/issue-19371')
-rw-r--r-- | tests/run-make-fulldeps/issue-19371/Makefile | 9 | ||||
-rw-r--r-- | tests/run-make-fulldeps/issue-19371/foo.rs | 71 |
2 files changed, 80 insertions, 0 deletions
diff --git a/tests/run-make-fulldeps/issue-19371/Makefile b/tests/run-make-fulldeps/issue-19371/Makefile new file mode 100644 index 000000000..994e50801 --- /dev/null +++ b/tests/run-make-fulldeps/issue-19371/Makefile @@ -0,0 +1,9 @@ +include ../tools.mk + +# This test ensures that rustc compile_input can be called twice in one task +# without causing a panic. +# The program needs the path to rustc to get sysroot. + +all: + $(RUSTC) foo.rs + $(call RUN,foo $(TMPDIR) $(RUSTC)) diff --git a/tests/run-make-fulldeps/issue-19371/foo.rs b/tests/run-make-fulldeps/issue-19371/foo.rs new file mode 100644 index 000000000..5bb38fc02 --- /dev/null +++ b/tests/run-make-fulldeps/issue-19371/foo.rs @@ -0,0 +1,71 @@ +#![feature(rustc_private)] + +extern crate rustc_driver; +extern crate rustc_interface; +extern crate rustc_session; +extern crate rustc_span; + +use rustc_interface::interface; +use rustc_session::config::{Input, Options, OutputType, OutputTypes}; +use rustc_span::source_map::FileName; + +use std::path::PathBuf; + +fn main() { + let src = r#" + fn main() {} + "#; + + let args: Vec<String> = std::env::args().collect(); + + if args.len() < 4 { + panic!("expected rustc path"); + } + + let tmpdir = PathBuf::from(&args[1]); + + let mut sysroot = PathBuf::from(&args[3]); + sysroot.pop(); + sysroot.pop(); + + compile(src.to_string(), tmpdir.join("out"), sysroot.clone()); + + compile(src.to_string(), tmpdir.join("out"), sysroot.clone()); +} + +fn compile(code: String, output: PathBuf, sysroot: PathBuf) { + let mut opts = Options::default(); + opts.output_types = OutputTypes::new(&[(OutputType::Exe, None)]); + opts.maybe_sysroot = Some(sysroot); + + if let Ok(linker) = std::env::var("RUSTC_LINKER") { + opts.cg.linker = Some(linker.into()); + } + + let name = FileName::anon_source_code(&code); + let input = Input::Str { name, input: code }; + + let config = interface::Config { + opts, + crate_cfg: Default::default(), + crate_check_cfg: Default::default(), + input, + output_file: Some(output), + output_dir: None, + file_loader: None, + lint_caps: Default::default(), + parse_sess_created: None, + register_lints: None, + override_queries: None, + make_codegen_backend: None, + registry: rustc_driver::diagnostics_registry(), + }; + + interface::run_compiler(config, |compiler| { + // This runs all the passes prior to linking, too. + let linker = compiler.enter(|queries| queries.linker()); + if let Ok(linker) = linker { + linker.link(); + } + }); +} |