diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 39d14ed6..2e1d8d17 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -58,9 +58,7 @@ runs: libwebkit2gtk-4.1-dev \ libxdo-dev \ pkg-config \ - libssl-dev \ - libzstd-dev \ - zstd + libssl-dev - name: Install protoc uses: arduino/setup-protoc@v3 @@ -83,8 +81,6 @@ runs: - name: Install Zig if: inputs.install-cross-tools == 'true' uses: mlugg/setup-zig@v2 - with: - version: 0.13.0 - name: Install cargo-zigbuild if: inputs.install-cross-tools == 'true' diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1bf9c913..f3e98f2f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -146,6 +146,8 @@ jobs: if: needs.build-check.outputs.should_build == 'true' runs-on: ${{ matrix.os }} timeout-minutes: 60 + env: + RUSTFLAGS: ${{ matrix.cross == 'false' && '-C target-cpu=native' || '' }} strategy: fail-fast: false matrix: @@ -153,23 +155,29 @@ jobs: # Linux builds - os: ubuntu-latest target: x86_64-unknown-linux-musl + cross: false platform: linux - os: ubuntu-latest target: aarch64-unknown-linux-musl + cross: true platform: linux # macOS builds - os: macos-latest target: aarch64-apple-darwin + cross: false platform: macos - os: macos-latest target: x86_64-apple-darwin + cross: false platform: macos # # Windows builds (temporarily disabled) # - os: windows-latest # target: x86_64-pc-windows-msvc + # cross: false # platform: windows # - os: windows-latest # target: aarch64-pc-windows-msvc + # cross: true # platform: windows steps: - name: Checkout repository @@ -185,23 +193,50 @@ jobs: cache-shared-key: build-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }} github-token: ${{ secrets.GITHUB_TOKEN }} cache-save-if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') }} - install-cross-tools: true + install-cross-tools: ${{ matrix.cross }} - - name: Build RustFS using build-rustfs.sh + - name: Download static console assets run: | - # Use unified build script for consistent builds - ./build-rustfs.sh --platform ${{ matrix.target }} - env: - # Set environment variables for zstd-sys to avoid target parsing issues - ZSTD_SYS_USE_PKG_CONFIG: 1 - PKG_CONFIG_ALLOW_CROSS: 1 - # For musl targets, use system zstd if available - CC_x86_64_unknown_linux_musl: zig cc -target x86_64-linux-musl - CXX_x86_64_unknown_linux_musl: zig c++ -target x86_64-linux-musl - AR_x86_64_unknown_linux_musl: zig ar - CC_aarch64_unknown_linux_musl: zig cc -target aarch64-linux-musl - CXX_aarch64_unknown_linux_musl: zig c++ -target aarch64-linux-musl - AR_aarch64_unknown_linux_musl: zig ar + mkdir -p ./rustfs/static + if [[ "${{ matrix.platform }}" == "windows" ]]; then + curl.exe -L "https://dl.rustfs.com/artifacts/console/rustfs-console-latest.zip" -o console.zip --retry 3 --retry-delay 5 --max-time 300 + if [[ $? -eq 0 ]]; then + unzip -o console.zip -d ./rustfs/static + rm console.zip + else + echo "Warning: Failed to download console assets, continuing without them" + echo "// Static assets not available" > ./rustfs/static/empty.txt + fi + else + chmod +w ./rustfs/static/LICENSE || true + curl -L "https://dl.rustfs.com/artifacts/console/rustfs-console-latest.zip" \ + -o console.zip --retry 3 --retry-delay 5 --max-time 300 + if [[ $? -eq 0 ]]; then + unzip -o console.zip -d ./rustfs/static + rm console.zip + else + echo "Warning: Failed to download console assets, continuing without them" + echo "// Static assets not available" > ./rustfs/static/empty.txt + fi + fi + + - name: Build RustFS + run: | + # Force rebuild by touching build.rs + touch rustfs/build.rs + + if [[ "${{ matrix.cross }}" == "true" ]]; then + if [[ "${{ matrix.platform }}" == "windows" ]]; then + # Use cross for Windows ARM64 + cargo install cross --git https://github.com/cross-rs/cross + cross build --release --target ${{ matrix.target }} -p rustfs --bins + else + # Use zigbuild for Linux ARM64 + cargo zigbuild --release --target ${{ matrix.target }} -p rustfs --bins + fi + else + cargo build --release --target ${{ matrix.target }} -p rustfs --bins + fi - name: Create release package id: package @@ -248,8 +283,8 @@ jobs: fi fi - # build-rustfs.sh outputs to target/release/${platform}/rustfs - cd target/release/${{ matrix.target }} + # Native/cross compilation outputs to target/${target}/release/rustfs + cd target/${{ matrix.target }}/release zip "../../../${PACKAGE_NAME}.zip" rustfs cd ../../.. diff --git a/build-rustfs.sh b/build-rustfs.sh index c0eeb0c9..2e23aa4e 100755 --- a/build-rustfs.sh +++ b/build-rustfs.sh @@ -188,12 +188,6 @@ setup_rust_environment() { # Set environment variables for zstd-sys to avoid target parsing issues export ZSTD_SYS_USE_PKG_CONFIG=1 export PKG_CONFIG_ALLOW_CROSS=1 - - # Use system zstd if available for musl builds - if [[ "$PLATFORM" == *"musl"* ]]; then - export ZSTD_SYS_USE_PKG_CONFIG=1 - export PKG_CONFIG_ALLOW_CROSS=1 - fi fi fi @@ -357,43 +351,41 @@ build_binary() { # Create output directory mkdir -p "${OUTPUT_DIR}/${PLATFORM}" - # Build command - choose the best tool for cross-compilation - local build_cmd="cargo build" + # Simple build logic matching the working version (4fb4b353) + # Force rebuild by touching build.rs + touch rustfs/build.rs + + # Determine build command based on platform and cross-compilation needs + local build_cmd="" local current_platform=$(detect_platform) + print_message $BLUE "📦 Using working version build logic..." + # Check if we need cross-compilation if [ "$PLATFORM" != "$current_platform" ]; then - # Check if the target is a macOS target + # Cross-compilation needed if [[ "$PLATFORM" == *"apple-darwin"* ]]; then - print_message $YELLOW "🍎 macOS target detected, using native cargo build" - print_message $YELLOW "💡 Note: macOS targets must be built natively on macOS runners" - build_cmd="cargo build" - elif [[ "$PLATFORM" == *"linux"* ]]; then - # For Linux targets, prefer cargo-zigbuild over cross for better glibc compatibility - if command -v cargo-zigbuild &> /dev/null; then - build_cmd="cargo zigbuild" - print_message $YELLOW "🔧 Linux cross-compilation detected, using 'cargo-zigbuild' for better glibc compatibility" - elif command -v cross &> /dev/null; then - build_cmd="cross build" - print_message $YELLOW "🔄 Cross-compilation detected, using 'cross' tool" - else - print_message $YELLOW "⚠️ Cross-compilation detected but neither 'cargo-zigbuild' nor 'cross' tool found" - print_message $YELLOW "📦 Installing cross tool as fallback..." - cargo install cross --git https://github.com/cross-rs/cross - build_cmd="cross build" - fi - else - # For other targets, use cross - if command -v cross &> /dev/null; then - build_cmd="cross build" - print_message $YELLOW "🔄 Cross-compilation detected, using 'cross' tool" - else - print_message $YELLOW "⚠️ Cross-compilation detected but 'cross' tool not found" + print_message $RED "❌ macOS cross-compilation not supported" + print_message $YELLOW "💡 macOS targets must be built natively on macOS runners" + return 1 + elif [[ "$PLATFORM" == *"windows"* ]]; then + # Use cross for Windows ARM64 + if ! command -v cross &> /dev/null; then print_message $YELLOW "📦 Installing cross tool..." cargo install cross --git https://github.com/cross-rs/cross - build_cmd="cross build" fi + build_cmd="cross build" + else + # Use zigbuild for Linux ARM64 (matches working version) + if ! command -v cargo-zigbuild &> /dev/null; then + print_message $RED "❌ cargo-zigbuild not found. Please install it first." + return 1 + fi + build_cmd="cargo zigbuild" fi + else + # Native compilation + build_cmd="cargo build" fi if [ "$BUILD_TYPE" = "release" ]; then @@ -401,11 +393,11 @@ build_binary() { fi build_cmd+=" --target $PLATFORM" - build_cmd+=" --bin $BINARY_NAME" + build_cmd+=" -p rustfs --bins" print_message $BLUE "📦 Executing: $build_cmd" - # Execute build + # Execute build (this matches exactly what the working version does) if eval $build_cmd; then print_message $GREEN "✅ Successfully built for $PLATFORM" @@ -438,33 +430,6 @@ build_binary() { print_message $GREEN "✅ Build completed successfully" else print_message $RED "❌ Failed to build for $PLATFORM" - - # Provide helpful suggestions for cross-compilation failures - if [ "$PLATFORM" != "$(detect_platform)" ]; then - if [[ "$PLATFORM" == *"apple-darwin"* ]]; then - print_message $YELLOW "💡 macOS build suggestions:" - print_message $YELLOW " 1. macOS targets must be built natively on macOS systems" - print_message $YELLOW " 2. Use GitHub Actions with macos-latest runner" - print_message $YELLOW " 3. Ensure Xcode command line tools are installed" - print_message $YELLOW " 4. Try: rustup target add $PLATFORM" - elif [[ "$PLATFORM" == *"linux"* ]]; then - print_message $YELLOW "💡 Linux cross-compilation suggestions:" - print_message $YELLOW " 1. Install cargo-zigbuild for better glibc compatibility:" - print_message $YELLOW " cargo install cargo-zigbuild" - print_message $YELLOW " 2. Install Zig compiler: https://ziglang.org/download/" - print_message $YELLOW " 3. Use Docker build: make build-docker" - print_message $YELLOW " 4. Use GitHub Actions for multi-platform builds" - print_message $YELLOW " 5. Build natively on the target platform" - print_message $YELLOW " 6. Try: rustup target add $PLATFORM" - else - print_message $YELLOW "💡 Cross-compilation suggestions:" - print_message $YELLOW " 1. Use Docker build: make build-docker" - print_message $YELLOW " 2. Use GitHub Actions for multi-platform builds" - print_message $YELLOW " 3. Build natively on the target platform" - print_message $YELLOW " 4. Use 'make docker-buildx' for multi-arch Docker images" - fi - fi - return 1 fi }