Skip to content
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
7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ readme = "README.md"
crate-type = ["cdylib"]

[features]
default = ["monado"]
default = ["monado", "git-version"]
static-openxr = ["openxr/static"]
tracing = ["dep:tracy-client", "openvr/tracing"]
monado = ["dep:openxr_mndx_xdev_space"]
# Derive the reported version from `git describe`. Disable when building outside
# of a git checkout and pass XRIZER_VERSION instead.
git-version = ["dep:vergen-gitcl"]

[workspace]
members = ["xbuild"]
Expand Down Expand Up @@ -74,7 +77,7 @@ lz4_flex = { version = "0.12.0", default-features = false, features = ["frame"]
[build-dependencies]
anyhow = "1.0.99"
shaders = { path = "shaders" }
vergen-gitcl = "1.0.8"
vergen-gitcl = { version = "1.0.8", optional = true }

[dev-dependencies]
libloading = "0.8.5"
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ cargo xbuild --release

After building, the output directory can be used as a runtime directory. If you built the dev build, this will be `<path to xrizer repo>/target/debug`, and for the release build this is `<path to xrizer repo>/target/release`.

The version xrizer reports comes from `git describe`, via the default `git-version` feature. Builds that don't have a git checkout - distribution packages and other builds from a source tarball - can disable that feature with `--no-default-features` (re-enabling the other default features they want, e.g. `--features monado`) and set `XRIZER_VERSION` at build time instead. `XRIZER_VERSION` takes precedence over `git describe` whenever it is set.

# Contributing

All contributions welcome.
Expand Down
29 changes: 26 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use anyhow::anyhow;
use std::env;
use vergen_gitcl::{Emitter, GitclBuilder};

fn main() -> Result<(), anyhow::Error> {
let out_dir = env::var("OUT_DIR").unwrap();
Expand Down Expand Up @@ -35,6 +34,30 @@ fn main() -> Result<(), anyhow::Error> {
println!("cargo::rustc-env=XRIZER_OPENVR_PLATFORM_DIR={platform_location}");
println!("cargo::rustc-env=XRIZER_OPENVR_VRCLIENT_NAME={vrclient_name}");

let builder = GitclBuilder::default().describe(true, true, None).build()?;
Emitter::default().add_instructions(&builder)?.emit()
emit_version()
}

/// Emit the version that is reported at runtime.
///
/// XRIZER_VERSION lets builds that have no git checkout - distribution packages
/// and other builds from a source tarball - supply their own version. Otherwise
/// the version is derived from `git describe` if the `git-version` feature is
/// enabled, and falls back to the version from Cargo.toml if it is not.
fn emit_version() -> Result<(), anyhow::Error> {
println!("cargo::rerun-if-env-changed=XRIZER_VERSION");

if let Some(version) = env::var("XRIZER_VERSION").ok().filter(|v| !v.is_empty()) {
println!("cargo::rustc-env=XRIZER_VERSION={version}");
return Ok(());
}

#[cfg(feature = "git-version")]
{
use vergen_gitcl::{Emitter, GitclBuilder};

let builder = GitclBuilder::default().describe(true, true, None).build()?;
Emitter::default().add_instructions(&builder)?.emit()?;
}

Ok(())
}
9 changes: 5 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,11 @@ fn init_logging() {
})
.init();

let mut version = env!("VERGEN_GIT_DESCRIBE");
if version == "VERGEN_IDEMPOTENT_OUTPUT" {
version = env!("CARGO_PKG_VERSION");
}
let version = option_env!("XRIZER_VERSION")
.or_else(|| {
option_env!("VERGEN_GIT_DESCRIBE").filter(|v| *v != "VERGEN_IDEMPOTENT_OUTPUT")
})
.unwrap_or(env!("CARGO_PKG_VERSION"));
log::info!("Initializing XRizer version {version}");
if let Some(err) = startup_err {
log::warn!("{err}");
Expand Down
Loading