|
1 | | -// Additional parameters for Android build of BoringSSL. |
2 | | -// |
3 | | -// Requires Android NDK >= 19. |
4 | | -const CMAKE_PARAMS_ANDROID_NDK: &[(&str, &[(&str, &str)])] = &[ |
5 | | - ("aarch64", &[("ANDROID_ABI", "arm64-v8a")]), |
6 | | - ("arm", &[("ANDROID_ABI", "armeabi-v7a")]), |
7 | | - ("x86", &[("ANDROID_ABI", "x86")]), |
8 | | - ("x86_64", &[("ANDROID_ABI", "x86_64")]), |
9 | | -]; |
10 | | - |
11 | | -// iOS. |
12 | | -const CMAKE_PARAMS_IOS: &[(&str, &[(&str, &str)])] = &[ |
13 | | - ("aarch64", &[ |
14 | | - ("CMAKE_OSX_ARCHITECTURES", "arm64"), |
15 | | - ("CMAKE_OSX_SYSROOT", "iphoneos"), |
16 | | - ]), |
17 | | - ("x86_64", &[ |
18 | | - ("CMAKE_OSX_ARCHITECTURES", "x86_64"), |
19 | | - ("CMAKE_OSX_SYSROOT", "iphonesimulator"), |
20 | | - ]), |
21 | | -]; |
22 | | - |
23 | | -// ARM Linux. |
24 | | -const CMAKE_PARAMS_ARM_LINUX: &[(&str, &[(&str, &str)])] = &[ |
25 | | - ("aarch64", &[("CMAKE_SYSTEM_PROCESSOR", "aarch64")]), |
26 | | - ("arm", &[("CMAKE_SYSTEM_PROCESSOR", "arm")]), |
27 | | -]; |
28 | | - |
29 | | -/// Returns the platform-specific output path for lib. |
30 | | -/// |
31 | | -/// MSVC generator on Windows place static libs in a target sub-folder, |
32 | | -/// so adjust library location based on platform and build target. |
33 | | -/// See issue: https://github.com/alexcrichton/cmake-rs/issues/18 |
34 | | -fn get_boringssl_platform_output_path() -> String { |
35 | | - if cfg!(target_env = "msvc") { |
36 | | - // Code under this branch should match the logic in cmake-rs |
37 | | - let debug_env_var = |
38 | | - std::env::var("DEBUG").expect("DEBUG variable not defined in env"); |
39 | | - |
40 | | - let deb_info = match &debug_env_var[..] { |
41 | | - "false" => false, |
42 | | - "true" => true, |
43 | | - unknown => panic!("Unknown DEBUG={unknown} env var."), |
44 | | - }; |
45 | | - |
46 | | - let opt_env_var = std::env::var("OPT_LEVEL") |
47 | | - .expect("OPT_LEVEL variable not defined in env"); |
48 | | - |
49 | | - let subdir = match &opt_env_var[..] { |
50 | | - "0" => "Debug", |
51 | | - "1" | "2" | "3" => |
52 | | - if deb_info { |
53 | | - "RelWithDebInfo" |
54 | | - } else { |
55 | | - "Release" |
56 | | - }, |
57 | | - "s" | "z" => "MinSizeRel", |
58 | | - unknown => panic!("Unknown OPT_LEVEL={unknown} env var."), |
59 | | - }; |
60 | | - |
61 | | - subdir.to_string() |
62 | | - } else { |
63 | | - "".to_string() |
64 | | - } |
65 | | -} |
66 | | - |
67 | | -/// Returns a new cmake::Config for building BoringSSL. |
68 | | -/// |
69 | | -/// It will add platform-specific parameters if needed. |
70 | | -fn get_boringssl_cmake_config() -> cmake::Config { |
71 | | - let arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap(); |
72 | | - let os = std::env::var("CARGO_CFG_TARGET_OS").unwrap(); |
73 | | - let pwd = std::env::current_dir().unwrap(); |
74 | | - |
75 | | - let mut boringssl_cmake = cmake::Config::new("deps/boringssl"); |
76 | | - |
77 | | - // Add platform-specific parameters. |
78 | | - match os.as_ref() { |
79 | | - "android" => { |
80 | | - // We need ANDROID_NDK_HOME to be set properly. |
81 | | - let android_ndk_home = std::env::var("ANDROID_NDK_HOME") |
82 | | - .expect("Please set ANDROID_NDK_HOME for Android build"); |
83 | | - let android_ndk_home = std::path::Path::new(&android_ndk_home); |
84 | | - for (android_arch, params) in CMAKE_PARAMS_ANDROID_NDK { |
85 | | - if *android_arch == arch { |
86 | | - for (name, value) in *params { |
87 | | - boringssl_cmake.define(name, value); |
88 | | - } |
89 | | - } |
90 | | - } |
91 | | - let toolchain_file = |
92 | | - android_ndk_home.join("build/cmake/android.toolchain.cmake"); |
93 | | - let toolchain_file = toolchain_file.to_str().unwrap(); |
94 | | - boringssl_cmake.define("CMAKE_TOOLCHAIN_FILE", toolchain_file); |
95 | | - |
96 | | - // 21 is the minimum level tested. You can give higher value. |
97 | | - boringssl_cmake.define("ANDROID_NATIVE_API_LEVEL", "21"); |
98 | | - boringssl_cmake.define("ANDROID_STL", "c++_shared"); |
99 | | - |
100 | | - boringssl_cmake |
101 | | - }, |
102 | | - |
103 | | - "ios" => { |
104 | | - for (ios_arch, params) in CMAKE_PARAMS_IOS { |
105 | | - if *ios_arch == arch { |
106 | | - for (name, value) in *params { |
107 | | - boringssl_cmake.define(name, value); |
108 | | - } |
109 | | - } |
110 | | - } |
111 | | - |
112 | | - // Bitcode is always on. |
113 | | - let bitcode_cflag = "-fembed-bitcode"; |
114 | | - |
115 | | - // Hack for Xcode 10.1. |
116 | | - let target_cflag = if arch == "x86_64" { |
117 | | - "-target x86_64-apple-ios-simulator" |
118 | | - } else { |
119 | | - "" |
120 | | - }; |
121 | | - |
122 | | - let cflag = format!("{bitcode_cflag} {target_cflag}"); |
123 | | - |
124 | | - boringssl_cmake.define("CMAKE_ASM_FLAGS", &cflag); |
125 | | - boringssl_cmake.cflag(&cflag); |
126 | | - |
127 | | - boringssl_cmake |
128 | | - }, |
129 | | - |
130 | | - "linux" => match arch.as_ref() { |
131 | | - "aarch64" | "arm" => { |
132 | | - for (arm_arch, params) in CMAKE_PARAMS_ARM_LINUX { |
133 | | - if *arm_arch == arch { |
134 | | - for (name, value) in *params { |
135 | | - boringssl_cmake.define(name, value); |
136 | | - } |
137 | | - } |
138 | | - } |
139 | | - boringssl_cmake.define("CMAKE_SYSTEM_NAME", "Linux"); |
140 | | - boringssl_cmake.define("CMAKE_SYSTEM_VERSION", "1"); |
141 | | - |
142 | | - boringssl_cmake |
143 | | - }, |
144 | | - |
145 | | - "x86" => { |
146 | | - boringssl_cmake.define( |
147 | | - "CMAKE_TOOLCHAIN_FILE", |
148 | | - pwd.join("deps/boringssl/src/util/32-bit-toolchain.cmake") |
149 | | - .as_os_str(), |
150 | | - ); |
151 | | - |
152 | | - boringssl_cmake |
153 | | - }, |
154 | | - |
155 | | - _ => boringssl_cmake, |
156 | | - }, |
157 | | - |
158 | | - _ => { |
159 | | - // Configure BoringSSL for building on 32-bit non-windows platforms. |
160 | | - if arch == "x86" && os != "windows" { |
161 | | - boringssl_cmake.define( |
162 | | - "CMAKE_TOOLCHAIN_FILE", |
163 | | - pwd.join("deps/boringssl/src/util/32-bit-toolchain.cmake") |
164 | | - .as_os_str(), |
165 | | - ); |
166 | | - } |
167 | | - |
168 | | - boringssl_cmake |
169 | | - }, |
170 | | - } |
171 | | -} |
172 | | - |
173 | 1 | fn write_pkg_config() { |
174 | 2 | use std::io::prelude::*; |
175 | 3 |
|
@@ -216,40 +44,6 @@ fn target_dir_path() -> std::path::PathBuf { |
216 | 44 | } |
217 | 45 |
|
218 | 46 | fn main() { |
219 | | - if cfg!(feature = "boringssl-vendored") && |
220 | | - !cfg!(feature = "boringssl-boring-crate") && |
221 | | - !cfg!(feature = "openssl") |
222 | | - { |
223 | | - let bssl_dir = std::env::var("QUICHE_BSSL_PATH").unwrap_or_else(|_| { |
224 | | - let mut cfg = get_boringssl_cmake_config(); |
225 | | - |
226 | | - if cfg!(feature = "fuzzing") { |
227 | | - cfg.cxxflag("-DBORINGSSL_UNSAFE_DETERMINISTIC_MODE") |
228 | | - .cxxflag("-DBORINGSSL_UNSAFE_FUZZER_MODE"); |
229 | | - } |
230 | | - |
231 | | - cfg.build_target("ssl").build(); |
232 | | - cfg.build_target("crypto").build().display().to_string() |
233 | | - }); |
234 | | - |
235 | | - println!("cargo:rustc-link-arg=-Wl,-rpath,{bssl_dir}"); |
236 | | - |
237 | | - let build_path = get_boringssl_platform_output_path(); |
238 | | - let mut build_dir = format!("{bssl_dir}/build/{build_path}"); |
239 | | - |
240 | | - // If build directory doesn't exist, use the specified path as is. |
241 | | - if !std::path::Path::new(&build_dir).is_dir() { |
242 | | - build_dir = bssl_dir; |
243 | | - } |
244 | | - |
245 | | - println!("cargo:rustc-link-search=native={build_dir}"); |
246 | | - |
247 | | - let bssl_link_kind = std::env::var("QUICHE_BSSL_LINK_KIND") |
248 | | - .unwrap_or("static".to_string()); |
249 | | - println!("cargo:rustc-link-lib={bssl_link_kind}=ssl"); |
250 | | - println!("cargo:rustc-link-lib={bssl_link_kind}=crypto"); |
251 | | - } |
252 | | - |
253 | 47 | if cfg!(feature = "boringssl-boring-crate") { |
254 | 48 | println!("cargo:rustc-link-lib=static=ssl"); |
255 | 49 | println!("cargo:rustc-link-lib=static=crypto"); |
|
0 commit comments