build: build jerboa-aws with installed jerbuild (no ~/mine/jerboa dependency)

ober

ba1f3a0c648b0b248d42777f89729ee7ea01f64b

diff --git a/.gitignore b/.gitignore
index 0abee24..435ffcf 100644
--- a/.gitignore
+++ b/.gitignore
@@ -23,3 +23,4 @@
 
 .claude/
 .DS_Store
+support/ffi-symbols.gen
diff --git a/.jerbuild b/.jerbuild
index e17a594..604f3b2 100644
--- a/.jerbuild
+++ b/.jerbuild
@@ -1,9 +1,17 @@
-;; Build jerboa-aws with a standalone jerbuild binary.
+;; Build jerboa-aws with a standalone jerbuild binary: `jerbuild build`.
+;;
+;; jerbuild bundles Chez Scheme + the jerboa stdlib + the jerboa-native Rust
+;; crate, so this needs only jerbuild + a C compiler + cargo — no jerboa source
+;; checkout. jerboa-native provides Rustls HTTPS (tls + crypto).
 
 (entry "aws.ss")
 (output "jerboa-aws")
-(requires "cc" "cargo")
-(notes "Uses the jerbuild-bundled jerboa-native-rs crate for Rustls HTTPS.")
 (libdirs "lib")
+;; Register the linked-in jerboa-native symbols (regenerated per-platform by
+;; the Makefile). No JERBOA_STATIC: the std net module loads libc for socket()
+;; normally, and the default main.c registers these symbols.
+(ffi-symbols "support/ffi-symbols.gen")
 (rust-crates
-  ("@bundle/jerboa-native-rs/Cargo.toml" features: "tls"))
+  ("@bundle/jerboa-native-rs/Cargo.toml"
+   features: "tls,crypto"
+   no-default-features: #t))
diff --git a/Makefile b/Makefile
index 812b30b..347e32e 100644
--- a/Makefile
+++ b/Makefile
@@ -1,114 +1,45 @@
-JERBOA_HOME ?= $(HOME)/mine/jerboa
-SCHEME ?= $(JERBOA_HOME)/.chez/bin/scheme
-JERBOA ?= $(JERBOA_HOME)/lib
-GHERKIN ?= $(HOME)/mine/gherkin/src
-JERBOAHTTPS ?= $(HOME)/mine/jerboa-https/src
-JERBOASSL ?= $(HOME)/mine/jerboa-ssl/src
-LIBDIRS = lib:$(JERBOA):$(GHERKIN):$(JERBOAHTTPS):$(JERBOASSL)
-COMPILE = $(SCHEME) -q --libdirs $(LIBDIRS) --compile-imported-libraries
-
-# Cross-compile uses libdirs minus gherkin (unused by jerboa-aws code).
-XC_LIBDIRS = lib:$(JERBOA):$(JERBOAHTTPS):$(JERBOASSL)
-MUSL_OPENSSL_DIR ?= $(HOME)/musl-openssl
-FREEBSD_SYSROOT  ?= $(HOME)/freebsd-sysroot
-
-.PHONY: all compile binary build run run-pssm clean help test pssm \
-        linux linux-amd64 freebsd freebsd-amd64 \
-        jerboa-aws-linux-amd64 jerboa-aws-freebsd-amd64
-
-all: compile
-
-compile:
-	@echo "=== Compiling .sls → .so ==="
-	$(COMPILE) < build-all.ss
+# jerbuild bundles Chez Scheme + the jerboa stdlib + the jerboa-native Rust
+# crate, so building jerboa-aws needs only jerbuild + a C compiler + cargo —
+# no jerboa source checkout. jerboa-native provides Rustls HTTPS (tls,crypto).
+JERBUILD ?= jerbuild
+JH := $(shell $(JERBUILD) --jerboa-home 2>/dev/null)
+ifeq ($(JH),)
+$(error jerbuild not found on PATH (or '$(JERBUILD) --jerboa-home' failed). Install jerbuild, or set JERBUILD=/path/to/jerbuild)
+endif
+
+NATIVE_DIR := $(JH)/jerboa-native-rs/target/release
+LIBDIRS    := --libdirs lib:$(JH)/lib
+JEXEC      := $(JERBUILD) exec $(LIBDIRS)
+BIN        := jerboa-aws
+BIN_DIR    := $(HOME)/.local/bin
+
+.PHONY: all build binary run test install clean
+
+all: binary
+
+# Standalone native binary via .jerbuild (entry aws.ss -> jerboa-aws).
+# Two passes: pass 1 cargo-builds jerboa-native into jerbuild's cache; we then
+# regenerate the FFI symbol list (platform-correct) and relink.
+binary:
+	@touch support/ffi-symbols.gen
+	$(JERBUILD) build
+	sh support/gen-ffi-symbols.sh
+	$(JERBUILD) build
 
 build: binary
 
-binary: compile
-	@echo "=== Building standalone binary ==="
-	$(SCHEME) -q --libdirs $(LIBDIRS) --program build-binary.ss
-
-run:
-	$(SCHEME) --libdirs $(LIBDIRS) --program aws.ss $(ARGS)
-
-run-pssm:
-	$(SCHEME) --libdirs $(LIBDIRS) --program pssm.ss $(ARGS)
-
-pssm: compile
-	@echo "=== Building pssm alias ==="
-	@echo '#!/bin/sh' > pssm
-	@echo 'exec $(SCHEME) --libdirs "$(LIBDIRS)" --program "$(CURDIR)/pssm.ss" "$$@"' >> pssm
-	@chmod +x pssm
-	@echo "Created ./pssm"
+run: binary
+	./$(BIN) $(ARGS)
 
 test:
-	@echo "=== Running tests ==="
-	$(SCHEME) --libdirs $(LIBDIRS) --script test/test-all.ss
-
-clean:
-	find lib -name '*.so' -o -name '*.wpo' | xargs rm -f 2>/dev/null || true
-	rm -f jerboa-aws jerboa-aws-main.o
-	rm -f jerboa_aws_program.h jerboa_aws_petite_boot.h
-	rm -f jerboa_aws_scheme_boot.h jerboa_aws_app_boot.h
-	rm -f jerboa-aws-all.so aws.so aws.wpo jerboa-aws.boot
-	rm -f pssm
-	rm -f jerboa-aws-linux-amd64   jerboa-aws-linux-amd64-main.c   jerboa-aws-linux-amd64.wp.so
-	rm -f jerboa-aws-freebsd-amd64 jerboa-aws-freebsd-amd64-main.c jerboa-aws-freebsd-amd64.wp.so
-	rm -f petite_boot.h scheme_boot.h jaws_program.h
+	DYLD_FALLBACK_LIBRARY_PATH="$(NATIVE_DIR)" LD_LIBRARY_PATH="$(NATIVE_DIR):$$LD_LIBRARY_PATH" \
+	$(JEXEC) test/test-all.ss
 
-# ── Cross-compile targets ──────────────────────────────────────────────────
-# Linux x86_64 musl (static): bundles jerboa-ssl/jerboa-https + AWS code into a
-# single ELF. Requires:
-#   - $(JERBOA_HOME)/.chez-cross-ta6le      (cross-built Chez install)
-#   - x86_64-linux-musl-gcc                  on PATH
-#   - $(MUSL_OPENSSL_DIR)/usr/{lib,include}  (Alpine static libssl.a + libcrypto.a)
-#   - $(JERBOASSL)/../jerboa_ssl_shim-linux-musl.o
-#
-linux:        linux-amd64
-linux-amd64:  jerboa-aws-linux-amd64
-jerboa-aws-linux-amd64:
-	@command -v x86_64-linux-musl-gcc >/dev/null 2>&1 || { \
-	  echo "Error: x86_64-linux-musl-gcc not on PATH. brew install FiloSottile/musl-cross/musl-cross"; exit 1; }
-	@test -d $(JERBOA_HOME)/.chez-cross-ta6le || { \
-	  echo "Error: $(JERBOA_HOME)/.chez-cross-ta6le missing. cd $(JERBOA_HOME) && make binary"; exit 1; }
-	@test -f $(MUSL_OPENSSL_DIR)/usr/lib/libssl.a || { \
-	  echo "Error: $(MUSL_OPENSSL_DIR)/usr/lib/libssl.a missing."; exit 1; }
-	@test -f $(JERBOASSL)/../jerboa_ssl_shim-linux-musl.o || { \
-	  echo "Error: jerboa_ssl_shim-linux-musl.o missing. cd $(JERBOASSL)/.. && make jerboa_ssl_shim-linux-musl.o"; exit 1; }
-	JERBOA_HOME=$(JERBOA_HOME) MUSL_OPENSSL_DIR=$(MUSL_OPENSSL_DIR) \
-	  $(SCHEME) -q --libdirs "$(XC_LIBDIRS)" --script build-jaws-cross.ss
+install: binary
+	mkdir -p $(BIN_DIR)
+	install -m 0755 $(BIN) $(BIN_DIR)/$(BIN)
+	@echo "Installed $(BIN) to $(BIN_DIR)/$(BIN)"
 
-# FreeBSD 14 amd64 (dynamic): libssl/libcrypto resolved from FreeBSD base at
-# runtime. Requires:
-#   - $(JERBOA_HOME)/.chez-cross-ta6fb       (cross-built Chez install)
-#   - x86_64-unknown-freebsd14-clang         wrapper on PATH
-#   - $(FREEBSD_SYSROOT)                     (extracted base.txz)
-#   - $(JERBOASSL)/../jerboa_ssl_shim-freebsd-amd64.o
-#
-freebsd:        freebsd-amd64
-freebsd-amd64:  jerboa-aws-freebsd-amd64
-jerboa-aws-freebsd-amd64:
-	@command -v x86_64-unknown-freebsd14-clang >/dev/null 2>&1 || { \
-	  echo "Error: x86_64-unknown-freebsd14-clang wrapper not on PATH. See ~/.local/bin"; exit 1; }
-	@test -d $(JERBOA_HOME)/.chez-cross-ta6fb || { \
-	  echo "Error: $(JERBOA_HOME)/.chez-cross-ta6fb missing. cd $(JERBOA_HOME) && make binary"; exit 1; }
-	@test -d $(FREEBSD_SYSROOT) || { \
-	  echo "Error: $(FREEBSD_SYSROOT) missing. Extract base.txz to ~/freebsd-sysroot"; exit 1; }
-	@test -f $(JERBOASSL)/../jerboa_ssl_shim-freebsd-amd64.o || { \
-	  echo "Error: jerboa_ssl_shim-freebsd-amd64.o missing. cd $(JERBOASSL)/.. && make jerboa_ssl_shim-freebsd-amd64.o"; exit 1; }
-	JERBOA_HOME=$(JERBOA_HOME) FREEBSD_SYSROOT=$(FREEBSD_SYSROOT) \
-	  $(SCHEME) -q --libdirs "$(XC_LIBDIRS)" --script build-jaws-freebsd-cross.ss
-
-help:
-	@echo "Targets:"
-	@echo "  all                       - Compile all modules"
-	@echo "  build                     - Build standalone binary (./jerboa-aws)"
-	@echo "  pssm                      - Build pssm wrapper script (./pssm)"
-	@echo "  run                       - Run interpreted (ARGS='ec2 describe-instances')"
-	@echo "  run-pssm                  - Run pssm interpreted (ARGS=\"'web-*' uptime\")"
-	@echo "  test                      - Run tests"
-	@echo "  clean                     - Remove build artifacts"
-	@echo ""
-	@echo "Cross-compile from macOS:"
-	@echo "  linux-amd64               - Build jerboa-aws-linux-amd64 (static musl)"
-	@echo "  freebsd-amd64             - Build jerboa-aws-freebsd-amd64 (dynamic)"
+clean:
+	rm -f $(BIN)
+	find . \( -name '*.so' -o -name '*.wpo' \) -delete 2>/dev/null || true
diff --git a/support/gen-ffi-symbols.sh b/support/gen-ffi-symbols.sh
new file mode 100755
index 0000000..0ad50bf
--- /dev/null
+++ b/support/gen-ffi-symbols.sh
@@ -0,0 +1,22 @@
+#!/bin/sh
+# Regenerate support/ffi-symbols.gen from the jerboa-native archive that
+# jerbuild cargo-builds into its bundle cache. Run between the two `jerbuild
+# build` passes so the static binary registers exactly the jerboa_* symbols
+# present for THIS platform + feature set (e.g. epoll on Linux, kqueue on
+# macOS). The output is .gitignored — it is a build artifact, not source.
+set -e
+JH="$(jerbuild --jerboa-home 2>/dev/null)"
+A="$JH/jerboa-native-rs/target/release/libjerboa_native.a"
+OUT="$(dirname "$0")/ffi-symbols.gen"
+if [ ! -f "$A" ]; then
+  echo "gen-ffi-symbols: $A not found (run 'jerbuild build' once first)" >&2
+  : > "$OUT"
+  exit 0
+fi
+{
+  echo "# AUTOGENERATED by support/gen-ffi-symbols.sh from libjerboa_native.a."
+  echo "# jerboa-native FFI symbols registered via Sforeign_symbol() (see .jerbuild)."
+  echo ""
+  nm -gjU "$A" 2>/dev/null | sed 's/^_//' | grep -E '^jerboa_[A-Za-z0-9_]+$' | sort -u
+} > "$OUT"
+echo "gen-ffi-symbols: wrote $(grep -c '^jerboa_' "$OUT") symbols to $OUT"