Skip to content

Commit 167ba18

Browse files
committed
Build help/cleanups
1 parent 2b7b97e commit 167ba18

2 files changed

Lines changed: 35 additions & 52 deletions

File tree

boring-sys/build/config.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub(crate) struct Env {
3333
pub(crate) debug: Option<OsString>,
3434
pub(crate) opt_level: Option<OsString>,
3535
pub(crate) android_ndk_home: Option<PathBuf>,
36-
pub(crate) cmake_toolchain_file: Option<PathBuf>,
36+
pub(crate) cmake_toolchain_file_is_set: bool,
3737
pub(crate) cpp_runtime_lib: Option<OsString>,
3838
/// C compiler (ignored if using FIPS)
3939
pub(crate) cc: Option<OsString>,
@@ -160,7 +160,7 @@ impl Env {
160160

161161
// The passed name is the non-fips version of the environment variable,
162162
// to help look for them in the repository.
163-
assert!(name.starts_with(BORING_BSSL_PREFIX));
163+
debug_assert!(name.starts_with(BORING_BSSL_PREFIX));
164164

165165
let non_fips = target_var(name);
166166
if is_fips_like {
@@ -181,13 +181,15 @@ impl Env {
181181
source_path: boringssl_var("BORING_BSSL_SOURCE_PATH").map(PathBuf::from), // gets BORING_BSSL_FIPS_SOURCE_PATH if fips is enabled
182182
assume_patched: boringssl_var("BORING_BSSL_ASSUME_PATCHED") // gets BORING_BSSL_FIPS_ASSUME_PATCHED if fips is enabled
183183
.is_some_and(|v| !v.is_empty()),
184+
// only used when cross-compiling
184185
sysroot: boringssl_var("BORING_BSSL_SYSROOT").map(PathBuf::from), // gets BORING_BSSL_FIPS_SYSROOT if fips is enabled
186+
// only used when cross-compiling
185187
compiler_external_toolchain: boringssl_var("BORING_BSSL_COMPILER_EXTERNAL_TOOLCHAIN") // gets BORING_BSSL_FIPS_COMPILER_EXTERNAL_TOOLCHAIN if fips is enabled
186188
.map(PathBuf::from),
187189
debug: target_var("DEBUG"),
188190
opt_level: target_var("OPT_LEVEL"),
189191
android_ndk_home: target_var("ANDROID_NDK_HOME").map(Into::into),
190-
cmake_toolchain_file: target_var("CMAKE_TOOLCHAIN_FILE").map(Into::into),
192+
cmake_toolchain_file_is_set: var("CMAKE_TOOLCHAIN_FILE").is_some(),
191193
cpp_runtime_lib: target_var("BORING_BSSL_RUST_CPPLIB"),
192194
// matches the `cc` crate
193195
cc: target_only_var("CC"),

boring-sys/build/main.rs

Lines changed: 30 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ fn get_boringssl_cmake_config(config: &Config) -> cmake::Config {
204204
let src_path = get_boringssl_source_path(config);
205205
let mut boringssl_cmake = cmake::Config::new(src_path);
206206

207-
if config.env.cmake_toolchain_file.is_some() {
207+
if config.env.cmake_toolchain_file_is_set {
208+
println!("cargo::warning=CMAKE_TOOLCHAIN_FILE var set; won't customize cmake vars");
208209
return boringssl_cmake;
209210
}
210211

@@ -213,14 +214,18 @@ fn get_boringssl_cmake_config(config: &Config) -> cmake::Config {
213214
// This is required now because newest BoringSSL requires CMake 3.22 which
214215
// uses the new logic with CMAKE_MSVC_RUNTIME_LIBRARY introduced in CMake 3.15.
215216
// https://github.com/rust-lang/cmake-rs/pull/30#issuecomment-2969758499
216-
if config.target_features.iter().any(|f| f == "crt-static") {
217-
boringssl_cmake.define("CMAKE_MSVC_RUNTIME_LIBRARY", "MultiThreaded");
217+
let rt = if config.target_features.iter().any(|f| f == "crt-static") {
218+
"MultiThreaded"
218219
} else {
219-
boringssl_cmake.define("CMAKE_MSVC_RUNTIME_LIBRARY", "MultiThreadedDLL");
220-
}
220+
"MultiThreadedDLL"
221+
};
222+
boringssl_cmake.define("CMAKE_MSVC_RUNTIME_LIBRARY", rt);
221223
}
222224

223225
if config.host == config.target {
226+
if config.env.compiler_external_toolchain.is_some() {
227+
println!("cargo::warning=COMPILER_EXTERNAL_TOOLCHAIN won't be used");
228+
}
224229
return boringssl_cmake;
225230
}
226231

@@ -253,7 +258,7 @@ fn get_boringssl_cmake_config(config: &Config) -> cmake::Config {
253258
}
254259

255260
// Add platform-specific parameters for cross-compilation.
256-
match &*config.target_os {
261+
let toolchain_file = match &*config.target_os {
257262
"android" => {
258263
// We need ANDROID_NDK_HOME to be set properly.
259264
let android_ndk_home = config
@@ -266,68 +271,44 @@ fn get_boringssl_cmake_config(config: &Config) -> cmake::Config {
266271
boringssl_cmake.define(name, value);
267272
}
268273
let toolchain_file = android_ndk_home.join("build/cmake/android.toolchain.cmake");
269-
let toolchain_file = toolchain_file.to_str().unwrap();
270-
eprintln!("android toolchain={toolchain_file}");
271-
boringssl_cmake.define("CMAKE_TOOLCHAIN_FILE", toolchain_file);
272274

273275
// 21 is the minimum level tested. You can give higher value.
274276
boringssl_cmake.define("CMAKE_SYSTEM_VERSION", "21");
275277
boringssl_cmake.define("CMAKE_ANDROID_STL_TYPE", "c++_shared");
278+
Some(toolchain_file)
276279
}
277-
278280
os @ ("macos" | "ios") => {
279281
for (name, value) in cmake_params_apple(config) {
280282
eprintln!("{os} arch={} add {}={}", config.target_arch, name, value);
281283
boringssl_cmake.define(name, value);
282284
}
285+
None
283286
}
284-
285287
"windows" if config.host.contains("windows") => {
286288
// BoringSSL's CMakeLists.txt isn't set up for cross-compiling using Visual Studio.
287289
// Disable assembly support so that it at least builds.
288290
boringssl_cmake.define("OPENSSL_NO_ASM", "YES");
291+
None
289292
}
290-
291293
"linux" => match &*config.target_arch {
292-
"x86" => {
293-
boringssl_cmake.define(
294-
"CMAKE_TOOLCHAIN_FILE",
295-
// `src_path` can be a path relative to the manifest dir, but
296-
// cmake hates that.
297-
config
298-
.manifest_dir
299-
.join(src_path)
300-
.join("util/32-bit-toolchain.cmake")
301-
.as_os_str(),
302-
);
303-
}
304-
"aarch64" => {
305-
boringssl_cmake.define(
306-
"CMAKE_TOOLCHAIN_FILE",
307-
config
308-
.manifest_dir
309-
.join("cmake/aarch64-linux.cmake")
310-
.as_os_str(),
311-
);
312-
}
313-
"arm" => {
314-
boringssl_cmake.define(
315-
"CMAKE_TOOLCHAIN_FILE",
316-
config
317-
.manifest_dir
318-
.join("cmake/armv7-linux.cmake")
319-
.as_os_str(),
320-
);
321-
}
322-
_ => {
323-
println!(
324-
"cargo:warning=no toolchain file configured by boring-sys for {}",
325-
config.target
326-
);
327-
}
294+
"x86" => Some(
295+
config
296+
.manifest_dir
297+
.join(src_path)
298+
.join("util/32-bit-toolchain.cmake"),
299+
),
300+
"aarch64" => Some(config.manifest_dir.join("cmake/aarch64-linux.cmake")),
301+
"arm" => Some(config.manifest_dir.join("cmake/armv7-linux.cmake")),
302+
_ => None,
328303
},
304+
_ => None,
305+
};
329306

330-
_ => {}
307+
if let Some(tf) = toolchain_file {
308+
eprintln!("{} toolchain={}", config.target_os, tf.display());
309+
boringssl_cmake.define("CMAKE_TOOLCHAIN_FILE", tf);
310+
} else {
311+
println!("cargo:warning=no toolchain file set for {}", config.target);
331312
}
332313

333314
boringssl_cmake

0 commit comments

Comments
 (0)