|
5 | 5 | // TODO: this surely needs to become much smarter and more flexible.
|
6 | 6 |
|
7 | 7 | extern crate cc;
|
| 8 | +#[cfg(target_env = "msvc")] |
| 9 | +extern crate vcpkg; |
8 | 10 | extern crate pkg_config;
|
9 | 11 | extern crate regex;
|
10 | 12 | extern crate sha2;
|
@@ -36,21 +38,75 @@ fn cpp_platform_specifics(cfg: &mut cc::Build) {
|
36 | 38 | cfg.file("tectonic/XeTeXFontMgr_Mac.mm");
|
37 | 39 | }
|
38 | 40 |
|
| 41 | +// Windows platform specifics: |
| 42 | +#[cfg(target_os = "windows")] |
| 43 | +const LIBS: &'static str = "fontconfig harfbuzz >= 1.4 harfbuzz-icu icu-uc freetype2 graphite2 libpng zlib"; |
| 44 | +#[cfg(target_os = "windows")] |
| 45 | +#[allow(dead_code)] |
| 46 | +const VCPKG_LIBS: &[&[&'static str]] = &[ |
| 47 | + &["fontconfig"], &["harfbuzz"], &["icu"], &["freetype"], &["graphite2"], &["libpng"], &["zlib"]]; |
| 48 | +//FIXME: it should actually be harfbuzz[icu], but currently vcpkg-rs doesn't support features. |
| 49 | + |
| 50 | +#[cfg(target_os = "windows")] |
| 51 | +fn c_platform_specifics(cfg: &mut cc::Build) { |
| 52 | + let target = env::var("TARGET").unwrap(); |
| 53 | + if target.contains("msvc") { |
| 54 | + cfg |
| 55 | + .file("tectonic/msvc/dirent.c") |
| 56 | + .file("tectonic/msvc/getopt.c") |
| 57 | + .file("tectonic/msvc/win32error.c") |
| 58 | + .include("tectonic/msvc/"); |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +#[cfg(target_os = "windows")] |
| 63 | +fn cpp_platform_specifics(cfg: &mut cc::Build) { |
| 64 | + let target = env::var("TARGET").unwrap(); |
| 65 | + if target.contains("msvc") { |
| 66 | + cfg |
| 67 | + .include("tectonic/msvc/"); |
| 68 | + } |
| 69 | + cfg.file("tectonic/XeTeXFontMgr_FC.cpp"); |
| 70 | +} |
| 71 | + |
39 | 72 |
|
40 |
| -// Not-MacOS: |
| 73 | +// Not-MacOS or Windows: |
41 | 74 |
|
42 |
| -#[cfg(not(target_os = "macos"))] |
| 75 | +#[cfg(not(any(target_os = "macos", target_os = "windows")))] |
43 | 76 | const LIBS: &'static str = "fontconfig harfbuzz >= 1.4 harfbuzz-icu icu-uc freetype2 graphite2 libpng zlib";
|
44 | 77 |
|
45 |
| -#[cfg(not(target_os = "macos"))] |
| 78 | +#[cfg(not(any(target_os = "macos", target_os = "windows")))] |
46 | 79 | fn c_platform_specifics(_: &mut cc::Build) {
|
47 | 80 | }
|
48 | 81 |
|
49 |
| -#[cfg(not(target_os = "macos"))] |
| 82 | +#[cfg(not(any(target_os = "macos", target_os = "windows")))] |
50 | 83 | fn cpp_platform_specifics(cfg: &mut cc::Build) {
|
51 | 84 | cfg.file("tectonic/XeTeXFontMgr_FC.cpp");
|
52 | 85 | }
|
53 | 86 |
|
| 87 | +#[cfg(target_env = "msvc")] |
| 88 | +fn load_vcpkg_deps() { |
| 89 | + for dep in VCPKG_LIBS { |
| 90 | + if dep.len() <= 1 { |
| 91 | + vcpkg::find_package(dep[0]).expect("failed to load package from vcpkg"); |
| 92 | + } else { |
| 93 | + let mut config = vcpkg::Config::new(); |
| 94 | + for lib in &dep[1..] { |
| 95 | + config.lib_name(lib); |
| 96 | + } |
| 97 | + config.find_package(dep[0]).expect("failed to load package from vcpkg"); |
| 98 | + } |
| 99 | + } |
| 100 | +} |
| 101 | + |
| 102 | +#[cfg(not(target_env = "msvc"))] |
| 103 | +fn load_vcpkg_deps() { |
| 104 | + panic!() |
| 105 | +} |
| 106 | + |
| 107 | +fn load_pkg_config_deps() { |
| 108 | + pkg_config::Config::new().cargo_metadata(true).probe(LIBS).unwrap(); |
| 109 | +} |
54 | 110 |
|
55 | 111 | fn main() {
|
56 | 112 | // We (have to) rerun the search again below to emit the metadata at the right time.
|
@@ -272,11 +328,21 @@ fn main() {
|
272 | 328 | // Now that we've emitted the info for our own libraries, we can emit the
|
273 | 329 | // info for their dependents.
|
274 | 330 |
|
275 |
| - pkg_config::Config::new().cargo_metadata(true).probe(LIBS).unwrap(); |
| 331 | + if cfg!(target_env = "msvc") { |
| 332 | + load_vcpkg_deps(); |
| 333 | + } else { |
| 334 | + load_pkg_config_deps(); |
| 335 | + } |
276 | 336 |
|
277 | 337 | // Tell cargo to rerun build.rs only if files in the tectonic/ directory have changed.
|
278 | 338 | for file in PathBuf::from("tectonic").read_dir().unwrap() {
|
279 | 339 | let file = file.unwrap();
|
280 | 340 | println!("cargo:rerun-if-changed={}", file.path().display());
|
281 | 341 | }
|
| 342 | + |
| 343 | + #[cfg(target_env = "msvc")] |
| 344 | + for file in PathBuf::from("tectonic/msvc").read_dir().unwrap() { |
| 345 | + let file = file.unwrap(); |
| 346 | + println!("cargo:rerun-if-changed={}", file.path().display()); |
| 347 | + } |
282 | 348 | }
|
0 commit comments