Debian Codegraph @

build.rs

raw symbols SCIP
1 extern crate cc;
2
3 use std::env;
4 use std::fs;
5 use std::path::PathBuf;
6
7 const VERSION: &str = "1.33.90";
8
9 fn main() {
10 let target = env::var("TARGET").unwrap();
11 let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
12 let ver = fs::read_to_string("nghttp2/lib/includes/nghttp2/nghttp2ver.h.in")
13 .unwrap()
14 .replace("@PACKAGE_VERSION@", VERSION)
15 .replace("@PACKAGE_VERSION_NUM@", "0x01214a");
16
17 let install = out_dir.join("i");
18 let include = install.join("include");
19 let lib = install.join("lib");
20 let pkgconfig = lib.join("pkgconfig");
21 fs::create_dir_all(include.join("nghttp2")).unwrap();
22 fs::create_dir_all(&pkgconfig).unwrap();
23 fs::write(include.join("nghttp2/nghttp2ver.h"), ver).unwrap();
24
25 let mut cfg = cc::Build::new();
26 cfg.include("nghttp2/lib/includes")
27 .include(&include)
28 .file("nghttp2/lib/nghttp2_buf.c")
29 .file("nghttp2/lib/nghttp2_callbacks.c")
30 .file("nghttp2/lib/nghttp2_debug.c")
31 .file("nghttp2/lib/nghttp2_frame.c")
32 .file("nghttp2/lib/nghttp2_hd.c")
33 .file("nghttp2/lib/nghttp2_hd_huffman.c")
34 .file("nghttp2/lib/nghttp2_hd_huffman_data.c")
35 .file("nghttp2/lib/nghttp2_helper.c")
36 .file("nghttp2/lib/nghttp2_http.c")
37 .file("nghttp2/lib/nghttp2_map.c")
38 .file("nghttp2/lib/nghttp2_mem.c")
39 .file("nghttp2/lib/nghttp2_npn.c")
40 .file("nghttp2/lib/nghttp2_option.c")
41 .file("nghttp2/lib/nghttp2_outbound_item.c")
42 .file("nghttp2/lib/nghttp2_pq.c")
43 .file("nghttp2/lib/nghttp2_priority_spec.c")
44 .file("nghttp2/lib/nghttp2_queue.c")
45 .file("nghttp2/lib/nghttp2_rcbuf.c")
46 .file("nghttp2/lib/nghttp2_session.c")
47 .file("nghttp2/lib/nghttp2_stream.c")
48 .file("nghttp2/lib/nghttp2_submit.c")
49 .file("nghttp2/lib/nghttp2_version.c")
50 .warnings(false)
51 .define("NGHTTP2_STATICLIB", None)
52 .define("HAVE_NETINET_IN", None)
53 .out_dir(&lib);
54
55 if target.contains("windows") {
56 // Apparently MSVC doesn't have `ssize_t` defined as a type
57 if target.contains("msvc") {
58 match &env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap()[..] {
59 "64" => {
60 cfg.define("ssize_t", "int64_t");
61 }
62 "32" => {
63 cfg.define("ssize_t", "int32_t");
64 }
65 s => panic!("unknown pointer size: {}", s),
66 }
67 }
68 } else {
69 cfg.define("HAVE_ARPA_INET_H", None);
70 }
71 cfg.compile("nghttp2");
72
73 println!("cargo:root={}", install.display());
74
75 let pc = fs::read_to_string("nghttp2/lib/libnghttp2.pc.in")
76 .unwrap()
77 .replace("@prefix@", install.to_str().unwrap())
78 .replace("@exec_prefix@", "")
79 .replace("@libdir@", lib.to_str().unwrap())
80 .replace("@includedir@", include.to_str().unwrap())
81 .replace("@VERSION@", VERSION);
82 fs::write(pkgconfig.join("libnghttp2.pc"), pc).unwrap();
83 fs::copy(
84 "nghttp2/lib/includes/nghttp2/nghttp2.h",
85 include.join("nghttp2/nghttp2.h"),
86 )
87 .unwrap();
88 }