|
| 1 | +name: cli-rs release |
| 2 | + |
| 3 | +# Builds opencode-native, the Rust client in packages/cli-rs, natively on each runner below and keeps each archive as an |
| 4 | +# artifact. A cli-rs-v<version> tag also publishes them as a GitHub release. It never becomes Latest: the monorepo's |
| 5 | +# Latest release drives OpenCode's own update paths. |
| 6 | +on: |
| 7 | + push: |
| 8 | + tags: |
| 9 | + - "cli-rs-v*" |
| 10 | + pull_request: |
| 11 | + paths: |
| 12 | + - .github/workflows/release-cli-rs.yml |
| 13 | + workflow_dispatch: |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: read |
| 17 | + |
| 18 | +concurrency: |
| 19 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 20 | + cancel-in-progress: ${{ github.event_name == 'pull_request' }} |
| 21 | + |
| 22 | +jobs: |
| 23 | + build: |
| 24 | + strategy: |
| 25 | + fail-fast: false |
| 26 | + matrix: |
| 27 | + include: |
| 28 | + # Zig links Linux against glibc 2.17, OpenTUI's floor. zig_sha is the archive's, from ziglang.org. |
| 29 | + - runner: ubuntu-24.04 |
| 30 | + target: x86_64-unknown-linux-gnu |
| 31 | + zig: x86_64-linux-gnu.2.17 |
| 32 | + zig_sha: 3581863e3cbcfd0fce0efc682ce7e9e93da96668a977791d356a26d2a7e9b17a |
| 33 | + - runner: ubuntu-24.04-arm |
| 34 | + target: aarch64-unknown-linux-gnu |
| 35 | + zig: aarch64-linux-gnu.2.17 |
| 36 | + zig_sha: a1546d5646eb184437918d6635ca6b762a0e889eac09cef720ee7a1ed3fe7795 |
| 37 | + - { runner: macos-15-intel, target: x86_64-apple-darwin } |
| 38 | + - { runner: macos-15, target: aarch64-apple-darwin } |
| 39 | + - { runner: windows-2025, target: x86_64-pc-windows-msvc, exe: .exe } |
| 40 | + runs-on: ${{ matrix.runner }} |
| 41 | + timeout-minutes: 60 |
| 42 | + defaults: |
| 43 | + run: |
| 44 | + shell: bash |
| 45 | + working-directory: packages/cli-rs |
| 46 | + env: |
| 47 | + OPENCODE_NATIVE_COMMIT: ${{ github.sha }} |
| 48 | + CARGO_PROFILE_DIST_STRIP: symbols |
| 49 | + MACOSX_DEPLOYMENT_TARGET: "13.0" |
| 50 | + # No Visual C++ runtime to install beside the .exe. |
| 51 | + CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_RUSTFLAGS: -C target-feature=+crt-static |
| 52 | + steps: |
| 53 | + - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 |
| 54 | + with: |
| 55 | + persist-credentials: false |
| 56 | + - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0 |
| 57 | + with: |
| 58 | + bun-version-file: package.json |
| 59 | + # The version opencode-native --version prints: the tag's, or 0.0.0-<commit> for any other run. |
| 60 | + - name: Version |
| 61 | + run: | |
| 62 | + version=0.0.0-$GITHUB_SHA |
| 63 | + if [[ $GITHUB_REF == refs/tags/cli-rs-v* ]]; then version=${GITHUB_REF_NAME#cli-rs-v}; fi |
| 64 | + echo "OPENCODE_VERSION=$version" >> "$GITHUB_ENV" |
| 65 | + # Zig 0.17.1 as the C and C++ compiler and the linker. The wrapper drops flags zig rejects: cc's --target, and |
| 66 | + # rustc's Cortex-A53 erratum fix on aarch64. |
| 67 | + - if: matrix.zig |
| 68 | + working-directory: ${{ runner.temp }} |
| 69 | + run: | |
| 70 | + file=zig-$(uname -m)-linux-0.17.1 |
| 71 | + curl -fsSL --retry 3 -o zig.tar.xz "https://ziglang.org/download/0.17.1/$file.tar.xz" |
| 72 | + echo "${{ matrix.zig_sha }} zig.tar.xz" | sha256sum -c |
| 73 | + tar -xJf zig.tar.xz |
| 74 | + for tool in cc c++; do |
| 75 | + cat > "zig-$tool" <<EOF |
| 76 | + #!/bin/sh |
| 77 | + for a; do shift; case \$a in --target=*|-Wl,--fix-cortex-a53-843419) ;; *) set -- "\$@" "\$a" ;; esac; done |
| 78 | + exec "$PWD/$file/zig" $tool -target ${{ matrix.zig }} "\$@" |
| 79 | + EOF |
| 80 | + chmod +x "zig-$tool" |
| 81 | + done |
| 82 | + triple=$(tr a-z- A-Z_ <<< "${{ matrix.target }}") |
| 83 | + { echo "CARGO_TARGET_${triple}_LINKER=$PWD/zig-cc"; echo "CC_${triple,,}=$PWD/zig-cc" |
| 84 | + echo "CXX_${triple,,}=$PWD/zig-c++"; echo "CXXSTDLIB_${triple,,}=c++"; } >> "$GITHUB_ENV" |
| 85 | + # rustup reads rust-toolchain.toml; `bun run cargo` first fetches OpenTUI's native library from its release. |
| 86 | + - run: rustup toolchain install |
| 87 | + - run: bun run cargo build --locked --profile dist --bin opencode-native |
| 88 | + - name: Check glibc 2.17 and no libstdc++ |
| 89 | + if: matrix.zig |
| 90 | + run: "! readelf -dV target/dist/opencode-native | grep -E 'GLIBC_2\\.(1[89]|[2-9][0-9])|libstdc\\+\\+'" |
| 91 | + - name: Package |
| 92 | + run: | |
| 93 | + name=opencode-native-$OPENCODE_VERSION-${{ matrix.target }} |
| 94 | + mkdir -p "dist/$name" |
| 95 | + cp "target/dist/opencode-native${{ matrix.exe }}" "dist/$name/" |
| 96 | + # Our licence, and OpenTUI's licences (FFmpeg's among them) from its native release zip. |
| 97 | + cp ../../LICENSE "dist/$name/" |
| 98 | + cp -r .opentui/*/host/licenses "dist/$name/" |
| 99 | + tar -C dist -czf "dist/$name.tar.gz" "$name" |
| 100 | + ls -l "dist/$name" "dist/$name.tar.gz" |
| 101 | + - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 |
| 102 | + with: |
| 103 | + name: opencode-native-${{ matrix.target }} |
| 104 | + path: packages/cli-rs/dist/*.tar.gz |
| 105 | + if-no-files-found: error |
| 106 | + compression-level: 0 |
| 107 | + |
| 108 | + release: |
| 109 | + needs: build |
| 110 | + if: startsWith(github.ref, 'refs/tags/cli-rs-v') |
| 111 | + runs-on: ubuntu-24.04 |
| 112 | + permissions: |
| 113 | + contents: write |
| 114 | + steps: |
| 115 | + - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 |
| 116 | + with: |
| 117 | + pattern: opencode-native-* |
| 118 | + merge-multiple: true |
| 119 | + - name: Publish |
| 120 | + env: |
| 121 | + GH_TOKEN: ${{ github.token }} |
| 122 | + run: | |
| 123 | + sha256sum ./*.tar.gz > SHA256SUMS |
| 124 | + gh release create "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" --verify-tag --latest=false \ |
| 125 | + --title "opencode-native ${GITHUB_REF_NAME#cli-rs-v}" --notes "The Rust client (packages/cli-rs) at $GITHUB_SHA." \ |
| 126 | + ./*.tar.gz SHA256SUMS |
0 commit comments