Update Rust build system: use rustup with musl target for static builds
This commit is contained in:
@@ -43,7 +43,14 @@ RUN apk add --no-cache \
|
||||
grep \
|
||||
findutils \
|
||||
# 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
|
||||
RUN mkdir -p /build/initramfs /build/kernel /build/output /build/github /build/configs/zinit /mnt/zinit
|
||||
|
||||
@@ -33,10 +33,15 @@ RUN apk add --no-cache \
|
||||
grep \
|
||||
findutils \
|
||||
jq \
|
||||
# Go and Rust for source compilation
|
||||
# Go for source compilation
|
||||
go \
|
||||
rust \
|
||||
cargo
|
||||
# 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 standard directories
|
||||
RUN mkdir -p /build/initramfs /build/kernel /build/output /build/github /build/configs/zinit /mnt/zinit /build/source /build/cache
|
||||
|
||||
@@ -51,29 +51,21 @@ build_rust_component() {
|
||||
fi
|
||||
|
||||
# Build the project
|
||||
echo " Compiling with cargo..."
|
||||
if command -v cargo >/dev/null; then
|
||||
cargo build --release
|
||||
echo " Compiling with cargo for musl target..."
|
||||
|
||||
# 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
|
||||
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"
|
||||
|
||||
echo " Success: $install_path/$binary_name installed to Alpine root"
|
||||
echo " Success: $install_path/$binary_name installed to Alpine root (musl static)"
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user