|
| 1 | +on: [push] |
| 2 | +name: build |
| 3 | + |
| 4 | +jobs: |
| 5 | + build: |
| 6 | + name: Build |
| 7 | + runs-on: ubuntu-latest |
| 8 | + strategy: |
| 9 | + fail-fast: false |
| 10 | + matrix: |
| 11 | + include: |
| 12 | + - target: x86_64-unknown-linux-gnu |
| 13 | + windows: false |
| 14 | + - target: aarch64-unknown-linux-gnu |
| 15 | + windows: false |
| 16 | + - target: arm-unknown-linux-gnueabi |
| 17 | + windows: false |
| 18 | + - target: arm-unknown-linux-gnueabihf |
| 19 | + windows: false |
| 20 | + - target: x86_64-unknown-linux-musl |
| 21 | + windows: false |
| 22 | + - target: aarch64-unknown-linux-musl |
| 23 | + windows: false |
| 24 | + - target: arm-unknown-linux-musleabi |
| 25 | + windows: false |
| 26 | + - target: arm-unknown-linux-musleabihf |
| 27 | + windows: false |
| 28 | + - target: x86_64-apple-darwin |
| 29 | + windows: false |
| 30 | + - target: aarch64-apple-darwin |
| 31 | + windows: false |
| 32 | + - target: x86_64-pc-windows-gnu |
| 33 | + windows: true |
| 34 | + - target: i686-pc-windows-gnu |
| 35 | + windows: true |
| 36 | + steps: |
| 37 | + - name: Checkout |
| 38 | + uses: actions/checkout@v4 |
| 39 | + |
| 40 | + - name: Install dependencies |
| 41 | + run: | |
| 42 | + mkdir -p ~/.zig |
| 43 | +
|
| 44 | + curl -fsSL \ |
| 45 | + "https://ziglang.org/download/0.13.0/zig-linux-$(uname -m)-0.13.0.tar.xz" | \ |
| 46 | + tar -xJ -C ~/.zig --strip-components 1 |
| 47 | +
|
| 48 | + chmod a+rx ~/.zig/zig |
| 49 | + sudo ln -sf ~/.zig/zig /usr/local/bin/zig |
| 50 | +
|
| 51 | + - name: Cache |
| 52 | + uses: actions/cache@v4 |
| 53 | + env: |
| 54 | + cache-name: rust-cache |
| 55 | + with: |
| 56 | + path: | |
| 57 | + ~/.cargo |
| 58 | + ~/.rustup |
| 59 | + target |
| 60 | + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }} |
| 61 | + restore-keys: | |
| 62 | + ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.target }}- |
| 63 | + ${{ runner.os }}-build-${{ matrix.target }}- |
| 64 | + ${{ runner.os }}-${{ matrix.target }}- |
| 65 | +
|
| 66 | + - name: Install Rust toolchain |
| 67 | + run: | |
| 68 | + rustup update --no-self-update nightly |
| 69 | + rustup component add --toolchain nightly rustfmt rust-src |
| 70 | + rustup default nightly |
| 71 | +
|
| 72 | + rustup target add ${{ matrix.target }} |
| 73 | +
|
| 74 | + - name: Install cargo-binstall |
| 75 | + uses: cargo-bins/cargo-binstall@main |
| 76 | + |
| 77 | + - name: Install cargo-zigbuild |
| 78 | + run: | |
| 79 | + cargo binstall cargo-zigbuild -y |
| 80 | +
|
| 81 | + - name: Install cross |
| 82 | + run: | |
| 83 | + cargo binstall cross -y |
| 84 | +
|
| 85 | + - name: Build |
| 86 | + if: matrix.windows != true |
| 87 | + run: | |
| 88 | + cargo zigbuild --bin kjspkg --target ${{ matrix.target }} |
| 89 | + cargo zigbuild --bin kjspkg --release --target ${{ matrix.target }} |
| 90 | +
|
| 91 | + mkdir bin |
| 92 | +
|
| 93 | + cp -v target/${{ matrix.target }}/debug/kjspkg bin/kjspkg-debug |
| 94 | + cp -v target/${{ matrix.target }}/release/kjspkg bin/kjspkg |
| 95 | +
|
| 96 | + - name: Build (windows) |
| 97 | + if: matrix.windows == true |
| 98 | + run: | |
| 99 | + cross build --bin kjspkg --target ${{ matrix.target }} |
| 100 | + cross build --bin kjspkg --release --target ${{ matrix.target }} |
| 101 | +
|
| 102 | + mkdir bin |
| 103 | +
|
| 104 | + cp -v target/${{ matrix.target }}/debug/kjspkg.exe bin/kjspkg-debug.exe |
| 105 | + cp -v target/${{ matrix.target }}/release/kjspkg.exe bin/kjspkg.exe |
| 106 | +
|
| 107 | + - name: Upload artifacts |
| 108 | + uses: actions/upload-artifact@v4 |
| 109 | + with: |
| 110 | + name: binaries-${{ matrix.target }} |
| 111 | + path: bin/* |
| 112 | + merge: |
| 113 | + name: Merge Artifacts |
| 114 | + runs-on: ubuntu-latest |
| 115 | + needs: |
| 116 | + - build |
| 117 | + steps: |
| 118 | + - name: Download Artifacts |
| 119 | + uses: actions/download-artifact@v4 |
| 120 | + with: |
| 121 | + path: ./artifacts |
| 122 | + |
| 123 | + - name: Merge artifacts |
| 124 | + run: | |
| 125 | + mkdir bin |
| 126 | +
|
| 127 | + for target in ./artifacts/*; do |
| 128 | + targetname="$(basename "$target")" |
| 129 | + targetname="${targetname/binaries-/}" |
| 130 | +
|
| 131 | + for file in $target/*; do |
| 132 | + if [[ "$file" == *".exe" ]]; then |
| 133 | + newpath="${file/\.exe/"-$targetname.exe"}" |
| 134 | + newpath="./bin/$(basename "$newpath")" |
| 135 | +
|
| 136 | + cp -v "$file" "$newpath" |
| 137 | + else |
| 138 | + newpath="$file-$targetname" |
| 139 | + newpath="./bin/$(basename "$newpath")" |
| 140 | +
|
| 141 | + cp -v "$file" "$newpath" |
| 142 | + fi |
| 143 | + done |
| 144 | + done |
| 145 | + |
| 146 | + - name: Upload artifacts |
| 147 | + uses: actions/upload-artifact@v4 |
| 148 | + with: |
| 149 | + name: binaries |
| 150 | + path: bin/* |
0 commit comments