Skip to content

Commit 7cd5051

Browse files
committed
Fix autosetup
1 parent c8b6329 commit 7cd5051

2 files changed

Lines changed: 199 additions & 29 deletions

File tree

Makefile

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,37 +24,18 @@ fix: setup
2424
test: setup
2525
cargo build -p ljd -p ljx -p ljx-parquet-exporter
2626
cargo build -p otlp-demo --bin otlp-bofh-emitter
27-
@if command -v cargo-nextest >/dev/null 2>&1; then \
28-
cargo nextest run $(CORE_WORKSPACE); \
29-
else \
30-
echo "cargo-nextest not available, falling back to cargo test $(CORE_WORKSPACE)"; \
31-
cargo test $(CORE_WORKSPACE); \
32-
fi
27+
cargo nextest run $(CORE_WORKSPACE)
3328

3429
test-unit: setup
3530
cargo build -p ljx-parquet-exporter
36-
@if command -v cargo-nextest >/dev/null 2>&1; then \
37-
cargo nextest run -p logjet --lib -p ljd --bins -p ljx --bin ljx; \
38-
else \
39-
echo "cargo-nextest not available, falling back to cargo test unit-only targets"; \
40-
cargo test -p logjet --lib; \
41-
cargo test -p ljd --bin ljd; \
42-
cargo test -p ljx --bin ljx; \
43-
fi
31+
cargo nextest run -p logjet --lib -p ljd --bins -p ljx --bin ljx
4432

4533
test-integration: setup
4634
cargo build -p ljd -p ljx -p ljx-parquet-exporter
4735
cargo build -p otlp-demo --bin otlp-bofh-emitter
48-
@if command -v cargo-nextest >/dev/null 2>&1; then \
49-
cargo nextest run -p ljd --test bridge_flows; \
50-
cargo nextest run -p logjet --test ljx_cli; \
51-
cargo nextest run -p logjet --test ljx_export; \
52-
else \
53-
echo "cargo-nextest not available, falling back to cargo test integration targets"; \
54-
cargo test -p ljd --test bridge_flows; \
55-
cargo test -p logjet --test ljx_cli; \
56-
cargo test -p logjet --test ljx_export; \
57-
fi
36+
cargo nextest run -p ljd --test bridge_flows
37+
cargo nextest run -p logjet --test ljx_cli
38+
cargo nextest run -p logjet --test ljx_export
5839

5940
test-abi-matrix: setup
6041
bash scripts/test-exporter-abi-matrix.sh
@@ -97,11 +78,8 @@ stats:
9778
tokei . --exclude target --exclude .git
9879

9980
setup:
100-
@command -v rustc >/dev/null 2>&1 || { echo "rustc not found. Install Rust from https://rustup.rs"; exit 1; }
101-
@command -v cargo >/dev/null 2>&1 || { echo "cargo not found. Install Rust from https://rustup.rs"; exit 1; }
102-
@command -v rustup >/dev/null 2>&1 || { echo "rustup not found. Install Rust from https://rustup.rs"; exit 1; }
103-
@cargo clippy --version >/dev/null 2>&1 || { echo "clippy is missing. Run: rustup component add clippy"; exit 1; }
104-
@echo "Rust toolchain looks ready."
81+
@bash scripts/setup-rust.sh
82+
@echo "Setup complete."
10583

10684
setup-arm:
10785
@rustup target list --installed | grep -qx "$(ARM_TARGET)" || rustup target add "$(ARM_TARGET)"

scripts/setup-rust.sh

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
CARGO_HOME="${CARGO_HOME:-$HOME/.cargo}"
5+
CARGO_ENV="$CARGO_HOME/env"
6+
7+
if [ -f "$CARGO_ENV" ]; then
8+
source "$CARGO_ENV" 2>/dev/null || true
9+
fi
10+
11+
have_rustc() { command -v rustc >/dev/null 2>&1; }
12+
have_cargo() { command -v cargo >/dev/null 2>&1; }
13+
have_rustup() { command -v rustup >/dev/null 2>&1; }
14+
have_cc() { command -v cc >/dev/null 2>&1; }
15+
16+
# ── CC / system package helpers ─────────────────────────────────────────────
17+
18+
detect_pkg_manager() {
19+
case "$(uname -s)" in
20+
Linux)
21+
if [ -f /etc/os-release ]; then
22+
local id
23+
id=$(awk -F= '/^ID=/{print tolower($2)}' /etc/os-release | tr -d '"')
24+
case "$id" in
25+
ubuntu|debian|pop|linuxmint|elementary|zorin|neon) echo "apt:build-essential" ;;
26+
fedora|centos|rhel|rocky|almalinux) echo "dnf:gcc" ;;
27+
arch|manjaro|endeavouros) echo "pacman:gcc" ;;
28+
opensuse*|suse) echo "zypper:gcc" ;;
29+
*) echo "unknown" ;;
30+
esac
31+
else
32+
echo "unknown"
33+
fi
34+
;;
35+
FreeBSD) echo "pkg:gcc" ;;
36+
NetBSD) echo "pkgin:gcc12" ;;
37+
*) echo "unknown" ;;
38+
esac
39+
}
40+
41+
install_system_cc() {
42+
local manager="$1"
43+
local pkg_name="${manager#*:}"
44+
local cmd="${manager%%:*}"
45+
46+
case "$cmd" in
47+
apt)
48+
echo "Running: sudo apt install -y $pkg_name"
49+
sudo apt update && sudo apt install -y "$pkg_name"
50+
;;
51+
dnf)
52+
echo "Running: sudo dnf install -y $pkg_name"
53+
sudo dnf install -y "$pkg_name"
54+
;;
55+
pacman)
56+
echo "Running: sudo pacman -S --noconfirm $pkg_name"
57+
sudo pacman -S --noconfirm "$pkg_name"
58+
;;
59+
zypper)
60+
echo "Running: sudo zypper install -y $pkg_name"
61+
sudo zypper install -y "$pkg_name"
62+
;;
63+
pkg)
64+
echo "Running: sudo pkg install -y $pkg_name"
65+
sudo pkg install -y "$pkg_name"
66+
;;
67+
pkgin)
68+
echo "Running: sudo pkgin -y install $pkg_name"
69+
sudo pkgin -y install "$pkg_name"
70+
;;
71+
*)
72+
echo "Could not determine how to install a C compiler on this system."
73+
echo "Please install gcc or clang and re-run this script."
74+
return 1
75+
;;
76+
esac
77+
}
78+
79+
ensure_cc() {
80+
if have_cc; then
81+
return 0
82+
fi
83+
84+
echo ""
85+
echo "A C compiler (cc) is required to build Rust crates."
86+
echo ""
87+
88+
local manager
89+
manager=$(detect_pkg_manager)
90+
91+
if [ "$manager" = "unknown" ]; then
92+
echo "Could not detect your package manager."
93+
echo "Please install gcc or clang, then re-run this script."
94+
exit 1
95+
fi
96+
97+
local pkg_name="${manager#*:}"
98+
echo "Detected package manager: ${manager%%:*}"
99+
echo "Required package: $pkg_name"
100+
echo ""
101+
102+
read -r -p "Install $pkg_name now? [y/N] " answer
103+
case "$answer" in
104+
[yY]|[yY][eE][sS]) ;;
105+
*)
106+
echo "Please install gcc or clang, then re-run this script."
107+
exit 1
108+
;;
109+
esac
110+
111+
install_system_cc "$manager"
112+
113+
if ! have_cc; then
114+
echo "Failed to install C compiler. Please install it manually."
115+
exit 1
116+
fi
117+
echo "C compiler installed: $(cc --version 2>&1 | head -1)"
118+
}
119+
120+
# ── Main setup flow ─────────────────────────────────────────────────────────
121+
122+
if have_rustc && have_cargo && have_rustup; then
123+
echo "Rust toolchain already installed (rustc $(rustc --version | awk '{print $2}'))."
124+
if ! cargo clippy --version >/dev/null 2>&1; then
125+
echo "Installing missing clippy component..."
126+
rustup component add clippy
127+
fi
128+
ensure_cc
129+
echo ""
130+
if ! command -v cargo-nextest >/dev/null 2>&1; then
131+
echo "Installing cargo-nextest..."
132+
cargo install cargo-nextest --locked
133+
fi
134+
echo ""
135+
echo "Setup complete."
136+
exit 0
137+
fi
138+
ensure_cc
139+
echo ""
140+
echo "Setup complete."
141+
exit 0
142+
fi
143+
144+
echo ""
145+
echo "Rust is required to build this project."
146+
echo ""
147+
148+
if have_rustc || have_cargo || have_rustup; then
149+
echo "A partial Rust installation was detected. Run 'rustup update' and try again."
150+
exit 1
151+
fi
152+
153+
read -r -p "Install Rust from https://rustup.rs? [y/N] " answer
154+
case "$answer" in
155+
[yY]|[yY][eE][sS]) ;;
156+
*)
157+
echo "Rust not installed. Get it from https://rustup.rs, then re-run this script."
158+
exit 1
159+
;;
160+
esac
161+
162+
echo "Downloading and running rustup-init..."
163+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable
164+
165+
if [ -f "$CARGO_ENV" ]; then
166+
source "$CARGO_ENV" 2>/dev/null || true
167+
else
168+
export PATH="$CARGO_HOME/bin:$PATH"
169+
fi
170+
171+
echo ""
172+
echo "Rust installed. Version info:"
173+
rustc --version
174+
cargo --version
175+
rustup --version
176+
177+
echo ""
178+
echo "Installing clippy..."
179+
rustup component add clippy
180+
181+
ensure_cc
182+
183+
echo ""
184+
echo "Installing cargo-nextest..."
185+
if ! command -v cargo-nextest >/dev/null 2>&1; then
186+
cargo install cargo-nextest --locked
187+
else
188+
echo "cargo-nextest already installed."
189+
fi
190+
191+
echo ""
192+
echo "Setup complete."

0 commit comments

Comments
 (0)