-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More information in
--version
(#1388)
* Add the re_build_info and re_build_build_info crates * Add datetime * --version prints the full build info * Add git branch and clean/dirty flag * fix extra --dirty * Fix analytics link * Add note about not moving the viewer_analytics.rs file * Add About-menu with version number, target triplet, and build date also add link to rerun.io in it * Add help-button to rerun menu * Fix web build * Add crate-level docs * Rerun re_build_build_info when branch or commit hash changes * Fix merge-snafu * Ignore if the repo is dirty or clean
- Loading branch information
Showing
27 changed files
with
409 additions
and
110 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,3 @@ | ||
use std::process::Command; | ||
|
||
// Situations to consider | ||
// ---------------------- | ||
// | ||
// # Using the published crate | ||
// | ||
// The published crate carries its version around, which in turns gives us the git tag, which makes | ||
// the commit hash irrelevant. | ||
// We still need to compute _something_ so that we can actually build, but that value will be | ||
// ignored when the crate is built by the end user anyhow. | ||
// | ||
// # Working directly within the workspace | ||
// | ||
// When working within the workspace, we can simply try and call `git` and we're done. | ||
// | ||
// # Using an unpublished crate (e.g. `path = "..."` or `git = "..."` or `[patch.crates-io]`) | ||
// | ||
// In these cases we may or may not have access to the workspace (e.g. a `path = ...` import likely | ||
// will, while a crate patch won't). | ||
// | ||
// This is not an issue however, as we can simply try and see what we get. | ||
// If we manage to compute a commit hash, great, otherwise we still have the crate version to | ||
// fallback on. | ||
|
||
fn main() { | ||
// target triple | ||
println!( | ||
"cargo:rustc-env=__RERUN_TARGET_TRIPLE={}", | ||
std::env::var("TARGET").unwrap() | ||
); | ||
|
||
match git_hash() { | ||
Ok(git_hash) => { | ||
println!("cargo:rustc-env=__RERUN_GIT_HASH={git_hash}"); | ||
for path in glob::glob("../../.git/refs/heads/**").unwrap() { | ||
println!("cargo:rerun-if-changed={}", path.unwrap().to_string_lossy()); | ||
} | ||
} | ||
// NOTE: In 99% of cases, if `git_hash` failed it's because we're not in a git repository | ||
// to begin with, which happens because we've imported the published crate from crates.io. | ||
// | ||
// When that happens, we want the commit hash to be the git tag that corresponds to the | ||
// published version, so that one can always easily checkout the `git_hash` field in the | ||
// analytics. | ||
// | ||
// Example of unlikely cases where the above does not hold: | ||
// - `git` is not installed | ||
// - the user downloaded rerun as a tarball and then imported via a `path = ...` import | ||
// - others? | ||
Err(_) => println!( | ||
"cargo:rustc-env=__RERUN_GIT_HASH=v{}", | ||
env!("CARGO_PKG_VERSION") | ||
), | ||
} | ||
} | ||
|
||
fn git_hash() -> anyhow::Result<String> { | ||
let output = Command::new("git").args(["rev-parse", "HEAD"]).output()?; | ||
|
||
let git_hash = String::from_utf8(output.stdout)?; | ||
let git_hash = git_hash.trim(); | ||
if git_hash.is_empty() { | ||
anyhow::bail!("empty commit hash"); | ||
} | ||
|
||
let clean = Command::new("git") | ||
.args(["diff-files", "--quiet"]) | ||
.output()? | ||
.status | ||
.success(); | ||
|
||
Ok(format!("{}{}", git_hash, if clean { "" } else { "-dirty" })) | ||
re_build_build_info::export_env_vars(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[package] | ||
name = "re_build_build_info" | ||
authors.workspace = true | ||
description = "build.rs helpers for generating build info" | ||
edition.workspace = true | ||
homepage.workspace = true | ||
include.workspace = true | ||
license.workspace = true | ||
publish = true | ||
readme = "README.md" | ||
repository.workspace = true | ||
rust-version.workspace = true | ||
version.workspace = true | ||
|
||
[package.metadata.docs.rs] | ||
all-features = true | ||
|
||
|
||
[dependencies] | ||
anyhow.workspace = true | ||
glob = "0.3" | ||
time = { workspace = true, features = ["formatting"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
//! This crate is to be used from `build.rs` build scripts. | ||
//! | ||
//! Use this crate together with the `re_build_info` crate. | ||
use anyhow::Context as _; | ||
|
||
use std::process::Command; | ||
|
||
// Situations to consider | ||
// ---------------------- | ||
// | ||
// # Using the published crate | ||
// | ||
// The published crate carries its version around, which in turns gives us the git tag, which makes | ||
// the commit hash irrelevant. | ||
// We still need to compute _something_ so that we can actually build, but that value will be | ||
// ignored when the crate is built by the end user anyhow. | ||
// | ||
// # Working directly within the workspace | ||
// | ||
// When working within the workspace, we can simply try and call `git` and we're done. | ||
// | ||
// # Using an unpublished crate (e.g. `path = "..."` or `git = "..."` or `[patch.crates-io]`) | ||
// | ||
// In these cases we may or may not have access to the workspace (e.g. a `path = ...` import likely | ||
// will, while a crate patch won't). | ||
// | ||
// This is not an issue however, as we can simply try and see what we get. | ||
// If we manage to compute a commit hash, great, otherwise we still have the crate version to | ||
// fallback on. | ||
|
||
/// Call from the `build.rs` file of any crate you want to generate build info for. | ||
pub fn export_env_vars() { | ||
// target triple | ||
println!( | ||
"cargo:rustc-env=RE_BUILD_TARGET_TRIPLE={}", | ||
std::env::var("TARGET").unwrap() | ||
); | ||
|
||
let git_hash = git_hash().unwrap_or_default(); | ||
println!("cargo:rustc-env=RE_BUILD_GIT_HASH={git_hash}"); | ||
|
||
let git_branch = git_branch().unwrap_or_default(); | ||
println!("cargo:rustc-env=RE_BUILD_GIT_BRANCH={git_branch}"); | ||
|
||
let time_format = | ||
time::format_description::parse("[year]-[month]-[day]T[hour]:[minute]:[second]Z").unwrap(); | ||
let date_time = time::OffsetDateTime::now_utc() | ||
.format(&time_format) | ||
.unwrap(); | ||
println!("cargo:rustc-env=RE_BUILD_DATETIME={date_time}"); | ||
|
||
// Make sure we re-run the build script if the branch or commit changes: | ||
if let Ok(head_path) = git_path("HEAD") { | ||
eprintln!("cargo:rerun-if-changed={head_path}"); // Track changes to branch | ||
if let Ok(head) = std::fs::read_to_string(&head_path) { | ||
if let Some(git_file) = head.strip_prefix("ref: ") { | ||
if let Ok(path) = git_path(git_file) { | ||
eprintln!("cargo:rerun-if-changed={path}"); // Track changes to commit hash | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
fn run_command(cmd: &'static str, args: &[&str]) -> anyhow::Result<String> { | ||
let output = Command::new(cmd) | ||
.args(args) | ||
.output() | ||
.with_context(|| format!("running '{cmd}'"))?; | ||
Ok(String::from_utf8(output.stdout)?.trim().to_owned()) | ||
} | ||
|
||
fn git_hash() -> anyhow::Result<String> { | ||
let git_hash = run_command("git", &["rev-parse", "HEAD"])?; | ||
if git_hash.is_empty() { | ||
anyhow::bail!("empty commit hash"); | ||
} | ||
Ok(git_hash) | ||
} | ||
|
||
fn git_branch() -> anyhow::Result<String> { | ||
run_command("git", &["symbolic-ref", "--short", "HEAD"]) | ||
} | ||
|
||
/// From <https://git-scm.com/docs/git-rev-parse>: | ||
/// | ||
/// Resolve `$GIT_DIR/<path>` and takes other path relocation variables such as `$GIT_OBJECT_DIRECTORY`, `$GIT_INDEX_FILE…` into account. | ||
/// For example, if `$GIT_OBJECT_DIRECTORY` is set to /foo/bar then `git rev-parse --git-path objects/abc` returns `/foo/bar/abc`. | ||
fn git_path(path: &str) -> anyhow::Result<String> { | ||
run_command("git", &["rev-parse", "--git-path", path]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "re_build_info" | ||
authors.workspace = true | ||
description = "Information about the build. Use together with re_build_build_info" | ||
edition.workspace = true | ||
homepage.workspace = true | ||
include.workspace = true | ||
license.workspace = true | ||
publish = true | ||
readme = "README.md" | ||
repository.workspace = true | ||
rust-version.workspace = true | ||
version.workspace = true | ||
|
||
[package.metadata.docs.rs] | ||
all-features = true |
Oops, something went wrong.
4f8468a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rust Benchmark
datastore/insert/batch/rects/insert
549792
ns/iter (± 3167
)553015
ns/iter (± 6215
)0.99
datastore/latest_at/batch/rects/query
1842
ns/iter (± 12
)1859
ns/iter (± 1
)0.99
datastore/latest_at/missing_components/primary
356
ns/iter (± 2
)355
ns/iter (± 3
)1.00
datastore/latest_at/missing_components/secondaries
419
ns/iter (± 5
)423
ns/iter (± 0
)0.99
datastore/range/batch/rects/query
151052
ns/iter (± 1292
)155102
ns/iter (± 140
)0.97
mono_points_arrow/generate_message_bundles
48445375
ns/iter (± 1774428
)47120530
ns/iter (± 669492
)1.03
mono_points_arrow/generate_messages
136702497
ns/iter (± 1659147
)126295565
ns/iter (± 1184888
)1.08
mono_points_arrow/encode_log_msg
164855431
ns/iter (± 1057345
)154542958
ns/iter (± 1639842
)1.07
mono_points_arrow/encode_total
351685210
ns/iter (± 3606074
)327157402
ns/iter (± 2075839
)1.07
mono_points_arrow/decode_log_msg
186173612
ns/iter (± 1905498
)181480995
ns/iter (± 1039788
)1.03
mono_points_arrow/decode_message_bundles
73076209
ns/iter (± 1177197
)63653200
ns/iter (± 860200
)1.15
mono_points_arrow/decode_total
256329369
ns/iter (± 2419251
)240086886
ns/iter (± 1479949
)1.07
batch_points_arrow/generate_message_bundles
322821
ns/iter (± 2754
)326585
ns/iter (± 554
)0.99
batch_points_arrow/generate_messages
6190
ns/iter (± 71
)6246
ns/iter (± 80
)0.99
batch_points_arrow/encode_log_msg
365590
ns/iter (± 3324
)373484
ns/iter (± 2663
)0.98
batch_points_arrow/encode_total
712129
ns/iter (± 6658
)717265
ns/iter (± 3685
)0.99
batch_points_arrow/decode_log_msg
346470
ns/iter (± 3586
)352908
ns/iter (± 1515
)0.98
batch_points_arrow/decode_message_bundles
1992
ns/iter (± 23
)2031
ns/iter (± 14
)0.98
batch_points_arrow/decode_total
355692
ns/iter (± 2599
)354202
ns/iter (± 1953
)1.00
arrow_mono_points/insert
6985053068
ns/iter (± 176020015
)6175273502
ns/iter (± 26181726
)1.13
arrow_mono_points/query
1717200
ns/iter (± 14682
)1742076
ns/iter (± 16239
)0.99
arrow_batch_points/insert
2603860
ns/iter (± 19505
)2705043
ns/iter (± 31465
)0.96
arrow_batch_points/query
17440
ns/iter (± 101
)17139
ns/iter (± 145
)1.02
tuid/Tuid::random
34
ns/iter (± 0
)34
ns/iter (± 0
)1
This comment was automatically generated by workflow using github-action-benchmark.