changeset 222:a8d6435dc021 hg-web

[hg-web] Run local stack through Bazel
author MrJuneJune <me@mrjunejune.com>
date Sun, 02 Aug 2026 09:07:36 -0700
parents ce7f4400c2de
children 0e7b9464248d
files AGENT.md hg-web/BUILD hg-web/README.md hg-web/dev.sh
diffstat 4 files changed, 113 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AGENT.md	Sun Aug 02 09:07:36 2026 -0700
@@ -0,0 +1,21 @@
+# Agent instructions
+
+## Bazel is the project interface
+
+All project execution must happen through Bazel. Use existing `bazel build`,
+`bazel test`, and `bazel run` targets instead of invoking compiled binaries,
+language runtimes, package managers, generated scripts, or multiple services
+manually.
+
+When a workflow needs several processes or commands, add a Bazel target that
+owns their startup, runfiles, supervision, shutdown, and exit status. The user
+should need one `bazel run` command.
+
+For hg-web development, run the complete local stack with:
+
+```bash
+bazel run //hg-web:dev
+```
+
+Add or update the smallest relevant Bazel target whenever code cannot be built,
+tested, run, bundled, or orchestrated through Bazel.
--- a/hg-web/BUILD	Sun Aug 02 09:01:24 2026 -0700
+++ b/hg-web/BUILD	Sun Aug 02 09:07:36 2026 -0700
@@ -1,4 +1,5 @@
 load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
+load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
 load("//gui_ze:gui_ze.bzl", "move_files_into_dir", "bundle", "bun_bundle")
 
 # Source files
@@ -67,6 +68,15 @@
   data = [":all_assets"],
 )
 
+sh_binary(
+  name = "dev",
+  srcs = ["dev.sh"],
+  data = [
+    ":hg_web_server",
+    "@bazel_tools//tools/bash/runfiles",
+  ],
+)
+
 bundle(
   name = "hg_web_server_bundle",
   binary = ":hg_web_server",
--- a/hg-web/README.md	Sun Aug 02 09:01:24 2026 -0700
+++ b/hg-web/README.md	Sun Aug 02 09:07:36 2026 -0700
@@ -173,18 +173,14 @@
 bazel test //seobeo/tests:all
 ```
 
-Run the Mercurial backend:
+Build and run the complete local stack with one Bazel command:
 
 ```bash
-hg serve -a 127.0.0.1 -p 4444
+bazel run //hg-web:dev
 ```
 
-Run the deployable bundle from its own directory so the static root resolves:
-
-```bash
-cd bazel-bin/hg-web/hg_web_server_bundle
-./hg_web_server
-```
+This starts `hg serve` on `127.0.0.1:4444` and `hg_web_server` on port `6970`.
+Stopping the Bazel target stops both child processes.
 
 The bundle contains `hg_web_server` and `hg-web/src/`, including generated
 `page.js`, markdown WASM, highlight.js, styles, and image assets.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hg-web/dev.sh	Sun Aug 02 09:07:36 2026 -0700
@@ -0,0 +1,78 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+if [[ -n "${RUNFILES_DIR:-}" ]]; then
+  source "$RUNFILES_DIR/bazel_tools/tools/bash/runfiles/runfiles.bash"
+elif [[ -n "${RUNFILES_MANIFEST_FILE:-}" ]]; then
+  runfiles_library="$(
+    grep -sm1 '^bazel_tools/tools/bash/runfiles/runfiles.bash ' \
+      "$RUNFILES_MANIFEST_FILE" | cut -d' ' -f2-
+  )"
+  source "$runfiles_library"
+elif [[ -d "$0.runfiles" ]]; then
+  RUNFILES_DIR="$0.runfiles"
+  export RUNFILES_DIR
+  source "$RUNFILES_DIR/bazel_tools/tools/bash/runfiles/runfiles.bash"
+elif [[ -f "$0.runfiles_manifest" ]]; then
+  RUNFILES_MANIFEST_FILE="$0.runfiles_manifest"
+  export RUNFILES_MANIFEST_FILE
+  runfiles_library="$(
+    grep -sm1 '^bazel_tools/tools/bash/runfiles/runfiles.bash ' \
+      "$RUNFILES_MANIFEST_FILE" | cut -d' ' -f2-
+  )"
+  source "$runfiles_library"
+else
+  echo "Bazel runfiles are unavailable." >&2
+  exit 1
+fi
+
+workspace="${BUILD_WORKSPACE_DIRECTORY:-}"
+if [[ -z "$workspace" || ! -d "$workspace/.hg" ]]; then
+  echo "Run this target from the Zenbu workspace." >&2
+  exit 1
+fi
+
+server="$(rlocation _main/hg-web/hg_web_server)"
+runfiles_workspace="$(dirname "$(dirname "$server")")"
+hg_pid=""
+server_pid=""
+
+cleanup() {
+  trap - EXIT INT TERM
+  for pid in "$server_pid" "$hg_pid"; do
+    if [[ -n "$pid" ]] && kill -0 "$pid" 2>/dev/null; then
+      kill "$pid" 2>/dev/null || true
+    fi
+  done
+  for pid in "$server_pid" "$hg_pid"; do
+    if [[ -n "$pid" ]]; then
+      wait "$pid" 2>/dev/null || true
+    fi
+  done
+}
+
+trap cleanup EXIT
+trap 'exit 130' INT TERM
+
+hg --repository "$workspace" serve \
+  --address 127.0.0.1 \
+  --port 4444 \
+  --accesslog - \
+  --errorlog - &
+hg_pid=$!
+
+(
+  cd "$runfiles_workspace"
+  exec "$server"
+) &
+server_pid=$!
+
+echo "hg-web: http://127.0.0.1:6970"
+echo "Mercurial wire endpoint: http://127.0.0.1:6970/repo"
+echo "Press Ctrl-C to stop both servers."
+
+set +e
+wait -n "$hg_pid" "$server_pid"
+status=$?
+set -e
+exit "$status"