From 15a4934f52bb6dfd2b0e6419b22ba9e4e502bb10 Mon Sep 17 00:00:00 2001 From: Jordan Rose Date: Thu, 12 Feb 2026 10:51:36 -0800 Subject: [PATCH] boring-sys: Support static MSVC runtime --- .github/workflows/ci.yml | 9 +++++++++ boring-sys/build/config.rs | 8 ++++++++ boring-sys/build/main.rs | 6 +++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1c104a3dc..4e184afb3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -226,6 +226,15 @@ jobs: RUSTC_BOOTSTRAP: 1 # for -Z checksum-freshness # CI's Windows doesn't have required root certs extra_test_args: --workspace --exclude tokio-boring --exclude hyper-boring -Z checksum-freshness + - thing: x86_64-msvc-static + target: x86_64-pc-windows-msvc + rust: stable-x86_64-msvc + os: windows-latest + custom_env: + RUSTC_BOOTSTRAP: 1 # for -Z checksum-freshness + RUSTFLAGS: -Dwarnings -C target-feature=+crt-static + # CI's Windows doesn't have required root certs + extra_test_args: --workspace --exclude tokio-boring --exclude hyper-boring -Z checksum-freshness env: CARGO_HOME: ${{ github.workspace }}/.cache/cargo CARGO_BUILD_BUILD_DIR: ${{ github.workspace }}/.cache/build-dir diff --git a/boring-sys/build/config.rs b/boring-sys/build/config.rs index e344f9acb..99934e172 100644 --- a/boring-sys/build/config.rs +++ b/boring-sys/build/config.rs @@ -12,6 +12,7 @@ pub(crate) struct Config { pub(crate) target_os: String, pub(crate) unix: bool, pub(crate) target_env: String, + pub(crate) target_features: Vec, pub(crate) features: Features, pub(crate) env: Env, } @@ -51,6 +52,12 @@ impl Config { let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap(); let unix = env::var("CARGO_CFG_UNIX").is_ok(); + let target_features = env::var("CARGO_CFG_TARGET_FEATURE") + .unwrap_or_default() + .split(',') + .map(|s| s.to_owned()) + .collect(); + let features = Features::from_env(); let env = Env::from_env(&host, &target, features.is_fips_like()); @@ -69,6 +76,7 @@ impl Config { target_os, unix, target_env, + target_features, features, env, }; diff --git a/boring-sys/build/main.rs b/boring-sys/build/main.rs index 0fe124157..450a167d6 100644 --- a/boring-sys/build/main.rs +++ b/boring-sys/build/main.rs @@ -217,7 +217,11 @@ fn get_boringssl_cmake_config(config: &Config) -> cmake::Config { // This is required now because newest BoringSSL requires CMake 3.22 which // uses the new logic with CMAKE_MSVC_RUNTIME_LIBRARY introduced in CMake 3.15. // https://github.com/rust-lang/cmake-rs/pull/30#issuecomment-2969758499 - boringssl_cmake.define("CMAKE_MSVC_RUNTIME_LIBRARY", "MultiThreadedDLL"); + if config.target_features.iter().any(|f| f == "crt-static") { + boringssl_cmake.define("CMAKE_MSVC_RUNTIME_LIBRARY", "MultiThreaded"); + } else { + boringssl_cmake.define("CMAKE_MSVC_RUNTIME_LIBRARY", "MultiThreadedDLL"); + } } if config.host == config.target {