Skip to content

Commit caf9e7f

Browse files
authored
build(just): support local aionrs patches (#502)
## Summary - Add a shared Justfile `_cargo` helper that injects local aionrs SDK patches when `AIONRS` is set. - Route build, debug build, lint, lint-fix, test, run, and run-release through the helper. - Restore a clean `Cargo.lock` after local patch resolution so local testing does not dirty the repo. ## Testing - `git diff --check origin/main..HEAD` - `AIONRS=../wt-aionrs-boii-fix-aio-168 just _cargo tree -p aion-agent --depth 0` - `just --dry-run build -f`
1 parent 0627249 commit caf9e7f

1 file changed

Lines changed: 78 additions & 8 deletions

File tree

justfile

Lines changed: 78 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,82 @@ setup:
77
git config core.hooksPath .githooks
88
@echo "✅ Git hooks enabled"
99

10+
# Run cargo with optional local aionrs SDK patches.
11+
_cargo *ARGS:
12+
#!/usr/bin/env bash
13+
set -euo pipefail
14+
15+
cargo_config=()
16+
restore_cargo_lock=false
17+
cargo_lock_snapshot=""
18+
19+
restore_local_lockfile() {
20+
if [[ "$restore_cargo_lock" == "true" && -n "$cargo_lock_snapshot" && -f "$cargo_lock_snapshot" ]]; then
21+
cp "$cargo_lock_snapshot" Cargo.lock
22+
fi
23+
if [[ -n "$cargo_lock_snapshot" ]]; then
24+
rm -f "$cargo_lock_snapshot"
25+
fi
26+
}
27+
trap restore_local_lockfile EXIT
28+
29+
if [[ -n "${AIONRS:-}" ]]; then
30+
if [[ ! -d "$AIONRS" ]]; then
31+
echo "AIONRS does not exist or is not a directory: $AIONRS" >&2
32+
exit 1
33+
fi
34+
35+
aionrs_root=$(cd "$AIONRS" && pwd -P)
36+
crates=(
37+
aion-agent
38+
aion-providers
39+
aion-types
40+
aion-protocol
41+
aion-config
42+
aion-mcp
43+
)
44+
45+
for crate in "${crates[@]}"; do
46+
crate_dir="$aionrs_root/crates/$crate"
47+
if [[ ! -f "$crate_dir/Cargo.toml" ]]; then
48+
echo "AIONRS is missing $crate: $crate_dir/Cargo.toml" >&2
49+
exit 1
50+
fi
51+
52+
toml_path=${crate_dir//\\/\\\\}
53+
toml_path=${toml_path//\"/\\\"}
54+
cargo_config+=(--config "patch.'https://github.com/iOfficeAI/aionrs.git'.$crate.path = \"$toml_path\"")
55+
done
56+
57+
echo "Using local aionrs SDK: $aionrs_root" >&2
58+
59+
if [[ -f Cargo.lock ]]; then
60+
if git diff --quiet -- Cargo.lock && git diff --cached --quiet -- Cargo.lock; then
61+
cargo_lock_snapshot=$(mktemp)
62+
cp Cargo.lock "$cargo_lock_snapshot"
63+
restore_cargo_lock=true
64+
else
65+
echo "Cargo.lock already has changes; leaving any AIONRS lockfile updates in place." >&2
66+
fi
67+
fi
68+
fi
69+
70+
set +e
71+
if ((${#cargo_config[@]})); then
72+
cargo "${cargo_config[@]}" {{ARGS}}
73+
else
74+
cargo {{ARGS}}
75+
fi
76+
status=$?
77+
set -e
78+
exit "$status"
79+
1080
# Build in release mode and install to ~/.cargo/bin
1181
# Use `just build --force` to skip cache check
1282
build *FLAGS: lint-fix fmt
1383
#!/usr/bin/env bash
1484
set -euo pipefail
15-
cargo build --release
85+
just _cargo build --release
1686
new_sum=$(shasum -a 256 target/release/aioncore | cut -d' ' -f1)
1787
force=false
1888
for flag in {{FLAGS}}; do
@@ -38,7 +108,7 @@ build *FLAGS: lint-fix fmt
38108
build-debug *FLAGS:
39109
#!/usr/bin/env bash
40110
set -euo pipefail
41-
cargo build
111+
just _cargo build
42112
new_sum=$(shasum -a 256 target/debug/aioncore | cut -d' ' -f1)
43113
force=false
44114
for flag in {{FLAGS}}; do
@@ -63,7 +133,7 @@ install:
63133

64134
# Run all tests
65135
test:
66-
cargo nextest run --workspace
136+
just _cargo nextest run --workspace
67137

68138
# Ensure already-shipped database migrations stay immutable
69139
migration-check:
@@ -75,11 +145,11 @@ migration-check-test:
75145

76146
# Lint (warnings = errors)
77147
lint:
78-
cargo clippy --workspace -- -D warnings
148+
just _cargo clippy --workspace -- -D warnings
79149

80150
lint-fix:
81-
cargo fix --allow-dirty --allow-staged
82-
cargo clippy --fix --workspace --allow-dirty --allow-staged -- -D warnings
151+
just _cargo fix --allow-dirty --allow-staged
152+
just _cargo clippy --fix --workspace --allow-dirty --allow-staged -- -D warnings
83153

84154
# Format code
85155
fmt:
@@ -94,11 +164,11 @@ check: migration-check lint fmt-check test
94164

95165
# Run the server (debug)
96166
run *ARGS:
97-
cargo run --bin aioncore -- {{ARGS}}
167+
just _cargo run --bin aioncore -- {{ARGS}}
98168

99169
# Run the server (release)
100170
run-release *ARGS:
101-
cargo run --release --bin aioncore -- {{ARGS}}
171+
just _cargo run --release --bin aioncore -- {{ARGS}}
102172

103173
# Pre-push gate: migration check, format, lint, auto-commit fixes, test, then push
104174
push *ARGS: migration-check lint-fix fmt _auto-commit-fixes test

0 commit comments

Comments
 (0)