-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJustfile
More file actions
326 lines (291 loc) · 14.7 KB
/
Justfile
File metadata and controls
326 lines (291 loc) · 14.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
set dotenv-load:=true
# default recipe to list all available commands
default:
@just --list
fmt:
cargo fmt --all
check:
cargo check --all-features --workspace
cargo fmt --all -- --check
cargo clippy --all-targets --all-features -- -D warnings
just docs-check
# run cargo clippy
lint:
cargo clippy --all-targets --all-features -- -D warnings
lint-fix:
cargo clippy --fix --all-targets --all-features -- -D warnings
# Test commands
test:
cargo test --all-features --workspace
# Build statically linked binaries for Linux, macOS, and Windows
# Usage: just build-static [target]
# Builds fully static Linux binaries that work on any Linux system, macOS binaries, and Windows executables
# Examples:
# just build-static # builds all targets
# just build-static linux-x86_64
# just build-static linux-aarch64
# just build-static linux-riscv64
# just build-static windows-x86_64
# just build-static windows-arm64
# just build-static macos-arm64
# just build-static macos-x86_64
#
# Prerequisites on Debian/Ubuntu:
# apt install gcc-aarch64-linux-gnu gcc-riscv64-linux-gnu gcc-mingw-w64 pkg-config libssl-dev build-essential
# rustup target add x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu riscv64gc-unknown-linux-gnu x86_64-pc-windows-gnu aarch64-pc-windows-msvc
# Prerequisites on macOS:
# rustup target add x86_64-apple-darwin aarch64-apple-darwin
build-static target="all":
#!/usr/bin/env bash
set -euo pipefail
# Set up Rust environment (macOS only)
# Detect cargo/rustup location - handles both regular users and root
if [ "$(uname)" = "Darwin" ]; then
if [ -d "$HOME/.cargo" ]; then
CARGO_HOME_DIR="$HOME/.cargo"
RUSTUP_HOME_DIR="$HOME/.rustup"
elif [ -d "/var/root/.cargo" ]; then
CARGO_HOME_DIR="/var/root/.cargo"
RUSTUP_HOME_DIR="/var/root/.rustup"
elif [ -d "/root/.cargo" ]; then
CARGO_HOME_DIR="/root/.cargo"
RUSTUP_HOME_DIR="/root/.rustup"
else
echo "Error: Cannot find cargo installation"
exit 1
fi
export PATH="${CARGO_HOME_DIR}/bin:$PATH"
export CARGO_HOME="${CARGO_HOME:-${CARGO_HOME_DIR}}"
export RUSTUP_HOME="${RUSTUP_HOME:-${RUSTUP_HOME_DIR}}"
export RUSTC_WRAPPER=sccache
fi
# Set up sccache directory (macOS only)
if [ "$(uname)" = "Darwin" ]; then
if [ -z "${SCCACHE_DIR:-}" ]; then
if [ -d "/var/root" ] && [ "$HOME" = "/var/root" ]; then
export SCCACHE_DIR="/var/root/Library/Caches/Mozilla.sccache"
else
export SCCACHE_DIR="${HOME}/Library/Caches/Mozilla.sccache"
fi
fi
fi
# Use SQLx offline mode to avoid needing database during build
export SQLX_OFFLINE=true
# Determine which profile to use
# Use "release" if CI_COMMIT_TAG is set (tagged release), otherwise use "testing"
if [ -n "${CI_COMMIT_TAG:-}" ]; then
PROFILE="release"
echo "Building with 'release' profile (CI_COMMIT_TAG is set)"
else
PROFILE="testing"
echo "Building with 'testing' profile (CI_COMMIT_TAG is not set)"
fi
# Set flags for static linking with glibc
# Note: We avoid PIE (Position Independent Executable) for static builds
export RUSTFLAGS="-C target-feature=+crt-static -C link-arg=-static -C link-arg=-no-pie"
# Setup cross-compilation for glibc targets
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc
export CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc
export AR_aarch64_unknown_linux_gnu=aarch64-linux-gnu-ar
export CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_GNU_LINKER=riscv64-linux-gnu-gcc
export CC_riscv64gc_unknown_linux_gnu=riscv64-linux-gnu-gcc
export AR_riscv64gc_unknown_linux_gnu=riscv64-linux-gnu-ar
# Setup cross-compilation for Windows ARM64 with clang
export CC_aarch64_pc_windows_msvc=clang
export CXX_aarch64_pc_windows_msvc=clang++
export AR_aarch64_pc_windows_msvc=llvm-ar
# Determine version string
if [ -n "${CI_COMMIT_TAG:-}" ]; then
VERSION="${CI_COMMIT_TAG#v}"
else
# Use commit SHA if available, otherwise use date only
if [ -n "${CI_COMMIT_SHA:-}" ]; then
COMMIT_SHORT=$(echo "${CI_COMMIT_SHA}" | cut -c1-8)
VERSION="$(date +%Y%m%d).$COMMIT_SHORT"
else
VERSION="$(date +%Y%m%d)"
fi
fi
# Create output directory
mkdir -p target/binaries
# Function to clean up assets after build
cleanup_assets() {
if [ -n "${CI:-}" ]; then
echo "Cleaning up UI assets and cache (CI environment detected)..."
rm -rf ./target/site
# Clean incremental compilation cache
rm -rf ./target/release/incremental
rm -rf ./target/testing/incremental
# Clean cargo cache for the profile that was used
if [ "$PROFILE" = "release" ]; then
cargo clean --release 2>/dev/null || true
else
cargo clean --profile testing 2>/dev/null || true
fi
echo "✓ Cleanup complete"
fi
}
case "{{target}}" in
# Linux targets
"linux-x86_64"|"x86_64")
echo "Building static binary for x86_64-unknown-linux-gnu..."
rustup target add x86_64-unknown-linux-gnu || true
cargo build --profile "$PROFILE" --locked --bin ricochet --target x86_64-unknown-linux-gnu
cp target/x86_64-unknown-linux-gnu/$PROFILE/ricochet target/binaries/ricochet-linux-x86_64
cleanup_assets
echo "✓ Built static x86_64-unknown-linux-gnu successfully"
echo "Binary location: target/binaries/ricochet-linux-x86_64"
;;
"linux-aarch64"|"aarch64")
echo "Building static binary for aarch64-unknown-linux-gnu..."
rustup target add aarch64-unknown-linux-gnu || true
cargo build --profile "$PROFILE" --locked --bin ricochet --target aarch64-unknown-linux-gnu
cp target/aarch64-unknown-linux-gnu/$PROFILE/ricochet target/binaries/ricochet-linux-aarch64
cleanup_assets
echo "✓ Built static aarch64-unknown-linux-gnu successfully"
echo "Binary location: target/binaries/ricochet-linux-aarch64"
;;
"linux-riscv64"|"riscv64"|"riscv")
echo "Building static binary for riscv64gc-unknown-linux-gnu..."
rustup target add riscv64gc-unknown-linux-gnu || true
cargo build --profile "$PROFILE" --locked --bin ricochet --target riscv64gc-unknown-linux-gnu
cp target/riscv64gc-unknown-linux-gnu/$PROFILE/ricochet target/binaries/ricochet-linux-riscv64
cleanup_assets
echo "✓ Built static riscv64gc-unknown-linux-gnu successfully"
echo "Binary location: target/binaries/ricochet-linux-riscv64"
;;
# Windows targets
"windows-x86_64"|"windows"|"win")
echo "Building static binary for x86_64-pc-windows-gnu..."
rustup target add x86_64-pc-windows-gnu || true
# Windows builds use different RUSTFLAGS
RUSTFLAGS="-C target-feature=+crt-static" cargo build --profile "$PROFILE" --locked --bin ricochet --target x86_64-pc-windows-gnu
cp target/x86_64-pc-windows-gnu/$PROFILE/ricochet.exe target/binaries/ricochet-windows-x86_64.exe
cleanup_assets
echo "✓ Built static x86_64-pc-windows-gnu successfully"
echo "Binary location: target/binaries/ricochet-windows-x86_64.exe"
;;
"windows-arm64")
echo "Building static binary for aarch64-pc-windows-msvc..."
rustup target add aarch64-pc-windows-msvc || true
# Windows ARM64 builds use MSVC target with static CRT
RUSTFLAGS="-C target-feature=+crt-static" cargo build --profile "$PROFILE" --locked --bin ricochet --target aarch64-pc-windows-msvc
cp target/aarch64-pc-windows-msvc/$PROFILE/ricochet.exe target/binaries/ricochet-windows-arm64.exe
cleanup_assets
echo "✓ Built static aarch64-pc-windows-msvc successfully"
echo "Binary location: target/binaries/ricochet-windows-arm64.exe"
;;
# macOS targets
"macos-arm64"|"macos-arm"|"darwin-arm64")
echo "Building binary for aarch64-apple-darwin..."
rustup target add aarch64-apple-darwin || true
# macOS uses different RUSTFLAGS (no static linking flags)
RUSTFLAGS="" cargo build --profile "$PROFILE" --locked --bin ricochet --target aarch64-apple-darwin
cp target/aarch64-apple-darwin/$PROFILE/ricochet target/binaries/ricochet-macos-arm64
cleanup_assets
echo "✓ Built aarch64-apple-darwin successfully"
echo "Binary location: target/binaries/ricochet-macos-arm64"
;;
"macos-x86_64"|"macos-x64"|"darwin-x86")
echo "Building binary for x86_64-apple-darwin..."
rustup target add x86_64-apple-darwin || true
# macOS uses different RUSTFLAGS (no static linking flags)
RUSTFLAGS="" cargo build --profile "$PROFILE" --locked --bin ricochet --target x86_64-apple-darwin
cp target/x86_64-apple-darwin/$PROFILE/ricochet target/binaries/ricochet-macos-x86_64
cleanup_assets
echo "✓ Built x86_64-apple-darwin successfully"
echo "Binary location: target/binaries/ricochet-macos-x86_64"
;;
"all")
echo "Building binaries for all targets..."
echo "Building static x86_64-unknown-linux-gnu..."
rustup target add x86_64-unknown-linux-gnu || true
cargo build --profile "$PROFILE" --locked --bin ricochet --target x86_64-unknown-linux-gnu
cp target/x86_64-unknown-linux-gnu/$PROFILE/ricochet target/binaries/ricochet-linux-x86_64
echo "Building static aarch64-unknown-linux-gnu..."
rustup target add aarch64-unknown-linux-gnu || true
cargo build --profile "$PROFILE" --locked --bin ricochet --target aarch64-unknown-linux-gnu
cp target/aarch64-unknown-linux-gnu/$PROFILE/ricochet target/binaries/ricochet-linux-aarch64
echo "Building static riscv64gc-unknown-linux-gnu..."
rustup target add riscv64gc-unknown-linux-gnu || true
cargo build --profile "$PROFILE" --locked --bin ricochet --target riscv64gc-unknown-linux-gnu
cp target/riscv64gc-unknown-linux-gnu/$PROFILE/ricochet target/binaries/ricochet-linux-riscv64
echo "Building static x86_64-pc-windows-gnu..."
rustup target add x86_64-pc-windows-gnu || true
RUSTFLAGS="-C target-feature=+crt-static" cargo build --profile "$PROFILE" --locked --bin ricochet --target x86_64-pc-windows-gnu
cp target/x86_64-pc-windows-gnu/$PROFILE/ricochet.exe target/binaries/ricochet-windows-x86_64.exe
echo "Building static aarch64-pc-windows-msvc..."
rustup target add aarch64-pc-windows-msvc || true
RUSTFLAGS="-C target-feature=+crt-static" cargo build --profile "$PROFILE" --locked --bin ricochet --target aarch64-pc-windows-msvc
cp target/aarch64-pc-windows-msvc/$PROFILE/ricochet.exe target/binaries/ricochet-windows-arm64.exe
echo "Building aarch64-apple-darwin..."
rustup target add aarch64-apple-darwin || true
RUSTFLAGS="" cargo build --profile "$PROFILE" --locked --bin ricochet --target aarch64-apple-darwin
cp target/aarch64-apple-darwin/$PROFILE/ricochet target/binaries/ricochet-macos-arm64
echo "Building x86_64-apple-darwin..."
rustup target add x86_64-apple-darwin || true
RUSTFLAGS="" cargo build --profile "$PROFILE" --locked --bin ricochet --target x86_64-apple-darwin
cp target/x86_64-apple-darwin/$PROFILE/ricochet target/binaries/ricochet-macos-x86_64
cleanup_assets
echo "All binaries built successfully!"
echo "Binaries location:"
echo " - Linux x86_64: target/binaries/ricochet-linux-x86_64"
echo " - Linux aarch64: target/binaries/ricochet-linux-aarch64"
echo " - Linux riscv64: target/binaries/ricochet-linux-riscv64"
echo " - Windows x86_64: target/binaries/ricochet-windows-x86_64.exe"
echo " - Windows ARM64: target/binaries/ricochet-windows-arm64.exe"
echo " - macOS ARM64: target/binaries/ricochet-macos-arm64"
echo " - macOS x86_64: target/binaries/ricochet-macos-x86_64"
;;
*)
echo "Unknown target: {{target}}"
echo "Available targets:"
echo " - linux-x86_64 Linux x86_64"
echo " - linux-aarch64 Linux ARM64"
echo " - linux-riscv64 Linux RISC-V 64"
echo " - windows-x86_64 Windows x86_64"
echo " - windows-arm64 Windows ARM64"
echo " - macos-arm64 macOS ARM64"
echo " - macos-x86_64 macOS x86_64"
echo " - all All targets"
echo ""
echo "Legacy aliases (deprecated):"
echo " - x86_64 -> linux-x86_64"
echo " - aarch64 -> linux-aarch64"
echo " - riscv64 (riscv) -> linux-riscv64"
echo " - windows (win) -> windows-x86_64"
exit 1
;;
esac
# Install debug version locally
install:
cargo install --path . --debug
build-local PROFILE="release":
cargo build --profile {{PROFILE}} --bin ricochet
# Move built binary to local bin
move-cli-local PROFILE="release": (build-local PROFILE)
sudo cp target/{{PROFILE}}/ricochet ~/.local/bin/ricochet-dev
# generate CLI documentation
docs:
@echo "Generating CLI documentation..."
@mkdir -p docs
@cargo run --quiet -- generate-docs > docs/cli-commands.md 2>/dev/null
@echo "✓ Documentation generated: docs/cli-commands.md"
# check if CLI documentation is up-to-date
docs-check:
@echo "Checking if CLI documentation is up-to-date..."
@mkdir -p docs
@cargo run --quiet -- generate-docs > /tmp/cli-commands-generated.md 2>/dev/null
@if ! diff -q docs/cli-commands.md /tmp/cli-commands-generated.md > /dev/null 2>&1; then \
echo "❌ ERROR: CLI documentation is out of date!"; \
echo ""; \
echo "Run 'just docs' to update the documentation."; \
echo ""; \
echo "Differences:"; \
diff -u docs/cli-commands.md /tmp/cli-commands-generated.md || true; \
rm -f /tmp/cli-commands-generated.md; \
exit 1; \
else \
echo "✓ CLI documentation is up-to-date"; \
rm -f /tmp/cli-commands-generated.md; \
fi