From 5090b49be2a11d5bef20ffff98c44ebd602c941b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Fri, 8 May 2026 10:43:17 +0200 Subject: [PATCH 1/4] Add ENV list parameter to cargo_build() Allow callers to pass additional environment variables to the cargo process. This will be used to pass OPENSSL_STATIC, OPENSSL_LIB_DIR, and OPENSSL_INCLUDE_DIR for controlling how openssl-sys locates and links OpenSSL. --- cmake/CMakeCargo.cmake | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cmake/CMakeCargo.cmake b/cmake/CMakeCargo.cmake index 7278f25b..7d9f93e6 100644 --- a/cmake/CMakeCargo.cmake +++ b/cmake/CMakeCargo.cmake @@ -115,9 +115,10 @@ # __target — custom target driving the cargo build # # The caller controls Rust compiler flags via CMAKE_Rust_FLAGS (passed as -# RUSTFLAGS) and the build profile via CMAKE_BUILD_TYPE. +# RUSTFLAGS) and the build profile via CMAKE_BUILD_TYPE. Additional +# environment variables for the cargo process can be passed via ENV. function(cargo_build) - cmake_parse_arguments(CARGO "" "NAME;CRATE_TYPE" "FEATURES" ${ARGN}) + cmake_parse_arguments(CARGO "" "NAME;CRATE_TYPE" "FEATURES;ENV" ${ARGN}) string(REPLACE "-" "_" LIB_NAME ${CARGO_NAME}) if(NOT CARGO_CRATE_TYPE) @@ -236,7 +237,10 @@ function(cargo_build) ) # Set CARGO_TARGET_DIR and RUSTFLAGS in the cargo process environment. - set(CARGO_ENV_COMMAND ${CMAKE_COMMAND} -E env "CARGO_TARGET_DIR=${CARGO_TARGET_DIR}" "RUSTFLAGS=${CMAKE_Rust_FLAGS}") + set(CARGO_ENV_COMMAND ${CMAKE_COMMAND} -E env + "CARGO_TARGET_DIR=${CARGO_TARGET_DIR}" + "RUSTFLAGS=${CMAKE_Rust_FLAGS}" + ${CARGO_ENV}) add_custom_command( OUTPUT ${LIB_OUTPUTS} From e0c1413e03fe79b4ddacc3b034d0be03484cff33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Fri, 8 May 2026 10:56:49 +0200 Subject: [PATCH 2/4] build: pass OpenSSL paths from CMake to Cargo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Derive OPENSSL_LIB_DIR from the library path found by CMake's find_package(OpenSSL) and pass both OPENSSL_LIB_DIR and OPENSSL_INCLUDE_DIR to cargo_build() via the ENV parameter. This ensures openssl-sys finds the same OpenSSL installation that CMake found, rather than searching independently. No functional change — openssl-sys already dynamically links OpenSSL by default. --- cmake/Dependencies.cmake | 3 +++ scylla-rust-wrapper/CMakeLists.txt | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake index 903c68d0..36f36bdc 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake @@ -103,6 +103,9 @@ if(CASS_USE_OPENSSL) message(STATUS "${OPENSSL_NAME} version: v${OPENSSL_VERSION}") endif() + # Derive OPENSSL_LIB_DIR for passing to openssl-sys via environment. + get_filename_component(OPENSSL_LIB_DIR "${OPENSSL_SSL_LIBRARY}" DIRECTORY) + set(CASS_INCLUDES ${CASS_INCLUDES} ${OPENSSL_INCLUDE_DIR}) set(CASS_LIBS ${CASS_LIBS} ${OPENSSL_LIBRARIES}) endif() diff --git a/scylla-rust-wrapper/CMakeLists.txt b/scylla-rust-wrapper/CMakeLists.txt index 1385c798..8472fcdc 100644 --- a/scylla-rust-wrapper/CMakeLists.txt +++ b/scylla-rust-wrapper/CMakeLists.txt @@ -57,7 +57,9 @@ else() set(CMAKE_Rust_FLAGS "${CMAKE_Rust_FLAGS_SONAME}") endif() if(CASS_BUILD_SHARED) - cargo_build(NAME scylla_cpp_driver CRATE_TYPE cdylib) + cargo_build(NAME scylla_cpp_driver CRATE_TYPE cdylib + ENV "OPENSSL_LIB_DIR=${OPENSSL_LIB_DIR}" + "OPENSSL_INCLUDE_DIR=${OPENSSL_INCLUDE_DIR}") create_copy($ ${INSTALL_NAME_SHARED}) add_library(scylla-cpp-driver SHARED IMPORTED GLOBAL) add_dependencies(scylla-cpp-driver ${INSTALL_NAME_SHARED}_copy) @@ -75,7 +77,9 @@ if(CASS_BUILD_SHARED) endif() endif() if(CASS_BUILD_STATIC) - cargo_build(NAME scylla_cpp_driver CRATE_TYPE staticlib) + cargo_build(NAME scylla_cpp_driver CRATE_TYPE staticlib + ENV "OPENSSL_LIB_DIR=${OPENSSL_LIB_DIR}" + "OPENSSL_INCLUDE_DIR=${OPENSSL_INCLUDE_DIR}") create_copy($ ${INSTALL_NAME_STATIC}) add_library(scylla-cpp-driver_static STATIC IMPORTED GLOBAL) add_dependencies(scylla-cpp-driver_static ${INSTALL_NAME_STATIC}_copy) From 0e105515dbb68c33725340d277e7bff844719350 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Fri, 8 May 2026 14:51:19 +0200 Subject: [PATCH 3/4] build: use Requires.private for OpenSSL in static pkg-config file Change Requires to Requires.private in the static library's .pc file. Requires.private means pkg-config only exposes the dependency's flags when the consumer passes --static. Without --static, the dependency is ignored entirely. This is the correct semantics because: - OpenSSL is an internal implementation detail, not exposed in the public API headers. Consumers don't need OpenSSL's -I flags to compile against the driver. - Anyone linking the static .a should be using --static, which pulls in Requires.private deps. So static consumers still get -lssl. - If a consumer mistakenly uses the static .pc without --static (e.g. linking the .a directly), Requires would needlessly add OpenSSL flags that may conflict with their own OpenSSL usage. This matches the convention used by OpenSSL's own libssl.pc, which declares Requires.private: libcrypto rather than Requires:. --- scylla-rust-wrapper/scylla-cpp-driver_static.pc.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scylla-rust-wrapper/scylla-cpp-driver_static.pc.in b/scylla-rust-wrapper/scylla-cpp-driver_static.pc.in index 6c5b6f31..41567cc8 100644 --- a/scylla-rust-wrapper/scylla-cpp-driver_static.pc.in +++ b/scylla-rust-wrapper/scylla-cpp-driver_static.pc.in @@ -6,7 +6,7 @@ includedir=@includedir@ Name: scylla-cpp-rs-driver Description: ScyllaDB CPP RS Driver Version: @version@ -Requires: openssl +Requires.private: openssl Libs: -L${libdir} -lscylla-cpp-driver_static Cflags: -I${includedir} URL: https://github.com/scylladb/cpp-rs-driver/ From 23a7539ef1a8c5f208e67ecb4bd3c3b95cdaf61f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Fri, 8 May 2026 14:55:26 +0200 Subject: [PATCH 4/4] build: statically link OpenSSL into the static library MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pass OPENSSL_STATIC=1 to the staticlib cargo_build() invocation so openssl-sys links OpenSSL statically into libscylla-cpp-driver_static.a. This makes the static archive truly self-contained — users only need to link system libraries and OpenSSL's pkg-config dependencies. Since the cdylib and staticlib builds share CARGO_TARGET_DIR but pass different OPENSSL_STATIC values, they must not run concurrently — openssl-sys declares rerun-if-env-changed for that variable, and parallel invocations would thrash its build script cache. Serialize by making the staticlib target depend on the cdylib target when both are enabled. Append platform-specific system libraries to the static .pc file's Libs: line via @native_static_libs@. These are needed by the Rust runtime (pthreads, libdl, libm, etc.) and must be provided by the final linker when linking the static archive into an executable. Add libssl-dev to the list of build dependencies, since the static build needs static OpenSSL libraries, which are not provided by libssl1.1. --- Makefile | 2 +- scylla-rust-wrapper/CMakeLists.txt | 21 ++++++++++++++++++- .../scylla-cpp-driver_static.pc.in | 2 +- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 1e224265..f298e6cc 100644 --- a/Makefile +++ b/Makefile @@ -256,7 +256,7 @@ install-java8-if-missing: @sudo apt install -y openjdk-8-jre install-build-dependencies: update-apt-cache-if-needed - @sudo apt-get install -y libssl1.1 libuv1-dev libkrb5-dev libc6-dbg + @sudo apt-get install -y libssl1.1 libssl-dev libuv1-dev libkrb5-dev libc6-dbg # Alias for backward compatibility install-bin-dependencies: install-build-dependencies diff --git a/scylla-rust-wrapper/CMakeLists.txt b/scylla-rust-wrapper/CMakeLists.txt index 8472fcdc..58251a02 100644 --- a/scylla-rust-wrapper/CMakeLists.txt +++ b/scylla-rust-wrapper/CMakeLists.txt @@ -78,13 +78,21 @@ if(CASS_BUILD_SHARED) endif() if(CASS_BUILD_STATIC) cargo_build(NAME scylla_cpp_driver CRATE_TYPE staticlib - ENV "OPENSSL_LIB_DIR=${OPENSSL_LIB_DIR}" + ENV "OPENSSL_STATIC=1" + "OPENSSL_LIB_DIR=${OPENSSL_LIB_DIR}" "OPENSSL_INCLUDE_DIR=${OPENSSL_INCLUDE_DIR}") create_copy($ ${INSTALL_NAME_STATIC}) add_library(scylla-cpp-driver_static STATIC IMPORTED GLOBAL) add_dependencies(scylla-cpp-driver_static ${INSTALL_NAME_STATIC}_copy) set_target_properties(scylla-cpp-driver_static PROPERTIES IMPORTED_LOCATION ${CMAKE_BINARY_DIR}/${INSTALL_NAME_STATIC}) endif() +# When both builds share CARGO_TARGET_DIR, they must not run concurrently: +# they pass different OPENSSL_STATIC values, which causes openssl-sys's build +# script to re-run (due to rerun-if-env-changed). Concurrent cargo invocations +# with different env fingerprints would thrash the shared build script cache. +if(CASS_BUILD_SHARED AND CASS_BUILD_STATIC) + add_dependencies(scylla_cpp_driver_staticlib_target scylla_cpp_driver_cdylib_target) +endif() #------------------------------------- # Installation @@ -192,6 +200,17 @@ if(CASS_BUILD_STATIC) # Static library pkg-config file goes to dev package if(CASS_INSTALL_PKG_CONFIG) if(PKG_CONFIG_FOUND) + # System libraries needed when linking the static Rust archive. + # Ideally these would come from `cargo rustc -- --print native-static-libs`, + # but that flag is nightly-only. These are hardcoded approximations that + # may need updating if dependencies or Rust versions change. + if(APPLE) + set(native_static_libs "-lm -lpthread -ldl -framework Security -framework CoreFoundation") + elseif(WIN32) + set(native_static_libs "-lws2_32 -lbcrypt -luserenv -lntdll") + else() + set(native_static_libs "-lm -lpthread -ldl -lrt") + endif() configure_file("${CMAKE_CURRENT_SOURCE_DIR}/scylla-cpp-driver_static.pc.in" "scylla-cpp-driver_static.pc" @ONLY) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/scylla-cpp-driver_static.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" diff --git a/scylla-rust-wrapper/scylla-cpp-driver_static.pc.in b/scylla-rust-wrapper/scylla-cpp-driver_static.pc.in index 41567cc8..23dfc8e9 100644 --- a/scylla-rust-wrapper/scylla-cpp-driver_static.pc.in +++ b/scylla-rust-wrapper/scylla-cpp-driver_static.pc.in @@ -7,6 +7,6 @@ Name: scylla-cpp-rs-driver Description: ScyllaDB CPP RS Driver Version: @version@ Requires.private: openssl -Libs: -L${libdir} -lscylla-cpp-driver_static +Libs: -L${libdir} -lscylla-cpp-driver_static @native_static_libs@ Cflags: -I${includedir} URL: https://github.com/scylladb/cpp-rs-driver/