| | | 1 | | // SPDX-FileCopyrightText: 2026 Alper Çelik |
| | | 2 | | // SPDX-License-Identifier: MIT OR Apache-2.0 |
| | | 3 | | |
| | | 4 | | //! Runtime tracing. |
| | | 5 | | //! |
| | | 6 | | //! The harnesses (`scripts/smoke.sh`, `scripts/wayland-smoke.sh`, |
| | | 7 | | //! `scripts/sway-oracle.sh`) assert on `[tauri-runtime-qt] …` lines, but the |
| | | 8 | | //! packaged app is a **release** build — so gating those lines on |
| | | 9 | | //! `debug_assertions` meant CI asserted against output that a packaged app never |
| | | 10 | | //! prints. Opt in at runtime with `TAURIQT_TRACE=1` instead; the flake's check |
| | | 11 | | //! environment sets it, and a debug build behaves as before. |
| | | 12 | | |
| | | 13 | | /// True when tracing should be emitted: always in a debug build (the previous |
| | | 14 | | /// `#[cfg(debug_assertions)]` behaviour, so development is unchanged), and in a |
| | | 15 | | /// release build only when `TAURIQT_TRACE` is set — which is what the flake's |
| | | 16 | | /// check environment and the harness scripts do. |
| | | 17 | | /// |
| | | 18 | | /// Cached: the value cannot change usefully mid-process and this is consulted on |
| | | 19 | | /// hot paths. |
| | 2919 | 20 | | pub fn trace_enabled() -> bool { |
| | 21 | 21 | | static ENABLED: std::sync::LazyLock<bool> = std::sync::LazyLock::new(|| { |
| | 21 | 22 | | cfg!(debug_assertions) || std::env::var_os("TAURIQT_TRACE").is_some() |
| | 21 | 23 | | }); |
| | 2919 | 24 | | *ENABLED |
| | 2919 | 25 | | } |
| | | 26 | | |
| | | 27 | | /// `eprintln!` when [`trace_enabled`] — no formatting cost when tracing is off. |
| | | 28 | | #[macro_export] |
| | | 29 | | macro_rules! qtrace { |
| | | 30 | | ($($arg:tt)*) => { |
| | | 31 | | if $crate::trace::trace_enabled() { |
| | | 32 | | eprintln!($($arg)*); |
| | | 33 | | } |
| | | 34 | | }; |
| | | 35 | | } |