]> git.proxmox.com Git - rustc.git/blame - src/test/run-make-fulldeps/issue-19371/foo.rs
New upstream version 1.32.0+dfsg1
[rustc.git] / src / test / run-make-fulldeps / issue-19371 / foo.rs
CommitLineData
1a4d82fc
JJ
1// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2// file at the top-level directory of this distribution and at
3// http://rust-lang.org/COPYRIGHT.
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10
b039eaaf 11#![feature(rustc_private)]
c34b1796 12
1a4d82fc
JJ
13extern crate rustc;
14extern crate rustc_driver;
c34b1796 15extern crate rustc_lint;
92a42be0 16extern crate rustc_metadata;
3157f602 17extern crate rustc_errors;
94b46f34 18extern crate rustc_codegen_utils;
1a4d82fc
JJ
19extern crate syntax;
20
21use rustc::session::{build_session, Session};
b7449926 22use rustc::session::config::{Input, Options,
5bcae85e 23 OutputType, OutputTypes};
94b46f34 24use rustc_driver::driver::{self, compile_input, CompileController};
92a42be0 25use rustc_metadata::cstore::CStore;
3157f602 26use rustc_errors::registry::Registry;
b7449926 27use syntax::source_map::FileName;
94b46f34 28use rustc_codegen_utils::codegen_backend::CodegenBackend;
1a4d82fc 29
c34b1796 30use std::path::PathBuf;
92a42be0 31use std::rc::Rc;
c34b1796 32
1a4d82fc
JJ
33fn main() {
34 let src = r#"
35 fn main() {}
36 "#;
37
85aaf69f 38 let args: Vec<String> = std::env::args().collect();
1a4d82fc
JJ
39
40 if args.len() < 4 {
41 panic!("expected rustc path");
42 }
43
c34b1796 44 let tmpdir = PathBuf::from(&args[1]);
1a4d82fc 45
c34b1796 46 let mut sysroot = PathBuf::from(&args[3]);
1a4d82fc
JJ
47 sysroot.pop();
48 sysroot.pop();
49
50 compile(src.to_string(), tmpdir.join("out"), sysroot.clone());
51
52 compile(src.to_string(), tmpdir.join("out"), sysroot.clone());
53}
54
94b46f34 55fn basic_sess(opts: Options) -> (Session, Rc<CStore>, Box<CodegenBackend>) {
d9579d0f 56 let descriptions = Registry::new(&rustc::DIAGNOSTICS);
ea8adc8c 57 let sess = build_session(opts, None, descriptions);
94b46f34
XL
58 let codegen_backend = rustc_driver::get_codegen_backend(&sess);
59 let cstore = Rc::new(CStore::new(codegen_backend.metadata_loader()));
c34b1796 60 rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
94b46f34 61 (sess, cstore, codegen_backend)
1a4d82fc
JJ
62}
63
c34b1796 64fn compile(code: String, output: PathBuf, sysroot: PathBuf) {
0531ce1d 65 syntax::with_globals(|| {
b7449926 66 let mut opts = Options::default();
94b46f34
XL
67 opts.output_types = OutputTypes::new(&[(OutputType::Exe, None)]);
68 opts.maybe_sysroot = Some(sysroot);
69 if let Ok(linker) = std::env::var("RUSTC_LINKER") {
70 opts.cg.linker = Some(linker.into());
71 }
72 driver::spawn_thread_pool(opts, |opts| {
73 let (sess, cstore, codegen_backend) = basic_sess(opts);
74 let control = CompileController::basic();
75 let input = Input::Str { name: FileName::Anon, input: code };
76 let _ = compile_input(
77 codegen_backend,
78 &sess,
79 &cstore,
80 &None,
81 &input,
82 &None,
83 &Some(output),
84 None,
85 &control
86 );
87 });
0531ce1d 88 });
1a4d82fc 89}