Skip to content

Commit 721e139

Browse files
committed
Init repo
0 parents  commit 721e139

File tree

456 files changed

+1557186
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

456 files changed

+1557186
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
target
2+
enums/target
3+
*~

Cargo.lock

+2,119
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
[package]
2+
name = "rust-code-analysis"
3+
version = "0.0.1"
4+
authors = ["Calixte Denizet <[email protected]>"]
5+
edition = "2018"
6+
build = "build.rs"
7+
8+
[build-dependencies]
9+
cc = "^1.0.37"
10+
phf_codegen = "^0.7"
11+
12+
[dependencies]
13+
actix-http = "^0.2"
14+
actix-rt = "^0.2"
15+
actix-web = {version = "^1.0", features = ["ssl"]}
16+
aho-corasick = "^0.7"
17+
bytes = "^0.4"
18+
clap = "^2.33"
19+
enum-iterator = "^0.3"
20+
futures = "^0.1"
21+
globset = "^0.4"
22+
json = "^0.11"
23+
libc = "^0.2"
24+
tree-sitter = "^0.3.10"
25+
termcolor = "^1.0"
26+
crossbeam = "^0.7"
27+
lazy_static = "^1.3"
28+
num_cpus = "^1.10"
29+
openssl = "^0.10"
30+
petgraph = "^0.4.13"
31+
phf = { version = "0.7.24", features = ["macros"] }
32+
regex = "^1.1"
33+
serde = "^1.0"
34+
serde_json = "^1.0"
35+
walkdir = "^2.2"
36+
37+
[profile.release]
38+
opt-level = 3
39+
debug = false
40+
rpath = false
41+
lto = true
42+
debug-assertions = false
43+
codegen-units = 1
44+
panic = 'unwind'
45+
incremental = false
46+
overflow-checks = false

build.rs

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
extern crate cc;
2+
extern crate phf_codegen;
3+
4+
use std::{env, fs};
5+
use std::io::{BufWriter, Read, Write};
6+
use std::path::{Path, PathBuf};
7+
8+
const TREE_SITTER: &str = "tree-sitter-";
9+
10+
fn get_opt_level() -> u32 {
11+
env::var("OPT_LEVEL").unwrap().parse::<u32>().unwrap()
12+
}
13+
14+
fn get_cwd() -> &'static str {
15+
if is_enums() {
16+
".."
17+
} else {
18+
"."
19+
}
20+
}
21+
22+
fn is_enums() -> bool {
23+
let path = env::current_dir().unwrap();
24+
path.ends_with("enums")
25+
}
26+
27+
fn mk_predef(data_name: &str, set_name: &str) {
28+
let mut set = phf_codegen::Set::new();
29+
let mut file = fs::File::open(PathBuf::from(format!("./data/{}.txt", data_name))).unwrap();
30+
let mut data = Vec::new();
31+
file.read_to_end(&mut data).unwrap();
32+
for tok in data.split(|c| *c == b'\n') {
33+
let tok = std::str::from_utf8(tok).unwrap().trim();
34+
if !tok.is_empty() {
35+
set.entry(tok);
36+
}
37+
}
38+
let path = Path::new(&env::var("OUT_DIR").unwrap()).join(format!("gen_{}.rs", data_name));
39+
let mut file = BufWriter::new(fs::File::create(&path).unwrap());
40+
writeln!(&mut file, "static {}: phf::Set<&'static str> =", set_name).unwrap();
41+
set.build(&mut file).unwrap();
42+
writeln!(&mut file, ";").unwrap();
43+
}
44+
45+
fn collect_tree_sitter_dirs(ignore: Vec<String>) -> Vec<String> {
46+
let mut dirs = Vec::new();
47+
for entry in fs::read_dir(get_cwd()).unwrap() {
48+
if let Ok(entry) = entry {
49+
let path = entry.path();
50+
let dir = path.file_name().unwrap().to_str().unwrap().to_string();
51+
if dir.starts_with(TREE_SITTER) && !ignore.contains(&dir) {
52+
dirs.push(dir);
53+
}
54+
}
55+
}
56+
dirs
57+
}
58+
59+
fn collect_src_files(dir: &str) -> (Vec<String>, Vec<String>) {
60+
eprintln!("Collect files for {}", dir);
61+
62+
let mut c_files = Vec::new();
63+
let mut cpp_files = Vec::new();
64+
let path = PathBuf::from(get_cwd()).join(&dir).join("src");
65+
for entry in fs::read_dir(path).unwrap() {
66+
if let Ok(entry) = entry {
67+
let path = entry.path();
68+
if path
69+
.file_stem()
70+
.unwrap()
71+
.to_str()
72+
.unwrap()
73+
.starts_with("binding")
74+
{
75+
continue;
76+
}
77+
if let Some(ext) = path.extension() {
78+
if ext == "c" {
79+
c_files.push(path.to_str().unwrap().to_string());
80+
} else if ext == "cc" || ext == "cpp" || ext == "cxx" {
81+
cpp_files.push(path.to_str().unwrap().to_string());
82+
}
83+
}
84+
}
85+
}
86+
(c_files, cpp_files)
87+
}
88+
89+
fn build_c(files: Vec<String>, language: &str) {
90+
let mut build = cc::Build::new();
91+
for file in files {
92+
build
93+
.file(&file)
94+
.include(PathBuf::from(file).parent().unwrap())
95+
.pic(true)
96+
.opt_level(get_opt_level())
97+
.debug(true)
98+
.flag("-std=c99");
99+
}
100+
build.compile(&format!("tree-sitter-{}-c", language));
101+
}
102+
103+
fn build_cpp(files: Vec<String>, language: &str) {
104+
let mut build = cc::Build::new();
105+
for file in files {
106+
build
107+
.file(&file)
108+
.include(PathBuf::from(file).parent().unwrap())
109+
.pic(true)
110+
.opt_level(get_opt_level())
111+
.debug(true)
112+
.cpp(true);
113+
}
114+
build.compile(&format!("tree-sitter-{}-cpp", language));
115+
}
116+
117+
fn build_dir(dir: &str, language: &str) {
118+
eprintln!("Build language {}", language);
119+
let (c, cpp) = collect_src_files(&dir);
120+
build_c(c, &language);
121+
build_cpp(cpp, &language);
122+
}
123+
124+
fn main() {
125+
if !is_enums() {
126+
mk_predef("c_macros", "PREDEFINED_MACROS");
127+
mk_predef("c_specials", "SPECIALS");
128+
}
129+
let ignore = vec!["tree-sitter-typescript".to_string()];
130+
let dirs = collect_tree_sitter_dirs(ignore);
131+
for dir in dirs {
132+
let language = &dir[TREE_SITTER.len()..];
133+
build_dir(&dir, &language);
134+
}
135+
build_dir("tree-sitter-typescript/tsx", "tsx");
136+
build_dir("tree-sitter-typescript/typescript", "typescript");
137+
}

0 commit comments

Comments
 (0)