Skip to content

Commit

Permalink
chore(build): use shadow-rs for build info (#891)
Browse files Browse the repository at this point in the history
closes #890

---------

Co-authored-by: Zicklag <zicklag@katharostech.com>
  • Loading branch information
orhun and zicklag authored Dec 23, 2023
1 parent fc7cfe7 commit f1f0538
Show file tree
Hide file tree
Showing 4 changed files with 224 additions and 19 deletions.
208 changes: 191 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ serde_yaml = "0.9.25"
thiserror = "1.0.48"
peg = "0.8.1"
egui_extras = { version = "0.23.0", default-features = false }
git-version = "0.3.9"
shadow-rs = { version = "0.25.0", default-features = false }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
bevy_dylib = "0.11"
Expand Down Expand Up @@ -134,6 +134,9 @@ opt-level = 3
codegen-units = 1 # Improved rapier physics perf, so it might help other stuff, too
lto = true

[build-dependencies]
shadow-rs = "0.25.0"

[package.metadata.cargo-machete]
ignored = [
"tracing", # Needed to add `release_max_level_debug` feature
Expand Down
3 changes: 3 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() -> shadow_rs::SdResult<()> {
shadow_rs::new()
}
27 changes: 26 additions & 1 deletion src/ui/main_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ mod credits;
mod map_select;
mod player_select;
mod settings;
use shadow_rs::shadow;

// Generate build info.
shadow!(build_info);

#[derive(HasSchema, Debug, Default, Clone)]
#[repr(C)]
Expand Down Expand Up @@ -75,6 +79,26 @@ pub enum MenuPage {
NetworkGame,
}

static VERSION_STRING: Lazy<String> = Lazy::new(|| {
format!(
"{}{}",
build_info::PKG_VERSION,
if !build_info::SHORT_COMMIT.is_empty() {
format!(
"-{}{}",
build_info::SHORT_COMMIT,
if build_info::GIT_CLEAN {
""
} else {
" (dirty)"
}
)
} else {
String::default()
}
)
});

fn main_menu_system(world: &World) {
let ctx = (*world.resource::<EguiCtx>()).clone();

Expand All @@ -96,8 +120,9 @@ fn main_menu_system(world: &World) {
ui.add_space(5.0);
ui.with_layout(egui::Layout::right_to_left(egui::Align::Max), |ui| {
ui.add_space(5.0);

ui.add(
egui::TextEdit::singleline(&mut git_version::git_version!())
egui::TextEdit::singleline(&mut VERSION_STRING.as_str())
.text_color(egui::Color32::WHITE)
.horizontal_align(egui::Align::Max),
);
Expand Down

0 comments on commit f1f0538

Please sign in to comment.