Skip to content

Commit e936626

Browse files
author
Paul C
committed
feat: prebuilt binary support for WolfNet
Add GitHub Actions workflow to build musl static binaries for x86_64 and aarch64. setup.sh downloads prebuilt binaries first, skipping Rust install and source build entirely. Falls back to source if unavailable.
1 parent a99301b commit e936626

2 files changed

Lines changed: 194 additions & 69 deletions

File tree

.github/workflows/release.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: Build Release Binaries
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
- 'Cargo.toml'
8+
- 'src/**'
9+
10+
jobs:
11+
build:
12+
strategy:
13+
matrix:
14+
include:
15+
- target: x86_64-unknown-linux-musl
16+
arch: x86_64
17+
runner: ubuntu-latest
18+
- target: aarch64-unknown-linux-musl
19+
arch: aarch64
20+
runner: ubuntu-latest
21+
22+
runs-on: ${{ matrix.runner }}
23+
steps:
24+
- uses: actions/checkout@v4
25+
26+
- name: Install Rust
27+
uses: dtolnay/rust-toolchain@stable
28+
with:
29+
targets: ${{ matrix.target }}
30+
31+
- name: Install cross
32+
run: cargo install cross --git https://github.com/cross-rs/cross
33+
34+
- name: Build static binaries
35+
run: cross build --release --target ${{ matrix.target }}
36+
37+
- name: Get version
38+
id: version
39+
run: echo "version=$(grep '^version' Cargo.toml | head -1 | sed 's/.*\"\(.*\)\".*/\1/')" >> "$GITHUB_OUTPUT"
40+
41+
- name: Package binaries
42+
run: |
43+
mkdir -p dist
44+
cp target/${{ matrix.target }}/release/wolfnet dist/wolfnet-${{ matrix.arch }}
45+
cp target/${{ matrix.target }}/release/wolfnetctl dist/wolfnetctl-${{ matrix.arch }}
46+
chmod +x dist/wolfnet-${{ matrix.arch }} dist/wolfnetctl-${{ matrix.arch }}
47+
48+
- name: Upload artifact
49+
uses: actions/upload-artifact@v4
50+
with:
51+
name: wolfnet-${{ matrix.arch }}
52+
path: dist/*
53+
54+
release:
55+
needs: build
56+
runs-on: ubuntu-latest
57+
permissions:
58+
contents: write
59+
steps:
60+
- uses: actions/checkout@v4
61+
62+
- name: Get version
63+
id: version
64+
run: echo "version=$(grep '^version' Cargo.toml | head -1 | sed 's/.*\"\(.*\)\".*/\1/')" >> "$GITHUB_OUTPUT"
65+
66+
- name: Download all artifacts
67+
uses: actions/download-artifact@v4
68+
with:
69+
path: dist
70+
merge-multiple: true
71+
72+
- name: Create or update release
73+
env:
74+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
75+
run: |
76+
VERSION="v${{ steps.version.outputs.version }}"
77+
78+
# Delete existing release if it exists (update scenario)
79+
gh release delete "$VERSION" --yes 2>/dev/null || true
80+
git push --delete origin "$VERSION" 2>/dev/null || true
81+
82+
# Create release with binaries
83+
gh release create "$VERSION" \
84+
--title "WolfNet $VERSION" \
85+
--notes "Prebuilt static binaries for Linux x86_64 and aarch64 (ARM64/Raspberry Pi 4+)." \
86+
dist/wolfnet-x86_64 \
87+
dist/wolfnet-aarch64 \
88+
dist/wolfnetctl-x86_64 \
89+
dist/wolfnetctl-aarch64

setup.sh

Lines changed: 105 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,31 @@ else
6363
echo "✓ /dev/net/tun available"
6464
fi
6565

66+
# ─── Architecture detection for prebuilt binaries ──────────────────────────
67+
HOST_ARCH=$(uname -m)
68+
case "$HOST_ARCH" in
69+
x86_64) BINARY_ARCH="x86_64" ;;
70+
aarch64) BINARY_ARCH="aarch64" ;;
71+
*) BINARY_ARCH="" ;;
72+
esac
73+
74+
# Try prebuilt binaries first — skips Rust install, clone, and build entirely
75+
PREBUILT_OK=false
76+
if [ -n "$BINARY_ARCH" ]; then
77+
echo ""
78+
echo "Downloading prebuilt binaries for ${BINARY_ARCH}..."
79+
PREBUILT_URL="https://github.com/wolfsoftwaresystemsltd/WolfNet/releases/latest/download"
80+
if curl -fSL --connect-timeout 10 --max-time 120 -o /tmp/wolfnet "$PREBUILT_URL/wolfnet-${BINARY_ARCH}" 2>/dev/null; then
81+
chmod +x /tmp/wolfnet
82+
curl -fSL --connect-timeout 10 --max-time 60 -o /tmp/wolfnetctl "$PREBUILT_URL/wolfnetctl-${BINARY_ARCH}" 2>/dev/null && chmod +x /tmp/wolfnetctl || true
83+
PREBUILT_OK=true
84+
echo "✓ Prebuilt binaries downloaded"
85+
else
86+
echo "⚠ Prebuilt binaries not available — will build from source"
87+
rm -f /tmp/wolfnet /tmp/wolfnetctl
88+
fi
89+
fi
90+
6691
# Detect package manager
6792
if command -v apt &> /dev/null; then
6893
PKG_MANAGER="apt"
@@ -79,81 +104,85 @@ else
79104
exit 1
80105
fi
81106

82-
# Install dependencies
83-
echo ""
84-
echo "Installing system dependencies..."
85-
86-
if [ "$PKG_MANAGER" = "apt" ]; then
87-
apt update
88-
apt install -y git curl build-essential pkg-config libssl-dev
89-
elif [ "$PKG_MANAGER" = "dnf" ]; then
90-
dnf install -y git curl gcc gcc-c++ make openssl-devel pkg-config
91-
elif [ "$PKG_MANAGER" = "yum" ]; then
92-
yum install -y git curl gcc gcc-c++ make openssl-devel pkgconfig
93-
fi
107+
if [ "$PREBUILT_OK" = "false" ]; then
108+
# Need to build from source — install dependencies, Rust, and clone repo
94109

95-
echo "✓ System dependencies installed"
110+
# Install dependencies
111+
echo ""
112+
echo "Installing system dependencies..."
113+
114+
if [ "$PKG_MANAGER" = "apt" ]; then
115+
apt update
116+
apt install -y git curl build-essential pkg-config libssl-dev
117+
elif [ "$PKG_MANAGER" = "dnf" ]; then
118+
dnf install -y git curl gcc gcc-c++ make openssl-devel pkg-config
119+
elif [ "$PKG_MANAGER" = "yum" ]; then
120+
yum install -y git curl gcc gcc-c++ make openssl-devel pkgconfig
121+
fi
96122

97-
# Install Rust if not present (install as the real user, not root)
98-
CARGO_BIN="$REAL_HOME/.cargo/bin/cargo"
123+
echo "✓ System dependencies installed"
99124

100-
if [ -f "$CARGO_BIN" ]; then
101-
echo "✓ Rust already installed"
102-
elif command -v cargo &> /dev/null; then
103-
CARGO_BIN="$(command -v cargo)"
104-
echo "✓ Rust already installed (system-wide)"
105-
else
106-
echo ""
107-
echo "Installing Rust for user '$REAL_USER'..."
108-
if [ "$REAL_USER" = "root" ]; then
109-
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
125+
# Install Rust if not present (install as the real user, not root)
126+
CARGO_BIN="$REAL_HOME/.cargo/bin/cargo"
127+
128+
if [ -f "$CARGO_BIN" ]; then
129+
echo "✓ Rust already installed"
130+
elif command -v cargo &> /dev/null; then
131+
CARGO_BIN="$(command -v cargo)"
132+
echo "✓ Rust already installed (system-wide)"
110133
else
111-
su - "$REAL_USER" -c "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y"
134+
echo ""
135+
echo "Installing Rust for user '$REAL_USER'..."
136+
if [ "$REAL_USER" = "root" ]; then
137+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
138+
else
139+
su - "$REAL_USER" -c "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y"
140+
fi
141+
echo "✓ Rust installed"
112142
fi
113-
echo "✓ Rust installed"
114-
fi
115143

116-
# Ensure cargo is found
117-
export PATH="$REAL_HOME/.cargo/bin:/usr/local/bin:/usr/bin:$PATH"
144+
# Ensure cargo is found
145+
export PATH="$REAL_HOME/.cargo/bin:/usr/local/bin:/usr/bin:$PATH"
118146

119-
if ! command -v cargo &> /dev/null; then
120-
echo "✗ cargo not found after installation. Check Rust install."
121-
exit 1
122-
fi
147+
if ! command -v cargo &> /dev/null; then
148+
echo "✗ cargo not found after installation. Check Rust install."
149+
exit 1
150+
fi
123151

124-
echo "✓ Using cargo: $(command -v cargo)"
152+
echo "✓ Using cargo: $(command -v cargo)"
125153

126-
# Clone or update repository
127-
INSTALL_DIR="/opt/wolfscale-src"
128-
echo ""
129-
echo "Cloning WolfScale repository..."
154+
# Clone or update repository
155+
INSTALL_DIR="/opt/wolfscale-src"
156+
echo ""
157+
echo "Cloning WolfScale repository..."
130158

131-
if [ -d "$INSTALL_DIR" ]; then
132-
echo " Updating existing installation..."
133-
cd "$INSTALL_DIR"
134-
git fetch origin
135-
git reset --hard origin/main
136-
else
137-
git clone https://github.com/wolfsoftwaresystemsltd/WolfScale.git "$INSTALL_DIR"
138-
cd "$INSTALL_DIR"
139-
fi
159+
if [ -d "$INSTALL_DIR" ]; then
160+
echo " Updating existing installation..."
161+
cd "$INSTALL_DIR"
162+
git fetch origin
163+
git reset --hard origin/main
164+
else
165+
git clone https://github.com/wolfsoftwaresystemsltd/WolfScale.git "$INSTALL_DIR"
166+
cd "$INSTALL_DIR"
167+
fi
140168

141-
echo "✓ Repository cloned to $INSTALL_DIR"
169+
echo "✓ Repository cloned to $INSTALL_DIR"
142170

143-
# Build WolfNet (as the real user if possible, to use their cargo)
144-
echo ""
145-
echo "Building WolfNet (this may take a few minutes)..."
146-
cd "$INSTALL_DIR/wolfnet"
171+
# Build WolfNet (as the real user if possible, to use their cargo)
172+
echo ""
173+
echo "Building WolfNet (this may take a few minutes)..."
174+
cd "$INSTALL_DIR/wolfnet"
147175

148-
if [ "$REAL_USER" != "root" ] && [ -f "$REAL_HOME/.cargo/bin/cargo" ]; then
149-
# Build as the real user so cargo uses their toolchain
150-
chown -R "$REAL_USER:$REAL_USER" "$INSTALL_DIR"
151-
su - "$REAL_USER" -c "cd $INSTALL_DIR/wolfnet && $REAL_HOME/.cargo/bin/cargo build --release"
152-
else
153-
cargo build --release
154-
fi
176+
if [ "$REAL_USER" != "root" ] && [ -f "$REAL_HOME/.cargo/bin/cargo" ]; then
177+
# Build as the real user so cargo uses their toolchain
178+
chown -R "$REAL_USER:$REAL_USER" "$INSTALL_DIR"
179+
su - "$REAL_USER" -c "cd $INSTALL_DIR/wolfnet && $REAL_HOME/.cargo/bin/cargo build --release"
180+
else
181+
cargo build --release
182+
fi
155183

156-
echo "✓ Build complete"
184+
echo "✓ Build complete"
185+
fi
157186

158187
# Stop service if running (for upgrades)
159188
if systemctl is-active --quiet wolfnet 2>/dev/null; then
@@ -175,16 +204,23 @@ if [ -f "/usr/local/bin/wolfnet" ]; then
175204
else
176205
echo "Installing WolfNet..."
177206
fi
178-
cp "$INSTALL_DIR/wolfnet/target/release/wolfnet" /usr/local/bin/wolfnet
179-
chmod +x /usr/local/bin/wolfnet
180-
echo "✓ wolfnet installed to /usr/local/bin/wolfnet"
181207

182-
# Install wolfnetctl if it exists
183-
if [ -f "$INSTALL_DIR/wolfnet/target/release/wolfnetctl" ]; then
184-
cp "$INSTALL_DIR/wolfnet/target/release/wolfnetctl" /usr/local/bin/wolfnetctl
185-
chmod +x /usr/local/bin/wolfnetctl
186-
echo "✓ wolfnetctl installed to /usr/local/bin/wolfnetctl"
208+
if [ "$PREBUILT_OK" = "true" ]; then
209+
mv /tmp/wolfnet /usr/local/bin/wolfnet
210+
if [ -f /tmp/wolfnetctl ]; then
211+
mv /tmp/wolfnetctl /usr/local/bin/wolfnetctl
212+
echo "✓ wolfnetctl installed to /usr/local/bin/wolfnetctl"
213+
fi
214+
else
215+
cp "$INSTALL_DIR/wolfnet/target/release/wolfnet" /usr/local/bin/wolfnet
216+
chmod +x /usr/local/bin/wolfnet
217+
if [ -f "$INSTALL_DIR/wolfnet/target/release/wolfnetctl" ]; then
218+
cp "$INSTALL_DIR/wolfnet/target/release/wolfnetctl" /usr/local/bin/wolfnetctl
219+
chmod +x /usr/local/bin/wolfnetctl
220+
echo "✓ wolfnetctl installed to /usr/local/bin/wolfnetctl"
221+
fi
187222
fi
223+
echo "✓ wolfnet installed to /usr/local/bin/wolfnet"
188224

189225
# Create directories
190226
echo ""

0 commit comments

Comments
 (0)