# 手动触发的多架构发布包构建;产物只上传到本次 GitHub Actions 运行。 name: Package on: # 避免每次提交都执行耗时的交叉编译。 workflow_dispatch: jobs: build: runs-on: ${{ matrix.os }}-latest strategy: # 覆盖 Linux 四种架构、macOS 两种架构和 Windows 两种架构。 fail-fast: true matrix: include: - os: ubuntu arch: i386 target: i686-unknown-linux-gnu - os: ubuntu arch: armhf target: armv7-unknown-linux-gnueabihf - os: ubuntu arch: amd64 target: x86_64-unknown-linux-gnu - os: ubuntu arch: arm64 target: aarch64-unknown-linux-gnu - os: macos arch: amd64 target: x86_64-apple-darwin - os: macos arch: arm64 target: aarch64-apple-darwin - os: windows arch: i386 target: i686-pc-windows-msvc - os: windows arch: amd64 target: x86_64-pc-windows-msvc steps: - name: Checkout repository uses: actions/checkout@v4 - name: Install Rust uses: dtolnay/rust-toolchain@stable with: targets: ${{ matrix.target }} - name: Check crate # 在原生可运行的平台先验证 crates.io 打包内容,不真正发布。 if: matrix.os == 'macos' || matrix.os == 'windows' || matrix.os == 'ubuntu' && matrix.arch == 'amd64' run: cargo publish --dry-run --target ${{ matrix.target }} - name: Clippy (release mode) run: cargo clippy --release -- -D warnings - name: Test (release mode) # 只在可直接运行目标二进制的平台执行测试;测试后清理以免混入打包产物。 if: matrix.os == 'macos' || matrix.os == 'ubuntu' || matrix.os == 'windows' && matrix.arch == 'amd64' run: | cargo test --release --verbose -- --nocapture && cargo clean - name: Install Cross # Linux 非宿主架构通过 cross 的容器工具链编译。 if: matrix.os == 'ubuntu' run: cargo install cross --git https://github.com/cross-rs/cross - name: Build binary (Linux) if: matrix.os == 'ubuntu' run: cross build --release --target ${{ matrix.target }} - name: Build binary (macOS/Windows) if: matrix.os == 'macos' || matrix.os == 'windows' run: cargo build --release --target ${{ matrix.target }} - name: Upload build artifacts # 同时兼容 Unix 无扩展名程序和 Windows `.exe`。 uses: actions/upload-artifact@v4 with: name: build-${{ matrix.os }}-${{ matrix.target }} path: | target/*/release/dxf2elmt target/*/release/dxf2elmt.exe if-no-files-found: error