Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions crates/slipstream-ffi/build/picoquic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::openssl::OpenSslPaths;
use crate::util::locate_repo_root;
use std::env;
use std::fs;
use std::path::{Path, PathBuf};
use std::process::Command;

Expand Down Expand Up @@ -31,9 +32,16 @@ pub(crate) fn build_picoquic(
let mut command = Command::new(script);
command
.env("PICOQUIC_DIR", picoquic_dir)
.env("PICOQUIC_BUILD_DIR", build_dir)
.env("PICOQUIC_BUILD_DIR", &build_dir)
.env("PICOQUIC_TARGET", target);
if target.contains("android") {
let empty_pkg_config_dir = build_dir.join("empty-pkgconfig");
fs::create_dir_all(&empty_pkg_config_dir)?;
command
.env("CARGO_FEATURE_PICOQUIC_MINIMAL_BUILD", "1")
.env("PKG_CONFIG_PATH", "")
.env("PKG_CONFIG_LIBDIR", empty_pkg_config_dir)
.env("PKG_CONFIG_SYSROOT_DIR", "");
if let Ok(value) = env::var("ANDROID_NDK_HOME") {
command.env("ANDROID_NDK_HOME", value);
}
Expand All @@ -46,11 +54,19 @@ pub(crate) fn build_picoquic(
}
if let Some(root) = &openssl_paths.root {
command.env("OPENSSL_ROOT_DIR", root);

if let Some(crypto) = find_openssl_library(root, "crypto") {
command.env("OPENSSL_CRYPTO_LIBRARY", crypto);
}
if let Some(ssl) = find_openssl_library(root, "ssl") {
command.env("OPENSSL_SSL_LIBRARY", ssl);
Comment on lines +58 to +62
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve explicit OpenSSL library overrides

When callers set OPENSSL_ROOT_DIR together with explicit OPENSSL_SSL_LIBRARY/OPENSSL_CRYPTO_LIBRARY (which build.rs accepts as a supported override), these new Command.env calls replace the inherited explicit paths before scripts/build_picoquic.sh sees them. In cross-builds where the root is used for headers but the usable target libraries live in a different directory or have a nonstandard name, picoquic will be configured against the first lib{ssl,crypto}.{a,so} under the root instead of the caller-selected libraries, regressing previously working override-based builds.

Useful? React with 👍 / 👎.

}
}
let prefer_static_openssl = cfg!(feature = "openssl-static");
let vendored_openssl = cfg!(feature = "openssl-vendored");
let openssl_no_vendor = env::var_os("OPENSSL_NO_VENDOR").is_some();
let explicit_static = env::var_os("OPENSSL_USE_STATIC_LIBS").is_some();
if prefer_static_openssl && !openssl_no_vendor && !explicit_static {
if (prefer_static_openssl || vendored_openssl) && !openssl_no_vendor && !explicit_static {
command.env("OPENSSL_USE_STATIC_LIBS", "TRUE");
}
if let Some(include) = &openssl_paths.include {
Expand Down Expand Up @@ -251,6 +267,17 @@ fn has_picotls_header(dir: &Path) -> bool {
dir.join("picotls.h").exists()
}

fn find_openssl_library(root: &Path, stem: &str) -> Option<PathBuf> {
let candidates = [
root.join("lib").join(format!("lib{stem}.a")),
root.join("lib64").join(format!("lib{stem}.a")),
root.join("lib").join(format!("lib{stem}.so")),
root.join("lib64").join(format!("lib{stem}.so")),
];

candidates.into_iter().find(|candidate| candidate.exists())
}

fn windows_stage_candidates(dir: &Path, target: &str) -> Vec<PathBuf> {
let preferred_platform = if target.contains("aarch64") {
"ARM64"
Expand Down
3 changes: 2 additions & 1 deletion scripts/build_picoquic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ CMAKE_ARGS=(
BUILD_TARGET=()

if [[ -n "${CARGO_FEATURE_PICOQUIC_MINIMAL_BUILD:-}" ]]; then
case "${CARGO_FEATURE_PICOQUIC_MINIMAL_BUILD,,}" in
MINIMAL_BUILD_FLAG="$(printf '%s' "${CARGO_FEATURE_PICOQUIC_MINIMAL_BUILD}" | tr '[:upper:]' '[:lower:]')"
case "${MINIMAL_BUILD_FLAG}" in
1|true|yes|on)
CMAKE_ARGS+=(
"-DBUILD_DEMO=OFF"
Expand Down
Loading