-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
317 lines (298 loc) · 9.04 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
extern crate bindgen;
extern crate cc;
extern crate pkg_config;
use std::path::{Path, PathBuf};
use std::{env, fs};
fn main() {
// libyaml has a error config, so we need to maunaly do this
let libyaml = pkg_config::Config::new();
let mut libyaml_include = "".to_string();
if let Ok(lib) = libyaml.probe("yaml-0.1") {
libyaml_include = format!("{}", lib.include_paths[0].display());
}
println!("cargo:rustc-link-lib=xml2");
println!("cargo:rustc-link-lib=iconv");
println!("cargo:rustc-link-lib=jansson");
#[cfg(target_os = "macos")]
println!("cargo:rustc-link-lib=framework=ApplicationServices");
let ref src_path = Path::new("ctags");
let files = [
"main/args.c",
"main/colprint.c",
"main/dependency.c",
"main/entry.c",
"main/entry_private.c",
"main/error.c",
"main/field.c",
"main/flags.c",
"main/fmt.c",
"main/htable.c",
"main/keyword.c",
"main/kind.c",
"main/lregex.c",
"main/lxpath.c",
"main/main.c",
"main/mbcs.c",
"main/nestlevel.c",
"main/numarray.c",
"main/objpool.c",
"main/options.c",
"main/param.c",
"main/parse.c",
"main/portable-scandir.c",
"main/promise.c",
"main/ptag.c",
"main/ptrarray.c",
"main/rbtree.c",
"main/read.c",
"main/routines.c",
"main/seccomp.c",
"main/selectors.c",
"main/sort.c",
"main/stats.c",
"main/strlist.c",
"main/trace.c",
"main/trashbox.c",
"main/tokeninfo.c",
"main/unwindi.c",
"main/vstring.c",
"main/writer.c",
"main/writer-etags.c",
"main/writer-ctags.c",
"main/writer-json.c",
"main/writer-xref.c",
"main/xtag.c",
"main/repoinfo.c",
"main/mio.c",
"fnmatch/fnmatch.c",
// "gnu_regex/regcomp.c",
// "gnu_regex/regexec.c",
// "gnu_regex/regex_internal.c",
// "gnu_regex/regex.c",
"parsers/abaqus.c",
"parsers/abc.c",
"parsers/ada.c",
"parsers/ant.c",
"parsers/asciidoc.c",
"parsers/asm.c",
"parsers/asp.c",
"parsers/autoconf.c",
"parsers/autoit.c",
"parsers/automake.c",
"parsers/awk.c",
"parsers/basic.c",
"parsers/beta.c",
"parsers/bibtex.c",
"parsers/c.c",
"parsers/clojure.c",
"parsers/css.c",
"parsers/cobol.c",
"parsers/cpreprocessor.c",
"parsers/cxx/cxx.c",
"parsers/cxx/cxx_debug.c",
"parsers/cxx/cxx_debug_type.c",
"parsers/cxx/cxx_keyword.c",
"parsers/cxx/cxx_parser.c",
"parsers/cxx/cxx_parser_block.c",
"parsers/cxx/cxx_parser_function.c",
"parsers/cxx/cxx_parser_lambda.c",
"parsers/cxx/cxx_parser_namespace.c",
"parsers/cxx/cxx_parser_template.c",
"parsers/cxx/cxx_parser_tokenizer.c",
"parsers/cxx/cxx_parser_typedef.c",
"parsers/cxx/cxx_parser_using.c",
"parsers/cxx/cxx_parser_variable.c",
"parsers/cxx/cxx_subparser.c",
"parsers/cxx/cxx_qtmoc.c",
"parsers/cxx/cxx_scope.c",
"parsers/cxx/cxx_tag.c",
"parsers/cxx/cxx_token.c",
"parsers/cxx/cxx_token_chain.c",
"parsers/diff.c",
"parsers/dosbatch.c",
"parsers/dtd.c",
"parsers/dts.c",
"parsers/eiffel.c",
"parsers/erlang.c",
"parsers/falcon.c",
"parsers/flex.c",
"parsers/fortran.c",
"parsers/fypp.c",
"parsers/go.c",
"parsers/haskell.c",
"parsers/haxe.c",
"parsers/html.c",
"parsers/iniconf.c",
"parsers/itcl.c",
"parsers/jprop.c",
"parsers/jscript.c",
"parsers/json.c",
"parsers/julia.c",
"parsers/ldscript.c",
"parsers/lisp.c",
"parsers/lua.c",
"parsers/m4.c",
"parsers/make.c",
"parsers/matlab.c",
"parsers/myrddin.c",
"parsers/nsis.c",
"parsers/objc.c",
"parsers/ocaml.c",
"parsers/pascal.c",
"parsers/perl.c",
"parsers/perl-function-parameters.c",
"parsers/perl-moose.c",
"parsers/perl6.c",
"parsers/php.c",
"parsers/powershell.c",
"parsers/protobuf.c",
"parsers/python.c",
"parsers/pythonloggingconfig.c",
"parsers/r-r6class.c",
"parsers/r-s4class.c",
"parsers/r.c",
"parsers/rexx.c",
"parsers/robot.c",
"parsers/rpmspec.c",
"parsers/rst.c",
"parsers/ruby.c",
"parsers/rust.c",
"parsers/scheme.c",
"parsers/sh.c",
"parsers/slang.c",
"parsers/sml.c",
"parsers/sql.c",
"parsers/systemdunit.c",
"parsers/tcl.c",
"parsers/tcloo.c",
"parsers/tex.c",
"parsers/tex-beamer.c",
"parsers/ttcn.c",
"parsers/txt2tags.c",
"parsers/typescript.c",
"parsers/verilog.c",
"parsers/vhdl.c",
"parsers/vim.c",
"parsers/windres.c",
"parsers/yacc.c",
"parsers/yumrepo.c",
"optlib/RSpec.c",
"optlib/cmake.c",
"optlib/ctags-optlib.c",
"optlib/elixir.c",
"optlib/elm.c",
"optlib/gdbinit.c",
"optlib/inko.c",
"optlib/kconfig.c",
"optlib/man.c",
"optlib/markdown.c",
"optlib/meson.c",
"optlib/passwd.c",
"optlib/pod.c",
"optlib/qemuhx.c",
"optlib/puppetManifest.c",
"optlib/scss.c",
"optlib/systemtap.c",
"parsers/maven2.c",
"parsers/dbusintrospect.c",
"parsers/glade.c",
"parsers/svg.c",
"parsers/plist.c",
"parsers/relaxng.c",
"parsers/xml.c",
"parsers/xslt.c",
"parsers/yaml.c",
"parsers/ansibleplaybook.c",
// todo: add packcc convert
// todo: modify kotlin.c include path
"peg/kotlin.c",
"peg/varlink.c",
];
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
// wrapper.c from main.c without exit(0)
// let s = env!("CARGO_MANIFEST_DIR");
// let from = PathBuf::from(s).join("wrapper").join("wrapper.c");
// let ctags_dir = out_dir.join("ctags.c");
// fs::copy(&from, &ctags_dir).unwrap();
let ctags_dir = out_dir.join("ctags.c");
fs::write(ctags_dir.clone(), "").expect("");
let config_h = out_dir.join("config.h");
fs::write(
config_h,
format!(
"
#define CASE_INSENSITIVE_FILENAMES 1
#define DEFAULT_FILE_FORMAT 2
#define ETAGS \"etags\"
#define HAVE_ASPRINTF 1
#define HAVE_DECL__NSGETENVIRON 1
#define HAVE_DECL___ENVIRON 0
#define HAVE_DIRENT_H 1
#define HAVE_FCNTL_H 1
#define HAVE_ICONV 1
#define HAVE_JANSSON 1
#define HAVE_LIBXML 1
#define HAVE_LIBYAML 1
#define HAVE_MBLEN 1
#define HAVE_MKSTEMP 1
#define HAVE_OPENDIR 1
#define HAVE_PACKCC 0
#define HAVE_SCANDIR 1
#define HAVE_SETENV 1
#define HAVE_STAT_ST_INO 1
#define HAVE_STDBOOL_H 1
#define HAVE_STRCASECMP 1
#define HAVE_STRERROR 1
#define HAVE_STRNCASECMP 1
#define HAVE_STRSTR 1
#define HAVE_SYS_STAT_H 1
#define HAVE_SYS_TYPES_H 1
#define HAVE_TRUNCATE 1
#define HAVE_TYPEOF 1
#define HAVE_UNISTD_H 1
#define PACKAGE \"universal-ctags\"
#define PACKAGE_VERSION \"5.9.0\"
#define VERSION \"5.9.0\"
#define TMPDIR {:?}
", out_dir.display()),
)
.expect("Can't write config.h to OUT_DIR");
let peg_source = Path::new("ctags").join("peg");
let builder = bindgen::Builder::default()
.header("ctags/main/main_p.h")
.clang_arg("-std=gnu99")
.clang_arg(format!("-I{}", peg_source.display()))
.clang_arg("-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/")
.clang_arg("-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/libxml/")
;
let bindings = builder.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.generate()
.expect("Unable to generate bindings");
bindings
.write_to_file(out_dir.join("bindings.rs"))
.expect("Couldn't write bindings!");
let mut builder = cc::Build::new();
builder.files(src_path.iter());
builder
.flag("-DHAVE_CONFIG_H")
.flag("-std=gnu99")
.flag("-DUSE_SYSTEM_STRNLEN")
;
builder
.include(&out_dir)
.include(Path::new(&libyaml_include))
.include(Path::new("ctags").join("peg"))
.include(Path::new("ctags").join("parsers"))
.include(Path::new("ctags").join("optlib"))
.include(Path::new("ctags").join("fnmatch"))
.include(Path::new("ctags").join("gnu_regex"))
.include(Path::new("ctags").join("extra-cmds"))
.include(Path::new("ctags").join("main"))
;
for file in files.iter() {
builder.file(src_path.join(file));
}
builder.file(ctags_dir); // fake file;
builder.warnings(false);
builder.compile("ctags");
}