MAJOR ARCHITECTURAL CHANGE: - Add Rust components as git subtrees: zinit, mycelium, rfs - Replace git submodules with unified Rust workspace - Update compile-components.sh to use workspace build - Remove obsolete setup-submodules.sh script - Keep CoreX handling in fetch-github.sh (Go binary) BENEFITS: - Unified dependency management across Rust components - Single 'cargo build --workspace' command - Better IDE support and shared target directory - Improved build caching and version consistency Components structure: - components/zinit (subtree from threefoldtech/zinit) - components/mycelium (subtree from threefoldtech/mycelium) - components/rfs (subtree from threefoldtech/rfs) - CoreX handled by fetch-github.sh (binary download)
141 lines
4.2 KiB
Bash
Executable File
141 lines
4.2 KiB
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
|
|
ALPINE_ROOT="/build/initramfs"
|
|
OUTPUT_DIR="/build/output"
|
|
WORKSPACE_ROOT="/build"
|
|
|
|
echo "[+] Compiling Zero-OS components using Rust workspace..."
|
|
|
|
# Check if workspace is available
|
|
if [ ! -f "$WORKSPACE_ROOT/Cargo.toml" ]; then
|
|
echo "Error: Cargo workspace not found at $WORKSPACE_ROOT/Cargo.toml"
|
|
exit 1
|
|
fi
|
|
|
|
# Check if components exist
|
|
if [ ! -d "$WORKSPACE_ROOT/components" ]; then
|
|
echo "Error: Components directory not found. Workspace is not properly set up."
|
|
exit 1
|
|
fi
|
|
|
|
echo " Workspace components found:"
|
|
ls -1 "$WORKSPACE_ROOT/components/" | sed 's/^/ - /'
|
|
echo ""
|
|
|
|
# Function to build entire workspace
|
|
build_workspace() {
|
|
echo " Building Rust workspace for musl target..."
|
|
|
|
cd "$WORKSPACE_ROOT"
|
|
|
|
# Source cargo environment
|
|
. ~/.cargo/env
|
|
|
|
# Build all workspace members with musl target for static linking
|
|
echo " Running: cargo build --workspace --release --target x86_64-unknown-linux-musl"
|
|
CARGO_TARGET_DIR="$WORKSPACE_ROOT/target" cargo build --workspace --release --target x86_64-unknown-linux-musl
|
|
|
|
echo " Workspace build completed successfully"
|
|
return 0
|
|
}
|
|
|
|
# Function to install workspace binaries
|
|
install_workspace_binaries() {
|
|
local target_dir="$WORKSPACE_ROOT/target/x86_64-unknown-linux-musl/release"
|
|
|
|
echo " Installing workspace binaries..."
|
|
echo " Target directory: $target_dir"
|
|
|
|
# Debug: Show what was built
|
|
echo " Built binaries:"
|
|
ls -la "$target_dir" 2>/dev/null | grep -E '^-.*x.*' | awk '{print " " $9 " (" $5 " bytes)"}' || echo " No binaries found"
|
|
|
|
# Create output and alpine root directories
|
|
mkdir -p "$OUTPUT_DIR"
|
|
mkdir -p "$ALPINE_ROOT/sbin"
|
|
mkdir -p "$ALPINE_ROOT/usr/bin"
|
|
|
|
# Install specific binaries
|
|
local installed=0
|
|
|
|
# Install zinit
|
|
if [ -f "$target_dir/zinit" ]; then
|
|
cp "$target_dir/zinit" "$ALPINE_ROOT/sbin/"
|
|
cp "$target_dir/zinit" "$OUTPUT_DIR/"
|
|
chmod +x "$ALPINE_ROOT/sbin/zinit"
|
|
echo " ✓ zinit -> /sbin/zinit"
|
|
installed=$((installed + 1))
|
|
else
|
|
echo " ✗ zinit binary not found"
|
|
fi
|
|
|
|
# Install rfs (check for different possible names)
|
|
local rfs_binary=""
|
|
for name in "rfs" "rfs-server" "rfs-bin"; do
|
|
if [ -f "$target_dir/$name" ]; then
|
|
rfs_binary="$name"
|
|
break
|
|
fi
|
|
done
|
|
|
|
if [ -n "$rfs_binary" ]; then
|
|
cp "$target_dir/$rfs_binary" "$ALPINE_ROOT/usr/bin/rfs"
|
|
cp "$target_dir/$rfs_binary" "$OUTPUT_DIR/rfs"
|
|
chmod +x "$ALPINE_ROOT/usr/bin/rfs"
|
|
echo " ✓ $rfs_binary -> /usr/bin/rfs"
|
|
installed=$((installed + 1))
|
|
else
|
|
echo " ✗ rfs binary not found (checked: rfs, rfs-server, rfs-bin)"
|
|
fi
|
|
|
|
# Install mycelium (check in myceliumd subdirectory build)
|
|
if [ -f "$target_dir/mycelium" ]; then
|
|
cp "$target_dir/mycelium" "$ALPINE_ROOT/usr/bin/"
|
|
cp "$target_dir/mycelium" "$OUTPUT_DIR/"
|
|
chmod +x "$ALPINE_ROOT/usr/bin/mycelium"
|
|
echo " ✓ mycelium -> /usr/bin/mycelium"
|
|
installed=$((installed + 1))
|
|
else
|
|
echo " ✗ mycelium binary not found"
|
|
fi
|
|
|
|
echo " Installed $installed out of 3 expected binaries"
|
|
return 0
|
|
}
|
|
|
|
# Ensure Alpine root directory exists
|
|
if [ ! -d "$ALPINE_ROOT" ]; then
|
|
echo " Creating Alpine initramfs root at $ALPINE_ROOT"
|
|
mkdir -p "$ALPINE_ROOT"
|
|
fi
|
|
|
|
# Build workspace
|
|
if build_workspace; then
|
|
echo " ✓ Workspace build completed"
|
|
else
|
|
echo " ✗ Workspace build failed"
|
|
exit 1
|
|
fi
|
|
|
|
# Install binaries
|
|
install_workspace_binaries
|
|
|
|
echo ""
|
|
echo "[+] Zero-OS component compilation completed using Rust workspace"
|
|
|
|
# Show installed binaries info
|
|
echo ""
|
|
echo "[+] Compiled Zero-OS components in Alpine root:"
|
|
for binary in "/sbin/zinit" "/usr/bin/rfs" "/usr/bin/mycelium"; do
|
|
if [ -x "$ALPINE_ROOT$binary" ]; then
|
|
size=$(stat -c%s "$ALPINE_ROOT$binary" 2>/dev/null || echo "unknown")
|
|
echo " $binary (${size} bytes)"
|
|
else
|
|
echo " $binary (NOT BUILT)"
|
|
fi
|
|
done
|
|
|
|
echo ""
|
|
echo "[+] Compiled binaries also saved to: $OUTPUT_DIR"
|
|
echo "[+] Zero-OS Rust workspace compilation complete!" |