Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor our build.rs files #3789

Merged
merged 13 commits into from
Oct 11, 2023
7 changes: 7 additions & 0 deletions crates/re_build_tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ pub(crate) fn should_output_cargo_build_instructions() -> bool {
OUTPUT_CARGO_BUILD_INSTRUCTIONS.load(Ordering::Relaxed)
}

/// Are we running inside the workspace of <https://github.com/rerun-io/rerun> ?
///
/// Otherwise we might be running on users machines.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an oddly formulated comment 🤔 Running inside the workspace and running on users machines are not antithetical

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, good catch - I'll improve the naming and documentation

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to communicate "Rerun user"

pub fn is_in_rerun_workspace() -> bool {
is_tracked_env_var_set("IS_IN_RERUN_WORKSPACE")
}

/// Call from the `build.rs` file of any crate you want to generate build info for.
///
/// Use this crate together with the `re_build_info` crate.
Expand Down
2 changes: 1 addition & 1 deletion crates/re_build_tools/src/rebuild_detector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::should_output_cargo_build_instructions;
/// This will work even if the package depends on crates that are outside of the workspace,
/// included with `path = …`
pub fn rebuild_if_crate_changed(pkg_name: &str) {
if !is_tracked_env_var_set("IS_IN_RERUN_WORKSPACE") {
if !crate::is_in_rerun_workspace() {
// Only run if we are in the rerun workspace, not on users machines.
return;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/re_renderer/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ fn main() {
// repository.
return;
}
if !is_tracked_env_var_set("IS_IN_RERUN_WORKSPACE") {
if !re_build_tools::is_in_rerun_workspace() {
// Only run if we are in the rerun workspace, not on users machines.
return;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/re_types/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn main() {
return;
}

if !is_tracked_env_var_set("IS_IN_RERUN_WORKSPACE") {
if !re_build_tools::is_in_rerun_workspace() {
// Only run if we are in the rerun workspace, not on users machines.
return;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/re_types_builder/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn main() {
return;
}

if !is_tracked_env_var_set("IS_IN_RERUN_WORKSPACE") {
if !re_build_tools::is_in_rerun_workspace() {
// Only run if we are in the rerun workspace, not on users machines.
return;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/re_viewer/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ fn write_examples_manifest() -> Result<()> {
}

fn write_examples_manifest_if_necessary() {
if !re_build_tools::is_tracked_env_var_set("IS_IN_RERUN_WORKSPACE")
if !re_build_tools::is_in_rerun_workspace()
|| re_build_tools::is_tracked_env_var_set("RERUN_IS_PUBLISHING")
{
return;
Expand Down
2 changes: 1 addition & 1 deletion crates/re_web_viewer_server/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use re_build_tools::{
};

fn main() {
if !is_tracked_env_var_set("IS_IN_RERUN_WORKSPACE") {
if !re_build_tools::is_in_rerun_workspace() {
// Only run if we are in the rerun workspace, not on users machines.
return;
}
Expand Down
4 changes: 2 additions & 2 deletions examples/rust/objectron/build.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use std::path::PathBuf;

use re_build_tools::{is_tracked_env_var_set, write_file_if_necessary};
use re_build_tools::write_file_if_necessary;

fn main() -> Result<(), std::io::Error> {
if std::env::var("CI").is_ok() {
// No need to run this on CI (which means setting up `protoc` etc) since the code is committed
// anyway.
return Ok(());
}
if !is_tracked_env_var_set("IS_IN_RERUN_WORKSPACE") {
if !re_build_tools::is_in_rerun_workspace() {
// Only run if we are in the rerun workspace, not on users machines (if we ever publish the example).
return Ok(());
}
Expand Down