Skip to content

Commit d08642c

Browse files
committed
ref(opt): compile out Clay's unused debug-tools UI
Clay's debug inspector (Clay__RenderDebugView, ~700 lines + ~150 UI strings) is reachable from the exported Clay_EndLayout behind a runtime debugModeEnabled branch, so --gc-sections can't drop it; at -O2 clang inlines it into the layout monolith. clayterm never enables debug mode, so it's dead weight. Adds an upstream-compatible CLAY_DISABLE_DEBUG_TOOLS guard (patches/clay-disable-debug-tools.patch) applied to the clay submodule at build time and opted in via -DCLAY_DISABLE_DEBUG_TOOLS. raw wasm 155,934 -> 111,234 (-28.7%); brotli 41,809 -> 30,417; npm esm/wasm.js 53,143 -> 38,903 (-13.9 KB unpacked). Cold path only (debugModeEnabled always false at runtime); deno task test passes.
1 parent 48ff4bb commit d08642c

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
CC = clang
22
TARGET = clayterm.wasm
33
SRC = src/module.c
4+
CLAY_PATCH = patches/clay-disable-debug-tools.patch
45

56
CFLAGS = --target=wasm32 -nostdlib -O2 \
67
-ffunction-sections -fdata-sections \
78
-mbulk-memory \
89
-DCLAY_IMPLEMENTATION -DCLAY_WASM \
10+
-DCLAY_DISABLE_DEBUG_TOOLS \
911
-Isrc -I.
1012

1113
EXPORTS = \
@@ -46,13 +48,20 @@ all: $(TARGET) wasm.ts
4648

4749
DEPS = $(wildcard src/*.c src/*.h)
4850

49-
$(TARGET): $(DEPS)
51+
# Gate out Clay's unused debug-tools UI (upstream-compatible #ifndef guards),
52+
# opted in via -DCLAY_DISABLE_DEBUG_TOOLS. Idempotent (skips if the guard is
53+
# already present) and verified (fails the build if it didn't apply).
54+
# Drop once Clay ships the flag upstream.
55+
$(TARGET): $(DEPS) $(CLAY_PATCH)
56+
@grep -q CLAY_DISABLE_DEBUG_TOOLS clay/clay.h || git -C clay apply ../$(CLAY_PATCH)
57+
@grep -q CLAY_DISABLE_DEBUG_TOOLS clay/clay.h || { echo "ERROR: failed to apply $(CLAY_PATCH) to clay/clay.h" >&2; exit 1; }
5058
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(SRC)
5159

5260
wasm.ts: $(TARGET)
5361
deno run --allow-read --allow-write tasks/bundle-wasm.ts
5462

5563
clean:
5664
rm -f $(TARGET) wasm.ts
65+
-git -C clay checkout -- clay.h
5766

5867
.PHONY: all clean
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
diff --git a/clay.h b/clay.h
2+
index 80d8393..8bf723b 100644
3+
--- a/clay.h
4+
+++ b/clay.h
5+
@@ -3145,6 +3145,7 @@ CLAY_DLL_EXPORT Clay_ElementIdArray Clay_GetPointerOverIds(void) {
6+
return Clay_GetCurrentContext()->pointerOverIds;
7+
}
8+
9+
+#ifndef CLAY_DISABLE_DEBUG_TOOLS
10+
#pragma region DebugTools
11+
Clay_Color CLAY__DEBUGVIEW_COLOR_1 = {58, 56, 52, 255};
12+
Clay_Color CLAY__DEBUGVIEW_COLOR_2 = {62, 60, 58, 255};
13+
@@ -3842,6 +3843,7 @@ void Clay__RenderDebugView(void) {
14+
}
15+
}
16+
#pragma endregion
17+
+#endif // CLAY_DISABLE_DEBUG_TOOLS
18+
19+
uint32_t Clay__debugViewWidth = 400;
20+
Clay_Color Clay__debugViewHighlightColor = { 168, 66, 28, 100 };
21+
@@ -4237,11 +4239,13 @@ Clay_RenderCommandArray Clay_EndLayout(void) {
22+
Clay_Context* context = Clay_GetCurrentContext();
23+
Clay__CloseElement();
24+
bool elementsExceededBeforeDebugView = context->booleanWarnings.maxElementsExceeded;
25+
+#ifndef CLAY_DISABLE_DEBUG_TOOLS
26+
if (context->debugModeEnabled && !elementsExceededBeforeDebugView) {
27+
context->warningsEnabled = false;
28+
Clay__RenderDebugView();
29+
context->warningsEnabled = true;
30+
}
31+
+#endif // CLAY_DISABLE_DEBUG_TOOLS
32+
if (context->booleanWarnings.maxElementsExceeded) {
33+
Clay_String message;
34+
if (!elementsExceededBeforeDebugView) {

0 commit comments

Comments
 (0)