| 1 |
name: Release |
| 2 |
|
| 3 |
on: |
| 4 |
push: |
| 5 |
tags: ["v*"] |
| 6 |
workflow_dispatch: |
| 7 |
|
| 8 |
permissions: |
| 9 |
contents: read |
| 10 |
|
| 11 |
jobs: |
| 12 |
release-crates-io: |
| 13 |
name: Release crates.io |
| 14 |
runs-on: ubuntu-latest |
| 15 |
if: startsWith(github.ref, 'refs/tags/') |
| 16 |
environment: |
| 17 |
name: crates.io |
| 18 |
url: ${{ steps.set_url.outputs.env_url }} |
| 19 |
steps: |
| 20 |
- uses: actions/checkout@v4 |
| 21 |
- uses: dtolnay/rust-toolchain@stable |
| 22 |
- name: cargo login |
| 23 |
run: cargo login ${{ secrets.CRATES_IO_TOKEN }} |
| 24 |
- name: cargo publish |
| 25 |
run: cargo publish |
| 26 |
- name: Set environment url |
| 27 |
id: set_url |
| 28 |
run: | |
| 29 |
VERSION=$(echo $GITHUB_REF | sed -e "s#refs/tags/v##g") |
| 30 |
echo "env_url=https://crates.io/crates/maturin/$VERSION" >> $GITHUB_OUTPUT |
| 31 |
|
| 32 |
build: |
| 33 |
name: Build ${{ matrix.target }} |
| 34 |
strategy: |
| 35 |
fail-fast: false |
| 36 |
matrix: |
| 37 |
target: |
| 38 |
- x86_64-unknown-linux-musl |
| 39 |
- x86_64-apple-darwin |
| 40 |
- x86_64-pc-windows-msvc |
| 41 |
- i686-pc-windows-msvc |
| 42 |
- aarch64-pc-windows-msvc |
| 43 |
include: |
| 44 |
- target: x86_64-unknown-linux-musl |
| 45 |
os: ubuntu-latest |
| 46 |
name: maturin-x86_64-unknown-linux-musl.tar.gz |
| 47 |
- target: x86_64-apple-darwin |
| 48 |
os: macos-latest |
| 49 |
name: maturin-x86_64-apple-darwin.tar.gz |
| 50 |
- target: x86_64-pc-windows-msvc |
| 51 |
os: windows-latest |
| 52 |
name: maturin-x86_64-pc-windows-msvc.zip |
| 53 |
- target: i686-pc-windows-msvc |
| 54 |
os: windows-latest |
| 55 |
name: maturin-i686-pc-windows-msvc.zip |
| 56 |
- target: aarch64-pc-windows-msvc |
| 57 |
os: windows-latest |
| 58 |
name: maturin-aarch64-pc-windows-msvc.zip |
| 59 |
runs-on: ${{ matrix.os }} |
| 60 |
env: |
| 61 |
CARGO_PROFILE_RELEASE_LTO: "fat" |
| 62 |
steps: |
| 63 |
# Largely inspired by https://github.com/starship/starship/blob/35a0a20f5c4fea6a08e1b91ff631b089eef8fc50/.github/workflows/deploy.yml |
| 64 |
- uses: actions/checkout@v4 |
| 65 |
- uses: dtolnay/rust-toolchain@stable |
| 66 |
with: |
| 67 |
targets: ${{ matrix.target }} |
| 68 |
|
| 69 |
- name: Install musl tools |
| 70 |
if: matrix.os == 'ubuntu-latest' |
| 71 |
run: sudo apt-get install -y musl-tools |
| 72 |
|
| 73 |
# Install gnu-tar because BSD tar is buggy |
| 74 |
# https://github.com/actions/cache/issues/403 |
| 75 |
- name: Install GNU tar (macOS) |
| 76 |
if: matrix.os == 'macos-latest' |
| 77 |
run: | |
| 78 |
brew install gnu-tar |
| 79 |
echo "/usr/local/opt/gnu-tar/libexec/gnubin" >> $GITHUB_PATH |
| 80 |
|
| 81 |
# Those two will also create target/${{ matrix.target }}/maturin |
| 82 |
- name: Build wheel (with sdist) |
| 83 |
if: matrix.target == 'x86_64-unknown-linux-musl' |
| 84 |
run: | |
| 85 |
cargo run -- build --release -b bin --sdist -o dist --target ${{ matrix.target }} --features password-storage --compatibility manylinux2010 musllinux_1_1 |
| 86 |
|
| 87 |
# ring doesn't support aarch64 windows yet |
| 88 |
- name: Build wheel (windows aarch64) |
| 89 |
if: matrix.target == 'aarch64-pc-windows-msvc' |
| 90 |
run: cargo run -- build --release -b bin -o dist --target ${{ matrix.target }} --no-default-features --features full,native-tls |
| 91 |
|
| 92 |
- name: Build wheel (without sdist) |
| 93 |
if: ${{ matrix.target != 'x86_64-unknown-linux-musl' && matrix.target != 'aarch64-pc-windows-msvc' }} |
| 94 |
run: cargo run -- build --release -b bin -o dist --target ${{ matrix.target }} --features password-storage |
| 95 |
|
| 96 |
- name: Build wheel (macOS universal2) |
| 97 |
if: matrix.target == 'x86_64-apple-darwin' |
| 98 |
env: |
| 99 |
DEVELOPER_DIR: /Applications/Xcode.app/Contents/Developer |
| 100 |
MACOSX_DEPLOYMENT_TARGET: "10.12" |
| 101 |
run: | |
| 102 |
# set SDKROOT for C dependencies like ring and bzip2 |
| 103 |
export SDKROOT=$(xcrun --sdk macosx --show-sdk-path) |
| 104 |
rustup target add aarch64-apple-darwin |
| 105 |
cargo run -- build --release -b bin -o dist --target universal2-apple-darwin --features password-storage |
| 106 |
|
| 107 |
- name: Archive binary (windows) |
| 108 |
if: matrix.os == 'windows-latest' |
| 109 |
run: | |
| 110 |
cd target/${{ matrix.target }}/release |
| 111 |
7z a ../../../${{ matrix.name }} ${{ github.event.repository.name }}.exe |
| 112 |
cd - |
| 113 |
|
| 114 |
- name: Archive binary (linux and macOS) |
| 115 |
if: matrix.os != 'windows-latest' |
| 116 |
run: | |
| 117 |
cd target/${{ matrix.target }}/release |
| 118 |
tar czvf ../../../${{ matrix.name }} ${{ github.event.repository.name }} |
| 119 |
cd - |
| 120 |
|
| 121 |
- name: Archive binary (macOS aarch64) |
| 122 |
if: matrix.os == 'macos-latest' |
| 123 |
run: | |
| 124 |
cd target/aarch64-apple-darwin/release |
| 125 |
tar czvf ../../../maturin-aarch64-apple-darwin.tar.gz ${{ github.event.repository.name }} |
| 126 |
cd - |
| 127 |
|
| 128 |
- name: Upload wheel artifacts |
| 129 |
uses: actions/upload-artifact@v4 |
| 130 |
with: |
| 131 |
name: wheels-${{ matrix.target }} |
| 132 |
path: dist |
| 133 |
|
| 134 |
- name: Upload binary artifacts |
| 135 |
uses: actions/upload-artifact@v4 |
| 136 |
with: |
| 137 |
name: binaries-${{ matrix.target }} |
| 138 |
path: | |
| 139 |
*.tar.gz |
| 140 |
*.zip |
| 141 |
|
| 142 |
build-musl: |
| 143 |
name: Build ${{ matrix.platform.target }} |
| 144 |
runs-on: ubuntu-latest |
| 145 |
strategy: |
| 146 |
fail-fast: false |
| 147 |
matrix: |
| 148 |
platform: |
| 149 |
- target: "aarch64-unknown-linux-musl" |
| 150 |
image: "rust-musl-cross:aarch64-musl" |
| 151 |
compatibility: "manylinux2014 musllinux_1_1" |
| 152 |
- target: "armv7-unknown-linux-musleabihf" |
| 153 |
image: "rust-musl-cross:armv7-musleabihf" |
| 154 |
compatibility: "manylinux2014 musllinux_1_1" |
| 155 |
- target: "i686-unknown-linux-musl" |
| 156 |
image: "rust-musl-cross:i686-musl" |
| 157 |
compatibility: "manylinux2010 musllinux_1_1" |
| 158 |
- target: "arm-unknown-linux-musleabihf" |
| 159 |
image: "rust-musl-cross:arm-musleabihf" |
| 160 |
compatibility: "linux" |
| 161 |
- target: "powerpc64le-unknown-linux-musl" |
| 162 |
image: "rust-musl-cross:powerpc64le-musl" |
| 163 |
compatibility: "manylinux2014 musllinux_1_1" |
| 164 |
lto: "off" |
| 165 |
- target: "s390x-unknown-linux-gnu" |
| 166 |
image: "manylinux2014-cross:s390x" |
| 167 |
compatibility: "manylinux2014" |
| 168 |
- target: "loongarch64-unknown-linux-gnu" |
| 169 |
image: "manylinux_2_36-cross:loongarch64" |
| 170 |
compatibility: "manylinux_2_36" |
| 171 |
- target: "riscv64gc-unknown-linux-gnu" |
| 172 |
image: "manylinux_2_31-cross:riscv64" |
| 173 |
compatibility: "manylinux_2_31" |
| 174 |
container: |
| 175 |
image: docker://ghcr.io/rust-cross/${{ matrix.platform.image }} |
| 176 |
env: |
| 177 |
RUSTUP_HOME: /root/.rustup |
| 178 |
CARGO_HOME: /root/.cargo |
| 179 |
CARGO_PROFILE_RELEASE_LTO: "${{ matrix.platform.lto || 'fat' }}" |
| 180 |
steps: |
| 181 |
- uses: actions/checkout@v4 |
| 182 |
# powerpc64le-unknown-linux-musl doesn't have official std library release |
| 183 |
- run: rustup target add --toolchain stable ${{ matrix.platform.target }} |
| 184 |
if: ${{ !contains(fromJson('["powerpc64le-unknown-linux-musl", "s390x-unknown-linux-gnu", "loongarch64-unknown-linux-gnu", "riscv64gc-unknown-linux-gnu"]'), matrix.platform.target) }} |
| 185 |
- uses: dtolnay/rust-toolchain@stable |
| 186 |
if: contains(fromJson('["s390x-unknown-linux-gnu", "loongarch64-unknown-linux-gnu", "riscv64gc-unknown-linux-gnu"]'), matrix.platform.target) |
| 187 |
with: |
| 188 |
targets: ${{ matrix.platform.target }} |
| 189 |
- name: Build wheel |
| 190 |
env: |
| 191 |
# Make psm compile, see https://github.com/rust-lang/stacker/issues/79 |
| 192 |
CFLAGS_s390x_unknown_linux_gnu: "-march=z10" |
| 193 |
run: | |
| 194 |
sudo python3 -m pip install -U --pre maturin |
| 195 |
maturin build --release -b bin -o dist \ |
| 196 |
--target ${{ matrix.platform.target }} \ |
| 197 |
--compatibility ${{ matrix.platform.compatibility }} \ |
| 198 |
--features password-storage |
| 199 |
- name: Archive binary |
| 200 |
run: tar czvf target/release/maturin-${{ matrix.platform.target }}.tar.gz -C target/${{ matrix.platform.target }}/release maturin |
| 201 |
- name: Upload wheel artifacts |
| 202 |
# loongarch64 is not allowed to publish to pypi currently, see https://github.com/pypi/warehouse/blob/348117529910181cb8c14e9b5fb00fcf4dbaf07c/warehouse/forklift/legacy.py#L114-L185 |
| 203 |
if: matrix.platform.target != 'loongarch64-unknown-linux-gnu' |
| 204 |
uses: actions/upload-artifact@v4 |
| 205 |
with: |
| 206 |
name: wheels-${{ matrix.platform.target }} |
| 207 |
path: dist |
| 208 |
- name: Upload binary artifacts |
| 209 |
uses: actions/upload-artifact@v4 |
| 210 |
with: |
| 211 |
name: binaries-${{ matrix.platform.target }} |
| 212 |
path: target/release/maturin-${{ matrix.platform.target }}.tar.gz |
| 213 |
|
| 214 |
release-pypi: |
| 215 |
permissions: |
| 216 |
# Used to sign the release's artifacts |
| 217 |
# and upload to PyPI using trusted publisher. |
| 218 |
id-token: write |
| 219 |
# Used to upload release artifacts. |
| 220 |
contents: write |
| 221 |
# Use to generate artifact attestation. |
| 222 |
attestations: write |
| 223 |
name: Publish to PyPI |
| 224 |
runs-on: ubuntu-latest |
| 225 |
environment: |
| 226 |
name: PyPI |
| 227 |
url: ${{ steps.set_url.outputs.env_url }} |
| 228 |
needs: [build, build-musl] |
| 229 |
steps: |
| 230 |
- uses: actions/download-artifact@v4 |
| 231 |
with: |
| 232 |
pattern: wheels-* |
| 233 |
merge-multiple: true |
| 234 |
- name: Generate artifact attestation |
| 235 |
uses: actions/attest-build-provenance@v2 |
| 236 |
with: |
| 237 |
subject-path: | |
| 238 |
./*.tar.gz |
| 239 |
./*.whl |
| 240 |
- uses: actions/setup-python@v5 |
| 241 |
if: startsWith(github.ref, 'refs/tags/') |
| 242 |
with: |
| 243 |
python-version: "3.10" |
| 244 |
- name: Publish |
| 245 |
if: startsWith(github.ref, 'refs/tags/') |
| 246 |
run: | |
| 247 |
pip install maturin |
| 248 |
maturin upload --skip-existing * |
| 249 |
- name: Set environment url |
| 250 |
id: set_url |
| 251 |
run: | |
| 252 |
VERSION=$(echo $GITHUB_REF | sed -e "s#refs/tags/v##g") |
| 253 |
echo "env_url=https://pypi.org/project/maturin/$VERSION" >> $GITHUB_OUTPUT |
| 254 |
|
| 255 |
release-github: |
| 256 |
permissions: |
| 257 |
# Used to sign the release's artifacts. |
| 258 |
id-token: write |
| 259 |
# Used to upload release artifacts. |
| 260 |
contents: write |
| 261 |
# Use to generate artifact attestation. |
| 262 |
attestations: write |
| 263 |
name: Publish to GitHub releases |
| 264 |
runs-on: ubuntu-latest |
| 265 |
needs: [build, build-musl] |
| 266 |
steps: |
| 267 |
- uses: actions/download-artifact@v4 |
| 268 |
with: |
| 269 |
pattern: binaries-* |
| 270 |
merge-multiple: true |
| 271 |
- name: Generate artifact attestation |
| 272 |
uses: actions/attest-build-provenance@v2 |
| 273 |
with: |
| 274 |
subject-path: | |
| 275 |
./*.tar.gz |
| 276 |
./*.zip |
| 277 |
./*.deb |
| 278 |
- name: Release |
| 279 |
if: startsWith(github.ref, 'refs/tags/') |
| 280 |
uses: softprops/action-gh-release@v2 |
| 281 |
with: |
| 282 |
files: | |
| 283 |
*.tar.gz |
| 284 |
*.zip |
| 285 |
*.deb |
| 286 |
prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') }} |
| 287 |
generate_release_notes: true |