Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
CC = clang
TARGET = clayterm.wasm
SRC = src/module.c
CLAY_PATCH = patches/clay-disable-debug-tools.patch

CFLAGS = --target=wasm32 -nostdlib -O2 \
-ffunction-sections -fdata-sections \
-mbulk-memory \
-DCLAY_IMPLEMENTATION -DCLAY_WASM \
-DCLAY_DISABLE_DEBUG_TOOLS \
-Isrc -I.

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

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

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

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

clean:
rm -f $(TARGET) wasm.ts
-git -C clay checkout -- clay.h

.PHONY: all clean
34 changes: 34 additions & 0 deletions patches/clay-disable-debug-tools.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
diff --git a/clay.h b/clay.h
index 80d8393..8bf723b 100644
--- a/clay.h
+++ b/clay.h
@@ -3145,6 +3145,7 @@ CLAY_DLL_EXPORT Clay_ElementIdArray Clay_GetPointerOverIds(void) {
return Clay_GetCurrentContext()->pointerOverIds;
}

+#ifndef CLAY_DISABLE_DEBUG_TOOLS
#pragma region DebugTools
Clay_Color CLAY__DEBUGVIEW_COLOR_1 = {58, 56, 52, 255};
Clay_Color CLAY__DEBUGVIEW_COLOR_2 = {62, 60, 58, 255};
@@ -3842,6 +3843,7 @@ void Clay__RenderDebugView(void) {
}
}
#pragma endregion
+#endif // CLAY_DISABLE_DEBUG_TOOLS

uint32_t Clay__debugViewWidth = 400;
Clay_Color Clay__debugViewHighlightColor = { 168, 66, 28, 100 };
@@ -4237,11 +4239,13 @@ Clay_RenderCommandArray Clay_EndLayout(void) {
Clay_Context* context = Clay_GetCurrentContext();
Clay__CloseElement();
bool elementsExceededBeforeDebugView = context->booleanWarnings.maxElementsExceeded;
+#ifndef CLAY_DISABLE_DEBUG_TOOLS
if (context->debugModeEnabled && !elementsExceededBeforeDebugView) {
context->warningsEnabled = false;
Clay__RenderDebugView();
context->warningsEnabled = true;
}
+#endif // CLAY_DISABLE_DEBUG_TOOLS
if (context->booleanWarnings.maxElementsExceeded) {
Clay_String message;
if (!elementsExceededBeforeDebugView) {
Loading