From f1829141a378702b5d65ac0b79d583f9406f88a8 Mon Sep 17 00:00:00 2001 From: Jan De Landtsheer Date: Fri, 15 Aug 2025 22:44:19 +0200 Subject: [PATCH] Update Rust build system: use rustup with musl target for static builds --- build/Dockerfile.alpine | 9 ++++++++- build/Dockerfile.cached | 11 +++++++--- scripts/compile-components.sh | 38 ++++++++++++++--------------------- 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/build/Dockerfile.alpine b/build/Dockerfile.alpine index fde7f6b..bce2142 100644 --- a/build/Dockerfile.alpine +++ b/build/Dockerfile.alpine @@ -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 diff --git a/build/Dockerfile.cached b/build/Dockerfile.cached index e186d2e..8c231f2 100644 --- a/build/Dockerfile.cached +++ b/build/Dockerfile.cached @@ -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 diff --git a/scripts/compile-components.sh b/scripts/compile-components.sh index 7a3c98a..27e10c5 100755 --- a/scripts/compile-components.sh +++ b/scripts/compile-components.sh @@ -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 - - # Install binary to Alpine root - 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 - 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 + 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/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 (musl static)" + return 0 } # Function to build Go project from submodule