rust/tests/run-make-fulldeps/issue-19371/foo.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

72 lines
1.9 KiB
Rust
Raw Normal View History

#![feature(rustc_private)]
2019-11-15 12:41:50 -06:00
extern crate rustc_driver;
2023-01-13 09:19:25 -06:00
extern crate rustc_interface;
extern crate rustc_session;
2020-01-01 17:01:07 -06:00
extern crate rustc_span;
use rustc_interface::interface;
2023-01-13 09:19:25 -06:00
use rustc_session::config::{Input, Options, OutputType, OutputTypes};
2020-01-01 17:01:07 -06:00
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,
2019-11-15 12:41:50 -06:00
registry: rustc_driver::diagnostics_registry(),
};
interface::run_compiler(config, |compiler| {
// This runs all the passes prior to linking, too.
2023-01-13 09:19:25 -06:00
let linker = compiler.enter(|queries| queries.linker());
2019-11-24 14:12:38 -06:00
if let Ok(linker) = linker {
linker.link();
}
});
}