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.
|
|
|
|
|
2015-09-30 10:08:37 -07:00
|
|
|
#![feature(rustc_private)]
|
2015-03-05 18:33:58 -08:00
|
|
|
|
2014-11-28 21:56:09 -07:00
|
|
|
extern crate rustc;
|
2014-12-05 00:00:06 -05:00
|
|
|
extern crate rustc_driver;
|
2015-02-25 22:44:44 +11:00
|
|
|
extern crate rustc_lint;
|
2015-11-25 01:23:22 +02:00
|
|
|
extern crate rustc_metadata;
|
2016-06-22 12:50:19 -04:00
|
|
|
extern crate rustc_errors;
|
2017-10-30 18:42:21 +01:00
|
|
|
extern crate rustc_trans_utils;
|
2014-11-28 21:56:09 -07:00
|
|
|
extern crate syntax;
|
|
|
|
|
|
|
|
use rustc::session::{build_session, Session};
|
2017-12-14 08:09:19 +01:00
|
|
|
use rustc::session::config::{basic_options, Input,
|
2016-08-02 16:53:58 -04:00
|
|
|
OutputType, OutputTypes};
|
2017-12-14 08:09:19 +01:00
|
|
|
use rustc_driver::driver::{compile_input, CompileController};
|
2015-11-25 01:23:22 +02:00
|
|
|
use rustc_metadata::cstore::CStore;
|
2016-06-22 12:50:19 -04:00
|
|
|
use rustc_errors::registry::Registry;
|
2017-12-14 08:09:19 +01:00
|
|
|
use syntax::codemap::FileName;
|
2017-10-30 18:42:21 +01:00
|
|
|
use rustc_trans_utils::trans_crate::TransCrate;
|
2014-11-28 21:56:09 -07:00
|
|
|
|
2015-02-26 21:00:43 -08:00
|
|
|
use std::path::PathBuf;
|
2015-11-22 21:02:04 +02:00
|
|
|
use std::rc::Rc;
|
2015-02-26 21:00:43 -08:00
|
|
|
|
2014-11-28 21:56:09 -07:00
|
|
|
fn main() {
|
|
|
|
let src = r#"
|
|
|
|
fn main() {}
|
|
|
|
"#;
|
|
|
|
|
2015-02-16 16:04:02 +02:00
|
|
|
let args: Vec<String> = std::env::args().collect();
|
2014-11-28 21:56:09 -07:00
|
|
|
|
|
|
|
if args.len() < 4 {
|
|
|
|
panic!("expected rustc path");
|
|
|
|
}
|
|
|
|
|
2015-03-23 15:54:39 -07:00
|
|
|
let tmpdir = PathBuf::from(&args[1]);
|
2014-11-28 21:56:09 -07:00
|
|
|
|
2015-03-23 15:54:39 -07:00
|
|
|
let mut sysroot = PathBuf::from(&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());
|
|
|
|
}
|
|
|
|
|
2017-10-30 18:42:21 +01:00
|
|
|
fn basic_sess(sysroot: PathBuf) -> (Session, Rc<CStore>, Box<TransCrate>) {
|
2014-11-28 21:56:09 -07:00
|
|
|
let mut opts = basic_options();
|
2016-08-09 08:44:11 -04:00
|
|
|
opts.output_types = OutputTypes::new(&[(OutputType::Exe, None)]);
|
2014-11-28 21:56:09 -07:00
|
|
|
opts.maybe_sysroot = Some(sysroot);
|
2017-10-10 23:06:22 +03:00
|
|
|
if let Ok(linker) = std::env::var("RUSTC_LINKER") {
|
2017-12-14 08:09:19 +01:00
|
|
|
opts.cg.linker = Some(linker.into());
|
2017-10-10 23:06:22 +03:00
|
|
|
}
|
2014-11-28 21:56:09 -07:00
|
|
|
|
2015-04-28 12:48:22 +10:00
|
|
|
let descriptions = Registry::new(&rustc::DIAGNOSTICS);
|
2017-09-09 11:02:18 -07:00
|
|
|
let sess = build_session(opts, None, descriptions);
|
2018-01-22 07:29:24 -08:00
|
|
|
let trans = rustc_driver::get_trans(&sess);
|
2017-10-30 18:42:21 +01:00
|
|
|
let cstore = Rc::new(CStore::new(trans.metadata_loader()));
|
2015-02-25 22:44:44 +11:00
|
|
|
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
|
2017-10-30 18:42:21 +01:00
|
|
|
(sess, cstore, trans)
|
2014-11-28 21:56:09 -07:00
|
|
|
}
|
|
|
|
|
2015-02-26 21:00:43 -08:00
|
|
|
fn compile(code: String, output: PathBuf, sysroot: PathBuf) {
|
2017-10-30 18:42:21 +01:00
|
|
|
let (sess, cstore, trans) = basic_sess(sysroot);
|
2015-01-11 15:03:34 +13:00
|
|
|
let control = CompileController::basic();
|
2017-12-14 08:09:19 +01:00
|
|
|
let input = Input::Str { name: FileName::Anon, input: code };
|
2017-10-30 18:42:21 +01:00
|
|
|
let _ = compile_input(
|
|
|
|
trans,
|
|
|
|
&sess,
|
|
|
|
&cstore,
|
|
|
|
&None,
|
|
|
|
&input,
|
|
|
|
&None,
|
|
|
|
&Some(output),
|
|
|
|
None,
|
|
|
|
&control
|
|
|
|
);
|
2014-11-28 21:56:09 -07:00
|
|
|
}
|