ruma
ruma copied to clipboard
Allow selecting owned identifier memory representation via regular environment variable
Currently, it is only possible to select the memory representation (Box
or Arc
) for identifiers (docs) via a RUSTFLAGS
--cfg
setting. Changing RUSTFLAGS
leads to the entire dependency chain being recompiled. As a cheaper solution, we can read an environment variable in ruma-common
s build script, and emit
cargo:rustc-cfg=ruma_identifiers_storage=ENV_VARIABLE_VALUE
cargo:rerun-if-env-changed=ENV_VARIABLE_NAME
(docs)
Then when people change the environment variable, only ruma-common and its dependents will be rebuilt.
Doesn't this require a build.rs
?
Yes, is that problematic?
I don't think so, but just making sure
What is the benefit over using cargo features?
Cargo features are additive and can be enabled from any place in the dependency tree. For the owned identifier representation, one specific value must be set (it wouldn't make sense to activate multiple ones).
It can become a compiler error to activate multiple ones. This has potential to make some libraries unusable with each other, but I think in practice all libraries will delegate this decision to the main binary (specially when docs encourage that). I would prefer cargo features for better tooling support and less problems like this, but YMMV.
If it'll become a compiler error, then multiple libraries will become mutually exclusively incompatible with eachother, which is not what we want