ccgo 3.10.4

A high-performance C++ cross-platform build CLI
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
name: Release

on:
  push:
    tags:
      - 'v*.*.*'
  workflow_dispatch:
    inputs:
      tag:
        description: 'Release tag (e.g., v0.1.0)'
        required: false
        type: string

env:
  PACKAGE_NAME: ccgo
  CARGO_INCREMENTAL: 0
  CARGO_NET_RETRY: 10
  CARGO_TERM_COLOR: always
  RUSTUP_MAX_RETRIES: 10

permissions:
  contents: write
  id-token: write

jobs:
  # Build source distribution
  sdist:
    name: Build sdist
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: '3.11'
      - name: Build sdist
        uses: PyO3/maturin-action@v1
        with:
          command: sdist
          args: --out dist
      - name: Upload sdist
        uses: actions/upload-artifact@v4
        with:
          name: wheels-sdist
          path: dist

  # Build wheels for Linux
  linux:
    name: Build Linux ${{ matrix.target }}
    runs-on: ${{ matrix.runner }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - runner: ubuntu-latest
            target: x86_64
          - runner: ubuntu-24.04-arm
            target: aarch64
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: '3.11'
      - name: Build wheels
        uses: PyO3/maturin-action@v1
        with:
          target: ${{ matrix.target }}
          args: --release --locked --out dist
          manylinux: '2_17'
      - name: Upload wheels
        uses: actions/upload-artifact@v4
        with:
          name: wheels-linux-${{ matrix.target }}
          path: dist
      - name: Archive binary
        run: |
          ARCH=${{ matrix.target }}
          if [ "$ARCH" = "x86_64" ]; then
            TARGET=x86_64-unknown-linux-gnu
          else
            TARGET=aarch64-unknown-linux-gnu
          fi
          ARCHIVE_NAME=${{ env.PACKAGE_NAME }}-$TARGET
          ARCHIVE_FILE=$ARCHIVE_NAME.tar.gz

          mkdir -p $ARCHIVE_NAME
          cp target/$TARGET/release/${{ env.PACKAGE_NAME }} $ARCHIVE_NAME/
          tar czvf $ARCHIVE_FILE $ARCHIVE_NAME
          shasum -a 256 $ARCHIVE_FILE > $ARCHIVE_FILE.sha256
      - name: Upload binary
        uses: actions/upload-artifact@v4
        with:
          name: binaries-linux-${{ matrix.target }}
          path: |
            *.tar.gz
            *.sha256

  # Build wheels for Windows
  windows:
    name: Build Windows ${{ matrix.target }}
    runs-on: windows-latest
    strategy:
      fail-fast: false
      matrix:
        include:
          - target: x86_64
            rust_target: x86_64-pc-windows-msvc
          - target: aarch64
            rust_target: aarch64-pc-windows-msvc
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: '3.11'
      - name: Build wheels
        uses: PyO3/maturin-action@v1
        with:
          target: ${{ matrix.target }}
          args: --release --locked --out dist
      - name: Upload wheels
        uses: actions/upload-artifact@v4
        with:
          name: wheels-windows-${{ matrix.target }}
          path: dist
      - name: Archive binary
        shell: bash
        run: |
          TARGET=${{ matrix.rust_target }}
          ARCHIVE_NAME=${{ env.PACKAGE_NAME }}-$TARGET
          ARCHIVE_FILE=$ARCHIVE_NAME.zip

          mkdir -p $ARCHIVE_NAME
          cp target/$TARGET/release/${{ env.PACKAGE_NAME }}.exe $ARCHIVE_NAME/
          7z a $ARCHIVE_FILE $ARCHIVE_NAME
          sha256sum $ARCHIVE_FILE > $ARCHIVE_FILE.sha256
      - name: Upload binary
        uses: actions/upload-artifact@v4
        with:
          name: binaries-windows-${{ matrix.target }}
          path: |
            *.zip
            *.sha256

  # Build wheels for macOS
  macos:
    name: Build macOS ${{ matrix.target }}
    runs-on: ${{ matrix.runner }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - runner: macos-15-intel
            target: x86_64
          - runner: macos-15
            target: aarch64
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: '3.11'
      - name: Build wheels
        uses: PyO3/maturin-action@v1
        with:
          target: ${{ matrix.target }}
          args: --release --locked --out dist
      - name: Upload wheels
        uses: actions/upload-artifact@v4
        with:
          name: wheels-macos-${{ matrix.target }}
          path: dist
      - name: Archive binary
        run: |
          ARCH=${{ matrix.target }}
          if [ "$ARCH" = "x86_64" ]; then
            TARGET=x86_64-apple-darwin
          else
            TARGET=aarch64-apple-darwin
          fi
          ARCHIVE_NAME=${{ env.PACKAGE_NAME }}-$TARGET
          ARCHIVE_FILE=$ARCHIVE_NAME.tar.gz

          mkdir -p $ARCHIVE_NAME
          cp target/$TARGET/release/${{ env.PACKAGE_NAME }} $ARCHIVE_NAME/
          tar czvf $ARCHIVE_FILE $ARCHIVE_NAME
          shasum -a 256 $ARCHIVE_FILE > $ARCHIVE_FILE.sha256
      - name: Upload binary
        uses: actions/upload-artifact@v4
        with:
          name: binaries-macos-${{ matrix.target }}
          path: |
            *.tar.gz
            *.sha256

  # Create GitHub Release
  github-release:
    name: Create GitHub Release
    runs-on: ubuntu-latest
    if: startsWith(github.ref, 'refs/tags/')
    needs: [sdist, linux, windows, macos]
    steps:
      - uses: actions/checkout@v4
      - name: Download all binaries
        uses: actions/download-artifact@v4
        with:
          pattern: binaries-*
          path: binaries
          merge-multiple: true
      - name: Extract version
        id: version
        run: echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT
      - name: Create Release
        uses: softprops/action-gh-release@v2
        with:
          files: binaries/*
          body: |
            ## Installation

            **Python Package (PyPI):**
            ```bash
            pip install ccgo==${{ steps.version.outputs.VERSION }}
            # or
            pip install --upgrade ccgo
            ```

            **Homebrew (macOS/Linux):**
            ```bash
            brew tap zhlinh/ccgo
            brew trust --formula zhlinh/ccgo/ccgo
            brew install ccgo
            ```

            **Rust Binary (crates.io):**
            ```bash
            cargo install ccgo
            ```

            **Pre-built Binaries:**
            Download platform-specific binaries from the assets below.

            ## Quick Start

            ```bash
            # Create a new C++ cross-platform project
            ccgo new my-project

            # Build for different platforms
            cd my-project/<project_name>
            ccgo build android
            ccgo build ios
            ccgo build macos
            ccgo build linux
            ccgo build windows

            # Cross-platform builds using Docker
            ccgo build linux --docker
            ccgo build windows --docker
            ccgo build macos --docker
            ccgo build ios --docker
            ```

            See [CHANGELOG.md](CHANGELOG.md) for details.
          generate_release_notes: true
          draft: false
          prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') || contains(github.ref, 'rc') }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

  # Publish to PyPI
  publish-pypi:
    name: Publish to PyPI
    runs-on: ubuntu-latest
    if: startsWith(github.ref, 'refs/tags/')
    needs: [sdist, linux, windows, macos]
    environment:
      name: release
    permissions:
      id-token: write
    steps:
      - name: Download all wheels
        uses: actions/download-artifact@v4
        with:
          pattern: wheels-*
          path: dist
          merge-multiple: true
      - name: Publish to PyPI
        uses: pypa/gh-action-pypi-publish@release/v1

  # Publish to crates.io
  publish-crates:
    name: Publish to crates.io
    runs-on: ubuntu-latest
    if: startsWith(github.ref, 'refs/tags/')
    needs: [sdist, linux, windows, macos]
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - name: Verify build
        run: cargo build --release --locked
      - name: Run tests
        run: cargo test --locked
      - name: Publish to crates.io
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
        run: cargo publish --locked

  # Update Homebrew tap Formula
  publish-homebrew:
    name: Update Homebrew tap
    runs-on: ubuntu-latest
    if: startsWith(github.ref, 'refs/tags/') && !contains(github.ref, 'alpha') && !contains(github.ref, 'beta') && !contains(github.ref, 'rc')
    needs: [github-release]
    steps:
      - name: Download binary artifacts
        uses: actions/download-artifact@v4
        with:
          pattern: binaries-*
          path: binaries
          merge-multiple: true
      - name: Extract SHA256 checksums
        id: sha
        run: |
          extract_sha() {
            local file="binaries/$1.sha256"
            if [ ! -f "$file" ]; then
              echo "Error: missing checksum file $file" >&2
              exit 1
            fi
            awk '{print $1}' "$file"
          }
          {
            echo "darwin_arm64=$(extract_sha ccgo-aarch64-apple-darwin.tar.gz)"
            echo "darwin_x86_64=$(extract_sha ccgo-x86_64-apple-darwin.tar.gz)"
            echo "linux_arm64=$(extract_sha ccgo-aarch64-unknown-linux-gnu.tar.gz)"
            echo "linux_x86_64=$(extract_sha ccgo-x86_64-unknown-linux-gnu.tar.gz)"
          } >> "$GITHUB_OUTPUT"
      - name: Clone Homebrew tap
        env:
          HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
        run: |
          git clone "https://x-access-token:${HOMEBREW_TAP_TOKEN}@github.com/zhlinh/homebrew-ccgo.git" tap

      - name: Initialize Formula if not exists
        run: |
          mkdir -p tap/Formula
          if [ ! -f "tap/Formula/ccgo.rb" ]; then
            echo "Formula not found, creating a new one..."
            cat << 'EOF' > tap/Formula/ccgo.rb
          class Ccgo < Formula
            desc "A high-performance C++ cross-platform build CLI"
            homepage "https://github.com/zhlinh/ccgo"
            version "0.0.0"
            license "MIT"

            on_macos do
              if Hardware::CPU.arm?
                url "https://github.com/zhlinh/ccgo/releases/download/v#{version}/ccgo-aarch64-apple-darwin.tar.gz"
                sha256 "0000000000000000000000000000000000000000000000000000000000000000" # darwin-arm64
              end
              if Hardware::CPU.intel?
                url "https://github.com/zhlinh/ccgo/releases/download/v#{version}/ccgo-x86_64-apple-darwin.tar.gz"
                sha256 "0000000000000000000000000000000000000000000000000000000000000000" # darwin-x86_64
              end
            end

            on_linux do
              if Hardware::CPU.arm?
                url "https://github.com/zhlinh/ccgo/releases/download/v#{version}/ccgo-aarch64-unknown-linux-gnu.tar.gz"
                sha256 "0000000000000000000000000000000000000000000000000000000000000000" # linux-arm64
              end
              if Hardware::CPU.intel?
                url "https://github.com/zhlinh/ccgo/releases/download/v#{version}/ccgo-x86_64-unknown-linux-gnu.tar.gz"
                sha256 "0000000000000000000000000000000000000000000000000000000000000000" # linux-x86_64
              end
            end

            def install
              bin.install "ccgo"
            end
          end
          EOF
          else
            echo "Formula already exists, skipping initialization."
          fi

      - name: Update Formula
        env:
          VERSION: ${{ github.ref_name }}
          SHA_DARWIN_ARM64: ${{ steps.sha.outputs.darwin_arm64 }}
          SHA_DARWIN_X86_64: ${{ steps.sha.outputs.darwin_x86_64 }}
          SHA_LINUX_ARM64: ${{ steps.sha.outputs.linux_arm64 }}
          SHA_LINUX_X86_64: ${{ steps.sha.outputs.linux_x86_64 }}
        run: |
          VERSION_NO_V=${VERSION#v}
          FORMULA=tap/Formula/ccgo.rb

          # Bump version
          sed -i -E "s/^  version \"[^\"]+\"/  version \"${VERSION_NO_V}\"/" "$FORMULA"

          # Patch each sha256 by its marker comment
          sed -i -E "s|sha256 \"[0-9a-f]+\" # darwin-arm64|sha256 \"${SHA_DARWIN_ARM64}\" # darwin-arm64|" "$FORMULA"
          sed -i -E "s|sha256 \"[0-9a-f]+\" # darwin-x86_64|sha256 \"${SHA_DARWIN_X86_64}\" # darwin-x86_64|" "$FORMULA"
          sed -i -E "s|sha256 \"[0-9a-f]+\" # linux-arm64|sha256 \"${SHA_LINUX_ARM64}\" # linux-arm64|" "$FORMULA"
          sed -i -E "s|sha256 \"[0-9a-f]+\" # linux-x86_64|sha256 \"${SHA_LINUX_X86_64}\" # linux-x86_64|" "$FORMULA"

          echo "--- Updated Formula ---"
          cat "$FORMULA"

      - name: Commit and push
        working-directory: tap
        run: |
          git config user.name "github-actions[bot]"
          git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
          if git ls-files --error-unmatch Formula/ccgo.rb > /dev/null 2>&1 && git diff --quiet Formula/ccgo.rb; then
            echo "No changes to Formula — skipping commit"
            exit 0
          fi
          git add Formula/ccgo.rb
          git commit -m "Update ccgo to ${GITHUB_REF_NAME#v}"
          git push