From 910a3182f761ca77afb4e648687ba93a1a4174bc Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sun, 26 Oct 2025 17:42:08 +0000 Subject: [PATCH] fix: Prevent crash on process exit on MacOS --- src/core/info/rustc.rs | 9 +++++++-- src/macros/rustc.rs | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/core/info/rustc.rs b/src/core/info/rustc.rs index 60156301..034ff6f4 100644 --- a/src/core/info/rustc.rs +++ b/src/core/info/rustc.rs @@ -5,13 +5,17 @@ use std::{collections::BTreeMap, sync::OnceLock}; -use crate::{SyncMutex, utils::exchange}; +use crate::utils::exchange; /// Raw capture of rustc flags used to build each crate in the project. Informed /// by rustc_flags_capture macro (one in each crate's mod.rs). This is /// done during static initialization which is why it's mutex-protected and pub. /// Should not be written to by anything other than our macro. -pub static FLAGS: SyncMutex> = SyncMutex::new(BTreeMap::new()); +/// +/// We specifically use a std mutex here because parking_lot cannot be used +/// after thread local storage is destroyed on MacOS. +pub static FLAGS: std::sync::Mutex> = + std::sync::Mutex::new(BTreeMap::new()); /// Processed list of enabled features across all project crates. This is /// generated from the data in FLAGS. @@ -24,6 +28,7 @@ fn init_features() -> Vec<&'static str> { let mut features = Vec::new(); FLAGS .lock() + .expect("locked") .iter() .for_each(|(_, flags)| append_features(&mut features, flags)); diff --git a/src/macros/rustc.rs b/src/macros/rustc.rs index f302b152..b9d1611b 100644 --- a/src/macros/rustc.rs +++ b/src/macros/rustc.rs @@ -15,13 +15,13 @@ pub(super) fn flags_capture(args: TokenStream) -> TokenStream { #[ctor] fn _set_rustc_flags() { - conduwuit_core::info::rustc::FLAGS.lock().insert(#crate_name, &RUSTC_FLAGS); + conduwuit_core::info::rustc::FLAGS.lock().expect("locked").insert(#crate_name, &RUSTC_FLAGS); } // static strings have to be yanked on module unload #[dtor] fn _unset_rustc_flags() { - conduwuit_core::info::rustc::FLAGS.lock().remove(#crate_name); + conduwuit_core::info::rustc::FLAGS.lock().expect("locked").remove(#crate_name); } };