diff --git a/crates/re_build_examples/src/manifest.rs b/crates/re_build_examples/src/manifest.rs index b1b5f11cf7d6..13fce903f84d 100644 --- a/crates/re_build_examples/src/manifest.rs +++ b/crates/re_build_examples/src/manifest.rs @@ -92,9 +92,9 @@ fn get_base_url(build_env: Environment) -> anyhow::Result { // In the CondaBuild environment we can't trust the git_branch name -- if it exists // at all it's going to be the feedstock branch-name, not our Rerun branch. However // conda should ONLY be building released versions, so we want to version the manifest. - let versioned_manifest = matches!(build_env, Environment::CondaBuild) || { + let versioned_manifest = build_env == Environment::CondaBuild || { let branch = re_build_tools::git_branch()?; - if branch == "main" || !re_build_tools::is_on_ci() { + if branch == "main" || build_env != Environment::RerunCI { // on `main` and local builds, use `version/main` // this will point to data uploaded by `.github/workflows/reusable_upload_examples.yml` // on every commit to the `main` branch diff --git a/crates/re_build_tools/src/lib.rs b/crates/re_build_tools/src/lib.rs index ec47d104c43a..96d62b974e57 100644 --- a/crates/re_build_tools/src/lib.rs +++ b/crates/re_build_tools/src/lib.rs @@ -58,13 +58,13 @@ pub(crate) fn should_output_cargo_build_instructions() -> bool { // ------------------ /// Where is this `build.rs` build script running? -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] 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_in_rerun_workspace && std::env::var("CI").is_ok() { // `CI` is an env-var set by GitHub actions. - eprintln!("Environment: env-var CI is set"); - Self::CI - } else if is_on_conda() { + eprintln!("Environment: env-var IS_IN_RERUN_WORKSPACE and CI are set"); + Self::RerunCI + } else if std::env::var("CONDA_BUILD").is_ok() { // `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 @@ -114,18 +116,6 @@ impl Environment { } } -/// Are we running on a CI machine? -pub fn is_on_ci() -> bool { - // `CI` is an env-var set by GitHub actions. - std::env::var("CI").is_ok() -} - -/// Are we running in the Conda build environment? -pub fn is_on_conda() -> bool { - // `CONDA_BUILD` is an env-var set by conda build - std::env::var("CONDA_BUILD").is_ok() -} - /// 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. @@ -133,7 +123,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 +133,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, @@ -194,7 +184,7 @@ pub fn export_build_info_vars_for_crate(crate_name: &str) { // We need to check `IS_IN_RERUN_WORKSPACE` in the build-script (here), // because otherwise it won't show up when compiling through maturin. // We must also make an exception for when we build actual wheels (on CI) for release. - if is_on_ci() { + if environment == Environment::RerunCI { // e.g. building wheels on CI. set_env("RE_BUILD_IS_IN_RERUN_WORKSPACE", "no"); } else { diff --git a/crates/re_build_tools/src/rebuild_detector.rs b/crates/re_build_tools/src/rebuild_detector.rs index c1c8f2cc2e95..9c566b70a80e 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 4745f1ffbec5..3118751fd4b8 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 749a08395813..ab29a9c864a6 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 23349226682f..04e393355099 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 eb4ff654b464..46ab9be92bde 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,