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;
|
2018-12-08 20:30:23 +01:00
|
|
|
extern crate rustc_interface;
|
2019-07-23 20:34:17 +03:00
|
|
|
extern crate rustc_driver as _;
|
2014-11-28 21:56:09 -07:00
|
|
|
extern crate syntax;
|
|
|
|
|
2018-12-08 20:30:23 +01:00
|
|
|
use rustc::session::DiagnosticOutput;
|
2018-07-26 12:36:11 -06:00
|
|
|
use rustc::session::config::{Input, Options,
|
2016-08-02 16:53:58 -04:00
|
|
|
OutputType, OutputTypes};
|
2018-12-08 20:30:23 +01:00
|
|
|
use rustc_interface::interface;
|
2018-08-18 12:14:03 +02:00
|
|
|
use syntax::source_map::FileName;
|
2014-11-28 21:56:09 -07:00
|
|
|
|
2015-02-26 21:00:43 -08:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2015-02-26 21:00:43 -08:00
|
|
|
fn compile(code: String, output: PathBuf, sysroot: PathBuf) {
|
2018-12-08 20:30:23 +01:00
|
|
|
let mut opts = Options::default();
|
|
|
|
opts.output_types = OutputTypes::new(&[(OutputType::Exe, None)]);
|
|
|
|
opts.maybe_sysroot = Some(sysroot);
|
|
|
|
|
|
|
|
if let Ok(linker) = std::env::var("RUSTC_LINKER") {
|
|
|
|
opts.cg.linker = Some(linker.into());
|
|
|
|
}
|
|
|
|
|
|
|
|
let name = FileName::anon_source_code(&code);
|
|
|
|
let input = Input::Str { name, input: code };
|
|
|
|
|
|
|
|
let config = interface::Config {
|
|
|
|
opts,
|
|
|
|
crate_cfg: Default::default(),
|
|
|
|
input,
|
|
|
|
input_path: None,
|
|
|
|
output_file: Some(output),
|
|
|
|
output_dir: None,
|
|
|
|
file_loader: None,
|
|
|
|
diagnostic_output: DiagnosticOutput::Default,
|
|
|
|
stderr: None,
|
|
|
|
crate_name: None,
|
|
|
|
lint_caps: Default::default(),
|
2019-10-10 19:33:00 -04:00
|
|
|
register_lints: None,
|
2018-12-08 20:30:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
interface::run_compiler(config, |compiler| {
|
2019-08-30 17:27:35 +10:00
|
|
|
// This runs all the passes prior to linking, too.
|
|
|
|
compiler.link().ok();
|
2018-03-07 02:44:10 +01:00
|
|
|
});
|
2014-11-28 21:56:09 -07:00
|
|
|
}
|