fix(startup): detect aws-lc's CPU features at start, as before

This commit is contained in:
FredApps committed 2026-11-12 19:39:12 +01:00
1 parent d0ab739f30
commit 5a53828c70
5 files changed
+23 -7

No files matched your search

+5 -4
View File
@@ -6,9 +6,10 @@ xtask = "run -p xtask --"
[target.wasm32-unknown-unknown]
rustflags = ["-C", "target-feature=+simd128"]
# aws-lc (digital signatures and TLS, through aws-lc-rs) detects the CPU on first use, not in a
# static initializer before `main`. On x86 it reads `OPENSSL_ia32cap` then, and aborts when that
# asks for a feature the processor lacks; each executable first runs itself again without the
# variable (#2916, `pdfcraft_platform::crypto_env`), which it can only do once `main` runs.
# aws-lc (digital signatures and TLS, through aws-lc-rs) detects the CPU when `main` asks it to
# (`pdfcraft_sign::init_crypto`), not in a static initializer before `main`. On x86 it reads
# `OPENSSL_ia32cap` then, and aborts when that asks for a feature the processor lacks; each
# executable first runs itself again without the variable (#2916, `pdfcraft_platform::crypto_env`),
# which it can only do once `main` runs.
[env]
AWS_LC_SYS_CFLAGS = "-DBORINGSSL_NO_STATIC_INITIALIZER"
+2
View File
@@ -103,6 +103,8 @@ fn main() -> ExitCode {
if let Some(code) = pdfcraft_platform::crypto_env::run_without_cpu_override() {
std::process::exit(code);
}
// aws-lc detects the CPU's features here, where it used to before `main` (`init_crypto`).
pdfcraft_engine::sign::init_crypto();
// `std::env::args` panics on an argument that is not UTF-8 ("called `Result::unwrap()` on an
// `Err` value"), which a Latin-1 file name is, and it panics while collecting them: even
// `--help` ended that way. Such a name cannot be passed on either, since the paths here are
+2
View File
@@ -206,6 +206,8 @@ fn main() -> eframe::Result {
if let Some(code) = pdfcraft_platform::crypto_env::run_without_cpu_override() {
std::process::exit(code);
}
// aws-lc detects the CPU's features here, where it used to before `main` (`init_crypto`).
pdfcraft_engine::sign::init_crypto();
// Windows: the update helper is a copy of this program started with `--finish-update`.
#[cfg(windows)]
if let Some(result) = craft_update::self_update::finish(&pdfcraft_ui_egui::UPDATE_APP, &std::env::args_os().skip(1).collect::<Vec<_>>()) {
+4 -3
View File
@@ -10,10 +10,11 @@
//!
//! Two parts keep PdfCraft running:
//! - `.cargo/config.toml` builds aws-lc with `BORINGSSL_NO_STATIC_INITIALIZER`, so it detects
//! the CPU on first use (`CRYPTO_library_init`, which aws-lc-rs calls) instead of in a static
//! initializer before `main`.
//! the CPU when `CRYPTO_library_init` is called instead of in a static initializer before
//! `main`.
//! - [`run_without_cpu_override`], the first thing each executable's `main` does, runs the
//! program again without the variable, before anything uses aws-lc.
//! program again without the variable. Then `main` calls `pdfcraft_sign::init_crypto`, so the
//! CPU is detected at start as before, and every operation gets its fast code.
//!
//! Removing the variable from this process instead wouldn't work: aws-lc reads it through the C
//! runtime's `getenv`, whose copy of the environment `std::env::remove_var` doesn't change on
+10
View File
@@ -37,6 +37,16 @@ pub use status_layers::{StatusCaptions, has_status_layers, show_status_layers, s
pub use timestamp::{TimestampAuthority, TimestampQuery, TimestampToken};
pub use x509::{Certificate, Name};
/// Detect the CPU's features for aws-lc now. This build has it do so on first use rather than in
/// a static initializer before `main` (`.cargo/config.toml`, `pdfcraft_platform::crypto_env`), and
/// aws-lc-rs asks for it before most operations but not all: an RSA key generation went without,
/// and ran on aws-lc's portable code. So each executable calls this once at start, after
/// `crypto_env` has run it again without an `OPENSSL_ia32cap` that would stop it here.
#[cfg(not(target_arch = "wasm32"))]
pub fn init_crypto() {
aws_lc_rs::init();
}
#[derive(Debug, thiserror::Error)]
pub enum SignError {
#[error("malformed data: {0}")]