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.
12 extern crate rustc_driver;
15 use rustc::session::{build_session, Session};
16 use rustc::session::config::{basic_options, build_configuration, Input, OutputTypeExe};
17 use rustc_driver::driver::{compile_input, CompileController};
18 use syntax::diagnostics::registry::Registry;
25 let args = std::os::args();
28 panic!("expected rustc path");
31 let tmpdir = Path::new(args[1].as_slice());
33 let mut sysroot = Path::new(args[3].as_slice());
37 compile(src.to_string(), tmpdir.join("out"), sysroot.clone());
39 compile(src.to_string(), tmpdir.join("out"), sysroot.clone());
42 fn basic_sess(sysroot: Path) -> Session {
43 let mut opts = basic_options();
44 opts.output_types = vec![OutputTypeExe];
45 opts.maybe_sysroot = Some(sysroot);
47 let descriptions = Registry::new(&rustc::DIAGNOSTICS);
48 let sess = build_session(opts, None, descriptions);
52 fn compile(code: String, output: Path, sysroot: Path) {
53 let sess = basic_sess(sysroot);
54 let cfg = build_configuration(&sess);
55 let control = CompileController::basic();