Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于 用 GitHub Actions 进行持续集成 自动构建部分的更新 #1499

Open
hanshuaikang opened this issue Jan 5, 2025 · 0 comments

Comments

@hanshuaikang
Copy link

这一章节最后 用 GitHub Actions 进行持续集成 分享了关于 Rust 构建多个不同平台的包进行构建的内容,文档已经三年未更新,实测之后发现我的项目已经无法自动化构建了。看到评论区也有人留言对于如何构建 Macos Arm64 这些平台的困扰。于是将我所实践过之后的最新的方案分享给大家,希望可以帮助到更多的人。

github 上有很多开源的 action 可以更方便的完成多平台的自动化构建工作,我这边已经提了一个 pr 来去更新这部分内容,如果看到这个 issue 的朋友也遇到了类似的难题的话,可以参考我的项目 Nping 的配置。

https://github.com/hanshuaikang/Nping/blob/main/.github/workflows/release.yml

目前我使用的方案是使用: upload-rust-binary-action

实测可以流程生成 macos x86_64, macos arm64, windows, linux x86_64 和 linux arm64

完整的 yaml 如下:

使用时需要把 bin: nping 替换成你自己的 二进制 名称。

name: Release

on:
  push:
    tags:
      - 'v*.*.*'

permissions:
  contents: write

jobs:
  create-release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: taiki-e/create-gh-release-action@v1
        with:
          # (required) GitHub token for creating GitHub Releases.
          token: ${{ secrets.GITHUB_TOKEN }}

  upload-assets:
    needs: create-release
    strategy:
      matrix:
        include:
          - target: aarch64-unknown-linux-gnu
            os: ubuntu-latest
          - target: aarch64-apple-darwin
            os: macos-latest
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
          - target: x86_64-apple-darwin
            os: macos-latest
          # Universal macOS binary is supported as universal-apple-darwin.
          - target: universal-apple-darwin
            os: macos-latest
          - target: x86_64-pc-windows-msvc
            os: windows-latest
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v4
      - uses: taiki-e/upload-rust-binary-action@v1
        with:
          # (required) Comma-separated list of binary names (non-extension portion of filename) to build and upload.
          # Note that glob pattern is not supported yet.
          bin: nping
          # (optional) Target triple, default is host triple.
          target: ${{ matrix.target }}
          # (required) GitHub token for uploading assets to GitHub Releases.
          token: ${{ secrets.GITHUB_TOKEN }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant