Skip to content

Commit

Permalink
Only build web viewer on CI if we're in the Rerun workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Feb 12, 2024
1 parent 1c28f45 commit 0d7123f
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 14 deletions.
23 changes: 14 additions & 9 deletions crates/re_build_tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand All @@ -78,7 +78,7 @@ pub enum Environment {
/// Are we a developer running inside the workspace of <https://github.com/rerun-io/rerun> ?
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`,
Expand All @@ -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
Expand All @@ -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()
Expand All @@ -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,

Expand All @@ -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,

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 @@ -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,
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 @@ -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,

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 @@ -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,
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 @@ -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,

Expand Down
2 changes: 1 addition & 1 deletion examples/rust/objectron/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 0d7123f

Please sign in to comment.