add rustc build flags reflection

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-07-24 23:01:00 +00:00
parent 936d2915e2
commit 2100618d47
14 changed files with 119 additions and 5 deletions

View file

@ -58,6 +58,7 @@ checked_ops.workspace = true
chrono.workspace = true
conduit-macros.workspace = true
const-str.workspace = true
ctor.workspace = true
either.workspace = true
figment.workspace = true
http-body-util.workspace = true

View file

@ -2,4 +2,7 @@
//! etc information which can be queried by admins or used by developers.
pub mod cargo;
pub mod rustc;
pub mod version;
pub use conduit_macros::rustc_flags_capture;

53
src/core/info/rustc.rs Normal file
View file

@ -0,0 +1,53 @@
//! Information about the build related to rustc. This is a frontend interface
//! informed by proc-macros at build time. Since the project is split into
//! several crates, lower-level information is supplied from each crate during
//! static initialization.
use std::{
collections::BTreeMap,
sync::{Mutex, OnceLock},
};
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: Mutex<BTreeMap<&str, &[&str]>> = Mutex::new(BTreeMap::new());
/// Processed list of enabled features across all project crates. This is
/// generated from the data in FLAGS.
static FEATURES: OnceLock<Vec<&'static str>> = OnceLock::new();
/// List of features enabled for the project.
pub fn features() -> &'static Vec<&'static str> { FEATURES.get_or_init(init_features) }
fn init_features() -> Vec<&'static str> {
let mut features = Vec::new();
FLAGS
.lock()
.expect("locked")
.iter()
.for_each(|(_, flags)| append_features(&mut features, flags));
features.sort_unstable();
features.dedup();
features
}
fn append_features(features: &mut Vec<&'static str>, flags: &[&'static str]) {
let mut next_is_cfg = false;
for flag in flags {
let is_cfg = *flag == "--cfg";
let is_feature = flag.starts_with("feature=");
if exchange(&mut next_is_cfg, is_cfg) && is_feature {
if let Some(feature) = flag
.split_once('=')
.map(|(_, feature)| feature.trim_matches('"'))
{
features.push(feature);
}
}
}
}

View file

@ -12,12 +12,17 @@ pub mod utils;
pub use config::Config;
pub use error::Error;
pub use info::{version, version::version};
pub use info::{rustc_flags_capture, version, version::version};
pub use pdu::{PduBuilder, PduCount, PduEvent};
pub use server::Server;
pub use utils::{ctor, dtor};
pub use crate as conduit_core;
pub type Result<T, E = Error> = std::result::Result<T, E>;
rustc_flags_capture! {}
#[cfg(not(conduit_mods))]
pub mod mods {
#[macro_export]

View file

@ -15,6 +15,7 @@ pub mod time;
use std::cmp::{self, Ordering};
pub use ::ctor::{ctor, dtor};
pub use bytes::{increment, u64_from_bytes, u64_from_u8, u64_from_u8x8};
pub use debug::slice_truncated as debug_slice_truncated;
pub use hash::calculate_hash;