Files
c-relay-pg/plans/prevent_direct_make_plan.md

2.9 KiB

Plan: Prevent Direct make Usage — Always Use build_static.sh

Problem

An agent ran make instead of ./build_static.sh, which produced a dynamically-linked binary with SQLite backend instead of the static PostgreSQL binary. This caused the production relay to silently fall back to SQLite while the admin UI connected to PostgreSQL.

Solution

Modify the Makefile so that the relay build targets refuse to run directly and instruct the user to use build_static.sh instead. The Makefile will still handle submodule builds (nostr_core_lib, c_utils_lib) and utility targets.

Changes

1. Makefile — Guard the relay build targets

Replace the all, $(TARGET), x86, and arm64 targets with guards that print an error and exit:

# Default target — refuse direct build, instruct to use build_static.sh
all:
	@echo "============================================"
	@echo "  ERROR: Do not run 'make' directly!"
	@echo ""
	@echo "  This project requires a static MUSL build"
	@echo "  with PostgreSQL backend. Run:"
	@echo ""
	@echo "    ./build_static.sh"
	@echo ""
	@echo "  Or use the full build+restart script:"
	@echo ""
	@echo "    ./make_and_restart_relay.sh"
	@echo ""
	@echo "  The Makefile is only for submodule builds"
	@echo "  (nostr_core_lib, c_utils_lib) and utility"
	@echo "  targets (clean, install-deps, etc.)."
	@echo "============================================"
	@exit 1

Keep the submodule build targets ($(NOSTR_CORE_LIB), $(C_UTILS_LIB)) and utility targets (clean, install-deps, install-arm64-deps, force-version) as-is since they're harmless and useful.

2. AGENTS.md — Reinforce the rule

Add a prominent section at the top of AGENTS.md:

## CRITICAL: Never Run `make` Directly

**NEVER run `make` to build the relay binary.** The Makefile will refuse and
print an error. Always use:

- `./build_static.sh` — Build the static MUSL binary with PostgreSQL backend
- `./make_and_restart_relay.sh` — Build, kill old relay, and start new one

The Makefile exists only for submodule compilation (nostr_core_lib, c_utils_lib)
and utility targets (clean, install-deps). Running `make` directly produces a
dynamically-linked binary that will silently fall back to SQLite storage while
the admin UI connects to PostgreSQL — causing the admin page to show stale data.

3. build_static.sh — Already updated

Already done in the previous round — removed --db-backend option, hardcoded PostgreSQL.

4. make_and_restart_relay.sh — Already updated

Already done in the previous round — removed --db-backend option, always calls ./build_static.sh.

Execution Order

  1. Update Makefile — guard all, $(TARGET), x86, arm64 targets
  2. Update AGENTS.md — add prominent warning section