-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild-bin.sh
More file actions
54 lines (44 loc) · 1.57 KB
/
build-bin.sh
File metadata and controls
54 lines (44 loc) · 1.57 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
#!/usr/bin/env bash
# Installs build tools (wasm-pack, maturin) into ./bin/ using versions
# from [workspace.metadata.tools] in Cargo.toml.
# Output is captured to .logs/build/build-bin.txt.
#
# Usage:
# bash build-bin.sh
set -euo pipefail
MODULE="build-bin"
REPO_ROOT="$(cd "$(dirname "$0")" && pwd)"
LOG_DIR="$REPO_ROOT/.logs/build"
LOG_FILE="$LOG_DIR/$MODULE.txt"
mkdir -p "$LOG_DIR"
run() {
# Parse tool versions from Cargo.toml [workspace.metadata.tools]
WASM_PACK_VERSION=$(sed -n 's/^wasm-pack *= *"\(.*\)"/\1/p' "$REPO_ROOT/Cargo.toml")
MATURIN_VERSION=$(sed -n 's/^maturin *= *"\(.*\)"/\1/p' "$REPO_ROOT/Cargo.toml")
[ -n "$WASM_PACK_VERSION" ] || { echo "ERROR: Could not read wasm-pack version from Cargo.toml" >&2; exit 1; }
[ -n "$MATURIN_VERSION" ] || { echo "ERROR: Could not read maturin version from Cargo.toml" >&2; exit 1; }
BIN_DIR="$REPO_ROOT/bin"
install_if_needed() {
local name="$1" version="$2"
local bin="$BIN_DIR/$name"
if [ -x "$bin" ]; then
local installed
installed=$("$bin" --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
if [ "$installed" = "$version" ]; then
echo "$name $version already installed, skipping."
return
fi
fi
echo "Installing $name $version..."
cargo install "$name" --version "$version" --locked --root "$REPO_ROOT"
}
install_if_needed wasm-pack "$WASM_PACK_VERSION"
install_if_needed maturin "$MATURIN_VERSION"
echo "Done. Tools at $BIN_DIR/"
}
if run > "$LOG_FILE" 2>&1; then
echo "$MODULE: SUCCESS"
else
echo "$MODULE: ERROR"
exit 1
fi