Skip to content

Commit

Permalink
feat(egui,buildrs): reworks buildrs to remove dep from irox_egui_extras
Browse files Browse the repository at this point in the history
  • Loading branch information
spmadden committed Feb 8, 2025
1 parent 3f60129 commit c419ac5
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 56 deletions.
19 changes: 3 additions & 16 deletions libraries/build-rs/src/git.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
// Copyright 2023 IROX Contributors
// Copyright 2025 IROX Contributors
//

use crate::{BuildEnvironment, BuildVariable, Error, VariableSource, VariableType};
Expand Down Expand Up @@ -46,19 +46,6 @@ macro_rules! add_bool_varbl {
};
}

macro_rules! add_int_varbl {
($name:literal, $env:ident, $val:ident) => {
$env.variables.insert(
$name.to_string(),
BuildVariable {
source: VariableSource::Git,
name: $name.to_string(),
value: VariableType::Integer($val),
},
);
};
}

#[cfg(feature = "git")]
pub fn load_git_variables(env: &mut BuildEnvironment) -> Result<(), Error> {
let start_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap_or_default();
Expand Down Expand Up @@ -91,8 +78,8 @@ pub fn load_git_variables(env: &mut BuildEnvironment) -> Result<(), Error> {
let when = author.when();
let seconds = when.seconds();
let offset_seconds = when.offset_minutes() as i64 * 60;
add_int_varbl!("GIT_COMMIT_TIMESTAMP_SECS", env, seconds);
add_int_varbl!("GIT_COMMIT_TZ_OFFSET_SECS", env, offset_seconds);
add_str_varbl!("GIT_COMMIT_TIMESTAMP_SECS", env, seconds);
add_str_varbl!("GIT_COMMIT_TZ_OFFSET_SECS", env, offset_seconds);

let time = irox_time::epoch::UnixTimestamp::from_offset(Duration::from_seconds(seconds as u64));
let time = Into::<UTCDateTime>::into(time).format(&EXTENDED_DATE_TIME_FORMAT);
Expand Down
60 changes: 52 additions & 8 deletions libraries/build-rs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: MIT
// Copyright 2023 IROX Contributors
// Copyright 2025 IROX Contributors
//

//!
//! Compile-time build metadata injection inspired by `shadow-rs`
Expand Down Expand Up @@ -36,14 +37,26 @@ pub enum VariableSource {
pub enum VariableType {
String(String),
Bool(bool),
Integer(i64),
}
impl Display for VariableType {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
VariableType::String(s) => write!(f, "{s}"),
VariableType::Bool(b) => write!(f, "{b}"),
VariableType::Integer(i) => write!(f, "{i}"),
}
}
}
impl VariableType {
pub fn as_str(&self) -> &str {
match self {
VariableType::String(s) => s.as_str(),
VariableType::Bool(b) => {
if *b {
"true"
} else {
"false"
}
}
}
}
}
Expand All @@ -52,6 +65,42 @@ impl Display for VariableType {
pub struct BuildEnvironment {
pub(crate) variables: BTreeMap<String, BuildVariable>,
}
impl BuildEnvironment {
pub fn as_parsed_environment(&self) -> ParsedBuildVariables {
let mut out = ParsedBuildVariables::default();
for (k, v) in &self.variables {
let v = v.value.as_str();
if cargo::CARGO_ENV_VARIABLES.contains(&k.as_str()) {
out.cargo_items.insert(k, v);
out.grouped.entry("CARGO_ITEMS").or_default().insert(k, v);
} else if cargo::RUSTC_ENV_VARIABLES.contains(&k.as_str()) {
out.rustc_items.insert(k, v);
out.grouped.entry("RUSTC_ITEMS").or_default().insert(k, v);
} else if cargo::BUILD_HOST_VARIABLES.contains(&k.as_str()) {
out.build_host.insert(k, v);
out.grouped.entry("BUILD_HOST").or_default().insert(k, v);
} else {
#[cfg(feature = "git")]
if git::GIT_VARIABLES.contains(&k.as_str()) {
out.git_items.insert(k, v);
out.grouped.entry("GIT_ITEMS").or_default().insert(k, v);
}
}
out.all_items.insert(k, v);
}
out
}
}
#[derive(Default, Debug, Clone, Eq, PartialEq)]
pub struct ParsedBuildVariables<'a> {
pub all_items: BTreeMap<&'a str, &'a str>,
pub cargo_items: BTreeMap<&'a str, &'a str>,
pub rustc_items: BTreeMap<&'a str, &'a str>,
pub build_host: BTreeMap<&'a str, &'a str>,
pub git_items: BTreeMap<&'a str, &'a str>,

pub grouped: BTreeMap<&'a str, BTreeMap<&'a str, &'a str>>,
}

#[derive(Debug, Clone, Eq, PartialEq)]
pub struct BuildVariable {
Expand Down Expand Up @@ -231,9 +280,6 @@ pub fn write_environment<T: Write>(
VariableType::Bool(val) => {
writeln!(dest_file, "pub const {name}: bool = {val};")?;
}
VariableType::Integer(val) => {
writeln!(dest_file, "pub const {name}: i64 = {val};")?;
}
}
}

Expand Down Expand Up @@ -331,7 +377,6 @@ fn write_aggregation_block<T: Write>(
match varbl.value {
VariableType::String(_) => writeln!(dest_file, "\t\t(\"{name}\", {name}),")?,
VariableType::Bool(b) => writeln!(dest_file, "\t\t(\"{name}\", \"{b}\"),")?,
VariableType::Integer(i) => writeln!(dest_file, "\t\t(\"{name}\", \"{i}\"),")?,
}
}
writeln!(dest_file, "\t]))")?;
Expand Down Expand Up @@ -366,7 +411,6 @@ fn write_grouped_block<T: Write>(
match varbl.value {
VariableType::String(_) => writeln!(dest_file, "\t\t\t(\"{name}\", {name}),")?,
VariableType::Bool(b) => writeln!(dest_file, "\t\t\t(\"{name}\", \"{b}\"),")?,
VariableType::Integer(i) => writeln!(dest_file, "\t\t\t(\"{name}\", \"{i}\"),")?,
}
}
writeln!(dest_file, "\t\t])),")?;
Expand Down
12 changes: 5 additions & 7 deletions libraries/egui_extras/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ docsrs = ["eframe/x11", "eframe/wayland"]

[dependencies]
egui.workspace = true
eframe = { workspace = true, features = [] }
eframe = { workspace = true, default-features = false, features = [] }
ron.workspace = true
serde = { workspace = true, optional = true }
irox-bits = { workspace = true, optional = true, features = ["alloc"] }
Expand All @@ -39,16 +39,17 @@ profiling = { workspace = true, optional = true }
puffin = { workspace = true, optional = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
eframe = { workspace = true, features = ["wgpu"] }
eframe = { workspace = true, default-features = false, features = ["wgpu"] }
wasm-bindgen-futures.workspace = true

[dev-dependencies]
eframe = { workspace = true, features = ["glow", "default_fonts"] }
egui = { workspace = true, features = ["rayon"] }
eframe = { workspace = true, default-features = false, features = ["glow", "default_fonts"] }
egui = { workspace = true, default-features = false, features = ["rayon"] }
irox-time = { workspace = true, features = ["std"] }
irox-tools = { workspace = true, features = ["std"] }
puffin_http = { workspace = true }
irox-csv = { workspace = true }
irox-build-rs = { workspace = true, features = ["git"] }

[target.'cfg(target_os = "linux")'.dev-dependencies]
eframe = { workspace = true, features = ["x11", "wayland"] }
Expand All @@ -61,9 +62,6 @@ required-features = ["serde", "plots"]
name = "plotsperf"
required-features = ["plots"]

[build-dependencies]
irox-build-rs.workspace = true

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
11 changes: 0 additions & 11 deletions libraries/egui_extras/build.rs

This file was deleted.

15 changes: 11 additions & 4 deletions libraries/egui_extras/examples/irox_egui_gallery.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
// Copyright 2023 IROX Contributors
// Copyright 2025 IROX Contributors
//

use std::collections::BTreeMap;
Expand All @@ -9,16 +9,22 @@ use std::sync::Arc;
use eframe::emath::Align;
use eframe::{App, CreationContext, Frame};
use egui::{CentralPanel, Context, Layout, Pos2, Shape, Vec2, ViewportBuilder, Window};
use irox_build_rs::BuildEnvironment;
use irox_egui_extras::about::AboutWindow;
use irox_egui_extras::logplot::{BasicPlot, IntoColor32, PlotPoint};
use irox_egui_extras::progressbar::ProgressBar;
use irox_egui_extras::serde::EguiSerializer;
use irox_egui_extras::toolframe::{ToolApp, ToolFrame};
use irox_egui_extras::visuals::VisualsWindow;
use irox_imagery::Color;
use irox_tools::static_init;
use log::error;
use serde::Serialize;

static_init!(get_env, BuildEnvironment, {
irox_build_rs::generate_build_environment().unwrap_or_default()
});

pub fn main() {
let viewport = ViewportBuilder::default().with_inner_size(Vec2::new(1024., 800.));

Expand Down Expand Up @@ -205,15 +211,16 @@ impl App for TestApp {
ui.radio_value(&mut self.about_tabs, AboutTabs::Grouped, "Grouped");
ui.radio_value(&mut self.about_tabs, AboutTabs::All, "All");
});
let pe = get_env().as_parsed_environment();
match self.about_tabs {
AboutTabs::Important => {
AboutWindow::show_important(irox_egui_extras::build::get_ALL_ITEMS, ui);
AboutWindow::show_important(|| &pe.all_items, ui);
}
AboutTabs::Grouped => {
AboutWindow::show_grouped(irox_egui_extras::build::get_GROUPS, ui);
AboutWindow::show_grouped(|| &pe.grouped, ui);
}
AboutTabs::All => {
AboutWindow::show(irox_egui_extras::build::get_ALL_ITEMS, ui);
AboutWindow::show(|| &pe.all_items, ui);
}
}
});
Expand Down
9 changes: 4 additions & 5 deletions libraries/egui_extras/src/about.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
// Copyright 2023 IROX Contributors
// Copyright 2025 IROX Contributors
//

use egui::Ui;
Expand Down Expand Up @@ -85,10 +85,9 @@ impl AboutWindow {
}

pub fn show_grouped<
F: Fn() -> &'static std::collections::BTreeMap<
&'static str,
std::collections::BTreeMap<&'static str, &'static str>,
>,
'a,
F: Fn()
-> &'a std::collections::BTreeMap<&'a str, std::collections::BTreeMap<&'a str, &'a str>>,
>(
providerfn: F,
ui: &mut Ui,
Expand Down
7 changes: 2 additions & 5 deletions libraries/egui_extras/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: MIT
// Copyright 2023 IROX Contributors
// Copyright 2025 IROX Contributors
//

//!
//! Stuff that should have been in [`egui`], but isn't.
Expand Down Expand Up @@ -40,10 +41,6 @@ pub mod serde;
pub mod toolframe;
pub mod visuals;

pub mod build {
include!(concat!(env!("OUT_DIR"), "/builders.rs"));
}

pub trait WithAlpha {
#[must_use]
fn with_alpha(self, alpha: u8) -> Self;
Expand Down

0 comments on commit c419ac5

Please # to comment.