Created
November 26, 2017 08:59
-
-
Save sinkuu/b8454acd637c9fcb6675af06d8cc1b37 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(rustc_private)] | |
extern crate getopts; | |
extern crate rustc; | |
extern crate rustc_driver; | |
extern crate rustc_errors; | |
extern crate syntax; | |
use rustc::session::Session; | |
use rustc::session::config::{self, ErrorOutputType, Input}; | |
use rustc_driver::{Compilation, CompilerCalls, RustcDefaultCalls}; | |
use rustc_driver::driver::CompileController; | |
use std::path::PathBuf; | |
use syntax::ast; | |
struct AdventMirCompilerCalls { | |
default: RustcDefaultCalls, | |
} | |
impl Default for AdventMirCompilerCalls { | |
fn default() -> Self { | |
Self { | |
default: RustcDefaultCalls, | |
} | |
} | |
} | |
impl<'a> CompilerCalls<'a> for AdventMirCompilerCalls { | |
fn early_callback( | |
&mut self, | |
matches: &getopts::Matches, | |
sopts: &config::Options, | |
cfg: &ast::CrateConfig, | |
descriptions: &rustc_errors::registry::Registry, | |
output: ErrorOutputType, | |
) -> Compilation { | |
self.default.early_callback( | |
matches, | |
sopts, | |
cfg, | |
descriptions, | |
output, | |
) | |
} | |
fn no_input( | |
&mut self, | |
matches: &getopts::Matches, | |
sopts: &config::Options, | |
cfg: &ast::CrateConfig, | |
odir: &Option<PathBuf>, | |
ofile: &Option<PathBuf>, | |
descriptions: &rustc_errors::registry::Registry, | |
) -> Option<(Input, Option<PathBuf>)> { | |
self.default.no_input( | |
matches, | |
sopts, | |
cfg, | |
odir, | |
ofile, | |
descriptions, | |
) | |
} | |
fn late_callback( | |
&mut self, | |
matches: &getopts::Matches, | |
sess: &Session, | |
crate_stores: &rustc::middle::cstore::CrateStore, | |
input: &Input, | |
odir: &Option<PathBuf>, | |
ofile: &Option<PathBuf>, | |
) -> Compilation { | |
self.default.late_callback( | |
matches, | |
sess, | |
crate_stores, | |
input, | |
odir, | |
ofile, | |
) | |
} | |
fn build_controller( | |
&mut self, | |
sess: &Session, | |
matches: &getopts::Matches, | |
) -> CompileController<'a> { | |
self.default.build_controller(sess, matches) | |
} | |
} | |
fn main() { | |
let sysroot = std::process::Command::new("rustc") | |
.args(&["--print", "sysroot"]) | |
.output() | |
.unwrap() | |
.stdout; | |
let sysroot = std::str::from_utf8(&sysroot) | |
.unwrap() | |
.trim_right() | |
.to_string(); | |
rustc_driver::in_rustc_thread(|| { | |
let args: Vec<_> = std::env::args() | |
.chain(vec!["--sysroot".to_string(), sysroot]) | |
.collect(); | |
rustc_driver::run_compiler( | |
&args, | |
&mut AdventMirCompilerCalls::default(), | |
None, | |
None, | |
).0 | |
.expect("run_compiler failed"); | |
}).expect("in_rustc_thread failed"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment