Update Rust build system: use rustup with musl target for static builds

This commit is contained in:
2025-08-15 22:44:19 +02:00
parent 756b7e5514
commit f1829141a3
3 changed files with 31 additions and 27 deletions

View File

@@ -43,7 +43,14 @@ RUN apk add --no-cache \
grep \ grep \
findutils \ findutils \
# JSON processing for GitHub API # JSON processing for GitHub API
jq jq \
# Rustup for proper Rust musl builds
rustup
# Setup Rust toolchain for musl builds
RUN rustup-init -y --default-toolchain stable && \
. ~/.cargo/env && \
rustup target add x86_64-unknown-linux-musl
# Create directories # Create directories
RUN mkdir -p /build/initramfs /build/kernel /build/output /build/github /build/configs/zinit /mnt/zinit RUN mkdir -p /build/initramfs /build/kernel /build/output /build/github /build/configs/zinit /mnt/zinit

View File

@@ -33,10 +33,15 @@ RUN apk add --no-cache \
grep \ grep \
findutils \ findutils \
jq \ jq \
# Go and Rust for source compilation # Go for source compilation
go \ go \
rust \ # Rustup for proper Rust musl builds
cargo rustup
# Setup Rust toolchain for musl builds
RUN rustup-init -y --default-toolchain stable && \
. ~/.cargo/env && \
rustup target add x86_64-unknown-linux-musl
# Create standard directories # Create standard directories
RUN mkdir -p /build/initramfs /build/kernel /build/output /build/github /build/configs/zinit /mnt/zinit /build/source /build/cache RUN mkdir -p /build/initramfs /build/kernel /build/output /build/github /build/configs/zinit /mnt/zinit /build/source /build/cache

View File

@@ -51,29 +51,21 @@ build_rust_component() {
fi fi
# Build the project # Build the project
echo " Compiling with cargo..." echo " Compiling with cargo for musl target..."
if command -v cargo >/dev/null; then
cargo build --release # Source cargo environment
. ~/.cargo/env
# Build with musl target for static linking
cargo build --release --target x86_64-unknown-linux-musl
# Install binary to Alpine root # Install binary to Alpine root
mkdir -p "$ALPINE_ROOT$install_path" mkdir -p "$ALPINE_ROOT$install_path"
cp "target/release/$binary_name" "$ALPINE_ROOT$install_path/" cp "target/x86_64-unknown-linux-musl/release/$binary_name" "$ALPINE_ROOT$install_path/"
chmod +x "$ALPINE_ROOT$install_path/$binary_name" chmod +x "$ALPINE_ROOT$install_path/$binary_name"
echo " Success: $install_path/$binary_name installed to Alpine root" echo " Success: $install_path/$binary_name installed to Alpine root (musl static)"
return 0 return 0
else
echo " Error: cargo not found - installing Rust..."
apk add --no-cache rust cargo
cargo build --release
mkdir -p "$ALPINE_ROOT$install_path"
cp "target/release/$binary_name" "$ALPINE_ROOT$install_path/"
chmod +x "$ALPINE_ROOT$install_path/$binary_name"
echo " Success: $install_path/$binary_name installed to Alpine root"
return 0
fi
} }
# Function to build Go project from submodule # Function to build Go project from submodule