🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
chore(ai-gateway): Cache rust builds (#17440)
Ben Bachem30c8ac9231b3
diff --git a/ai-gateway/README.md b/ai-gateway/README.mdindex f847ed3dab..229e9866ff 100644--- a/ai-gateway/README.md+++ b/ai-gateway/README.md@@ -22,11 +22,12 @@ pnpm dev```This starts the gateway alongside the other development services. Turbo Watch-recompiles and restarts the gateway after Rust source changes; Web and worker-keep their built-in watchers. The gateway loads the root `.env` and listens on-the first available port starting at 8080. This lets multiple worktrees run-their development stacks at the same time. Add overrides from the table below-to your root `.env`; exported shell variables take precedence.+restores the cached debug gateway binary when its inputs are unchanged, then+rebuilds and restarts it after Rust source changes; Web and worker keep their+built-in watchers. The gateway loads the root `.env` and listens on the first+available port starting at 8080. This lets multiple worktrees run their+development stacks at the same time. Add overrides from the table below to your+root `.env`; exported shell variables take precedence.Without a Web URL, the process starts with liveness available; readiness andinference return 503. To enable inference, configure the Web URL and shared service key.@@ -237,7 +238,10 @@ pnpm --filter ai-gateway formatThese scripts delegate to Cargo. Root `pnpm build`, `pnpm typecheck`, `pnpm lint`and `pnpm test` include the gateway; its Turbo tasks have no Prisma/JavaScript-dependencies and disable Turbo caching, leaving incremental builds to Cargo.+dependencies. Turbo caches successful checks and only the final release binary,+not Cargo's potentially large `target` directory. Development similarly caches+only the final debug binary so unchanged gateway builds can be reused across+worktrees.The JavaScript CI jobs and commit-hook lint exclude it; the dedicated Rust CI jobruns its checks without Node. Root Prettier formatting remains JavaScript/CSS-only;use the gateway `format` script for Rust. Docker builds also use Cargo directly.diff --git a/ai-gateway/package.json b/ai-gateway/package.jsonindex 06c6ae9322..4ec6b25fc1 100644--- a/ai-gateway/package.json+++ b/ai-gateway/package.json@@ -2,8 +2,9 @@"name": "ai-gateway","private": true,"scripts": {- "dev": "dotenv -e ../.env -v LANGFUSE_AI_GATEWAY_AUTO_INCREMENT_LISTEN_PORT=true -- cargo run --locked",+ "dev": "dotenv -e ../.env -v LANGFUSE_AI_GATEWAY_AUTO_INCREMENT_LISTEN_PORT=true -- bash scripts/run-dev.sh","build": "cargo build --release --locked",+ "build:dev": "cargo build --locked","typecheck": "cargo check --locked --all-targets","lint": "cargo fmt --all -- --check && cargo clippy --locked --all-targets -- -D warnings","test": "cargo test --locked",diff --git a/ai-gateway/scripts/run-dev.sh b/ai-gateway/scripts/run-dev.shnew file mode 100644index 0000000000..01761fc763--- /dev/null+++ b/ai-gateway/scripts/run-dev.sh@@ -0,0 +1,20 @@+#!/usr/bin/env bash++set -euo pipefail++target_dir="${CARGO_TARGET_DIR:-target}"+if [[ -n "${CARGO_BUILD_TARGET:-}" ]]; then+ target_dir="${target_dir}/${CARGO_BUILD_TARGET}"+fi++binary="${target_dir}/debug/ai-gateway"++if [[ -z "${TURBO_HASH:-}" || ( ! -f "${binary}" && ! -f "${binary}.exe" ) ]]; then+ cargo build --locked+fi++if [[ -f "${binary}.exe" ]]; then+ binary="${binary}.exe"+fi++exec "${binary}"diff --git a/ai-gateway/turbo.json b/ai-gateway/turbo.jsonindex d7757ad0e4..64c197d6b0 100644--- a/ai-gateway/turbo.json+++ b/ai-gateway/turbo.json@@ -2,14 +2,78 @@"extends": ["//"],"tasks": {"dev": {- "dependsOn": [],+ "dependsOn": ["build:dev"],"cache": false,"persistent": true,"interruptible": true},- "build": { "dependsOn": [], "cache": false, "outputs": [] },- "typecheck": { "dependsOn": [], "cache": false, "outputs": [] },- "lint": { "dependsOn": [], "cache": false, "outputs": [] },- "test": { "dependsOn": [], "cache": false, "outputs": [] }+ "build": {+ "dependsOn": [],+ "cache": true,+ "outputs": [+ "target/**/release/ai-gateway",+ "target/**/release/ai-gateway.exe"+ ],+ "env": [+ "CARGO_BUILD_TARGET",+ "CARGO_TARGET_DIR",+ "CARGO_INCREMENTAL",+ "RUSTC",+ "RUSTFLAGS",+ "CARGO_ENCODED_RUSTFLAGS"+ ]+ },+ "build:dev": {+ "dependsOn": [],+ "cache": true,+ "outputs": [+ "target/**/debug/ai-gateway",+ "target/**/debug/ai-gateway.exe"+ ],+ "env": [+ "CARGO_BUILD_TARGET",+ "CARGO_TARGET_DIR",+ "CARGO_INCREMENTAL",+ "RUSTC",+ "RUSTFLAGS",+ "CARGO_ENCODED_RUSTFLAGS"+ ]+ },+ "typecheck": {+ "dependsOn": [],+ "cache": true,+ "outputs": [],+ "env": [+ "CARGO_BUILD_TARGET",+ "CARGO_INCREMENTAL",+ "RUSTC",+ "RUSTFLAGS",+ "CARGO_ENCODED_RUSTFLAGS"+ ]+ },+ "lint": {+ "dependsOn": [],+ "cache": true,+ "outputs": [],+ "env": [+ "CARGO_BUILD_TARGET",+ "CARGO_INCREMENTAL",+ "RUSTC",+ "RUSTFLAGS",+ "CARGO_ENCODED_RUSTFLAGS"+ ]+ },+ "test": {+ "dependsOn": [],+ "cache": true,+ "outputs": [],+ "env": [+ "CARGO_BUILD_TARGET",+ "CARGO_INCREMENTAL",+ "RUSTC",+ "RUSTFLAGS",+ "CARGO_ENCODED_RUSTFLAGS"+ ]+ }}}