Skip to content

Commit 5325fd8

Browse files
authored
Show list of enabled feature with rerun --version (#7744)
### What This automatically includes the list of enabled features for the top-level crate in `rerun --version` as well as the Rerun menu. ### Native ![image](https://github.com/user-attachments/assets/24dba8bb-c64b-46e1-8a69-1cf59b4d8d5e) ### Web ![image](https://github.com/user-attachments/assets/f5039d0c-643c-4b42-8722-4c8da45dd44b) ### Checklist * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [x] I've included a screenshot or gif (if applicable) * [x] I have tested the web demo (if applicable): * Using examples from latest `main` build: [rerun.io/viewer](https://rerun.io/viewer/pr/7744?manifest_url=https://app.rerun.io/version/main/examples_manifest.json) * Using full set of examples from `nightly` build: [rerun.io/viewer](https://rerun.io/viewer/pr/7744?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json) * [x] The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG * [x] If applicable, add a new check to the [release checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)! * [x] If have noted any breaking changes to the log API in `CHANGELOG.md` and the migration guide - [PR Build Summary](https://build.rerun.io/pr/7744) - [Recent benchmark results](https://build.rerun.io/graphs/crates.html) - [Wasm size tracking](https://build.rerun.io/graphs/sizes.html) To run all checks from `main`, comment on the PR with `@rerun-bot full-check`.
1 parent a129747 commit 5325fd8

File tree

10 files changed

+59
-12
lines changed

10 files changed

+59
-12
lines changed

Cargo.lock

+2
Original file line numberDiff line numberDiff line change
@@ -5942,6 +5942,8 @@ dependencies = [
59425942
"indicatif",
59435943
"itertools 0.13.0",
59445944
"parking_lot",
5945+
"re_build_info",
5946+
"re_build_tools",
59455947
"re_log",
59465948
"re_mp4",
59475949
"re_rav1d",

crates/build/re_build_info/src/build_info.rs

+9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ pub struct BuildInfo {
1414
/// `CARGO_PKG_NAME`
1515
pub crate_name: &'static str,
1616

17+
/// Space-separated names of all features enabled for this crate.
18+
pub features: &'static str,
19+
1720
/// Crate version, parsed from `CARGO_PKG_VERSION`, ignoring any `+metadata` suffix.
1821
pub version: super::CrateVersion,
1922

@@ -74,6 +77,7 @@ impl std::fmt::Display for BuildInfo {
7477
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
7578
let Self {
7679
crate_name,
80+
features,
7781
version,
7882
rustc_version,
7983
llvm_version,
@@ -89,6 +93,10 @@ impl std::fmt::Display for BuildInfo {
8993

9094
write!(f, "{crate_name} {version}")?;
9195

96+
if !features.is_empty() {
97+
write!(f, " ({features})")?;
98+
}
99+
92100
if let Some(rustc_version) = rustc_version {
93101
write!(f, " [{rustc_version}")?;
94102
if let Some(llvm_version) = llvm_version {
@@ -147,6 +155,7 @@ impl CrateVersion {
147155
fn crate_version_from_build_info_string() {
148156
let build_info = BuildInfo {
149157
crate_name: "re_build_info",
158+
features: "default extra",
150159
version: CrateVersion {
151160
major: 0,
152161
minor: 10,

crates/build/re_build_info/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ macro_rules! build_info {
1515
() => {
1616
$crate::BuildInfo {
1717
crate_name: env!("CARGO_PKG_NAME"),
18+
features: env!("RE_BUILD_FEATURES"),
1819
version: $crate::CrateVersion::parse(env!("CARGO_PKG_VERSION")),
1920
rustc_version: env!("RE_BUILD_RUSTC_VERSION"),
2021
llvm_version: env!("RE_BUILD_LLVM_VERSION"),

crates/build/re_build_tools/src/lib.rs

+27
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ pub fn export_build_info_vars_for_crate(crate_name: &str) {
194194
);
195195
}
196196
}
197+
198+
set_env(
199+
"RE_BUILD_FEATURES",
200+
&enabled_features_of(crate_name).unwrap().join(" "),
201+
);
197202
}
198203

199204
/// ISO 8601 / RFC 3339 build time.
@@ -273,3 +278,25 @@ fn rust_llvm_versions() -> anyhow::Result<(String, String)> {
273278
pub fn cargo_metadata() -> anyhow::Result<cargo_metadata::Metadata> {
274279
Ok(cargo_metadata::MetadataCommand::new().exec()?)
275280
}
281+
282+
/// Returns a list of all the enabled features of the given package.
283+
pub fn enabled_features_of(crate_name: &str) -> anyhow::Result<Vec<String>> {
284+
let metadata = cargo_metadata()?;
285+
286+
let mut features = vec![];
287+
for package in &metadata.packages {
288+
if package.name == crate_name {
289+
for feature in package.features.keys() {
290+
println!("Checking if feature is enabled: {feature:?}");
291+
let feature_in_screaming_snake_case =
292+
feature.to_ascii_uppercase().replace('-', "_");
293+
if std::env::var(format!("CARGO_FEATURE_{feature_in_screaming_snake_case}")).is_ok()
294+
{
295+
features.push(feature.clone());
296+
}
297+
}
298+
}
299+
}
300+
301+
Ok(features)
302+
}

crates/store/re_video/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ nasm = [
3737

3838

3939
[dependencies]
40+
re_build_info.workspace = true
4041
re_log.workspace = true
4142
re_tracing.workspace = true
4243

@@ -61,6 +62,9 @@ dav1d = { workspace = true, optional = true, default-features = false, features
6162
[dev-dependencies]
6263
indicatif.workspace = true
6364

65+
[build-dependencies]
66+
re_build_tools.workspace = true
67+
6468

6569
[[example]]
6670
name = "frames"

crates/store/re_video/build.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
re_build_tools::export_build_info_vars_for_crate(env!("CARGO_PKG_NAME"));
3+
}

crates/store/re_video/src/lib.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,7 @@ pub use self::{
1313
time::{Time, Timescale},
1414
};
1515

16-
/// Which features was this crate compiled with?
17-
pub fn features() -> Vec<&'static str> {
18-
// TODO(emilk): is there a helper crate for this?
19-
let mut features = vec![];
20-
if cfg!(feature = "av1") {
21-
features.push("av1");
22-
}
23-
if cfg!(feature = "nasm") {
24-
features.push("nasm");
25-
}
26-
features
16+
/// Returns information about this crate
17+
pub fn build_info() -> re_build_info::BuildInfo {
18+
re_build_info::build_info!()
2719
}

crates/top/rerun/src/commands/entrypoint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ where
553553

554554
if args.version {
555555
println!("{build_info}");
556-
println!("Video features: {}", re_video::features().join(" "));
556+
println!("Video features: {}", re_video::build_info().features);
557557
return Ok(0);
558558
}
559559

crates/utils/re_analytics/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ impl Properties for re_build_info::BuildInfo {
345345
let git_hash = self.git_hash_or_tag();
346346
let Self {
347347
crate_name: _,
348+
features,
348349
version,
349350
rustc_version,
350351
llvm_version,
@@ -355,6 +356,7 @@ impl Properties for re_build_info::BuildInfo {
355356
datetime,
356357
} = self;
357358

359+
event.insert("features", features);
358360
event.insert("git_hash", git_hash);
359361
event.insert("rerun_version", version.to_string());
360362
event.insert("rust_version", rustc_version);

crates/viewer/re_viewer/src/ui/rerun_menu.rs

+7
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ impl App {
114114
fn about_rerun_ui(&self, frame: &eframe::Frame, ui: &mut egui::Ui) {
115115
let re_build_info::BuildInfo {
116116
crate_name,
117+
features,
117118
version,
118119
rustc_version,
119120
llvm_version,
@@ -138,6 +139,12 @@ impl App {
138139
{target_triple}"
139140
);
140141

142+
// It is really the features of `rerun-cli` (the `rerun` binary) that are interesting.
143+
// For the web-viewer we get `crate_name: "re_viewer"` here, which is much less interesting.
144+
if crate_name == "rerun-cli" && !features.is_empty() {
145+
label += &format!("\n{crate_name} features: {features}");
146+
}
147+
141148
if !rustc_version.is_empty() {
142149
label += &format!("\nrustc {rustc_version}");
143150
if !llvm_version.is_empty() {

0 commit comments

Comments
 (0)