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

Fix using rerun crate as a dependency on CI #5170

Merged
merged 3 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/re_build_examples/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ fn get_base_url(build_env: Environment) -> anyhow::Result<String> {
// 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
Expand Down
38 changes: 14 additions & 24 deletions crates/re_build_tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
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_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
Expand All @@ -114,26 +116,14 @@ 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.
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 +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,

Expand Down Expand Up @@ -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 {
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
Loading