Skip to content
This repository was archived by the owner on Mar 1, 2019. It is now read-only.

Commit d370939

Browse files
committed
Initial commit
0 parents  commit d370939

File tree

4 files changed

+124
-0
lines changed

4 files changed

+124
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target/
2+
**/*.rs.bk

Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "rls-rustc"
3+
version = "0.1.0"
4+
authors = ["Nick Cameron <[email protected]>"]
5+
description = "A simple shim around rustc to allow using save-analysis with a stable toolchain"
6+
license = "Apache-2.0/MIT"
7+
repository = "https://github.com/nrc/rls-rustc"
8+
categories = ["development-tools"]
9+
10+
[dependencies]

src/main.rs

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#![feature(rustc_private)]
2+
#![feature(box_syntax)]
3+
4+
extern crate env_logger;
5+
extern crate getopts;
6+
extern crate rustc;
7+
extern crate rustc_driver;
8+
extern crate rustc_errors;
9+
extern crate rustc_resolve;
10+
extern crate rustc_save_analysis;
11+
extern crate syntax;
12+
13+
use rustc_driver::{run, run_compiler, CompilerCalls, RustcDefaultCalls, Compilation};
14+
use rustc_driver::driver::CompileController;
15+
use rustc_save_analysis as save;
16+
use rustc_save_analysis::DumpHandler;
17+
use rustc::session::{early_error, Session};
18+
use rustc::session::config::{self, ErrorOutputType, Input};
19+
use rustc::util::common::time;
20+
use syntax::ast;
21+
22+
use std::path::PathBuf;
23+
use std::{env, process};
24+
25+
struct ShimCalls;
26+
27+
impl<'a> CompilerCalls<'a> for ShimCalls {
28+
fn early_callback(&mut self,
29+
a: &getopts::Matches,
30+
b: &config::Options,
31+
c: &ast::CrateConfig,
32+
d: &rustc_errors::registry::Registry,
33+
e: ErrorOutputType)
34+
-> Compilation {
35+
RustcDefaultCalls.early_callback(a, b, c, d, e)
36+
}
37+
38+
fn late_callback(&mut self,
39+
a: &getopts::Matches,
40+
b: &Session,
41+
c: &Input,
42+
d: &Option<PathBuf>,
43+
e: &Option<PathBuf>)
44+
-> Compilation {
45+
RustcDefaultCalls.late_callback(a, b, c, d, e)
46+
}
47+
48+
fn some_input(&mut self,
49+
a: Input,
50+
b: Option<PathBuf>)
51+
-> (Input, Option<PathBuf>) {
52+
RustcDefaultCalls.some_input(a, b)
53+
}
54+
55+
fn no_input(&mut self,
56+
a: &getopts::Matches,
57+
b: &config::Options,
58+
c: &ast::CrateConfig,
59+
d: &Option<PathBuf>,
60+
e: &Option<PathBuf>,
61+
f: &rustc_errors::registry::Registry)
62+
-> Option<(Input, Option<PathBuf>)> {
63+
RustcDefaultCalls.no_input(a, b, c, d, e, f)
64+
}
65+
66+
fn build_controller(&mut self, a: &Session, b: &getopts::Matches) -> CompileController<'a> {
67+
let mut result = RustcDefaultCalls.build_controller(a, b);
68+
69+
// TODO use enable_save_analysis
70+
result.keep_ast = true;
71+
72+
result.after_analysis.callback = box |state| {
73+
time(state.session.time_passes(), "save analysis", || {
74+
save::process_crate(state.tcx.unwrap(),
75+
state.expanded_crate.unwrap(),
76+
state.analysis.unwrap(),
77+
state.crate_name.unwrap(),
78+
None,
79+
DumpHandler::new(state.out_dir,
80+
state.crate_name.unwrap()))
81+
});
82+
};
83+
result.after_analysis.run_callback_on_error = true;
84+
result.make_glob_map = ::rustc_resolve::MakeGlobMap::Yes;
85+
86+
result
87+
}
88+
}
89+
90+
// TODO use exported version
91+
fn get_args() -> Vec<String> {
92+
env::args_os().enumerate()
93+
.map(|(i, arg)| arg.into_string().unwrap_or_else(|arg| {
94+
early_error(ErrorOutputType::default(),
95+
&format!("Argument {} is not valid Unicode: {:?}", i, arg))
96+
}))
97+
.collect()
98+
}
99+
100+
fn main() {
101+
env_logger::init().unwrap();
102+
103+
let result = run(|| run_compiler(&get_args(),
104+
&mut ShimCalls,
105+
None,
106+
None));
107+
process::exit(result as i32);
108+
}

0 commit comments

Comments
 (0)