Skip to content

Commit

Permalink
Gracefully handle cargo-metadata failures in users' environments (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Nov 28, 2024
1 parent b85fa9f commit 94f9d3c
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions crates/build/re_build_tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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", "<unknown>");
} 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 => "<error>".to_owned(),

Err(err) => panic!("{err}"),
};

set_env("RE_BUILD_FEATURES", &features);
}
}

Expand Down

0 comments on commit 94f9d3c

Please sign in to comment.