Skip to content
Merged
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
1 change: 1 addition & 0 deletions .bazelrc.ci
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ build --host_cxxopt=-std=c++17 --cxxopt=-std=c++17
startup --host_jvm_args=-Dbazel.DigestFunction=sha256

build --compilation_mode=opt
build --disk_cache=~/.cache/bazel-disk

# This is so we understand failures better
build --verbose_failures
Expand Down
21 changes: 8 additions & 13 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,14 @@ jobs:
- uses: actions/checkout@v3
- name: Switch to CI bazelrc
run: cp .bazelrc.ci .bazelrc
# Credit to the tensorboard repo for the cache configuration step
# https://github.com/tensorflow/tensorboard/blob/master/.github/workflows/ci.yml#L58
# Plenty of ways to do something similar but I really liked theirs
- name: 'Configure remote build cache usage'
env:
EVENT_TYPE: ${{ github.event_name }}
run: |
if [ "${EVENT_TYPE}" = pull_request ]; then
printf 'Using read-only cache (PR build)\n'
exit
fi
printf 'Using writable cache\n'
sed -i 's/common --remote_upload_local_results=false/common --remote_upload_local_results=true/' .bazelrc
- name: Cache Bazel disk cache
uses: actions/cache@v4
with:
path: ~/.cache/bazel-disk
key: bazel-disk-${{ runner.os }}-${{ hashFiles('MODULE.bazel', 'MODULE.bazel.lock') }}-${{ github.sha }}
restore-keys: |
bazel-disk-${{ runner.os }}-${{ hashFiles('MODULE.bazel', 'MODULE.bazel.lock') }}-
bazel-disk-${{ runner.os }}-
- name: bazel build
id: build
run: |
Expand Down
91 changes: 91 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
.PHONY: build build-backend build-web run run-backend run-web stop stop-backend stop-web logs-backend logs-web index status help

# Configuration
BACKEND_ADDR ?= localhost:9999
WEB_ADDR ?= 127.0.0.1:8910
INDEX_CONFIG ?= doc/examples/livegrep/index.json
DOCROOT = $(shell pwd)/bazel-bin/cmd/livegrep/livegrep_/livegrep.runfiles/_main/web

CODESEARCH_BIN = bazel-bin/src/tools/codesearch
LIVEGREP_BIN = bazel-bin/cmd/livegrep/livegrep_/livegrep

BACKEND_PID_FILE = /tmp/livegrep-backend.pid
WEB_PID_FILE = /tmp/livegrep-web.pid
BACKEND_LOG = /tmp/livegrep-backend.log
WEB_LOG = /tmp/livegrep-web.log

# Build targets
build: ## Build both backend and web frontend
bazel build //src/tools:codesearch //cmd/livegrep:livegrep

build-backend: ## Build only the codesearch backend
bazel build //src/tools:codesearch

build-web: ## Build only the web frontend
bazel build //cmd/livegrep:livegrep

# Run targets
run: build stop run-backend run-web ## Build and run everything
@echo "Livegrep is running at http://$(WEB_ADDR)"

run-backend: build-backend stop-backend ## Start the codesearch backend
$(CODESEARCH_BIN) -grpc $(BACKEND_ADDR) $(INDEX_CONFIG) > $(BACKEND_LOG) 2>&1 & echo $$! > $(BACKEND_PID_FILE)
@sleep 2
@if kill -0 $$(cat $(BACKEND_PID_FILE)) 2>/dev/null; then \
echo "Backend running (PID $$(cat $(BACKEND_PID_FILE))) on $(BACKEND_ADDR)"; \
else \
echo "Backend failed to start. Logs:"; cat $(BACKEND_LOG); exit 1; \
fi

run-web: build-web stop-web ## Start the web frontend (with template reload)
$(LIVEGREP_BIN) -listen $(WEB_ADDR) -connect $(BACKEND_ADDR) -docroot $(DOCROOT) -reload > $(WEB_LOG) 2>&1 & echo $$! > $(WEB_PID_FILE)
@sleep 2
@if kill -0 $$(cat $(WEB_PID_FILE)) 2>/dev/null; then \
echo "Web frontend running (PID $$(cat $(WEB_PID_FILE))) on http://$(WEB_ADDR)"; \
else \
echo "Web frontend failed to start. Logs:"; cat $(WEB_LOG); exit 1; \
fi

# Stop targets
stop: stop-web stop-backend ## Stop all services

stop-backend: ## Stop the codesearch backend
@if [ -f $(BACKEND_PID_FILE) ] && kill -0 $$(cat $(BACKEND_PID_FILE)) 2>/dev/null; then \
kill $$(cat $(BACKEND_PID_FILE)) && rm -f $(BACKEND_PID_FILE) && echo "Backend stopped"; \
else \
rm -f $(BACKEND_PID_FILE); \
fi

stop-web: ## Stop the web frontend
@if [ -f $(WEB_PID_FILE) ] && kill -0 $$(cat $(WEB_PID_FILE)) 2>/dev/null; then \
kill $$(cat $(WEB_PID_FILE)) && rm -f $(WEB_PID_FILE) && echo "Web frontend stopped"; \
else \
rm -f $(WEB_PID_FILE); \
fi

# Utility targets
logs-backend: ## Tail the backend logs
tail -f $(BACKEND_LOG)

logs-web: ## Tail the web frontend logs
tail -f $(WEB_LOG)

status: ## Check if services are running
@echo "Backend:"; \
if [ -f $(BACKEND_PID_FILE) ] && kill -0 $$(cat $(BACKEND_PID_FILE)) 2>/dev/null; then \
echo " Running (PID $$(cat $(BACKEND_PID_FILE)))"; \
else \
echo " Stopped"; \
fi
@echo "Web frontend:"; \
if [ -f $(WEB_PID_FILE) ] && kill -0 $$(cat $(WEB_PID_FILE)) 2>/dev/null; then \
echo " Running (PID $$(cat $(WEB_PID_FILE)))"; \
else \
echo " Stopped"; \
fi

index: build-backend ## Build an index file (use INDEX_OUTPUT to set path)
$(CODESEARCH_BIN) -index_only -dump_index $(or $(INDEX_OUTPUT),livegrep.idx) $(INDEX_CONFIG)

help: ## Show this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-16s\033[0m %s\n", $$1, $$2}'
Loading