1 /* Copyright (c) 2021, Google Inc.
2 *
3 * Permission to use, copy, modify, and/or distribute this software for any
4 * purpose with or without fee is hereby granted, provided that the above
5 * copyright notice and this permission notice appear in all copies.
6 *
7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14 */
15
16 use std::env;
17 use std::path::Path;
18 use std::path::PathBuf;
19
get_bssl_build_dir() -> PathBuf20 fn get_bssl_build_dir() -> PathBuf {
21 println!("cargo:rerun-if-env-changed=BORINGSSL_BUILD_DIR");
22 if let Some(build_dir) = env::var_os("BORINGSSL_BUILD_DIR") {
23 return PathBuf::from(build_dir);
24 }
25
26 let crate_dir = env::var_os("CARGO_MANIFEST_DIR").unwrap();
27 return Path::new(&crate_dir).join("../../build");
28 }
29
main()30 fn main() {
31 let bssl_build_dir = get_bssl_build_dir();
32 let bssl_sys_build_dir = bssl_build_dir.join("rust/bssl-sys");
33 let target = env::var("TARGET").unwrap();
34
35 // Find the bindgen generated target platform bindings file and set BINDGEN_RS_FILE
36 let bindgen_file = bssl_sys_build_dir.join(format!("wrapper_{}.rs", target));
37 println!("cargo:rustc-env=BINDGEN_RS_FILE={}", bindgen_file.display());
38
39 // Statically link libraries.
40 println!(
41 "cargo:rustc-link-search=native={}",
42 bssl_build_dir.join("crypto").display()
43 );
44 println!("cargo:rustc-link-lib=static=crypto");
45
46 println!(
47 "cargo:rustc-link-search=native={}",
48 bssl_build_dir.join("ssl").display()
49 );
50 println!("cargo:rustc-link-lib=static=ssl");
51
52 println!(
53 "cargo:rustc-link-search=native={}",
54 bssl_sys_build_dir.display()
55 );
56 println!("cargo:rustc-link-lib=static=rust_wrapper");
57 }
58