forked from tectonic-typesetting/tectonic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
282 lines (247 loc) · 8.72 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
// build.rs -- build helper script for Tectonic.
// Copyright 2016-2017 the Tectonic Project
// Licensed under the MIT License.
//
// TODO: this surely needs to become much smarter and more flexible.
extern crate cc;
extern crate pkg_config;
extern crate regex;
extern crate sha2;
use std::env;
use std::path::PathBuf;
// MacOS platform specifics:
#[cfg(target_os = "macos")]
const LIBS: &'static str = "harfbuzz harfbuzz-icu icu-uc freetype2 graphite2 libpng zlib";
#[cfg(target_os = "macos")]
fn c_platform_specifics(cfg: &mut cc::Build) {
cfg.define("XETEX_MAC", Some("1"));
cfg.file("tectonic/XeTeX_mac.c");
println!("cargo:rustc-link-lib=framework=Foundation");
println!("cargo:rustc-link-lib=framework=CoreFoundation");
println!("cargo:rustc-link-lib=framework=CoreGraphics");
println!("cargo:rustc-link-lib=framework=CoreText");
println!("cargo:rustc-link-lib=framework=AppKit");
}
#[cfg(target_os = "macos")]
fn cpp_platform_specifics(cfg: &mut cc::Build) {
cfg.define("XETEX_MAC", Some("1"));
cfg.file("tectonic/XeTeXFontInst_Mac.cpp");
cfg.file("tectonic/XeTeXFontMgr_Mac.mm");
}
// Not-MacOS:
#[cfg(not(target_os = "macos"))]
const LIBS: &'static str = "fontconfig harfbuzz harfbuzz-icu icu-uc freetype2 graphite2 libpng zlib";
#[cfg(not(target_os = "macos"))]
fn c_platform_specifics(_: &mut cc::Build) {
}
#[cfg(not(target_os = "macos"))]
fn cpp_platform_specifics(cfg: &mut cc::Build) {
cfg.file("tectonic/XeTeXFontMgr_FC.cpp");
}
fn main() {
// We (have to) rerun the search again below to emit the metadata at the right time.
let deps = pkg_config::Config::new().cargo_metadata(false).probe(LIBS).unwrap();
// First, emit the string pool C code. Sigh.
let out_dir = env::var("OUT_DIR").unwrap();
// Actually I'm not 100% sure that I can't compile the C and C++ code
// into one library, but who cares?
let mut ccfg = cc::Build::new();
let mut cppcfg = cc::Build::new();
let cflags = [
"-Wall",
"-Wcast-qual",
"-Wdate-time",
"-Wendif-labels",
"-Wextra",
"-Wextra-semi",
"-Wformat=2",
"-Winit-self",
"-Wlogical-op",
"-Wmissing-declarations",
"-Wmissing-include-dirs",
"-Wmissing-prototypes",
"-Wmissing-variable-declarations",
"-Wnested-externs",
"-Wold-style-definition",
"-Wpointer-arith",
"-Wredundant-decls",
"-Wstrict-prototypes",
"-Wsuggest-attribute=format",
"-Wswitch-bool",
"-Wundef",
"-Wwrite-strings",
// TODO: Fix existing warnings before enabling these:
// "-Wbad-function-cast",
// "-Wcast-align",
// "-Wconversion",
// "-Wdouble-promotion",
// "-Wshadow",
// "-Wsuggest-attribute=const",
// "-Wsuggest-attribute=noreturn",
// "-Wsuggest-attribute=pure",
// "-Wunreachable-code-aggresive",
"-Wno-unused-parameter",
"-Wno-implicit-fallthrough",
"-Wno-sign-compare",
"-std=gnu11"
];
for flag in &cflags {
ccfg.flag_if_supported(flag);
}
ccfg
.file("tectonic/bibtex.c")
.file("tectonic/core-bridge.c")
.file("tectonic/core-kpathutil.c")
.file("tectonic/dpx-agl.c")
.file("tectonic/dpx-bmpimage.c")
.file("tectonic/dpx-cff.c")
.file("tectonic/dpx-cff_dict.c")
.file("tectonic/dpx-cid.c")
.file("tectonic/dpx-cidtype0.c")
.file("tectonic/dpx-cidtype2.c")
.file("tectonic/dpx-cmap.c")
.file("tectonic/dpx-cmap_read.c")
.file("tectonic/dpx-cmap_write.c")
.file("tectonic/dpx-cs_type2.c")
.file("tectonic/dpx-dpxconf.c")
.file("tectonic/dpx-dpxcrypt.c")
.file("tectonic/dpx-dpxfile.c")
.file("tectonic/dpx-dpxutil.c")
.file("tectonic/dpx-dvi.c")
.file("tectonic/dpx-dvipdfmx.c")
.file("tectonic/dpx-epdf.c")
.file("tectonic/dpx-error.c")
.file("tectonic/dpx-fontmap.c")
.file("tectonic/dpx-jp2image.c")
.file("tectonic/dpx-jpegimage.c")
.file("tectonic/dpx-mem.c")
.file("tectonic/dpx-mfileio.c")
.file("tectonic/dpx-mpost.c")
.file("tectonic/dpx-numbers.c")
.file("tectonic/dpx-otl_conf.c")
.file("tectonic/dpx-otl_opt.c")
.file("tectonic/dpx-pdfcolor.c")
.file("tectonic/dpx-pdfdev.c")
.file("tectonic/dpx-pdfdoc.c")
.file("tectonic/dpx-pdfdraw.c")
.file("tectonic/dpx-pdfencoding.c")
.file("tectonic/dpx-pdfencrypt.c")
.file("tectonic/dpx-pdffont.c")
.file("tectonic/dpx-pdfnames.c")
.file("tectonic/dpx-pdfobj.c")
.file("tectonic/dpx-pdfparse.c")
.file("tectonic/dpx-pdfresource.c")
.file("tectonic/dpx-pdfximage.c")
.file("tectonic/dpx-pkfont.c")
.file("tectonic/dpx-pngimage.c")
.file("tectonic/dpx-pst.c")
.file("tectonic/dpx-pst_obj.c")
.file("tectonic/dpx-sfnt.c")
.file("tectonic/dpx-spc_color.c")
.file("tectonic/dpx-spc_dvipdfmx.c")
.file("tectonic/dpx-spc_dvips.c")
.file("tectonic/dpx-spc_html.c")
.file("tectonic/dpx-spc_misc.c")
.file("tectonic/dpx-spc_pdfm.c")
.file("tectonic/dpx-spc_tpic.c")
.file("tectonic/dpx-spc_util.c")
.file("tectonic/dpx-spc_xtx.c")
.file("tectonic/dpx-specials.c")
.file("tectonic/dpx-subfont.c")
.file("tectonic/dpx-t1_char.c")
.file("tectonic/dpx-t1_load.c")
.file("tectonic/dpx-tfm.c")
.file("tectonic/dpx-truetype.c")
.file("tectonic/dpx-tt_aux.c")
.file("tectonic/dpx-tt_cmap.c")
.file("tectonic/dpx-tt_glyf.c")
.file("tectonic/dpx-tt_gsub.c")
.file("tectonic/dpx-tt_post.c")
.file("tectonic/dpx-tt_table.c")
.file("tectonic/dpx-type0.c")
.file("tectonic/dpx-type1.c")
.file("tectonic/dpx-type1c.c")
.file("tectonic/dpx-unicode.c")
.file("tectonic/dpx-vf.c")
.file("tectonic/engine-interface.c")
.file("tectonic/errors.c")
.file("tectonic/io.c")
.file("tectonic/mathutil.c")
.file("tectonic/output.c")
.file("tectonic/stringpool.c")
.file("tectonic/synctex.c")
.file("tectonic/texmfmp.c")
.file("tectonic/xetex0.c")
.file("tectonic/XeTeX_ext.c")
.file("tectonic/xetexini.c")
.file("tectonic/XeTeX_pic.c")
.file("tectonic/xetex-linebreak.c")
.file("tectonic/xetex-shipout.c")
.define("HAVE_ZLIB", "1")
.define("HAVE_ZLIB_COMPRESS2", "1")
.define("ZLIB_CONST", "1")
.include(".")
.include(&out_dir);
let cppflags = [
"-std=c++14",
"-Wall",
"-Wdate-time",
"-Wendif-labels",
"-Wextra",
"-Wformat=2",
"-Wlogical-op",
"-Wmissing-declarations",
"-Wmissing-include-dirs",
"-Wpointer-arith",
"-Wredundant-decls",
"-Wsuggest-attribute=noreturn",
"-Wsuggest-attribute=format",
"-Wshadow",
"-Wswitch-bool",
"-Wundef",
// TODO: Fix existing warnings before enabling these:
// "-Wdouble-promotion",
// "-Wcast-align",
// "-Wconversion",
// "-Wextra-semi",
// "-Wmissing-variable-declarations",
// "-Wsuggest-attribute=const",
// "-Wsuggest-attribute=pure",
// "-Wunreachable-code-aggresive",
"-Wno-unused-parameter",
"-Wno-implicit-fallthrough",
];
for flag in &cppflags {
cppcfg.flag_if_supported(flag);
}
cppcfg
.cpp(true)
.flag("-Wall")
.file("tectonic/Engine.cpp")
.file("tectonic/XeTeXFontInst.cpp")
.file("tectonic/XeTeXFontMgr.cpp")
.file("tectonic/XeTeXLayoutInterface.cpp")
.file("tectonic/XeTeXOTMath.cpp")
.include(".")
.include(&out_dir);
for p in deps.include_paths {
ccfg.include(&p);
cppcfg.include(&p);
}
c_platform_specifics(&mut ccfg);
cpp_platform_specifics(&mut cppcfg);
if cfg!(target_endian = "big") {
ccfg.define("WORDS_BIGENDIAN", "1");
cppcfg.define("WORDS_BIGENDIAN", "1");
}
ccfg.compile("libtectonic_c.a");
cppcfg.compile("libtectonic_cpp.a");
// Now that we've emitted the info for our own libraries, we can emit the
// info for their dependents.
pkg_config::Config::new().cargo_metadata(true).probe(LIBS).unwrap();
// Tell cargo to rerun build.rs only if files in the tectonic/ directory have changed.
for file in PathBuf::from("tectonic").read_dir().unwrap() {
let file = file.unwrap();
println!("cargo:rerun-if-changed={}", file.path().display());
}
}