1 use std::env;
2
build_zlib_ng(target: &str, compat: bool)3 pub fn build_zlib_ng(target: &str, compat: bool) {
4 let mut cmake = cmake::Config::new("src/zlib-ng");
5 cmake
6 .define("BUILD_SHARED_LIBS", "OFF")
7 .define("ZLIB_COMPAT", if compat { "ON" } else { "OFF" })
8 .define("ZLIB_ENABLE_TESTS", "OFF")
9 .define("WITH_GZFILEOP", "ON");
10 if target.contains("s390x") {
11 // Enable hardware compression on s390x.
12 cmake
13 .define("WITH_DFLTCC_DEFLATE", "1")
14 .define("WITH_DFLTCC_INFLATE", "1")
15 .cflag("-DDFLTCC_LEVEL_MASK=0x7e");
16 }
17 if target == "i686-pc-windows-msvc" {
18 cmake.define("CMAKE_GENERATOR_PLATFORM", "Win32");
19 }
20
21 let install_dir = cmake.build();
22
23 let includedir = install_dir.join("include");
24 let libdir = install_dir.join("lib");
25 println!(
26 "cargo:rustc-link-search=native={}",
27 libdir.to_str().unwrap()
28 );
29 let mut debug_suffix = "";
30 let libname = if target.contains("windows") && target.contains("msvc") {
31 if env::var("OPT_LEVEL").unwrap() == "0" {
32 debug_suffix = "d";
33 }
34 "zlibstatic"
35 } else {
36 "z"
37 };
38 println!(
39 "cargo:rustc-link-lib=static={}{}{}",
40 libname,
41 if compat { "" } else { "-ng" },
42 debug_suffix,
43 );
44 println!("cargo:root={}", install_dir.to_str().unwrap());
45 println!("cargo:include={}", includedir.to_str().unwrap());
46 if !compat {
47 println!("cargo:rustc-cfg=zng");
48 }
49 }
50
51 #[allow(dead_code)]
main()52 fn main() {
53 let target = env::var("TARGET").unwrap();
54 build_zlib_ng(&target, false);
55 }
56