From 1012a36c94bd1dba6d0e79499411499208c111f9 Mon Sep 17 00:00:00 2001 From: min Date: Wed, 5 Nov 2025 20:22:33 -0500 Subject: [PATCH] Add bssl2 prefix to libs --- boring-sys/build/main.rs | 17 +- boring-sys/build/prefix.rs | 34 +-- boring-sys/patches/boringssl-prefix.patch | 280 ++++++++++++++++++++++ 3 files changed, 310 insertions(+), 21 deletions(-) create mode 100644 boring-sys/patches/boringssl-prefix.patch diff --git a/boring-sys/build/main.rs b/boring-sys/build/main.rs index 694bff6f..b0f4bd87 100644 --- a/boring-sys/build/main.rs +++ b/boring-sys/build/main.rs @@ -499,6 +499,9 @@ fn ensure_patches_applied(config: &Config) -> io::Result<()> { run_command(&["git"], |c| c.arg("init").current_dir(src_path))?; } + println!("cargo:warning=applying prefix patch to boringssl"); + apply_patch(config, "boringssl-prefix.patch")?; + println!("cargo:warning=applying 44b3df6f03d85c901767250329c571db405122d5 patch to boringssl"); apply_patch( config, @@ -612,8 +615,8 @@ fn built_boring_source_path(config: &Config) -> &PathBuf { cfg.define("CMAKE_POSITION_INDEPENDENT_CODE", "ON"); } - cfg.build_target("ssl").build(); - cfg.build_target("crypto").build() + cfg.build_target("bssl2_ssl").build(); + cfg.build_target("bssl2_crypto").build() }) } @@ -625,7 +628,7 @@ fn link_in_precompiled_bcm_o(config: &Config) { .expect("`fips-link-precompiled` requires `BORING_BSSL_FIPS_PRECOMPILED_BCM_O` env variable to be specified"); let libcrypto_path = bssl_dir - .join("build/crypto/libcrypto.a") + .join("build/bssl2_crypto/libbssl2_crypto.a") .canonicalize() .unwrap(); @@ -696,12 +699,12 @@ fn emit_link_directives(config: &Config) { } else { // todo(rmehra): clean this up, I think these are pretty redundant println!( - "cargo:rustc-link-search=native={}/build/crypto/{}", + "cargo:rustc-link-search=native={}/build/bssl2_crypto/{}", bssl_dir.display(), build_path ); println!( - "cargo:rustc-link-search=native={}/build/ssl/{}", + "cargo:rustc-link-search=native={}/build/bssl2_ssl/{}", bssl_dir.display(), build_path ); @@ -723,8 +726,8 @@ fn emit_link_directives(config: &Config) { if let Some(cpp_lib) = get_cpp_runtime_lib(config) { println!("cargo:rustc-link-lib={cpp_lib}"); } - println!("cargo:rustc-link-lib=static=crypto"); - println!("cargo:rustc-link-lib=static=ssl"); + println!("cargo:rustc-link-lib=static=bssl2_crypto"); + println!("cargo:rustc-link-lib=static=bssl2_ssl"); if config.target_os == "windows" { // Rust 1.87.0 compat - https://github.com/rust-lang/rust/pull/138233 diff --git a/boring-sys/build/prefix.rs b/boring-sys/build/prefix.rs index 8addbc3c..308bb14f 100644 --- a/boring-sys/build/prefix.rs +++ b/boring-sys/build/prefix.rs @@ -1,9 +1,12 @@ -use crate::{config::Config, pick_best_android_ndk_toolchain, run_command}; +use crate::{ + config::Config, get_boringssl_platform_output_path, pick_best_android_ndk_toolchain, + run_command, +}; use std::{fs, io::Write, path::PathBuf}; // The prefix to add to all symbols // RBSSL = Rust BoringSSL, chosen arbitrarily to avoid collisions with other projects -const PREFIX: &str = "RBSSL"; +const PREFIX: &str = "RBSSL2"; // Callback to add a `link_name` macro with the prefix to all generated bindings #[derive(Debug)] @@ -32,22 +35,25 @@ fn android_toolchain(config: &Config) -> PathBuf { pub fn prefix_symbols(config: &Config) { // List static libraries to prefix symbols in - eprintln!("{:?}", config.out_dir); - eprintln!("{:?}", config.out_dir); - eprintln!("{:?}", config.out_dir); - eprintln!("{:?}", config.out_dir); + let build_path = config + .out_dir + .join("build") + .join(get_boringssl_platform_output_path(config)); let static_libs: Vec = [ - config.out_dir.join("build"), - config.out_dir.join("build").join("ssl"), - config.out_dir.join("build").join("crypto"), - config.out_dir.join("build").join("Debug"), - config.out_dir.join("build").join("Release"), + build_path.clone(), + build_path.join("bssl2_ssl"), + build_path.join("bssl2_crypto"), ] .iter() .flat_map(|dir| { - ["libssl.a", "libcrypto.a", "ssl.lib", "crypto.lib"] - .into_iter() - .map(move |file| PathBuf::from(dir).join(file)) + [ + "libbssl2_ssl.a", + "libbssl2_crypto.a", + "bssl2_ssl.lib", + "bssl2_crypto.lib", + ] + .into_iter() + .map(move |file| PathBuf::from(dir).join(file)) }) .filter(|p| p.exists()) .collect(); diff --git a/boring-sys/patches/boringssl-prefix.patch b/boring-sys/patches/boringssl-prefix.patch new file mode 100644 index 00000000..0d9f5fd8 --- /dev/null +++ b/boring-sys/patches/boringssl-prefix.patch @@ -0,0 +1,280 @@ +diff --git a/BUILD b/BUILD +index 206786442..4188c0859 100644 +--- a/BUILD ++++ b/BUILD +@@ -131,7 +131,7 @@ boringssl_copts_cxx = boringssl_copts + select({ + }) + + cc_library( +- name = "crypto", ++ name = "bssl2_crypto", + srcs = crypto_sources + crypto_internal_headers + asm_sources, + hdrs = crypto_headers + fips_fragments, + copts = boringssl_copts_c11, +@@ -144,14 +144,14 @@ cc_library( + ) + + cc_library( +- name = "ssl", ++ name = "bssl2_ssl", + srcs = ssl_sources + ssl_internal_headers, + hdrs = ssl_headers, + copts = boringssl_copts_cxx, + includes = ["src/include"], + visibility = ["//visibility:public"], + deps = [ +- ":crypto", ++ ":bssl2_crypto", + ], + ) + +@@ -160,5 +160,5 @@ cc_binary( + srcs = tool_sources + tool_headers, + copts = boringssl_copts_cxx, + visibility = ["//visibility:public"], +- deps = [":ssl"], ++ deps = [":bssl2_ssl"], + ) +diff --git a/CMakeLists.txt b/CMakeLists.txt +index faed2befa..fc7b38d5b 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -264,7 +264,7 @@ if(OPENSSL_NASM) + endif() + + add_library( +- crypto ++ bssl2_crypto + + ${CRYPTO_SOURCES_ASM_USED} + err_data.c +@@ -493,10 +493,10 @@ add_library( + src/crypto/x509v3/v3_utl.c + ) + +-target_include_directories(crypto PUBLIC $) ++target_include_directories(bssl2_crypto PUBLIC $) + + add_library( +- ssl ++ bssl2_ssl + + src/ssl/bio_ssl.cc + src/ssl/d1_both.cc +@@ -537,10 +537,10 @@ add_library( + src/ssl/tls_record.cc + ) + +-target_link_libraries(ssl crypto) ++target_link_libraries(bssl2_ssl bssl2_crypto) + + add_executable( +- bssl ++ bssl2_bssl + + src/tool/args.cc + src/tool/ciphers.cc +@@ -561,14 +561,13 @@ add_executable( + src/tool/transport_common.cc + ) + +-target_link_libraries(bssl ssl crypto) ++target_link_libraries(bssl2_bssl bssl2_ssl bssl2_crypto) + + if(NOT ANDROID) + find_package(Threads REQUIRED) +- target_link_libraries(crypto Threads::Threads) ++ target_link_libraries(bssl2_crypto Threads::Threads) + endif() + + if(WIN32) +- target_link_libraries(crypto ws2_32) ++ target_link_libraries(bssl2_crypto ws2_32) + endif() +- +diff --git a/src/crypto/CMakeLists.txt b/src/crypto/CMakeLists.txt +index cdb5ddca1..e9ef24a24 100644 +--- a/src/crypto/CMakeLists.txt ++++ b/src/crypto/CMakeLists.txt +@@ -62,7 +62,7 @@ add_custom_command( + ) + + add_library( +- crypto ++ bssl2_crypto + + asn1/a_bitstr.c + asn1/a_bool.c +@@ -291,26 +291,26 @@ add_library( + ${CRYPTO_FIPS_OBJECTS} + ) + if(OPENSSL_ASM) +- target_sources(crypto PRIVATE ${CRYPTO_SOURCES_ASM}) ++ target_sources(bssl2_crypto PRIVATE ${CRYPTO_SOURCES_ASM}) + endif() + if(OPENSSL_NASM) +- target_sources(crypto PRIVATE ${CRYPTO_SOURCES_NASM}) ++ target_sources(bssl2_crypto PRIVATE ${CRYPTO_SOURCES_NASM}) + endif() +-target_include_directories(crypto PUBLIC ++target_include_directories(bssl2_crypto PUBLIC + $ + $ + ) +-install_if_enabled(TARGETS crypto EXPORT OpenSSLTargets ${INSTALL_DESTINATION_DEFAULT}) +-set_property(TARGET crypto PROPERTY EXPORT_NAME Crypto) ++install_if_enabled(TARGETS bssl2_crypto EXPORT OpenSSLTargets ${INSTALL_DESTINATION_DEFAULT}) ++set_property(TARGET bssl2_crypto PROPERTY EXPORT_NAME Crypto) + + if(FIPS_SHARED) + # Rewrite libcrypto.so to inject the correct module hash value. This assumes + # UNIX-style library naming, but we only support FIPS mode on Linux anyway. + add_custom_command( +- TARGET crypto POST_BUILD ++ TARGET bssl2_crypto POST_BUILD + COMMAND ${GO_EXECUTABLE} run + ${CMAKE_CURRENT_SOURCE_DIR}/../util/fipstools/inject_hash/inject_hash.go +- -o libcrypto.so -in-object libcrypto.so ++ -o libbssl2_crypto.so -in-object libbssl2_crypto.so + # The DEPENDS argument to a POST_BUILD rule appears to be ignored. Thus + # go_executable isn't used (as it doesn't get built), but we list this + # dependency anyway in case it starts working in some CMake version. +@@ -319,27 +319,27 @@ if(FIPS_SHARED) + ) + endif() + +-add_dependencies(crypto boringssl_prefix_symbols) ++add_dependencies(bssl2_crypto boringssl_prefix_symbols) + + if(FIPS_DELOCATE OR FIPS_SHARED) +- add_dependencies(crypto bcm_o_target) ++ add_dependencies(bssl2_crypto bcm_o_target) + endif() + +-set_target_properties(crypto PROPERTIES LINKER_LANGUAGE C) ++set_target_properties(bssl2_crypto PROPERTIES LINKER_LANGUAGE C) + + if(WIN32) +- target_link_libraries(crypto ws2_32) ++ target_link_libraries(bssl2_crypto ws2_32) + endif() + + if(NOT ANDROID) + find_package(Threads REQUIRED) +- target_link_libraries(crypto Threads::Threads) ++ target_link_libraries(bssl2_crypto Threads::Threads) + endif() + + # Every target depends on crypto, so we add libcxx as a dependency here to + # simplify injecting it everywhere. + if(USE_CUSTOM_LIBCXX) +- target_link_libraries(crypto libcxx) ++ target_link_libraries(bssl2_crypto libcxx) + endif() + + # urandom_test is a separate binary because it needs to be able to observe the +@@ -350,7 +350,7 @@ add_executable( + + fipsmodule/rand/urandom_test.cc + ) +-target_link_libraries(urandom_test test_support_lib boringssl_gtest crypto) ++target_link_libraries(urandom_test test_support_lib boringssl_gtest bssl2_crypto) + add_dependencies(all_tests urandom_test) + + add_executable( +@@ -424,5 +424,5 @@ add_executable( + + $ + ) +-target_link_libraries(crypto_test test_support_lib boringssl_gtest_main crypto) ++target_link_libraries(crypto_test test_support_lib boringssl_gtest_main bssl2_crypto) + add_dependencies(all_tests crypto_test) +diff --git a/src/ssl/CMakeLists.txt b/src/ssl/CMakeLists.txt +index d8d997e34..f0471b379 100644 +--- a/src/ssl/CMakeLists.txt ++++ b/src/ssl/CMakeLists.txt +@@ -1,5 +1,5 @@ + add_library( +- ssl ++ bssl2_ssl + + bio_ssl.cc + d1_both.cc +@@ -42,9 +42,9 @@ add_library( + # Although libssl also provides headers that require an include directory, the + # flag is already specified by libcrypto, so we omit target_include_directories + # here. +-install_if_enabled(TARGETS ssl EXPORT OpenSSLTargets ${INSTALL_DESTINATION_DEFAULT}) +-set_property(TARGET ssl PROPERTY EXPORT_NAME SSL) +-target_link_libraries(ssl crypto) ++install_if_enabled(TARGETS bssl2_ssl EXPORT OpenSSLTargets ${INSTALL_DESTINATION_DEFAULT}) ++set_property(TARGET bssl2_ssl PROPERTY EXPORT_NAME SSL) ++target_link_libraries(bssl2_ssl crypto) + + add_executable( + ssl_test +@@ -53,5 +53,5 @@ add_executable( + ssl_test.cc + ssl_c_test.c + ) +-target_link_libraries(ssl_test test_support_lib boringssl_gtest_main ssl crypto) ++target_link_libraries(ssl_test test_support_lib boringssl_gtest_main bssl2_ssl bssl2_crypto) + add_dependencies(all_tests ssl_test) +diff --git a/src/tool/CMakeLists.txt b/src/tool/CMakeLists.txt +index 504710889..d5674fa9e 100644 +--- a/src/tool/CMakeLists.txt ++++ b/src/tool/CMakeLists.txt +@@ -1,5 +1,5 @@ + add_executable( +- bssl ++ bssl2_bssl + + args.cc + ciphers.cc +@@ -19,5 +19,5 @@ add_executable( + tool.cc + transport_common.cc + ) +-install_if_enabled(TARGETS bssl DESTINATION ${INSTALL_DESTINATION_DEFAULT}) +-target_link_libraries(bssl ssl crypto) ++install_if_enabled(TARGETS bssl2_bssl DESTINATION ${INSTALL_DESTINATION_DEFAULT}) ++target_link_libraries(bssl2_bssl bssl2_ssl bssl2_crypto) +diff --git a/src/util/BUILD.toplevel b/src/util/BUILD.toplevel +index 206786442..81f55c1af 100644 +--- a/src/util/BUILD.toplevel ++++ b/src/util/BUILD.toplevel +@@ -131,7 +131,7 @@ boringssl_copts_cxx = boringssl_copts + select({ + }) + + cc_library( +- name = "crypto", ++ name = "bssl2_crypto", + srcs = crypto_sources + crypto_internal_headers + asm_sources, + hdrs = crypto_headers + fips_fragments, + copts = boringssl_copts_c11, +@@ -144,21 +144,21 @@ cc_library( + ) + + cc_library( +- name = "ssl", ++ name = "bssl2_ssl", + srcs = ssl_sources + ssl_internal_headers, + hdrs = ssl_headers, + copts = boringssl_copts_cxx, + includes = ["src/include"], + visibility = ["//visibility:public"], + deps = [ +- ":crypto", ++ ":bssl2_crypto", + ], + ) + + cc_binary( +- name = "bssl", ++ name = "bssl2_bssl", + srcs = tool_sources + tool_headers, + copts = boringssl_copts_cxx, + visibility = ["//visibility:public"], +- deps = [":ssl"], ++ deps = [":bssl2_ssl"], + )