From 94f9d3c470549a11b65c1e8986272853407890fd Mon Sep 17 00:00:00 2001 From: Clement Rey Date: Thu, 28 Nov 2024 11:33:45 +0100 Subject: [PATCH] Gracefully handle `cargo-metadata` failures in users' environments (#8239) --- crates/build/re_build_tools/src/lib.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/crates/build/re_build_tools/src/lib.rs b/crates/build/re_build_tools/src/lib.rs index 33f473f230ef..b8df3f89d4f9 100644 --- a/crates/build/re_build_tools/src/lib.rs +++ b/crates/build/re_build_tools/src/lib.rs @@ -199,10 +199,20 @@ pub fn export_build_info_vars_for_crate(crate_name: &str) { // We can't query this during `cargo publish`, but we also don't need the info. set_env("RE_BUILD_FEATURES", ""); } else { - set_env( - "RE_BUILD_FEATURES", - &enabled_features_of(crate_name).unwrap().join(" "), - ); + let features = enabled_features_of(crate_name); + let features = match features { + Ok(features) => features.join(" "), + + // When building as a dependency on users' end, feature flag collection can fail for a + // bunch of reasons (e.g. there's no `cargo` to begin with (Bazel, Buck, etc)). + // Failing the build entirely is a bit too harsh in that case, everything will still + // work just fine otherwise. + Err(_err) if environment == Environment::UsedAsDependency => "".to_owned(), + + Err(err) => panic!("{err}"), + }; + + set_env("RE_BUILD_FEATURES", &features); } }