diff --git a/crates/oaknode/src/nodes/timeformat.rs b/crates/oaknode/src/nodes/timeformat.rs index 1caaa139f..7ab51915c 100644 --- a/crates/oaknode/src/nodes/timeformat.rs +++ b/crates/oaknode/src/nodes/timeformat.rs @@ -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"); diff --git a/crates/oakrender/build.rs b/crates/oakrender/build.rs index 8929a0aa7..e319edaac 100644 --- a/crates/oakrender/build.rs +++ b/crates/oakrender/build.rs @@ -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