From 7cf0d070efafafde2a57399bbf3519feadb5f64b Mon Sep 17 00:00:00 2001 From: Jan De Landtsheer Date: Sun, 31 Aug 2025 16:21:30 +0200 Subject: [PATCH] feat: Add perl for OpenSSL builds - Add perl to Dockerfile for rfs OpenSSL compilation - Clean up rustup environment (remove gcc complications) - Ready for complete build debugging --- Dockerfile | 27 ++-- build.log | 302 ++++++++++++++++++++++++++++++++++++++ components/mycelium | 1 + components/rfs | 1 + components/zinit | 1 + scripts/lib/components.sh | 94 ++++++++---- 6 files changed, 382 insertions(+), 44 deletions(-) create mode 100644 build.log create mode 160000 components/mycelium create mode 160000 components/rfs create mode 160000 components/zinit diff --git a/Dockerfile b/Dockerfile index 573e4b4..23081d1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,10 @@ # Zero OS Alpine Initramfs Builder Container FROM alpine:3.22 -# Install build dependencies including proper musl toolchain +# Install build dependencies including rustup RUN apk add --no-cache \ build-base \ - rust \ - cargo \ + rustup \ upx \ git \ wget \ @@ -19,17 +18,19 @@ RUN apk add --no-cache \ musl-utils \ pkgconfig \ openssl-dev \ + perl \ bash \ findutils \ grep \ sed \ coreutils -# Create musl-gcc wrapper (Alpine's gcc already targets musl) -RUN echo '#!/bin/sh' > /usr/bin/musl-gcc && \ - echo 'exec gcc -static "$@"' >> /usr/bin/musl-gcc && \ - chmod +x /usr/bin/musl-gcc && \ - which musl-gcc +# Setup rustup with stable and musl target +RUN rustup-init -y && \ + source /root/.cargo/env && \ + rustup install stable && \ + rustup target add x86_64-unknown-linux-musl && \ + echo 'source /root/.cargo/env' >> /etc/profile # Create non-root user for builds matching host user RUN adduser -D -s /bin/bash builder @@ -38,12 +39,8 @@ RUN adduser -D -s /bin/bash builder WORKDIR /workspace RUN chown builder:builder /workspace -# Set environment variables for musl static linking with Alpine's Rust -ENV RUSTFLAGS="-C target-feature=+crt-static -C linker=musl-gcc" -ENV CC="musl-gcc" -ENV TARGET_CC="musl-gcc" -ENV CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER="musl-gcc" - -# Don't switch to builder user yet - let the runtime handle it +# Set environment variables - rustup handles everything +ENV PATH="/root/.cargo/bin:${PATH}" +ENV RUSTFLAGS="-C target-feature=+crt-static" CMD ["/bin/bash"] \ No newline at end of file diff --git a/build.log b/build.log new file mode 100644 index 0000000..e8fa37d --- /dev/null +++ b/build.log @@ -0,0 +1,302 @@ + +================================================== +== ZERO-OS ALPINE INITRAMFS BUILDER == +== ThreeFold Edition == +================================================== + + +================================================== +SECTION: Setting up build environment +================================================== +[INFO] 2025-08-31 15:40:53 - Starting section: Setting up build environment +[INFO] 2025-08-31 15:40:53 - Project root: /home/delandtj/Threefold/zosbuilder +[INFO] 2025-08-31 15:40:53 - Alpine version: 3.22 +[INFO] 2025-08-31 15:40:53 - Kernel version: 6.12.44 +[INFO] 2025-08-31 15:40:53 - Rust target: x86_64-unknown-linux-musl +[INFO] 2025-08-31 15:40:53 - Optimization level: max +[INFO] 2025-08-31 15:40:53 - Skipping directory creation on host (container will create them) +[INFO] 2025-08-31 15:40:53 - All dependencies satisfied + +================================================== +SECTION: Verifying Configuration Files +================================================== +[INFO] 2025-08-31 15:40:53 - Starting section: Verifying Configuration Files +[INFO] 2025-08-31 15:40:53 - ✓ Configuration found: packages.list +[INFO] 2025-08-31 15:40:53 - ✓ Configuration found: sources.conf +[INFO] 2025-08-31 15:40:53 - ✓ Configuration found: modules.conf +[INFO] 2025-08-31 15:40:53 - ✓ Configuration found: kernel.config +[INFO] 2025-08-31 15:40:53 - ✓ Configuration found: firmware.conf +[INFO] 2025-08-31 15:40:53 - All configuration files verified +[INFO] 2025-08-31 15:40:53 - Build environment setup complete +[INFO] 2025-08-31 15:40:53 - Starting container build + +================================================== +SECTION: Detecting Container Runtime +================================================== +[INFO] 2025-08-31 15:40:53 - Starting section: Detecting Container Runtime +[INFO] 2025-08-31 15:40:53 - Using Podman as container runtime + +================================================== +SECTION: Verifying Rootless Container Setup +================================================== +[INFO] 2025-08-31 15:40:53 - Starting section: Verifying Rootless Container Setup +[INFO] 2025-08-31 15:40:53 - Checking podman rootless configuration +[INFO] 2025-08-31 15:40:53 - Executing: podman system info +[INFO] 2025-08-31 15:40:53 - Testing rootless container execution +[INFO] 2025-08-31 15:40:53 - Executing: podman run --rm alpine:3.22 echo Rootless container test successful +[INFO] 2025-08-31 15:40:54 - Rootless container setup verified + +================================================== +SECTION: Building Container Image +================================================== +[INFO] 2025-08-31 15:40:54 - Starting section: Building Container Image +[INFO] 2025-08-31 15:40:54 - Building container image: zero-os-builder:latest +[INFO] 2025-08-31 15:40:54 - Executing: podman build -t zero-os-builder:latest -f /home/delandtj/Threefold/zosbuilder/Dockerfile /home/delandtj/Threefold/zosbuilder +[INFO] 2025-08-31 15:40:54 - Container image built successfully: zero-os-builder:latest + +================================================== +SECTION: Running Build in Container +================================================== +[INFO] 2025-08-31 15:40:54 - Starting section: Running Build in Container +[INFO] 2025-08-31 15:40:54 - Executing: chmod +x /home/delandtj/Threefold/zosbuilder/./scripts/build.sh +[INFO] 2025-08-31 15:40:54 - Executing build command in container: ./scripts/build.sh --skip-tests +[INFO] 2025-08-31 15:40:54 - Executing: podman run --rm --privileged -v /home/delandtj/Threefold/zosbuilder:/workspace -w /workspace zero-os-builder:latest ./scripts/build.sh --skip-tests +[ERROR] 2025-08-31 15:41:01 - Command failed: podman run --rm --privileged -v /home/delandtj/Threefold/zosbuilder:/workspace -w /workspace zero-os-builder:latest ./scripts/build.sh --skip-tests +[ERROR] 2025-08-31 15:41:01 - Output: +================================================== +== ZERO-OS ALPINE INITRAMFS BUILDER == +== ThreeFold Edition == +================================================== + + +================================================== +SECTION: Setting up build environment +================================================== +[INFO] 2025-08-31 13:40:54 - Starting section: Setting up build environment +[INFO] 2025-08-31 13:40:54 - Project root: /workspace +[INFO] 2025-08-31 13:40:54 - Alpine version: 3.22 +[INFO] 2025-08-31 13:40:54 - Kernel version: 6.12.44 +[INFO] 2025-08-31 13:40:54 - Rust target: x86_64-unknown-linux-musl +[INFO] 2025-08-31 13:40:54 - Optimization level: max +[INFO] 2025-08-31 13:40:54 - Executing: mkdir -p /workspace/initramfs +[INFO] 2025-08-31 13:40:54 - Executing: mkdir -p /workspace/components +[INFO] 2025-08-31 13:40:54 - Executing: mkdir -p /workspace/kernel +[INFO] 2025-08-31 13:40:54 - Executing: mkdir -p /workspace/dist +[INFO] 2025-08-31 13:40:54 - All dependencies satisfied + +================================================== +SECTION: Verifying Configuration Files +================================================== +[INFO] 2025-08-31 13:40:54 - Starting section: Verifying Configuration Files +[INFO] 2025-08-31 13:40:54 - ✓ Configuration found: packages.list +[INFO] 2025-08-31 13:40:54 - ✓ Configuration found: sources.conf +[INFO] 2025-08-31 13:40:54 - ✓ Configuration found: modules.conf +[INFO] 2025-08-31 13:40:54 - ✓ Configuration found: kernel.config +[INFO] 2025-08-31 13:40:54 - ✓ Configuration found: firmware.conf +[INFO] 2025-08-31 13:40:54 - All configuration files verified +[INFO] 2025-08-31 13:40:54 - Build environment setup complete +[INFO] 2025-08-31 13:40:54 - Already in container, proceeding with build + +================================================== +SECTION: Starting Zero OS Alpine Initramfs Build +================================================== +[INFO] 2025-08-31 13:40:54 - Starting section: Starting Zero OS Alpine Initramfs Build + +================================================== +SECTION: Extracting Alpine Miniroot +================================================== +[INFO] 2025-08-31 13:40:54 - Starting section: Extracting Alpine Miniroot +[INFO] 2025-08-31 13:40:54 - Alpine version: 3.22 +[INFO] 2025-08-31 13:40:54 - Architecture: x86_64 +[INFO] 2025-08-31 13:40:54 - Target directory: /workspace/initramfs +[INFO] 2025-08-31 13:40:54 - Cleaning existing target directory +[INFO] 2025-08-31 13:40:54 - Executing: mkdir -p /workspace/initramfs +[INFO] 2025-08-31 13:40:54 - Downloading Alpine miniroot from: https://dl-cdn.alpinelinux.org/alpine/v3.22/releases/x86_64/alpine-minirootfs-3.22.0-x86_64.tar.gz +[INFO] 2025-08-31 13:40:54 - Executing: wget --progress=dot:giga -O /tmp/alpine-miniroot-3.22-x86_64.tar.gz https://dl-cdn.alpinelinux.org/alpine/v3.22/releases/x86_64/alpine-minirootfs-3.22.0-x86_64.tar.gz +[INFO] 2025-08-31 13:40:54 - Downloaded miniroot size: 3.5M +[INFO] 2025-08-31 13:40:54 - Extracting miniroot to: /workspace/initramfs +[INFO] 2025-08-31 13:40:54 - Executing: tar -xzf /tmp/alpine-miniroot-3.22-x86_64.tar.gz -C /workspace/initramfs +[INFO] 2025-08-31 13:40:54 - Executing: rm /tmp/alpine-miniroot-3.22-x86_64.tar.gz +[INFO] 2025-08-31 13:40:54 - Extracted Alpine release: 3.22.0 +[INFO] 2025-08-31 13:40:54 - Alpine miniroot extraction complete + +================================================== +SECTION: Configuring Alpine Repositories +================================================== +[INFO] 2025-08-31 13:40:54 - Starting section: Configuring Alpine Repositories +[INFO] 2025-08-31 13:40:54 - Configured Alpine repositories for version 3.22 + +================================================== +SECTION: Configuring Alpine System Settings +================================================== +[INFO] 2025-08-31 13:40:54 - Starting section: Configuring Alpine System Settings +[INFO] 2025-08-31 13:40:54 - chsh not available in minimal Alpine, skipping shell change +[INFO] 2025-08-31 13:40:54 - Root shell defaults to /bin/sh in Alpine +[INFO] 2025-08-31 13:40:54 - Alpine system configuration complete + +================================================== +SECTION: Installing Alpine Packages +================================================== +[INFO] 2025-08-31 13:40:54 - Starting section: Installing Alpine Packages + +================================================== +SECTION: Setting Up Alpine Chroot Environment +================================================== +[INFO] 2025-08-31 13:40:54 - Starting section: Setting Up Alpine Chroot Environment +[INFO] 2025-08-31 13:40:54 - Executing: mkdir -p /workspace/initramfs/proc +[INFO] 2025-08-31 13:40:54 - Executing: mkdir -p /workspace/initramfs/sys +[INFO] 2025-08-31 13:40:54 - Executing: mkdir -p /workspace/initramfs/dev +[INFO] 2025-08-31 13:40:54 - Executing: mkdir -p /workspace/initramfs/dev/pts +[INFO] 2025-08-31 13:40:54 - Executing: mkdir -p /workspace/initramfs/tmp +[INFO] 2025-08-31 13:40:54 - Executing: mkdir -p /workspace/initramfs/run +[INFO] 2025-08-31 13:40:54 - Mounting essential filesystems in chroot +[INFO] 2025-08-31 13:40:54 - Executing: mount --bind /proc /workspace/initramfs/proc +[INFO] 2025-08-31 13:40:54 - Executing: mount --bind /sys /workspace/initramfs/sys +[INFO] 2025-08-31 13:40:54 - Executing: mount --bind /dev /workspace/initramfs/dev +[INFO] 2025-08-31 13:40:54 - Executing: mount --bind /dev/pts /workspace/initramfs/dev/pts +[INFO] 2025-08-31 13:40:54 - Executing: cp -r /etc/resolv.conf /workspace/initramfs/etc/resolv.conf +[INFO] 2025-08-31 13:40:54 - Chroot environment setup complete +[INFO] 2025-08-31 13:40:54 - Updating package repositories +[INFO] 2025-08-31 13:40:54 - Executing: chroot /workspace/initramfs apk update +[INFO] 2025-08-31 13:40:55 - Installing 20 packages: +[INFO] 2025-08-31 13:40:55 - - alpine-baselayout +[INFO] 2025-08-31 13:40:55 - - busybox +[INFO] 2025-08-31 13:40:55 - - musl +[INFO] 2025-08-31 13:40:55 - - eudev +[INFO] 2025-08-31 13:40:55 - - eudev-hwids +[INFO] 2025-08-31 13:40:55 - - eudev-libs +[INFO] 2025-08-31 13:40:55 - - eudev-netifnames +[INFO] 2025-08-31 13:40:55 - - kmod +[INFO] 2025-08-31 13:40:55 - - util-linux +[INFO] 2025-08-31 13:40:55 - - iproute2 +[INFO] 2025-08-31 13:40:55 - - ethtool +[INFO] 2025-08-31 13:40:55 - - btrfs-progs +[INFO] 2025-08-31 13:40:55 - - dosfstools +[INFO] 2025-08-31 13:40:55 - - zlib +[INFO] 2025-08-31 13:40:55 - - dhcpcd +[INFO] 2025-08-31 13:40:55 - - tcpdump +[INFO] 2025-08-31 13:40:55 - - bmon +[INFO] 2025-08-31 13:40:55 - - haveged +[INFO] 2025-08-31 13:40:55 - - openssh-server +[INFO] 2025-08-31 13:40:55 - - zellij +[INFO] 2025-08-31 13:40:55 - Installing packages with apk +[INFO] 2025-08-31 13:40:55 - Executing: chroot /workspace/initramfs apk add --no-cache --no-scripts --clean-protected alpine-baselayout busybox musl eudev eudev-hwids eudev-libs eudev-netifnames kmod util-linux iproute2 ethtool btrfs-progs dosfstools zlib dhcpcd tcpdump bmon haveged openssh-server zellij + +================================================== +SECTION: Cleaning Up Alpine Chroot Environment +================================================== +[INFO] 2025-08-31 13:40:58 - Starting section: Cleaning Up Alpine Chroot Environment +[INFO] 2025-08-31 13:40:58 - Unmounting: /workspace/initramfs/dev/pts +[INFO] 2025-08-31 13:40:58 - Executing: umount /workspace/initramfs/dev/pts +[INFO] 2025-08-31 13:40:58 - Unmounting: /workspace/initramfs/dev +[INFO] 2025-08-31 13:40:58 - Executing: umount /workspace/initramfs/dev +[INFO] 2025-08-31 13:40:58 - Unmounting: /workspace/initramfs/sys +[INFO] 2025-08-31 13:40:58 - Executing: umount /workspace/initramfs/sys +[INFO] 2025-08-31 13:40:58 - Unmounting: /workspace/initramfs/proc +[INFO] 2025-08-31 13:40:58 - Executing: umount /workspace/initramfs/proc +[INFO] 2025-08-31 13:40:58 - Chroot cleanup complete +[INFO] 2025-08-31 13:40:58 - Package installation complete + +================================================== +SECTION: Installing Alpine Firmware Packages +================================================== +[INFO] 2025-08-31 13:40:58 - Starting section: Installing Alpine Firmware Packages + +================================================== +SECTION: Setting Up Alpine Chroot Environment +================================================== +[INFO] 2025-08-31 13:40:58 - Starting section: Setting Up Alpine Chroot Environment +[INFO] 2025-08-31 13:40:58 - Executing: mkdir -p /workspace/initramfs/proc +[INFO] 2025-08-31 13:40:58 - Executing: mkdir -p /workspace/initramfs/sys +[INFO] 2025-08-31 13:40:58 - Executing: mkdir -p /workspace/initramfs/dev +[INFO] 2025-08-31 13:40:58 - Executing: mkdir -p /workspace/initramfs/dev/pts +[INFO] 2025-08-31 13:40:58 - Executing: mkdir -p /workspace/initramfs/tmp +[INFO] 2025-08-31 13:40:58 - Executing: mkdir -p /workspace/initramfs/run +[INFO] 2025-08-31 13:40:58 - Mounting essential filesystems in chroot +[INFO] 2025-08-31 13:40:58 - Executing: mount --bind /proc /workspace/initramfs/proc +[INFO] 2025-08-31 13:40:58 - Executing: mount --bind /sys /workspace/initramfs/sys +[INFO] 2025-08-31 13:40:58 - Executing: mount --bind /dev /workspace/initramfs/dev +[INFO] 2025-08-31 13:40:58 - Executing: mount --bind /dev/pts /workspace/initramfs/dev/pts +[INFO] 2025-08-31 13:40:58 - Executing: cp -r /etc/resolv.conf /workspace/initramfs/etc/resolv.conf +[INFO] 2025-08-31 13:40:58 - Chroot environment setup complete +[INFO] 2025-08-31 13:40:58 - - linux-firmware-bnx2: Broadcom NetXtreme firmware +[INFO] 2025-08-31 13:40:58 - - linux-firmware-e100: Intel PRO/100 firmware +[INFO] 2025-08-31 13:40:58 - - linux-firmware-intel: Intel network and WiFi firmware (includes e1000e, igb, ixgbe, i40e, ice) +[INFO] 2025-08-31 13:40:58 - - linux-firmware-realtek: Realtek network firmware (r8169, etc.) +[INFO] 2025-08-31 13:40:58 - - linux-firmware-mellanox: Mellanox network firmware +[INFO] 2025-08-31 13:40:58 - - linux-firmware-qlogic: QLogic network firmware +[INFO] 2025-08-31 13:40:58 - Installing 6 firmware packages +[INFO] 2025-08-31 13:40:58 - Executing: chroot /workspace/initramfs apk add --no-cache linux-firmware-bnx2 linux-firmware-e100 linux-firmware-intel linux-firmware-realtek linux-firmware-mellanox linux-firmware-qlogic +[INFO] 2025-08-31 13:41:00 - Checking installed firmware files: +[INFO] 2025-08-31 13:41:00 - Firmware files: 196 (115M) + +================================================== +SECTION: Cleaning Up Alpine Chroot Environment +================================================== +[INFO] 2025-08-31 13:41:00 - Starting section: Cleaning Up Alpine Chroot Environment +[INFO] 2025-08-31 13:41:00 - Unmounting: /workspace/initramfs/dev/pts +[INFO] 2025-08-31 13:41:00 - Executing: umount /workspace/initramfs/dev/pts +[INFO] 2025-08-31 13:41:00 - Unmounting: /workspace/initramfs/dev +[INFO] 2025-08-31 13:41:00 - Executing: umount /workspace/initramfs/dev +[INFO] 2025-08-31 13:41:00 - Unmounting: /workspace/initramfs/sys +[INFO] 2025-08-31 13:41:00 - Executing: umount /workspace/initramfs/sys +[INFO] 2025-08-31 13:41:00 - Unmounting: /workspace/initramfs/proc +[INFO] 2025-08-31 13:41:00 - Executing: umount /workspace/initramfs/proc +[INFO] 2025-08-31 13:41:00 - Chroot cleanup complete +[INFO] 2025-08-31 13:41:00 - Firmware installation complete: 196 files + +================================================== +SECTION: Parsing Sources Configuration +================================================== +[INFO] 2025-08-31 13:41:00 - Starting section: Parsing Sources Configuration +[INFO] 2025-08-31 13:41:00 - Executing: mkdir -p /workspace/components +[INFO] 2025-08-31 13:41:00 - Processing components from: /workspace/config/sources.conf +[INFO] 2025-08-31 13:41:00 - Components directory: /workspace/components +[INFO] 2025-08-31 13:41:00 - Install directory: /workspace/initramfs +[INFO] 2025-08-31 13:41:00 - Building ThreeFold components (hardcoded for reliability) +[INFO] 2025-08-31 13:41:00 - Processing component 1: zinit (git) + +================================================== +SECTION: Downloading Git Component: zinit +================================================== +[INFO] 2025-08-31 13:41:00 - Starting section: Downloading Git Component: zinit +[INFO] 2025-08-31 13:41:00 - Repository: https://github.com/threefoldtech/zinit +[INFO] 2025-08-31 13:41:00 - Version/Branch: master +[INFO] 2025-08-31 13:41:00 - Target directory: /workspace/components/zinit +[INFO] 2025-08-31 13:41:00 - Cloning zinit from https://github.com/threefoldtech/zinit +[INFO] 2025-08-31 13:41:00 - Executing: git clone --depth 1 --branch master https://github.com/threefoldtech/zinit /workspace/components/zinit +[INFO] 2025-08-31 13:41:00 - Executing: cd /workspace/components/zinit +[INFO] 2025-08-31 13:41:00 - Current commit: 1852135945d3db78a8a15c9df60adbccf275220e +[INFO] 2025-08-31 13:41:00 - Git component download complete: zinit + +================================================== +SECTION: Building Component: zinit +================================================== +[INFO] 2025-08-31 13:41:00 - Starting section: Building Component: zinit +[INFO] 2025-08-31 13:41:00 - Executing: cd /workspace/components/zinit +[INFO] 2025-08-31 13:41:00 - Build function: build_zinit +[INFO] 2025-08-31 13:41:00 - Working directory: /workspace +[INFO] 2025-08-31 13:41:00 - Executing build function: build_zinit + +================================================== +SECTION: Building zinit with musl target +================================================== +[INFO] 2025-08-31 13:41:00 - Starting section: Building zinit with musl target + +================================================== +SECTION: Setting Up Rust Environment +================================================== +[INFO] 2025-08-31 13:41:00 - Starting section: Setting Up Rust Environment +[INFO] 2025-08-31 13:41:00 - Using system Rust (Alpine) with musl +[INFO] 2025-08-31 13:41:00 - Rust environment configured for musl builds +[INFO] 2025-08-31 13:41:00 - RUST_TARGET: x86_64-unknown-linux-musl +[INFO] 2025-08-31 13:41:00 - RUSTFLAGS: -C target-feature=+crt-static -C linker=musl-gcc +[INFO] 2025-08-31 13:41:00 - CC: musl-gcc +[INFO] 2025-08-31 13:41:00 - Building zinit from: /workspace/components/zinit +[INFO] 2025-08-31 13:41:00 - Executing: cd /workspace/components/zinit +[INFO] 2025-08-31 13:41:00 - Current directory: /workspace +[INFO] 2025-08-31 13:41:00 - Executing: cargo build --release --target x86_64-unknown-linux-musl +[ERROR] 2025-08-31 13:41:00 - Command failed: cargo build --release --target x86_64-unknown-linux-musl +[ERROR] 2025-08-31 13:41:00 - Output: error: could not find `Cargo.toml` in `/workspace` or any parent directory +[INFO] 2025-08-31 13:41:00 - Build process exiting with code: 1 +[INFO] 2025-08-31 15:41:01 - Build process exiting with code: 1 diff --git a/components/mycelium b/components/mycelium new file mode 160000 index 0000000..a9ba23d --- /dev/null +++ b/components/mycelium @@ -0,0 +1 @@ +Subproject commit a9ba23d7bd020411be51cd2359775f6f11b159e4 diff --git a/components/rfs b/components/rfs new file mode 160000 index 0000000..2b92afa --- /dev/null +++ b/components/rfs @@ -0,0 +1 @@ +Subproject commit 2b92afaf10e2a537ebe5d939ad810b5957e2f1d2 diff --git a/components/zinit b/components/zinit new file mode 160000 index 0000000..92444a7 --- /dev/null +++ b/components/zinit @@ -0,0 +1 @@ +Subproject commit 92444a767003e2126d17df45a7d4f7c8e5427129 diff --git a/scripts/lib/components.sh b/scripts/lib/components.sh index 9ac494e..215feca 100644 --- a/scripts/lib/components.sh +++ b/scripts/lib/components.sh @@ -83,17 +83,15 @@ function components_download_git() { log_info "Version/Branch: ${version}" log_info "Target directory: ${target_dir}" + # Always do fresh clone to avoid git state issues if [[ -d "$target_dir" ]]; then - log_info "Component ${name} already exists, updating..." - safe_execute cd "$target_dir" - safe_execute git fetch --all - safe_execute git checkout "$version" - safe_execute git pull origin "$version" 2>/dev/null || log_info "Already up to date" - else - log_info "Cloning ${name} from ${url}" - safe_execute git clone --depth 1 --branch "$version" "$url" "$target_dir" + log_info "Removing existing ${name} directory for fresh clone" + safe_execute rm -rf "$target_dir" fi + log_info "Cloning ${name} from ${url}" + safe_execute git clone --depth 1 --branch "$version" "$url" "$target_dir" + # Verify checkout safe_execute cd "$target_dir" local current_ref=$(git rev-parse HEAD) @@ -219,7 +217,13 @@ function components_build_component() { function components_setup_rust_env() { section_header "Setting Up Rust Environment" - # Check if we have rustup (Ubuntu/GitHub Actions) or system Rust (Alpine container) + # Source cargo environment if available + if [[ -f /root/.cargo/env ]]; then + log_info "Sourcing cargo environment from /root/.cargo/env" + source /root/.cargo/env + fi + + # Check if we have rustup (should be available now) if command_exists "rustup"; then log_info "Using rustup for Rust toolchain management" @@ -231,24 +235,11 @@ function components_setup_rust_env() { log_info "Rust target already installed: ${RUST_TARGET}" fi - # Set environment variables for rustup + # Set environment variables for rustup (clean and simple) export RUSTFLAGS="-C target-feature=+crt-static" - export CC_x86_64_unknown_linux_musl="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" + log_error "rustup not found after setup" + return 1 fi log_info "Rust environment configured for musl builds" @@ -269,10 +260,28 @@ function build_zinit() { log_info "Building zinit from: ${component_dir}" # Ensure we're in the correct directory - safe_execute cd "$component_dir" - log_info "Current directory: $(pwd)" + if [[ ! -d "$component_dir" ]]; then + log_error "Component directory not found: ${component_dir}" + return 1 + fi - # Build with musl target + # Don't use safe_execute for cd - it runs in subshell + log_info "Executing: cd $component_dir" + cd "$component_dir" || { + log_error "Failed to change to directory: $component_dir" + return 1 + } + + local current_dir=$(pwd) + log_info "Current directory: ${current_dir}" + + # Verify Cargo.toml exists + if [[ ! -f "Cargo.toml" ]]; then + log_error "Cargo.toml not found in: ${current_dir}" + return 1 + fi + + # Build with musl target (rustup properly configured) safe_execute cargo build --release --target "$RUST_TARGET" # Find and install binary @@ -302,6 +311,28 @@ function build_rfs() { log_info "Building rfs from: ${component_dir}" + # Ensure we're in the correct directory + if [[ ! -d "$component_dir" ]]; then + log_error "Component directory not found: ${component_dir}" + return 1 + fi + + # Don't use safe_execute for cd - it runs in subshell + log_info "Executing: cd $component_dir" + cd "$component_dir" || { + log_error "Failed to change to directory: $component_dir" + return 1 + } + + local current_dir=$(pwd) + log_info "Current directory: ${current_dir}" + + # Verify Cargo.toml exists + if [[ ! -f "Cargo.toml" ]]; then + log_error "Cargo.toml not found in: ${current_dir}" + return 1 + fi + # Build with musl target safe_execute cargo build --release --target "$RUST_TARGET" @@ -339,7 +370,12 @@ function build_mycelium() { return 1 fi - safe_execute cd "$myceliumd_dir" + # Don't use safe_execute for cd - it runs in subshell + log_info "Executing: cd $myceliumd_dir" + cd "$myceliumd_dir" || { + log_error "Failed to change to myceliumd directory: $myceliumd_dir" + return 1 + } log_info "Building in myceliumd subdirectory: $(pwd)" # Build with musl target