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.
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.
11 #![feature(rustc_private)]
14 extern crate rustc_driver;
15 extern crate rustc_lint;
16 extern crate rustc_metadata;
19 use rustc::session::{build_session, Session};
20 use rustc::session::config::{basic_options, build_configuration, Input, OutputType};
21 use rustc_driver::driver::{compile_input, CompileController};
22 use rustc_metadata::cstore::CStore;
23 use syntax::diagnostics::registry::Registry;
24 use syntax::parse::token;
26 use std::path::PathBuf;
34 let args: Vec<String> = std::env::args().collect();
37 panic!("expected rustc path");
40 let tmpdir = PathBuf::from(&args[1]);
42 let mut sysroot = PathBuf::from(&args[3]);
46 compile(src.to_string(), tmpdir.join("out"), sysroot.clone());
48 compile(src.to_string(), tmpdir.join("out"), sysroot.clone());
51 fn basic_sess(sysroot: PathBuf) -> (Session, Rc<CStore>) {
52 let mut opts = basic_options();
53 opts.output_types.insert(OutputType::Exe, None);
54 opts.maybe_sysroot = Some(sysroot);
56 let descriptions = Registry::new(&rustc::DIAGNOSTICS);
57 let cstore = Rc::new(CStore::new(token::get_ident_interner()));
58 let sess = build_session(opts, None, descriptions, cstore.clone());
59 rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
63 fn compile(code: String, output: PathBuf, sysroot: PathBuf) {
64 let (sess, cstore) = basic_sess(sysroot);
65 let cfg = build_configuration(&sess);
66 let control = CompileController::basic();
68 compile_input(sess, &cstore,