Skip to content

Improve support for custom OpenSSL selection#5848

Open
masa-koz wants to merge 2 commits intomicrosoft:mainfrom
masa-koz:masa-koz/custom-openssl
Open

Improve support for custom OpenSSL selection#5848
masa-koz wants to merge 2 commits intomicrosoft:mainfrom
masa-koz:masa-koz/custom-openssl

Conversation

@masa-koz
Copy link
Contributor

@masa-koz masa-koz commented Mar 7, 2026

Description

This pull request introduces improved support for building with an external OpenSSL installation, primarily by adding a new openssl_external feature and enhancing the build system to handle more flexible OpenSSL configuration. The changes affect CMake configuration, Rust feature flags, and build scripts to better support both static and shared linking, and to allow specifying OpenSSL paths via environment variables.

Build system and CMake improvements:

  • Added a new CMake cache variable QUIC_OPENSSL_ROOT_DIR to allow specifying the OpenSSL root directory, and updated OpenSSL selection logic to support this variable for both static and shared builds. [1] [2]
  • Enhanced the CMake logic to properly select between static and shared OpenSSL libraries based on the BUILD_SHARED_LIBS flag, and improved handling of imported OpenSSL targets to avoid duplicate dependency linking.

Rust feature and build script updates:

  • Introduced a new Cargo feature openssl_external for building with an external OpenSSL, and updated the build script (scripts/build.rs) to configure CMake accordingly by passing the appropriate variables from environment variables if set. [1] [2]
  • Adjusted the output directory logic in the build script to use lib on Windows and artifacts elsewhere, improving compatibility with different platforms.

Test and platform compatibility:

  • Updated test logic in src/rs/config.rs to recognize the new openssl_external feature when determining which TLS provider is active on Windows.

Testing

No

Documentation

TBD

@masa-koz masa-koz requested a review from a team as a code owner March 7, 2026 10:37
@codecov
Copy link

codecov bot commented Mar 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.01%. Comparing base (45a46f3) to head (1ff7fe5).
⚠️ Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5848      +/-   ##
==========================================
- Coverage   86.30%   85.01%   -1.30%     
==========================================
  Files          60       60              
  Lines       18732    18732              
==========================================
- Hits        16167    15925     -242     
- Misses       2565     2807     +242     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator

@guhetier guhetier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a general comment, this start to be a lot of options to handle OpenSSL.
I would be interesting to find a way to keep the complexity from getting out of hands, although I don't have a solution in mind, and it doesn't have to be in this PR.

option(QUIC_USE_EXTERNAL_OPENSSL "Use external OpenSSL instead of building from submodules" OFF)
set(QUIC_OPENSSL_INCLUDE_DIR "" CACHE PATH "Path to OpenSSL include directory")
set(QUIC_OPENSSL_LIB_DIR "" CACHE PATH "Path to OpenSSL library directory")
set(QUIC_OPENSSL_ROOT_DIR "" CACHE PATH "Path to OpenSSL Root directory")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
set(QUIC_OPENSSL_ROOT_DIR "" CACHE PATH "Path to OpenSSL Root directory")
set(QUIC_OPENSSL_ROOT_DIR "" CACHE PATH "Path to OpenSSL root directory")

message(FATAL_ERROR "libcrypto not found in ${QUIC_OPENSSL_LIB_DIR}")
endif()
find_library(LIB_SSL NAMES ssl libssl PATHS ${QUIC_OPENSSL_LIB_DIR} NO_DEFAULT_PATH)
if(BUILD_SHARED_LIBS)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: To simplify this a bit, I'd consider grouping the find_library and checking both at once:

if (BUILD_SHARED_LIBS)
    find...
    find...
else
    find...
    find...
endif
if(NOT LIB_SSL OR NOT LIB_CRYPTO) ...

target_link_libraries(OpenSSLQuic INTERFACE OpenSSL::SSL OpenSSL::Crypto)
# OpenSSL::SSL and OpenSSL::Crypto imported targets include their dependencies such as zstd.
# However, these dependencies will be linked in src/platform/CMakeLists.txt,
# so link only the main OpenSSL targets here to avoid duplication.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand why the duplication is a problem, doesn't CMake handle it?

Comment on lines +61 to +67
} else {
if let Ok(openssl_include_dir) = std::env::var("OPENSSL_INCLUDE_DIR") {
config.define("QUIC_OPENSSL_INCLUDE_DIR", openssl_include_dir);
}
if let Ok(openssl_lib_dir) = std::env::var("OPENSSL_LIB_DIR") {
config.define("QUIC_OPENSSL_LIB_DIR", openssl_lib_dir);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Either else if, or enforce the two are present (since CMake will need both or none)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants