From 57d242a8c961a2610528f88d924ba50b10e8f769 Mon Sep 17 00:00:00 2001 From: Michael Curtis Date: Sat, 14 Nov 2026 07:06:16 -0400 Subject: [PATCH 1/2] build: pin clang-format and the Mbed TLS Python in a make venv requirements-dev.txt pins clang-format==23.1.5 from PyPI, the same wheel on macOS and Linux, with jinja2 and jsonschema for inkwell's Mbed TLS generator. make venv installs them into build/venv; make debug points CMake's Python at it, and make format / the new format-check use its clang-format over one file list. CI's format job runs make format-check instead of apt's clang-format-18, whose layout moved with the runner image's point release (18.1.3 vs 18.1.8). Four files reformat under 23: the brace-initialiser macros in theme.c (the ones the two 18s disagreed about) and the pointer-to-array declarations. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 21 ++++++++------------- AGENTS.md | 4 +++- Makefile | 33 +++++++++++++++++++++++++++------ README.md | 2 +- requirements-dev.txt | 11 +++++++++++ src/fb/fb_draw.c | 4 ++-- src/theme/emoji_raster.c | 2 +- src/theme/theme.c | 36 +++++++++++++++++------------------- tests/suites/ui_shapes.c | 2 +- 9 files changed, 71 insertions(+), 44 deletions(-) create mode 100644 requirements-dev.txt diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e71ab3a..aed8830 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -164,20 +164,15 @@ jobs: format: name: clang-format - # Pinned, not ubuntu-latest: the formatter's output is the check, and it moves with the - # point release - 26.04's clang-format-18 (18.1.8) lays out tables that 24.04's (18.1.3) - # accepts differently, so an image bump fails files nobody touched. - runs-on: ubuntu-24.04 + # The formatter's output is the check, so it is pinned to the patch release in + # requirements-dev.txt and installed from PyPI by the Makefile - the same wheel a Mac formats + # with. apt's clang-format-18 moved with the runner image (24.04's 18.1.3 and 26.04's 18.1.8 + # lay tables out differently), which is why this job used to pin the image instead. + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Install clang-format - run: sudo apt-get update && sudo apt-get install -y clang-format-18 - - # The generated glyph tables are excluded for the reason they are in their own directory: - # 42k lines nobody wrote and nobody reads, and reformatting them would bury every real - # change in a diff the size of the repository. + # Through the Makefile, so the file list - which excludes the generated glyph tables, 42k + # lines nobody wrote and nobody reads - lives in exactly one place. - name: Check formatting - run: | - files=$(git ls-files '*.c' '*.h' | grep -v '^src/generated/') - clang-format-18 --dry-run --Werror $files + run: make format-check diff --git a/AGENTS.md b/AGENTS.md index b285c5d..72af753 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -38,7 +38,9 @@ scripts/kms-vm.py the KMS backend on QEMU's virtio-gpu, every frame ## Style -- clang-format 18, config in `.clang-format`. `make format` before pushing; CI checks it. +- clang-format, the exact version pinned in `requirements-dev.txt` (`make format` installs it into + `build/venv`; never format with whatever is on `PATH`), config in `.clang-format`. `make format` + before pushing; CI runs `make format-check`. `src/generated/` is excluded on purpose: reflowing megabytes of glyph tables is an unreadable diff. - `inkcell_` on everything public, `INKCELL_` on macros and enum members. A symbol carries the diff --git a/Makefile b/Makefile index b315990..9876571 100644 --- a/Makefile +++ b/Makefile @@ -3,12 +3,24 @@ BUILD ?= build -.PHONY: all test debug format clean gallery gallery-update +.PHONY: all venv test debug format format-check clean gallery gallery-update all: debug -debug: - cmake -S . -B $(BUILD) -G Ninja -DCMAKE_BUILD_TYPE=Debug +# The host tools in requirements-dev.txt - the Python inkwell's Mbed TLS generates its sources +# with, and the pinned clang-format - in a venv of their own, remade when that file changes. +VENV = $(BUILD)/venv +VENV_STAMP = $(VENV)/.installed + +venv: $(VENV_STAMP) +$(VENV_STAMP): requirements-dev.txt + python3 -m venv $(VENV) + $(VENV)/bin/pip install --quiet --disable-pip-version-check -r requirements-dev.txt + @touch $@ + +debug: $(VENV_STAMP) + cmake -S . -B $(BUILD) -G Ninja -DCMAKE_BUILD_TYPE=Debug \ + -DPython3_EXECUTABLE=$(abspath $(VENV))/bin/python3 cmake --build $(BUILD) # The verify step, and what CI runs: the unit suite plus the check that no renderer spells out @@ -46,9 +58,18 @@ gallery-update: debug # has ever run it over, is the one moment it did nothing. The CI check runs after the add and # caught it there instead, which is a round trip for something the author could have been told # locally. --others --exclude-standard is the untracked half, minus whatever .gitignore says. -format: - git ls-files --cached --others --exclude-standard '*.c' '*.h' \ - | grep -v '^src/generated/' | xargs clang-format -i +# +# `format-check` is what CI runs: the same list, changing nothing, failing on the first file that +# differs. The formatter is the one requirements-dev.txt pins, never whatever is on PATH. +FORMAT_FILES = $$(git ls-files --cached --others --exclude-standard '*.c' '*.h' \ + | grep -v '^src/generated/') +CLANG_FORMAT ?= $(VENV)/bin/clang-format + +format: $(VENV_STAMP) + $(CLANG_FORMAT) -i $(FORMAT_FILES) + +format-check: $(VENV_STAMP) + $(CLANG_FORMAT) --dry-run --Werror $(FORMAT_FILES) clean: rm -rf $(BUILD) diff --git a/README.md b/README.md index cccdaaf..b220955 100644 --- a/README.md +++ b/README.md @@ -222,7 +222,7 @@ forces the second on a machine that has the library. make test # debug build + ctest: the unit suite, the no-prose check, the golden sheet make debug # build only make gallery # the pictures (see above) -make format # clang-format, skipping the generated glyph tables +make format # the pinned clang-format, skipping the generated glyph tables ``` Sanitizers: `cmake -S . -B build -DINKCELL_ENABLE_ASAN=ON -DINKCELL_ENABLE_UBSAN=ON`. CI runs diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..971985d --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,11 @@ +# Host tools for this repo, installed into build/venv by `make venv` (the targets that need them +# make it first). jinja2 and jsonschema are what Mbed TLS generates its sources with. +# +# clang-format is pinned to the patch release because its output *is* the format check: two +# "clang-format 18"s (Ubuntu 24.04's 18.1.3 and 26.04's 18.1.8) lay the same table out +# differently, and Homebrew's is whatever is newest. This wheel is the same formatter on macOS and +# Linux, so `make format` on a laptop and `make format-check` in CI agree by construction. Bumping +# it is one line here plus one `make format` commit. +jinja2 +jsonschema +clang-format==23.1.5 diff --git a/src/fb/fb_draw.c b/src/fb/fb_draw.c index d0d0884..3807670 100644 --- a/src/fb/fb_draw.c +++ b/src/fb/fb_draw.c @@ -2257,7 +2257,7 @@ void inkcell_fb_draw_emoji_box(const struct inkcell_draw_state *state, int x, in if (!inkcell_fb_clip_box(state, x, top + first, drawn, rows, &clip)) { continue; } - uint8_t(*pixels)[4] = band; + uint8_t (*pixels)[4] = band; #if INKCELL_EMOJI_CACHE_SLOTS > 0 if (drawn <= INKCELL_EMOJI_BAND) { pixels = inkcell_fb_emoji_cached(sprite, drawn); @@ -2282,7 +2282,7 @@ void inkcell_fb_draw_emoji_box(const struct inkcell_draw_state *state, int x, in state->surface.size) { continue; } - uint8_t(*from)[4] = &pixels[(size_t)row * (size_t)drawn + (size_t)span.dx]; + uint8_t (*from)[4] = &pixels[(size_t)row * (size_t)drawn + (size_t)span.dx]; for (int i = 0; i < span.w; ++i, out += bpp) { /* The margin is a good share of every emoji, and a pixel with no opacity has nothing to add - premultiplied, it is all zero. */ diff --git a/src/theme/emoji_raster.c b/src/theme/emoji_raster.c index 9b99947..5a00c1f 100644 --- a/src/theme/emoji_raster.c +++ b/src/theme/emoji_raster.c @@ -376,7 +376,7 @@ static bool raster_path(struct raster *r, const uint8_t *at, const uint8_t *end, static void raster_composite(struct raster *r, const uint8_t rgba[4], uint8_t (*out)[4]) { for (int row = r->top_row; row <= r->bottom_row; ++row) { int32_t *acc = g_acc[row]; - uint8_t(*px)[4] = &out[(size_t)row * (size_t)r->width]; + uint8_t (*px)[4] = &out[(size_t)row * (size_t)r->width]; int32_t sum = 0; for (int x = 0; x < r->width; ++x) { sum += acc[x]; diff --git a/src/theme/theme.c b/src/theme/theme.c index 0a9dd47..2e160ad 100644 --- a/src/theme/theme.c +++ b/src/theme/theme.c @@ -41,8 +41,7 @@ #include #include -#define RGB(rr, gg, bb) \ - { .r = (rr), .g = (gg), .b = (bb) } +#define RGB(rr, gg, bb) {.r = (rr), .g = (gg), .b = (bb)} /* * The metrics the Brick's panel was tuned for. A theme that wants a different look overrides @@ -95,18 +94,19 @@ */ #define INKCELL_SHADOWS_LIGHT \ { \ - [INKCELL_ELEVATION_FLAT] = {0U, 0U, 0U}, [INKCELL_ELEVATION_RAISED] = {1U, 3U, 16U}, \ - [INKCELL_ELEVATION_FLOATING] = {2U, 5U, 22U}, [INKCELL_ELEVATION_MODAL] = {3U, 8U, 28U}, \ + [INKCELL_ELEVATION_FLAT] = {0U, 0U, 0U}, \ + [INKCELL_ELEVATION_RAISED] = {1U, 3U, 16U}, \ + [INKCELL_ELEVATION_FLOATING] = {2U, 5U, 22U}, \ + [INKCELL_ELEVATION_MODAL] = {3U, 8U, 28U}, \ } #define INKCELL_SHADOWS_DARK \ { \ - [INKCELL_ELEVATION_FLAT] = {0U, 0U, 0U}, [INKCELL_ELEVATION_RAISED] = {1U, 3U, 40U}, \ - [INKCELL_ELEVATION_FLOATING] = {2U, 5U, 50U}, [INKCELL_ELEVATION_MODAL] = {3U, 8U, 60U}, \ - } -#define INKCELL_SHADOWS_NONE \ - { \ - { 0U, 0U, 0U } \ + [INKCELL_ELEVATION_FLAT] = {0U, 0U, 0U}, \ + [INKCELL_ELEVATION_RAISED] = {1U, 3U, 40U}, \ + [INKCELL_ELEVATION_FLOATING] = {2U, 5U, 50U}, \ + [INKCELL_ELEVATION_MODAL] = {3U, 8U, 60U}, \ } +#define INKCELL_SHADOWS_NONE {{0U, 0U, 0U}} /* * The scrim and the shadows are taken as parameters rather than restated in the table, so a @@ -142,12 +142,12 @@ .tracking = INKCELL_SCALE(1) / 2, \ .line_pct = 100U, \ .tabular = true}, \ - }, \ + }, \ .space = \ { \ [INKCELL_SPACE_NONE] = 0U, [INKCELL_SPACE_XS] = 1U, [INKCELL_SPACE_SM] = 2U, \ [INKCELL_SPACE_MD] = 4U, [INKCELL_SPACE_LG] = 6U, \ - }, \ + }, \ .field_label_cols = 20U, .narrow_cols = 40U, .card_pad = 2U, .meter_thickness = 1U, \ .motion_ms = \ { \ @@ -155,29 +155,27 @@ [INKCELL_MOTION_MEDIUM] = 220U, \ [INKCELL_MOTION_LONG] = 320U, \ [INKCELL_MOTION_LOOP] = 1400U, \ - }, \ + }, \ .shape = \ { \ [INKCELL_SHAPE_NONE] = 0U, \ [INKCELL_SHAPE_SM] = 2U, \ [INKCELL_SHAPE_MD] = 3U, \ [INKCELL_SHAPE_LG] = 4U, \ - }, \ + }, \ .opacity = \ { \ [INKCELL_OPACITY_HOVER] = 8U, [INKCELL_OPACITY_FOCUS] = 12U, \ [INKCELL_OPACITY_PRESS] = 20U, [INKCELL_OPACITY_DISABLED] = 38U, \ [INKCELL_OPACITY_SCRIM] = (scrim), \ - }, \ + }, \ .shadow = shadows /* The default metrics: Material's 32% scrim, which is the figure every platform has converged on - enough that the eye stops reading the body, little enough that it can still see what the question is about, and a palette that needs more says so. */ -#define INKCELL_METRICS_DARK \ - { INKCELL_METRICS_FIELDS(32U, INKCELL_SHADOWS_DARK) } -#define INKCELL_METRICS_LIGHT \ - { INKCELL_METRICS_FIELDS(32U, INKCELL_SHADOWS_LIGHT) } +#define INKCELL_METRICS_DARK {INKCELL_METRICS_FIELDS(32U, INKCELL_SHADOWS_DARK)} +#define INKCELL_METRICS_LIGHT {INKCELL_METRICS_FIELDS(32U, INKCELL_SHADOWS_LIGHT)} static const struct inkcell_theme k_themes[] = diff --git a/tests/suites/ui_shapes.c b/tests/suites/ui_shapes.c index edb5318..66f6026 100644 --- a/tests/suites/ui_shapes.c +++ b/tests/suites/ui_shapes.c @@ -511,7 +511,7 @@ INKCELL_TEST_CASE(emoji_enlarged_stays_sharp, unit) { const int rows = box < INKCELL_EMOJI_BAND ? box : INKCELL_EMOJI_BAND; INKCELL_TEST_FAIL_IF(inkcell_emoji_render(sprite, box, first, rows, band) != 0, "the grinning face should render"); - uint8_t(*middle)[4] = &band[(size_t)(box / 2 - first) * (size_t)box]; + uint8_t (*middle)[4] = &band[(size_t)(box / 2 - first) * (size_t)box]; int ramp = 0; for (int x = 0; x < box / 2 && middle[x][3] < 255U; ++x) { ramp += middle[x][3] > 0U; From 4653c61c15d73ae5a8809a95d8e88be341cfdf7a Mon Sep 17 00:00:00 2001 From: Michael Curtis Date: Sat, 14 Nov 2026 07:06:16 -0400 Subject: [PATCH 2/2] chore(inkwell): bump to the clean build (inkwell#73) 46 commits forward, to the inkwell that builds without warnings and pins the same clang-format. Co-Authored-By: Claude Opus 5.5 --- third_party/inkwell | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/inkwell b/third_party/inkwell index effcd55..112ef41 160000 --- a/third_party/inkwell +++ b/third_party/inkwell @@ -1 +1 @@ -Subproject commit effcd55f83007b6cc4861e2aa08d0676a4c0d060 +Subproject commit 112ef41fa5114500aa66cba4476f37f3ab9b75e6