fix: Alpine Rust toolchain compatibility
- Remove rustup dependency from Dockerfile (not available in Alpine) - Update Rust environment setup to handle both rustup and system Rust - Fix musl-gcc linker configuration for Alpine containers - Support both GitHub Actions (rustup) and Alpine container (system) environments
This commit is contained in:
11
Dockerfile
11
Dockerfile
@@ -24,8 +24,8 @@ RUN apk add --no-cache \
|
|||||||
sed \
|
sed \
|
||||||
coreutils
|
coreutils
|
||||||
|
|
||||||
# Add Rust musl target
|
# Install musl-dev for Rust musl targeting (Alpine handles this differently than rustup)
|
||||||
RUN rustup target add x86_64-unknown-linux-musl
|
RUN apk add --no-cache musl-dev
|
||||||
|
|
||||||
# Create non-root user for builds
|
# Create non-root user for builds
|
||||||
RUN adduser -D -s /bin/bash builder && \
|
RUN adduser -D -s /bin/bash builder && \
|
||||||
@@ -34,9 +34,10 @@ RUN adduser -D -s /bin/bash builder && \
|
|||||||
# Set working directory
|
# Set working directory
|
||||||
WORKDIR /workspace
|
WORKDIR /workspace
|
||||||
|
|
||||||
# Set environment variables for static linking
|
# Set environment variables for musl static linking with Alpine's Rust
|
||||||
ENV RUSTFLAGS="-C target-feature=+crt-static"
|
ENV RUSTFLAGS="-C target-feature=+crt-static -C linker=musl-gcc"
|
||||||
ENV CC_x86_64_unknown_linux_musl="musl-gcc"
|
ENV CC="musl-gcc"
|
||||||
|
ENV TARGET_CC="musl-gcc"
|
||||||
ENV CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER="musl-gcc"
|
ENV CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER="musl-gcc"
|
||||||
|
|
||||||
# Default to builder user
|
# Default to builder user
|
||||||
|
|||||||
@@ -234,6 +234,10 @@ function components_build_component() {
|
|||||||
function components_setup_rust_env() {
|
function components_setup_rust_env() {
|
||||||
section_header "Setting Up Rust Environment"
|
section_header "Setting Up Rust Environment"
|
||||||
|
|
||||||
|
# Check if we have rustup (Ubuntu/GitHub Actions) or system Rust (Alpine container)
|
||||||
|
if command_exists "rustup"; then
|
||||||
|
log_info "Using rustup for Rust toolchain management"
|
||||||
|
|
||||||
# Ensure musl target is installed
|
# Ensure musl target is installed
|
||||||
if ! rustup target list --installed | grep -q "$RUST_TARGET"; then
|
if ! rustup target list --installed | grep -q "$RUST_TARGET"; then
|
||||||
log_info "Installing Rust target: ${RUST_TARGET}"
|
log_info "Installing Rust target: ${RUST_TARGET}"
|
||||||
@@ -242,14 +246,30 @@ function components_setup_rust_env() {
|
|||||||
log_info "Rust target already installed: ${RUST_TARGET}"
|
log_info "Rust target already installed: ${RUST_TARGET}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Set environment variables for static linking
|
# Set environment variables for rustup
|
||||||
export RUSTFLAGS="-C target-feature=+crt-static"
|
export RUSTFLAGS="-C target-feature=+crt-static"
|
||||||
export CC_x86_64_unknown_linux_musl="musl-gcc"
|
export CC_x86_64_unknown_linux_musl="musl-gcc"
|
||||||
export CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER="musl-gcc"
|
export CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER="musl-gcc"
|
||||||
|
else
|
||||||
|
log_info "Using system Rust (Alpine) with musl"
|
||||||
|
|
||||||
|
# Verify musl-gcc is available
|
||||||
|
if ! command_exists "musl-gcc"; then
|
||||||
|
log_error "musl-gcc not found. Install with: apk add musl-dev"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Set environment variables for system Rust
|
||||||
|
export RUSTFLAGS="-C target-feature=+crt-static -C linker=musl-gcc"
|
||||||
|
export CC="musl-gcc"
|
||||||
|
export TARGET_CC="musl-gcc"
|
||||||
|
export CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER="musl-gcc"
|
||||||
|
fi
|
||||||
|
|
||||||
log_info "Rust environment configured for musl builds"
|
log_info "Rust environment configured for musl builds"
|
||||||
log_info "RUST_TARGET: ${RUST_TARGET}"
|
log_info "RUST_TARGET: ${RUST_TARGET}"
|
||||||
log_info "RUSTFLAGS: ${RUSTFLAGS}"
|
log_info "RUSTFLAGS: ${RUSTFLAGS}"
|
||||||
|
log_info "CC: ${CC:-system-default}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Build function for zinit (standard Rust build)
|
# Build function for zinit (standard Rust build)
|
||||||
|
|||||||
Reference in New Issue
Block a user