perf: faster builds, leaner daemon, smoother install/run (0.9.20)
Reuse libcstcore.a for tests with -MMD incremental deps; idle-backoff the parliament seat loop; defer curl init and cache settings; add systemd helper. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -134,8 +134,9 @@ OBJ = $(SRC:.c=.o)
|
||||
# the GUI links the same engine the CLI/TUI/WebUI run. No TUI, no main.
|
||||
CORE_OBJ = $(CORE_SRC:.c=.o)
|
||||
CST_CORE_LIB = libcstcore.a
|
||||
HDRS = $(wildcard include/*.h) $(wildcard src/tools/*.h) $(CJSON_DIR)/cJSON.h \
|
||||
.gen/models_builtin.inc .gen/web_assets.inc
|
||||
# Generated embeds; per-file .d files (from -MMD) track the rest.
|
||||
GEN_INCS = .gen/models_builtin.inc .gen/web_assets.inc
|
||||
DEPFILES = $(OBJ:.o=.d)
|
||||
|
||||
TESTS = \
|
||||
tests/test_ctl_frontier \
|
||||
@@ -193,33 +194,29 @@ TEST_LIBS = -L$(SD_DIR) -lsashidown $(CURL_LIBS) $(RPATH_LIBS) $(TEST_SYS_LIBS)
|
||||
# keeps them, so the small tests link the OS layer too.
|
||||
TEST_OS_SRC = src/os_compat.c src/os_win.c src/util.c
|
||||
|
||||
.PHONY: all clean check demo sashidown-lib FORCE cmake-gcc cmake-clang asan install uninstall
|
||||
.PHONY: all clean check demo sashidown-lib cmake-gcc cmake-clang asan install \
|
||||
uninstall install-service
|
||||
|
||||
all: sashidown-lib cst-agent $(CST_CORE_LIB)
|
||||
|
||||
$(CST_CORE_LIB): $(CORE_OBJ) FORCE
|
||||
$(CST_CORE_LIB): $(CORE_OBJ)
|
||||
rm -f $@
|
||||
$(AR) rcs $@ $(CORE_OBJ)
|
||||
|
||||
cmake-gcc:
|
||||
cmake -B build-gcc -DCMAKE_C_COMPILER=gcc -DCST_BUILD_TUI=ON
|
||||
cmake --build build-gcc
|
||||
ctest --test-dir build-gcc --output-on-failure
|
||||
cmake --build build-gcc -j
|
||||
ctest --test-dir build-gcc --output-on-failure -j
|
||||
|
||||
cmake-clang:
|
||||
cmake -B build-clang -DCMAKE_C_COMPILER=clang -DCST_BUILD_TUI=ON
|
||||
cmake --build build-clang
|
||||
cmake --build build-clang -j
|
||||
|
||||
sashidown-lib: $(SD_DIR)/libsashidown.a
|
||||
|
||||
# The sub-make decides whether the archive is stale; FORCE only makes sure it
|
||||
# is asked, and -j builds wait for it before linking.
|
||||
$(SD_DIR)/libsashidown.a: FORCE
|
||||
# Always ask the sub-make; it no-ops when libsashidown.a is current.
|
||||
sashidown-lib:
|
||||
$(MAKE) -C $(SD_DIR) libsashidown.a
|
||||
|
||||
FORCE:
|
||||
|
||||
cst-agent: $(OBJ) $(SD_DIR)/libsashidown.a
|
||||
cst-agent: $(OBJ) sashidown-lib
|
||||
$(CC) $(CFLAGS) -o $@ $(OBJ) $(LDFLAGS) $(LDLIBS)
|
||||
|
||||
# Built-in model data as a C byte list (included by model_registry.c).
|
||||
@@ -232,11 +229,15 @@ cst-agent: $(OBJ) $(SD_DIR)/libsashidown.a
|
||||
@mkdir -p .gen
|
||||
@sh scripts/embed_web.sh $@ $(WEB_DIR)
|
||||
|
||||
%.o: %.c $(HDRS)
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
|
||||
# Incremental rebuilds: -MMD tracks real includes instead of every header.
|
||||
COMPILE_C = $(CC) $(CFLAGS) $(CPPFLAGS) -MMD -MP -c -o $@ $<
|
||||
|
||||
src/tui.o: src/tui.c $(HDRS) $(SD_DIR)/include/sashidown.h
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
|
||||
%.o: %.c
|
||||
$(COMPILE_C)
|
||||
|
||||
src/model_registry.o: .gen/models_builtin.inc
|
||||
src/webui.o: .gen/web_assets.inc
|
||||
src/tui.o: $(SD_DIR)/include/sashidown.h
|
||||
|
||||
tests/test_ctl_frontier: tests/test_ctl_frontier.c src/ctl_parse.c include/ctl.h $(TEST_OS_SRC)
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ tests/test_ctl_frontier.c src/ctl_parse.c $(TEST_OS_SRC) $(TEST_SYS_LIBS)
|
||||
@@ -244,7 +245,7 @@ tests/test_ctl_frontier: tests/test_ctl_frontier.c src/ctl_parse.c include/ctl.h
|
||||
tests/test_ctl_heredoc: tests/test_ctl_heredoc.c src/ctl_parse.c include/ctl.h $(TEST_OS_SRC)
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ tests/test_ctl_heredoc.c src/ctl_parse.c $(TEST_OS_SRC) $(TEST_SYS_LIBS)
|
||||
|
||||
tests/test_json_baseline: tests/test_json_baseline.c src/json_baseline.c $(CJSON_DIR)/cJSON.c $(HDRS) $(TEST_OS_SRC)
|
||||
tests/test_json_baseline: tests/test_json_baseline.c src/json_baseline.c $(CJSON_DIR)/cJSON.c $(TEST_OS_SRC)
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ tests/test_json_baseline.c src/json_baseline.c $(CJSON_DIR)/cJSON.c $(TEST_OS_SRC) $(TEST_SYS_LIBS)
|
||||
|
||||
tests/test_replay_starvation: tests/test_replay_starvation.c src/ctl_parse.c src/json_baseline.c $(CJSON_DIR)/cJSON.c $(TEST_OS_SRC)
|
||||
@@ -265,32 +266,47 @@ tests/test_pdf_text: tests/test_pdf_text.c src/pdf_text.c include/cst_pdf.h $(TE
|
||||
tests/test_markdown: tests/test_markdown.c $(SD_DIR)/libsashidown.a
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ tests/test_markdown.c $(LDFLAGS) -lsashidown -lm
|
||||
|
||||
tests/test_%: tests/test_%.c $(CORE_SRC) $(HDRS)
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $< $(CORE_SRC) $(TEST_LIBS)
|
||||
# Core tests reuse libcstcore.a — avoid recompiling ~35 .c files per binary.
|
||||
# Do not depend on the phony sashidown-lib target or every test relinks each check.
|
||||
tests/test_%: tests/test_%.c $(CST_CORE_LIB) $(SD_DIR)/libsashidown.a
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $< $(CST_CORE_LIB) $(TEST_LIBS)
|
||||
|
||||
$(TESTS): sashidown-lib
|
||||
$(SD_DIR)/libsashidown.a: sashidown-lib
|
||||
|
||||
check: $(TESTS)
|
||||
# Build test binaries with make -j; run them one-by-one for readable logs.
|
||||
check: sashidown-lib $(TESTS)
|
||||
@set -e; for t in $(TESTS); do echo "== $$t"; ./$$t; done
|
||||
|
||||
# AddressSanitizer + UBSan build of the agent and all tests.
|
||||
# Under a ptrace-based sandbox (some Termux setups) LeakSanitizer aborts with
|
||||
# "Tracer caught signal 11"; add ASAN_OPTIONS=detect_leaks=0 there.
|
||||
# AddressSanitizer + UBSan rebuild (clears objects so sanitizer flags apply).
|
||||
asan:
|
||||
$(MAKE) clean
|
||||
$(MAKE) sashidown-lib
|
||||
$(MAKE) CFLAGS="-std=c11 -Wall -Wextra -O1 -g -fsanitize=address,undefined -fno-sanitize-recover=undefined -fno-omit-frame-pointer" cst-agent check
|
||||
$(MAKE) CFLAGS="-std=c11 -Wall -Wextra -O1 -g -fsanitize=address,undefined -fno-sanitize-recover=undefined -fno-omit-frame-pointer" \
|
||||
sashidown-lib cst-agent check
|
||||
|
||||
demo: cst-agent
|
||||
./cst-agent --demo-ctl --workspace .
|
||||
|
||||
clean:
|
||||
rm -f $(OBJ) cst-agent $(CST_CORE_LIB) $(TESTS) .gen/models_builtin.inc \
|
||||
.gen/web_assets.inc
|
||||
rm -f $(OBJ) $(DEPFILES) cst-agent $(CST_CORE_LIB) $(TESTS) \
|
||||
.gen/models_builtin.inc .gen/web_assets.inc
|
||||
|
||||
install: cst-agent
|
||||
install -d "$(DESTDIR)$(PREFIX)/bin"
|
||||
install -m 0755 cst-agent "$(DESTDIR)$(PREFIX)/bin/cst-agent"
|
||||
|
||||
# Optional systemd --user unit for the parliament seat service.
|
||||
install-service: install
|
||||
install -d "$(DESTDIR)$(HOME)/.config/systemd/user"
|
||||
sed -e 's|@BIN@|$(PREFIX)/bin/cst-agent|g' \
|
||||
scripts/cst-agent-parliament.service.in \
|
||||
> "$(DESTDIR)$(HOME)/.config/systemd/user/cst-agent-parliament.service"
|
||||
@echo "Installed user unit. Enable with:"
|
||||
@echo " systemctl --user daemon-reload"
|
||||
@echo " systemctl --user enable --now cst-agent-parliament.service"
|
||||
@echo "(set CST_REALM_PASSWORD / CST_INSTANCE_ID in the drop-in or environment)"
|
||||
|
||||
uninstall:
|
||||
rm -f "$(DESTDIR)$(PREFIX)/bin/cst-agent"
|
||||
rm -f "$(HOME)/.config/systemd/user/cst-agent-parliament.service"
|
||||
|
||||
-include $(DEPFILES)
|
||||
|
||||
Reference in New Issue
Block a user