perf: Share Cargo build cache across git worktrees (#60)
Use a common target directory for all worktrees to avoid recompiling the backend in every worktree directory.
This commit is contained in:
@@ -1,7 +1,5 @@
|
|||||||
[env]
|
|
||||||
# Set macOS deployment target to avoid linker warnings
|
# Set macOS deployment target to avoid linker warnings
|
||||||
# Use Rust project defaults: 10.12 for x86_64, 11.0 for aarch64
|
# Use Rust project defaults: 10.12 for x86_64, 11.0 for aarch64
|
||||||
|
|
||||||
[target.x86_64-apple-darwin.env]
|
[target.x86_64-apple-darwin.env]
|
||||||
MACOSX_DEPLOYMENT_TARGET = "10.12"
|
MACOSX_DEPLOYMENT_TARGET = "10.12"
|
||||||
|
|
||||||
|
|||||||
17
package.json
17
package.json
@@ -3,17 +3,20 @@
|
|||||||
"version": "0.0.37",
|
"version": "0.0.37",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "export FRONTEND_PORT=$(node scripts/setup-dev-environment.js frontend) && export BACKEND_PORT=$(node scripts/setup-dev-environment.js backend) && concurrently \"cargo watch -w backend -x 'run --manifest-path backend/Cargo.toml'\" \"npm run frontend:dev\"",
|
"dev": "export FRONTEND_PORT=$(node scripts/setup-dev-environment.js frontend) && export BACKEND_PORT=$(node scripts/setup-dev-environment.js backend) && concurrently \"npm run backend:dev:watch\" \"npm run frontend:dev\"",
|
||||||
"build": "npm run frontend:build && cargo build --release --manifest-path backend/Cargo.toml && cargo build --release --bin mcp_task_server --manifest-path backend/Cargo.toml",
|
"build": "npm run frontend:build && npm run backend:build",
|
||||||
"build:single": "npm run frontend:build && cargo build --release --manifest-path backend/Cargo.toml",
|
"build:single": "npm run frontend:build && npm run backend:build:single",
|
||||||
"build:npm": "./build-npm-package.sh",
|
"build:npm": "./build-npm-package.sh",
|
||||||
"test:npm": "./test-npm-package.sh",
|
"test:npm": "./test-npm-package.sh",
|
||||||
"frontend:dev": "cd frontend && npm run dev -- --port ${FRONTEND_PORT:-3000} --open",
|
"frontend:dev": "cd frontend && npm run dev -- --port ${FRONTEND_PORT:-3000} --open",
|
||||||
"frontend:build": "cd frontend && npm run build",
|
"frontend:build": "cd frontend && npm run build",
|
||||||
"backend:dev": "BACKEND_PORT=$(node scripts/setup-dev-environment.js backend) cargo watch -w backend -x 'run --manifest-path backend/Cargo.toml'",
|
"cargo": "node scripts/cargo.js",
|
||||||
"backend:build": "cargo build --release --manifest-path backend/Cargo.toml",
|
"backend:dev": "BACKEND_PORT=$(node scripts/setup-dev-environment.js backend) npm run backend:dev:watch",
|
||||||
"backend:run": "cargo run --manifest-path backend/Cargo.toml",
|
"backend:dev:watch": "npm run cargo -- watch -w backend -x 'run --manifest-path backend/Cargo.toml'",
|
||||||
"backend:test": "cargo test --lib",
|
"backend:build": "npm run cargo -- build --release --manifest-path backend/Cargo.toml && npm run cargo -- build --release --bin mcp_task_server --manifest-path backend/Cargo.toml",
|
||||||
|
"backend:build:single": "npm run cargo -- build --release --manifest-path backend/Cargo.toml",
|
||||||
|
"backend:run" : "npm run cargo -- run --manifest-path backend/Cargo.toml",
|
||||||
|
"backend:test" : "npm run cargo -- test --lib",
|
||||||
"generate-types": "cd backend && cargo run --bin generate_types",
|
"generate-types": "cd backend && cargo run --bin generate_types",
|
||||||
"prepare-db": "node scripts/prepare-db.js",
|
"prepare-db": "node scripts/prepare-db.js",
|
||||||
"dev:clear-ports": "node scripts/setup-dev-environment.js clear"
|
"dev:clear-ports": "node scripts/setup-dev-environment.js clear"
|
||||||
|
|||||||
31
scripts/cargo.js
Normal file
31
scripts/cargo.js
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
/**
|
||||||
|
* Drop-in replacement for the `cargo` binary.
|
||||||
|
* If CARGO_TARGET_DIR is already set we leave it alone.
|
||||||
|
* Otherwise we compute a path that is the same for every git-worktree:
|
||||||
|
* <main-clone-root>/target
|
||||||
|
*
|
||||||
|
* Usage : node scripts/cargo.js <cargo-subcommand> […]
|
||||||
|
* NPM : "backend:build": "node scripts/cargo.js build --release …"
|
||||||
|
*/
|
||||||
|
const { spawnSync, execSync } = require('node:child_process');
|
||||||
|
const path = require('node:path');
|
||||||
|
|
||||||
|
function sharedTarget() {
|
||||||
|
try {
|
||||||
|
// Works in any work-tree folder
|
||||||
|
const common = execSync('git rev-parse --git-common-dir', { encoding: 'utf8' }).trim();
|
||||||
|
return path.resolve(common, '..', 'target');
|
||||||
|
} catch {
|
||||||
|
return undefined; // not a git repo? -> let Cargo use ./target
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const env = { ...process.env };
|
||||||
|
if (!env.CARGO_TARGET_DIR) {
|
||||||
|
const dir = sharedTarget();
|
||||||
|
if (dir) env.CARGO_TARGET_DIR = dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = spawnSync('cargo', process.argv.slice(2), { stdio: 'inherit', env });
|
||||||
|
process.exitCode = result.status;
|
||||||
Reference in New Issue
Block a user