Skip to content

Commit d0b60f9

Browse files
authored
Show list of enabled feature with rerun --version (#7885)
* Reverts #7770 * Re-applies #7744 The revert was because during `cargo publish`, a `Cargo.lock` file materialized, and that made cargo angry: ``` Failed to publish re_sdk: error: failed to verify package tarball Caused by: Source directory was modified by build.rs during cargo publish. Build scripts should not modify anything outside of OUT_DIR. Added: /home/runner/work/rerun/rerun/target/package/re_sdk-0.19.0-alpha.9/Cargo.lock ``` So in this PR we only query about which cargo features if we're NOT in a `cargo publish` build. That should work! We'll know when we next publish some crates :)
1 parent 60724a7 commit d0b60f9

File tree

10 files changed

+72
-13
lines changed

10 files changed

+72
-13
lines changed

Cargo.lock

+2
Original file line numberDiff line numberDiff line change
@@ -6186,6 +6186,8 @@ dependencies = [
61866186
"indicatif",
61876187
"itertools 0.13.0",
61886188
"parking_lot",
6189+
"re_build_info",
6190+
"re_build_tools",
61896191
"re_log",
61906192
"re_mp4",
61916193
"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

+43-1
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,16 @@ pub fn export_build_info_vars_for_crate(crate_name: &str) {
194194
);
195195
}
196196
}
197+
198+
if environment == Environment::PublishingCrates {
199+
// We can't query this during `cargo publish`, but we also don't need the info.
200+
set_env("RE_BUILD_FEATURES", "<unknown>");
201+
} else {
202+
set_env(
203+
"RE_BUILD_FEATURES",
204+
&enabled_features_of(crate_name).unwrap().join(" "),
205+
);
206+
}
197207
}
198208

199209
/// ISO 8601 / RFC 3339 build time.
@@ -269,7 +279,39 @@ fn rust_llvm_versions() -> anyhow::Result<(String, String)> {
269279
))
270280
}
271281

272-
/// Returns info parsed from an invocation of the `cargo metadata` command
282+
/// Returns info parsed from an invocation of the `cargo metadata` command.
283+
///
284+
/// You may not run this during crate publishing.
273285
pub fn cargo_metadata() -> anyhow::Result<cargo_metadata::Metadata> {
286+
// See https://github.com/rerun-io/rerun/pull/7885
287+
anyhow::ensure!(
288+
Environment::detect() != Environment::PublishingCrates,
289+
"Can't get metadata during crate publishing - it would create a Cargo.lock file"
290+
);
291+
274292
Ok(cargo_metadata::MetadataCommand::new().exec()?)
275293
}
294+
295+
/// Returns a list of all the enabled features of the given package.
296+
///
297+
/// You may not run this during crate publishing.
298+
pub fn enabled_features_of(crate_name: &str) -> anyhow::Result<Vec<String>> {
299+
let metadata = cargo_metadata()?;
300+
301+
let mut features = vec![];
302+
for package in &metadata.packages {
303+
if package.name == crate_name {
304+
for feature in package.features.keys() {
305+
println!("Checking if feature is enabled: {feature:?}");
306+
let feature_in_screaming_snake_case =
307+
feature.to_ascii_uppercase().replace('-', "_");
308+
if std::env::var(format!("CARGO_FEATURE_{feature_in_screaming_snake_case}")).is_ok()
309+
{
310+
features.push(feature.clone());
311+
}
312+
}
313+
}
314+
}
315+
316+
Ok(features)
317+
}

crates/store/re_video/Cargo.toml

+2
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

@@ -66,6 +67,7 @@ criterion.workspace = true
6667

6768
# For build.rs:
6869
[build-dependencies]
70+
re_build_tools.workspace = true
6971
cfg_aliases.workspace = true
7072

7173

crates/store/re_video/build.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
fn main() {
2+
re_build_tools::export_build_info_vars_for_crate(env!("CARGO_PKG_NAME"));
3+
24
// uncomment these when we update to Rust 1.80: https://blog.rust-lang.org/2024/05/06/check-cfg.html
35
// println!("cargo::rustc-check-cfg=cfg(native)");
46
// println!("cargo::rustc-check-cfg=cfg(linux_arm64)");

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)