fix: entry-point-less test binaries on Linux; gate timeformat test FFI

oakrender/build.rs: -Wl,-export_dynamic is the macOS spelling. Since
Rust 1.90 x86_64-unknown-linux-gnu links with rust-lld by default, and
lld parses the single-dash form as '-e xport_dynamic', every oakrender
integration test binary was linked with NO entry point and died with
SIGSEGV inside ld.so's dl_main (jumping to the image base) before
printing anything — the copier_test CI failure. Emit the flag on macOS
only.

oaknode timeformat: value_localtime_flag_routes_to_localtime_r called
localtime_r/gmtime_r directly, which do not exist on Windows. Factor
the cfg-gated FFI (localtime_r/gmtime_r vs _localtime64_s/_gmtime64_s)
into break_down_time() and use it from both value() and the test.
This commit is contained in:
2026-08-21 11:56:24 +08:00
parent 8660cbcf97
commit e163702a6b
2 changed files with 40 additions and 34 deletions
+29 -27
View File
@@ -82,6 +82,31 @@ extern "C" {
fn _gmtime64_s(result: *mut Tm, timep: *const i64) -> i32;
}
/// Split epoch seconds into calendar fields through the C library — local
/// time when `local` is set, UTC otherwise (C++ `localtime_r`/`gmtime_r`).
/// Shared by `value()` and its test so both stay on the same cfg-gated FFI.
fn break_down_time(secs: c_long, local: bool) -> Tm {
let mut tm: Tm = unsafe { std::mem::zeroed() };
#[cfg(not(target_os = "windows"))]
unsafe {
if local {
localtime_r(&secs, &mut tm);
} else {
gmtime_r(&secs, &mut tm);
}
}
#[cfg(target_os = "windows")]
unsafe {
let secs64 = secs as i64;
if local {
_localtime64_s(&mut tm, &secs64);
} else {
_gmtime64_s(&mut tm, &secs64);
}
}
tm
}
/// Expand Qt date/time format tokens (`QDateTime::toString` syntax):
/// the field tokens d/dd, M/MM, yy/yyyy, h/hh, H/HH, m/mm, s/ss, z/zz/zzz,
/// AP/ap/A/a, and single-quoted literal sections, mirroring Qt's
@@ -295,24 +320,7 @@ impl NodeBehavior for TimeFormatNode {
let secs = (ms_since_epoch / 1000) as c_long;
let ms = (ms_since_epoch % 1000) as i32;
let mut tm: Tm = unsafe { std::mem::zeroed() };
#[cfg(not(target_os = "windows"))]
unsafe {
if to_bool(&local_val) {
localtime_r(&secs, &mut tm);
} else {
gmtime_r(&secs, &mut tm);
}
}
#[cfg(target_os = "windows")]
unsafe {
let secs64 = secs as i64;
if to_bool(&local_val) {
_localtime64_s(&mut tm, &secs64);
} else {
_gmtime64_s(&mut tm, &secs64);
}
}
let tm = break_down_time(secs, to_bool(&local_val));
let output = format_date_time(&tm, ms, &to_text(&format_val));
table.push(crate::value::ValueType::Text, NodeValue::Text(output), None);
@@ -547,15 +555,9 @@ mod tests {
// Expected values computed through the same C library calls the C++
// makes — this validates the routing (which function is called for
// each flag value), not the C library itself.
let mut secs: c_long = 45296;
let mut local: Tm = unsafe { std::mem::zeroed() };
unsafe {
localtime_r(&secs, &mut local);
}
let mut utc: Tm = unsafe { std::mem::zeroed() };
unsafe {
gmtime_r(&secs, &mut utc);
}
let secs: c_long = 45296;
let local = break_down_time(secs, true);
let utc = break_down_time(secs, false);
let local_expected = format!("{:04}", local.tm_year + 1900);
let utc_expected = format!("{:04}", utc.tm_year + 1900);
assert_eq!(utc_expected, "1970");
+11 -7
View File
@@ -19,16 +19,20 @@
//! `-Wl,-export_dynamic` keeps the test binary's symbols in its dynamic
//! symbol table — originally so the M12 P0 decode bridge could resolve
//! the oakcodec C ABI with `dlsym(RTLD_DEFAULT)` (the decode bridge is a
//! direct Rust call now, but the flag is harmless and still matches the
//! root build.rs's app binary, M12 §0 / §5). The macOS framework flags
//! below are the load-bearing part: the bundled OpenColorIO's system
//! monitor references IOKit / ColorSync / CoreGraphics display APIs.
//! direct Rust call now). It is spelled the macOS way and is therefore
//! emitted on macOS only: on ELF platforms lld parses `-export_dynamic`
//! as `-e xport_dynamic` and links a binary with NO entry point, which
//! then dies with SIGSEGV inside ld.so at startup (Rust >= 1.90 links
//! x86_64-unknown-linux-gnu with rust-lld by default). The macOS
//! framework flags below are the load-bearing part: the bundled
//! OpenColorIO's system monitor references IOKit / ColorSync /
//! CoreGraphics display APIs.
fn main() {
// Only the test binaries need this; the library itself links no
// dynamic symbols.
println!("cargo:rustc-link-arg-tests=-Wl,-export_dynamic");
if std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("macos") {
// Only the test binaries need this; the library itself links no
// dynamic symbols. (macOS-only — see the module comment.)
println!("cargo:rustc-link-arg-tests=-Wl,-export_dynamic");
// The bundled OpenColorIO's macos system monitor references
// IOKit / ColorSync / CoreGraphics display APIs; the engine
// dylib links with `-undefined,dynamic_lookup`, so test binaries