grain.social is a photo sharing platform built on atproto.

fix: cli cross-compilation issues

Changed files
+94 -20
.github
workflows
cli
+73 -11
.github/workflows/cli.yml
··· 14 14 jobs: 15 15 build: 16 16 name: Build CLI Binaries 17 - runs-on: ubuntu-latest 17 + strategy: 18 + matrix: 19 + include: 20 + - target: x86_64-unknown-linux-gnu 21 + os: ubuntu-latest 22 + package: grain-linux-x86_64 23 + artifact: grain-linux-x86_64 24 + - target: aarch64-unknown-linux-gnu 25 + os: ubuntu-latest 26 + package: grain-linux-aarch64 27 + artifact: grain-linux-aarch64 28 + - target: x86_64-apple-darwin 29 + os: macos-13 # Intel Mac 30 + package: grain-macos-x86_64 31 + artifact: grain-darwin-x86_64 32 + - target: aarch64-apple-darwin 33 + os: macos-latest # Apple Silicon Mac 34 + package: grain-macos-aarch64 35 + artifact: grain-darwin-aarch64 36 + - target: x86_64-pc-windows-gnu 37 + os: ubuntu-latest 38 + package: grain-windows-x86_64 39 + artifact: grain-windows-x86_64.exe 40 + 41 + runs-on: ${{ matrix.os }} 18 42 defaults: 19 43 run: 20 44 working-directory: cli 45 + 21 46 steps: 22 47 - name: Checkout 23 48 uses: actions/checkout@v4 ··· 33 58 - name: Check flake 34 59 run: nix flake check 35 60 36 - - name: Build Darwin aarch64 only (for testing) 61 + - name: Build ${{ matrix.target }} 62 + run: nix build .#${{ matrix.package }} 63 + 64 + - name: Copy binary 37 65 run: | 38 - echo "Building for macOS aarch64 only..." 39 66 mkdir -p releases 40 - nix build .#grain-macos-aarch64 -o result-macos-aarch64 41 - cp result-macos-aarch64/bin/grain releases/grain-darwin-aarch64 67 + if [ "${{ matrix.target }}" == "x86_64-pc-windows-gnu" ]; then 68 + cp result/bin/grain.exe releases/${{ matrix.artifact }} 69 + else 70 + cp result/bin/grain releases/${{ matrix.artifact }} 71 + fi 72 + 73 + - name: Upload artifact 74 + uses: actions/upload-artifact@v4 75 + with: 76 + name: ${{ matrix.artifact }} 77 + path: cli/releases/${{ matrix.artifact }} 78 + retention-days: 7 79 + 80 + release: 81 + name: Create Release 82 + needs: build 83 + runs-on: ubuntu-latest 84 + steps: 85 + - name: Checkout 86 + uses: actions/checkout@v4 87 + 88 + - name: Download all artifacts 89 + uses: actions/download-artifact@v4 90 + with: 91 + path: artifacts 42 92 43 93 - name: Prepare release assets 44 94 run: | 45 95 mkdir -p release-assets 46 - cp releases/grain-darwin-aarch64 release-assets/ 47 - cp install.sh release-assets/ 96 + 97 + # Copy all binaries 98 + for dir in artifacts/*/; do 99 + for file in "$dir"*; do 100 + if [ -f "$file" ]; then 101 + cp "$file" release-assets/ 102 + fi 103 + done 104 + done 105 + 106 + # Copy install script 107 + cp cli/install.sh release-assets/ 48 108 49 109 # Create checksums 50 110 cd release-assets 51 - sha256sum grain-darwin-aarch64 > checksums.txt 111 + sha256sum * > checksums.txt 52 112 53 113 # List files for verification 54 114 ls -la ··· 72 132 files: | 73 133 cli/release-assets/* 74 134 body: | 75 - ## Grain CLI ${{ steps.tag.outputs.tag }} (Test Build) 76 - 77 - **Note: This is a test build with only macOS Apple Silicon support.** 135 + ## Grain CLI ${{ steps.tag.outputs.tag }} 78 136 79 137 ### Installation 80 138 ··· 85 143 86 144 Or download manually: 87 145 146 + - **Linux x86_64**: `grain-linux-x86_64` 147 + - **Linux aarch64**: `grain-linux-aarch64` 148 + - **macOS Intel**: `grain-darwin-x86_64` 88 149 - **macOS Apple Silicon**: `grain-darwin-aarch64` 150 + - **Windows x86_64**: `grain-windows-x86_64.exe` 89 151 90 152 ### Usage 91 153
+21 -9
cli/flake.nix
··· 55 55 cargoArtifacts = craneLib.buildDepsOnly commonArgs; 56 56 57 57 # Build function for different targets 58 - buildGrainCLI = target: craneLib.buildPackage (commonArgs // { 59 - inherit cargoArtifacts; 60 - CARGO_BUILD_TARGET = target; 61 - } // pkgs.lib.optionalAttrs (target == "x86_64-pc-windows-gnu") { 62 - depsBuildBuild = with pkgs; [ 63 - pkgsCross.mingwW64.stdenv.cc 64 - ]; 65 - CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER = "${pkgs.pkgsCross.mingwW64.stdenv.cc}/bin/x86_64-w64-mingw32-gcc"; 66 - }); 58 + buildGrainCLI = target: 59 + let 60 + # Only cross-compile if target is different from current system 61 + isCrossCompiling = target != system; 62 + in 63 + if isCrossCompiling then 64 + # For cross-compilation, use the native build but with target specified 65 + craneLib.buildPackage (commonArgs // { 66 + inherit cargoArtifacts; 67 + CARGO_BUILD_TARGET = target; 68 + } // pkgs.lib.optionalAttrs (target == "x86_64-pc-windows-gnu") { 69 + depsBuildBuild = with pkgs; [ 70 + pkgsCross.mingwW64.stdenv.cc 71 + ]; 72 + CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER = "${pkgs.pkgsCross.mingwW64.stdenv.cc}/bin/x86_64-w64-mingw32-gcc"; 73 + }) 74 + else 75 + # For native builds, don't specify target 76 + craneLib.buildPackage (commonArgs // { 77 + inherit cargoArtifacts; 78 + }); 67 79 68 80 in { 69 81 packages = {