Skip to content

Commit f1f0538

Browse files
orhunzicklag
andauthored
chore(build): use shadow-rs for build info (#891)
closes #890 --------- Co-authored-by: Zicklag <zicklag@katharostech.com>
1 parent fc7cfe7 commit f1f0538

4 files changed

Lines changed: 224 additions & 19 deletions

File tree

Cargo.lock

Lines changed: 191 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ serde_yaml = "0.9.25"
3535
thiserror = "1.0.48"
3636
peg = "0.8.1"
3737
egui_extras = { version = "0.23.0", default-features = false }
38-
git-version = "0.3.9"
38+
shadow-rs = { version = "0.25.0", default-features = false }
3939

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

137+
[build-dependencies]
138+
shadow-rs = "0.25.0"
139+
137140
[package.metadata.cargo-machete]
138141
ignored = [
139142
"tracing", # Needed to add `release_max_level_debug` feature

build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() -> shadow_rs::SdResult<()> {
2+
shadow_rs::new()
3+
}

src/ui/main_menu.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ mod credits;
66
mod map_select;
77
mod player_select;
88
mod settings;
9+
use shadow_rs::shadow;
10+
11+
// Generate build info.
12+
shadow!(build_info);
913

1014
#[derive(HasSchema, Debug, Default, Clone)]
1115
#[repr(C)]
@@ -75,6 +79,26 @@ pub enum MenuPage {
7579
NetworkGame,
7680
}
7781

82+
static VERSION_STRING: Lazy<String> = Lazy::new(|| {
83+
format!(
84+
"{}{}",
85+
build_info::PKG_VERSION,
86+
if !build_info::SHORT_COMMIT.is_empty() {
87+
format!(
88+
"-{}{}",
89+
build_info::SHORT_COMMIT,
90+
if build_info::GIT_CLEAN {
91+
""
92+
} else {
93+
" (dirty)"
94+
}
95+
)
96+
} else {
97+
String::default()
98+
}
99+
)
100+
});
101+
78102
fn main_menu_system(world: &World) {
79103
let ctx = (*world.resource::<EguiCtx>()).clone();
80104

@@ -96,8 +120,9 @@ fn main_menu_system(world: &World) {
96120
ui.add_space(5.0);
97121
ui.with_layout(egui::Layout::right_to_left(egui::Align::Max), |ui| {
98122
ui.add_space(5.0);
123+
99124
ui.add(
100-
egui::TextEdit::singleline(&mut git_version::git_version!())
125+
egui::TextEdit::singleline(&mut VERSION_STRING.as_str())
101126
.text_color(egui::Color32::WHITE)
102127
.horizontal_align(egui::Align::Max),
103128
);

0 commit comments

Comments
 (0)