]> git.lizzy.rs Git - rust.git/blob - src/test/run-make-fulldeps/issue-19371/foo.rs
Simplify SaveHandler trait
[rust.git] / src / test / run-make-fulldeps / issue-19371 / foo.rs
1 #![feature(rustc_private)]
2
3 extern crate rustc;
4 extern crate rustc_interface;
5 #[allow(unused_extern_crates)]
6 extern crate rustc_driver;
7 extern crate syntax;
8
9 use rustc::session::DiagnosticOutput;
10 use rustc::session::config::{Input, Options,
11                              OutputType, OutputTypes};
12 use rustc_interface::interface;
13 use syntax::source_map::FileName;
14
15 use std::path::PathBuf;
16
17 fn main() {
18     let src = r#"
19     fn main() {}
20     "#;
21
22     let args: Vec<String> = std::env::args().collect();
23
24     if args.len() < 4 {
25         panic!("expected rustc path");
26     }
27
28     let tmpdir = PathBuf::from(&args[1]);
29
30     let mut sysroot = PathBuf::from(&args[3]);
31     sysroot.pop();
32     sysroot.pop();
33
34     compile(src.to_string(), tmpdir.join("out"), sysroot.clone());
35
36     compile(src.to_string(), tmpdir.join("out"), sysroot.clone());
37 }
38
39 fn compile(code: String, output: PathBuf, sysroot: PathBuf) {
40     let mut opts = Options::default();
41     opts.output_types = OutputTypes::new(&[(OutputType::Exe, None)]);
42     opts.maybe_sysroot = Some(sysroot);
43
44     if let Ok(linker) = std::env::var("RUSTC_LINKER") {
45         opts.cg.linker = Some(linker.into());
46     }
47
48     let name = FileName::anon_source_code(&code);
49     let input = Input::Str { name, input: code };
50
51     let config = interface::Config {
52         opts,
53         crate_cfg: Default::default(),
54         input,
55         input_path: None,
56         output_file: Some(output),
57         output_dir: None,
58         file_loader: None,
59         diagnostic_output: DiagnosticOutput::Default,
60         stderr: None,
61         crate_name: None,
62         lint_caps: Default::default(),
63     };
64
65     interface::run_compiler(config, |compiler| {
66         compiler.compile().ok();
67     });
68 }