From 0d7123f4db38cd32d5f6029b19af67d00ed9d2f6 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Mon, 12 Feb 2024 11:44:36 +0100 Subject: [PATCH] Only build web viewer on CI if we're in the Rerun workspace --- crates/re_build_tools/src/lib.rs | 23 +++++++++++-------- crates/re_build_tools/src/rebuild_detector.rs | 2 +- crates/re_renderer/build.rs | 2 +- crates/re_types_builder/build.rs | 2 +- crates/re_web_viewer_server/build.rs | 2 +- examples/rust/objectron/build.rs | 2 +- 6 files changed, 19 insertions(+), 14 deletions(-) diff --git a/crates/re_build_tools/src/lib.rs b/crates/re_build_tools/src/lib.rs index ec47d104c43a5..f2d63b0a44957 100644 --- a/crates/re_build_tools/src/lib.rs +++ b/crates/re_build_tools/src/lib.rs @@ -63,8 +63,8 @@ pub enum Environment { /// We are running `cargo publish` (via `scripts/ci/crates.py`); _probably_ on CI. PublishingCrates, - /// We are running on CI, but NOT publishing crates - CI, + /// We are running on CI for the Rerun workspace, but NOT publishing crates. + RerunCI, /// We are running in the conda build environment. /// @@ -78,7 +78,7 @@ pub enum Environment { /// Are we a developer running inside the workspace of ? DeveloperInWorkspace, - /// We are not on CI, and not in the Rerun workspace. + /// We are not on Rerun's CI, and not in the Rerun workspace. /// /// This is _most likely_ a Rerun user who is compiling a `re_` crate /// because they depend on it either directly or indirectly in their `Cargo.toml`, @@ -91,19 +91,21 @@ pub enum Environment { impl Environment { /// Detect what environment we are running in. pub fn detect() -> Self { + let is_in_rerun_workspace = is_tracked_env_var_set("IS_IN_RERUN_WORKSPACE"); + if is_tracked_env_var_set("RERUN_IS_PUBLISHING") { // "RERUN_IS_PUBLISHING" is set by `scripts/ci/crates.py` eprintln!("Environment: env-var RERUN_IS_PUBLISHING is set"); Self::PublishingCrates - } else if is_on_ci() { + } else if is_on_ci() && is_in_rerun_workspace { // `CI` is an env-var set by GitHub actions. - eprintln!("Environment: env-var CI is set"); - Self::CI + eprintln!("Environment: env-var IS_IN_RERUN_WORKSPACE and CI are set"); + Self::RerunCI } else if is_on_conda() { // `CONDA_BUILD` is an env-var set by conda build eprintln!("Environment: env-var CONDA_BUILD is set"); Self::CondaBuild - } else if is_tracked_env_var_set("IS_IN_RERUN_WORKSPACE") { + } else if is_in_rerun_workspace { // IS_IN_RERUN_WORKSPACE is set by `.cargo/config.toml` and also in the Rust-analyzer settings in `.vscode/settings.json` eprintln!("Environment: env-var IS_IN_RERUN_WORKSPACE is set"); Self::DeveloperInWorkspace @@ -115,6 +117,9 @@ impl Environment { } /// Are we running on a CI machine? +/// +/// Note that this will be true for users compiling a +/// rerun crate dependency on their own GitHub Actions CI! pub fn is_on_ci() -> bool { // `CI` is an env-var set by GitHub actions. std::env::var("CI").is_ok() @@ -133,7 +138,7 @@ pub fn export_build_info_vars_for_crate(crate_name: &str) { let environment = Environment::detect(); let export_datetime = match environment { - Environment::PublishingCrates | Environment::CI | Environment::CondaBuild => true, + Environment::PublishingCrates | Environment::RerunCI | Environment::CondaBuild => true, Environment::DeveloperInWorkspace => EXPORT_BUILD_TIME_FOR_DEVELOPERS, @@ -143,7 +148,7 @@ pub fn export_build_info_vars_for_crate(crate_name: &str) { }; let export_git_info = match environment { - Environment::PublishingCrates | Environment::CI => true, + Environment::PublishingCrates | Environment::RerunCI => true, Environment::DeveloperInWorkspace => EXPORT_GIT_FOR_DEVELOPERS, diff --git a/crates/re_build_tools/src/rebuild_detector.rs b/crates/re_build_tools/src/rebuild_detector.rs index c1c8f2cc2e956..9c566b70a80ef 100644 --- a/crates/re_build_tools/src/rebuild_detector.rs +++ b/crates/re_build_tools/src/rebuild_detector.rs @@ -20,7 +20,7 @@ fn should_run() -> bool { Environment::PublishingCrates | Environment::CondaBuild => false, // Dependencies shouldn't change on CI, but who knows 🤷‍♂️ - Environment::CI => true, + Environment::RerunCI => true, // Yes - this is what we want tracking for. Environment::DeveloperInWorkspace => true, diff --git a/crates/re_renderer/build.rs b/crates/re_renderer/build.rs index 4745f1ffbec5a..3118751fd4b8b 100644 --- a/crates/re_renderer/build.rs +++ b/crates/re_renderer/build.rs @@ -110,7 +110,7 @@ fn should_run() -> bool { Environment::PublishingCrates => false, // The code we're generating here is actual source code that gets committed into the repository. - Environment::CI | Environment::CondaBuild => false, + Environment::RerunCI | Environment::CondaBuild => false, Environment::DeveloperInWorkspace => true, diff --git a/crates/re_types_builder/build.rs b/crates/re_types_builder/build.rs index 749a083958136..ab29a9c864a6f 100644 --- a/crates/re_types_builder/build.rs +++ b/crates/re_types_builder/build.rs @@ -22,7 +22,7 @@ fn should_run() -> bool { Environment::PublishingCrates => false, // The code we're generating here is actual source code that gets committed into the repository. - Environment::CI | Environment::CondaBuild => false, + Environment::RerunCI | Environment::CondaBuild => false, Environment::DeveloperInWorkspace => { // This `build.rs` depends on having `flatc` installed, diff --git a/crates/re_web_viewer_server/build.rs b/crates/re_web_viewer_server/build.rs index 23349226682f3..04e393355099a 100644 --- a/crates/re_web_viewer_server/build.rs +++ b/crates/re_web_viewer_server/build.rs @@ -18,7 +18,7 @@ fn should_run() -> bool { Environment::PublishingCrates => false, // TODO(emilk): only build the web viewer explicitly on CI - Environment::CI | Environment::CondaBuild => true, + Environment::RerunCI | Environment::CondaBuild => true, Environment::DeveloperInWorkspace => true, diff --git a/examples/rust/objectron/build.rs b/examples/rust/objectron/build.rs index eb4ff654b4643..46ab9be92bde4 100644 --- a/examples/rust/objectron/build.rs +++ b/examples/rust/objectron/build.rs @@ -12,7 +12,7 @@ fn should_run() -> bool { // No need to run this on CI (which means setting up `protoc` etc) // since the code is committed anyway. - Environment::CI | Environment::CondaBuild => false, + Environment::RerunCI | Environment::CondaBuild => false, // Sure - let's keep it up-to-date. Environment::DeveloperInWorkspace => true,