2014-11-28 21:56:09 -07:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
extern crate rustc;
|
2014-12-05 00:00:06 -05:00
|
|
|
extern crate rustc_driver;
|
2014-11-28 21:56:09 -07:00
|
|
|
extern crate syntax;
|
|
|
|
|
|
|
|
use rustc::session::{build_session, Session};
|
2014-12-05 00:00:06 -05:00
|
|
|
use rustc::session::config::{basic_options, build_configuration, Input, OutputTypeExe};
|
2015-01-11 15:03:34 +13:00
|
|
|
use rustc_driver::driver::{compile_input, CompileController};
|
2014-11-28 21:56:09 -07:00
|
|
|
use syntax::diagnostics::registry::Registry;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let src = r#"
|
|
|
|
fn main() {}
|
|
|
|
"#;
|
|
|
|
|
|
|
|
let args = std::os::args();
|
|
|
|
|
|
|
|
if args.len() < 4 {
|
|
|
|
panic!("expected rustc path");
|
|
|
|
}
|
|
|
|
|
2015-02-01 21:53:25 -05:00
|
|
|
let tmpdir = Path::new(&args[1]);
|
2014-11-28 21:56:09 -07:00
|
|
|
|
2015-02-01 21:53:25 -05:00
|
|
|
let mut sysroot = Path::new(&args[3]);
|
2014-11-28 21:56:09 -07:00
|
|
|
sysroot.pop();
|
|
|
|
sysroot.pop();
|
|
|
|
|
|
|
|
compile(src.to_string(), tmpdir.join("out"), sysroot.clone());
|
|
|
|
|
|
|
|
compile(src.to_string(), tmpdir.join("out"), sysroot.clone());
|
|
|
|
}
|
|
|
|
|
|
|
|
fn basic_sess(sysroot: Path) -> Session {
|
|
|
|
let mut opts = basic_options();
|
|
|
|
opts.output_types = vec![OutputTypeExe];
|
|
|
|
opts.maybe_sysroot = Some(sysroot);
|
|
|
|
|
2015-01-16 15:54:58 -08:00
|
|
|
let descriptions = Registry::new(&rustc::diagnostics::DIAGNOSTICS);
|
2014-11-28 21:56:09 -07:00
|
|
|
let sess = build_session(opts, None, descriptions);
|
|
|
|
sess
|
|
|
|
}
|
|
|
|
|
|
|
|
fn compile(code: String, output: Path, sysroot: Path) {
|
|
|
|
let sess = basic_sess(sysroot);
|
|
|
|
let cfg = build_configuration(&sess);
|
2015-01-11 15:03:34 +13:00
|
|
|
let control = CompileController::basic();
|
2014-11-28 21:56:09 -07:00
|
|
|
|
|
|
|
compile_input(sess,
|
|
|
|
cfg,
|
2014-12-05 00:00:06 -05:00
|
|
|
&Input::Str(code),
|
2014-11-28 21:56:09 -07:00
|
|
|
&None,
|
|
|
|
&Some(output),
|
2015-01-11 15:03:34 +13:00
|
|
|
None,
|
|
|
|
control);
|
2014-11-28 21:56:09 -07:00
|
|
|
}
|