From fb273553b50fa44df94db6260d65989d9c276a5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Sun, 8 Dec 2024 12:20:03 +0100 Subject: [PATCH] identifiers: Allow to set ruma_identifiers_storage cfg setting with env variable --- crates/ruma-common/CHANGELOG.md | 9 +++++++++ crates/ruma-common/build.rs | 10 ++++++++++ crates/ruma-events/CHANGELOG.md | 4 ++++ crates/ruma-events/build.rs | 10 ++++++++++ crates/ruma/src/lib.rs | 13 +++++++++++++ 5 files changed, 46 insertions(+) create mode 100644 crates/ruma-common/build.rs create mode 100644 crates/ruma-events/build.rs diff --git a/crates/ruma-common/CHANGELOG.md b/crates/ruma-common/CHANGELOG.md index 603e3b35..c1c2dc34 100644 --- a/crates/ruma-common/CHANGELOG.md +++ b/crates/ruma-common/CHANGELOG.md @@ -1,5 +1,14 @@ # [unreleased] +Improvements: + +- The `ruma_identifiers_storage` compile-time `cfg` setting can also be + configured by setting the `RUMA_IDENTIFIERS_STORAGE` environment variable at + compile time. It has the benefit of not requiring to re-compile all the crates + of the dependency chain when the value is changed. + +# 0.14.1 + Bug fixes: - The `KeyId::key_name` method now returns the key name. In 0.14.0, `key_name` diff --git a/crates/ruma-common/build.rs b/crates/ruma-common/build.rs new file mode 100644 index 00000000..df6c3c03 --- /dev/null +++ b/crates/ruma-common/build.rs @@ -0,0 +1,10 @@ +use std::env; + +fn main() { + // Set the `ruma_identifiers_storage` configuration from an environment variable. + if let Ok(value) = env::var("RUMA_IDENTIFIERS_STORAGE") { + println!("cargo:rustc-cfg=ruma_identifiers_storage={value}"); + } + + println!("cargo:rerun-if-env-changed=RUMA_IDENTIFIERS_STORAGE"); +} diff --git a/crates/ruma-events/CHANGELOG.md b/crates/ruma-events/CHANGELOG.md index f2cbe553..f3fc8533 100644 --- a/crates/ruma-events/CHANGELOG.md +++ b/crates/ruma-events/CHANGELOG.md @@ -3,6 +3,10 @@ Improvements: - Add unstable support for MSC4171 for the m.member_hints state event. +- The `ruma_identifiers_storage` compile-time `cfg` setting can also be + configured by setting the `RUMA_IDENTIFIERS_STORAGE` environment variable at + compile time. It has the benefit of not requiring to re-compile all the crates + of the dependency chain when the value is changed. Breaking changes: diff --git a/crates/ruma-events/build.rs b/crates/ruma-events/build.rs new file mode 100644 index 00000000..df6c3c03 --- /dev/null +++ b/crates/ruma-events/build.rs @@ -0,0 +1,10 @@ +use std::env; + +fn main() { + // Set the `ruma_identifiers_storage` configuration from an environment variable. + if let Ok(value) = env::var("RUMA_IDENTIFIERS_STORAGE") { + println!("cargo:rustc-cfg=ruma_identifiers_storage={value}"); + } + + println!("cargo:rerun-if-env-changed=RUMA_IDENTIFIERS_STORAGE"); +} diff --git a/crates/ruma/src/lib.rs b/crates/ruma/src/lib.rs index b30b19a0..b61caac0 100644 --- a/crates/ruma/src/lib.rs +++ b/crates/ruma/src/lib.rs @@ -73,6 +73,19 @@ //! //! If you are viewing this on `docs.rs`, you can have a look at the feature dependencies by //! clicking **Feature flags** in the toolbar at the top. +//! +//! # Compile-time `cfg` settings +//! +//! These settings are accepted at compile time to configure the generated code. They can be set as +//! `--cfg={key}={value}` using `RUSTFLAGS` or `.cargo/config.toml` (under `[build]` -> `rustflags = +//! ["..."]`). They can also be configured using an environment variable at compile time, which has +//! the benefit of not requiring to re-compile the whole dependency chain when their value is +//! changed. +//! +//! * `ruma_identifiers_storage` -- Choose the inner representation of `Owned*` wrapper types for +//! identifiers. By default they use [`Box`], setting the value to `Arc` makes them use +//! [`Arc`](std::sync::Arc). This can also be configured by setting the `RUMA_IDENTIFIERS_STORAGE` +//! environment variable. #![warn(missing_docs)] #![cfg_attr(docsrs, feature(doc_auto_cfg))]