Benjamin Brittain | 8d8d8f3 | 2021-09-28 10:00:50 -0400 | [diff] [blame] | 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 | |
Kenichi Ishibashi | e5abf58 | 2022-03-02 17:41:50 +0900 | [diff] [blame] | 16 | use std::env; |
| 17 | use std::path::Path; |
David Benjamin | 26669ff | 2023-04-21 15:12:24 -0400 | [diff] [blame] | 18 | use std::path::PathBuf; |
| 19 | |
Alex Gaynor | 8d71d24 | 2023-10-11 17:01:38 -0400 | [diff] [blame] | 20 | // Keep in sync with the list in include/openssl/opensslconf.h |
| 21 | const OSSL_CONF_DEFINES: &[&str] = &[ |
| 22 | "OPENSSL_NO_ASYNC", |
| 23 | "OPENSSL_NO_BF", |
| 24 | "OPENSSL_NO_BLAKE2", |
| 25 | "OPENSSL_NO_BUF_FREELISTS", |
| 26 | "OPENSSL_NO_CAMELLIA", |
| 27 | "OPENSSL_NO_CAPIENG", |
| 28 | "OPENSSL_NO_CAST", |
| 29 | "OPENSSL_NO_CMS", |
| 30 | "OPENSSL_NO_COMP", |
| 31 | "OPENSSL_NO_CT", |
| 32 | "OPENSSL_NO_DANE", |
| 33 | "OPENSSL_NO_DEPRECATED", |
| 34 | "OPENSSL_NO_DGRAM", |
| 35 | "OPENSSL_NO_DYNAMIC_ENGINE", |
| 36 | "OPENSSL_NO_EC_NISTP_64_GCC_128", |
| 37 | "OPENSSL_NO_EC2M", |
| 38 | "OPENSSL_NO_EGD", |
| 39 | "OPENSSL_NO_ENGINE", |
| 40 | "OPENSSL_NO_GMP", |
| 41 | "OPENSSL_NO_GOST", |
| 42 | "OPENSSL_NO_HEARTBEATS", |
| 43 | "OPENSSL_NO_HW", |
| 44 | "OPENSSL_NO_IDEA", |
| 45 | "OPENSSL_NO_JPAKE", |
| 46 | "OPENSSL_NO_KRB5", |
| 47 | "OPENSSL_NO_MD2", |
| 48 | "OPENSSL_NO_MDC2", |
| 49 | "OPENSSL_NO_OCB", |
| 50 | "OPENSSL_NO_OCSP", |
| 51 | "OPENSSL_NO_RC2", |
| 52 | "OPENSSL_NO_RC5", |
| 53 | "OPENSSL_NO_RFC3779", |
| 54 | "OPENSSL_NO_RIPEMD", |
| 55 | "OPENSSL_NO_RMD160", |
| 56 | "OPENSSL_NO_SCTP", |
| 57 | "OPENSSL_NO_SEED", |
| 58 | "OPENSSL_NO_SM2", |
| 59 | "OPENSSL_NO_SM3", |
| 60 | "OPENSSL_NO_SM4", |
| 61 | "OPENSSL_NO_SRP", |
| 62 | "OPENSSL_NO_SSL_TRACE", |
| 63 | "OPENSSL_NO_SSL2", |
| 64 | "OPENSSL_NO_SSL3", |
| 65 | "OPENSSL_NO_SSL3_METHOD", |
| 66 | "OPENSSL_NO_STATIC_ENGINE", |
| 67 | "OPENSSL_NO_STORE", |
| 68 | "OPENSSL_NO_WHIRLPOOL", |
| 69 | ]; |
| 70 | |
David Benjamin | 26669ff | 2023-04-21 15:12:24 -0400 | [diff] [blame] | 71 | fn get_bssl_build_dir() -> PathBuf { |
| 72 | println!("cargo:rerun-if-env-changed=BORINGSSL_BUILD_DIR"); |
| 73 | if let Some(build_dir) = env::var_os("BORINGSSL_BUILD_DIR") { |
| 74 | return PathBuf::from(build_dir); |
| 75 | } |
| 76 | |
| 77 | let crate_dir = env::var_os("CARGO_MANIFEST_DIR").unwrap(); |
| 78 | return Path::new(&crate_dir).join("../../build"); |
| 79 | } |
Kenichi Ishibashi | e5abf58 | 2022-03-02 17:41:50 +0900 | [diff] [blame] | 80 | |
Kenichi Ishibashi | 54c956b | 2024-03-17 16:02:03 +1000 | [diff] [blame] | 81 | fn get_cpp_runtime_lib() -> Option<String> { |
| 82 | println!("cargo:rerun-if-env-changed=BORINGSSL_RUST_CPPLIB"); |
| 83 | |
| 84 | if let Ok(cpp_lib) = env::var("BORINGSSL_RUST_CPPLIB") { |
| 85 | return Some(cpp_lib); |
| 86 | } |
| 87 | |
| 88 | if env::var_os("CARGO_CFG_UNIX").is_some() { |
| 89 | match env::var("CARGO_CFG_TARGET_OS").unwrap().as_ref() { |
| 90 | "macos" => Some("c++".into()), |
| 91 | _ => Some("stdc++".into()), |
| 92 | } |
| 93 | } else { |
| 94 | None |
| 95 | } |
| 96 | } |
| 97 | |
Benjamin Brittain | 8d8d8f3 | 2021-09-28 10:00:50 -0400 | [diff] [blame] | 98 | fn main() { |
David Benjamin | 26669ff | 2023-04-21 15:12:24 -0400 | [diff] [blame] | 99 | let bssl_build_dir = get_bssl_build_dir(); |
| 100 | let bssl_sys_build_dir = bssl_build_dir.join("rust/bssl-sys"); |
| 101 | let target = env::var("TARGET").unwrap(); |
Nabil Wadih | be79283 | 2023-02-14 11:46:37 -0800 | [diff] [blame] | 102 | |
Nabil Wadih | 404d98b | 2023-04-14 13:05:02 -0700 | [diff] [blame] | 103 | // Find the bindgen generated target platform bindings file and set BINDGEN_RS_FILE |
David Benjamin | 26669ff | 2023-04-21 15:12:24 -0400 | [diff] [blame] | 104 | let bindgen_file = bssl_sys_build_dir.join(format!("wrapper_{}.rs", target)); |
| 105 | println!("cargo:rustc-env=BINDGEN_RS_FILE={}", bindgen_file.display()); |
Kenichi Ishibashi | e5abf58 | 2022-03-02 17:41:50 +0900 | [diff] [blame] | 106 | |
Benjamin Brittain | 8d8d8f3 | 2021-09-28 10:00:50 -0400 | [diff] [blame] | 107 | // Statically link libraries. |
Kenichi Ishibashi | e5abf58 | 2022-03-02 17:41:50 +0900 | [diff] [blame] | 108 | println!( |
| 109 | "cargo:rustc-link-search=native={}", |
David Benjamin | 26669ff | 2023-04-21 15:12:24 -0400 | [diff] [blame] | 110 | bssl_build_dir.join("crypto").display() |
Kenichi Ishibashi | e5abf58 | 2022-03-02 17:41:50 +0900 | [diff] [blame] | 111 | ); |
Benjamin Brittain | 8d8d8f3 | 2021-09-28 10:00:50 -0400 | [diff] [blame] | 112 | println!("cargo:rustc-link-lib=static=crypto"); |
| 113 | |
Kenichi Ishibashi | e5abf58 | 2022-03-02 17:41:50 +0900 | [diff] [blame] | 114 | println!( |
| 115 | "cargo:rustc-link-search=native={}", |
David Benjamin | 26669ff | 2023-04-21 15:12:24 -0400 | [diff] [blame] | 116 | bssl_build_dir.join("ssl").display() |
Kenichi Ishibashi | e5abf58 | 2022-03-02 17:41:50 +0900 | [diff] [blame] | 117 | ); |
Benjamin Brittain | 8d8d8f3 | 2021-09-28 10:00:50 -0400 | [diff] [blame] | 118 | println!("cargo:rustc-link-lib=static=ssl"); |
| 119 | |
David Benjamin | 26669ff | 2023-04-21 15:12:24 -0400 | [diff] [blame] | 120 | println!( |
| 121 | "cargo:rustc-link-search=native={}", |
| 122 | bssl_sys_build_dir.display() |
| 123 | ); |
Benjamin Brittain | 8d8d8f3 | 2021-09-28 10:00:50 -0400 | [diff] [blame] | 124 | println!("cargo:rustc-link-lib=static=rust_wrapper"); |
Alex Gaynor | 8d71d24 | 2023-10-11 17:01:38 -0400 | [diff] [blame] | 125 | |
Kenichi Ishibashi | 54c956b | 2024-03-17 16:02:03 +1000 | [diff] [blame] | 126 | if let Some(cpp_lib) = get_cpp_runtime_lib() { |
| 127 | println!("cargo:rustc-link-lib={}", cpp_lib); |
| 128 | } |
| 129 | |
Alex Gaynor | 8d71d24 | 2023-10-11 17:01:38 -0400 | [diff] [blame] | 130 | println!("cargo:conf={}", OSSL_CONF_DEFINES.join(",")); |
Benjamin Brittain | 8d8d8f3 | 2021-09-28 10:00:50 -0400 | [diff] [blame] | 131 | } |