Skip to content

Commit

Permalink
Store fonts as binary files (#28)
Browse files Browse the repository at this point in the history
* Add fonts as binaries
* Rework generate_fonts_file to generate binary files
* Fix CI again
* Minimize binary size in examples
  • Loading branch information
Finomnis authored Dec 11, 2024
1 parent 3cfd508 commit 7da352b
Show file tree
Hide file tree
Showing 1,951 changed files with 2,020 additions and 9,784 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ jobs:
uses: actions/checkout@v3

- name: Install libsdl2-dev
run: sudo apt-get install -y libsdl2-dev
run: sudo apt-get update && sudo apt-get install -y libsdl2-dev

#- uses: Swatinem/rust-cache@v1

Expand Down Expand Up @@ -213,8 +213,11 @@ jobs:

#- uses: Swatinem/rust-cache@v1

- name: Regenerate and check
run: ./regenerate_fonts_file.sh --check --hide-progress
- name: Regenerate fonts
run: ./regenerate_fonts_file.sh --hide-progress

- name: Check for diffs
run: git status && test -z "$(git status --porcelain)"

msrv:
name: Minimum Supported Rust Version
Expand Down
6 changes: 6 additions & 0 deletions examples/simulator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ u8g2-fonts = { path = "../..", features = [
embedded-graphics = "0.8.0"
embedded-graphics-simulator = "0.5.0"
anyhow = "1.0.71"

[profile.release]
strip = true # Automatically strip symbols from the binary.
lto = true
codegen-units = 1

2 changes: 1 addition & 1 deletion regenerate_fonts_file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ set -eu
SCRIPTPATH=$( cd "$(dirname "$(readlink -f "$0")")" || exit 1 ; pwd -P )
cd "$SCRIPTPATH/tools/generate_fonts_file"

cargo run --release -- "$@" "$SCRIPTPATH/u8g2/csrc/u8g2_fonts.c" "$SCRIPTPATH/src/fonts.rs"
cargo run --release -- "$@" "$SCRIPTPATH/u8g2/csrc/u8g2_fonts.c" "$SCRIPTPATH/src/fonts"
13 changes: 13 additions & 0 deletions src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,16 @@ pub trait Font {
#[doc(hidden)]
const DATA: &'static [u8];
}

macro_rules! font_definitions {
( $($fontname:ident),* $(,)? ) => {
$(
pub struct $fontname;
impl $crate::Font for $fontname {
const DATA: &'static [u8] = include_bytes!(concat!(stringify!($fontname), ".u8g2font"));
}
)*
};
}

pub(crate) use font_definitions;
9,711 changes: 0 additions & 9,711 deletions src/fonts.rs

This file was deleted.

Loading

0 comments on commit 7da352b

Please sign in to comment.