Files
ome-metadata/.github/workflows/publish_pypi.yml
T
2026-10-01 19:52:38 +02:00

172 lines
6.5 KiB
YAML

name: Publish_py
on: [ workflow_dispatch ]
permissions:
contents: read
jobs:
pypi_publish:
name: Publish (pypi.org)
runs-on: ubuntu-latest
env:
CARGO_HOME: ${{ github.workspace }}/.cargo
RUSTUP_HOME: ${{ github.workspace }}/.rustup
RUSTUP_TOOLCHAIN: stable
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Restore cache
uses: actions/cache/restore@v4
with:
path: |
~/.cache/pip
~/.cache/pip-wheel
~/.cache/sccache
~/.cache/cargo-xwin
${{ env.CARGO_HOME }}
~/.osxcross
key: cache-ubuntu-maturin-cross-compile
- name: Install llvm
run: |
if ! command -v llvm-dlltool >/dev/null 2>&1; then
sudo apt update
sudo apt install -y llvm
fi
shell: bash
- name: Install Rust
run: |
export PATH="$CARGO_HOME/bin:$PATH"
if ! command -v rustup >/dev/null 2>&1; then
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
fi
rustup toolchain install stable --profile minimal
rustup default stable
echo "$CARGO_HOME/bin" >> "$GITHUB_PATH"
cargo --version
shell: bash
- name: Install sccache and maturin
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade maturin "ziglang==0.14.1"
python -m ziglang version
if ! command -v sccache >/dev/null 2>&1; then
cargo install sccache || pip install sccache
fi
shell: bash
- name: Install xwin
run: |
if ! command -v cargo-xwin >/dev/null 2>&1; then
cargo install cargo-xwin || pip install cargo-xwin
cargo xwin cache xwin
fi
shell: bash
- name: Install osxcross
run: |
export PATH="$HOME/.osxcross/bin:$PATH"
if [ ! -d "$HOME/.osxcross/bin" ]; then
wget ${{ secrets.OSXCROSS_LINK }} -O osxcross.tar.gz
tar -xzf osxcross.tar.gz -C ~/
mv ~/osxcross ~/.osxcross
fi
- name: Build wheels
shell: bash
run: |
export PATH="$HOME/.osxcross/bin:$PATH"
echo "HOME=$HOME CARGO_HOME=$CARGO_HOME RUSTUP_HOME=$RUSTUP_HOME"
command -v rustup
command -v cargo
rustup show
cargo --version
rm -rf dist
maturin sdist --out dist -m ome-metadata/Cargo.toml
rustup target add x86_64-unknown-linux-gnu
maturin build --release --out dist --target x86_64-unknown-linux-gnu --zig --auditwheel repair -m ome-metadata/Cargo.toml
rustup target add aarch64-unknown-linux-gnu
maturin build --release --out dist --target aarch64-unknown-linux-gnu --zig --auditwheel repair -m ome-metadata/Cargo.toml
rustup target add x86_64-unknown-linux-musl
maturin build --release --out dist --target x86_64-unknown-linux-musl --zig --auditwheel repair -m ome-metadata/Cargo.toml
rustup target add aarch64-unknown-linux-musl
maturin build --release --out dist --target aarch64-unknown-linux-musl --zig --auditwheel repair -m ome-metadata/Cargo.toml
rustup target add x86_64-pc-windows-msvc
maturin build --release --out dist --target x86_64-pc-windows-msvc --auditwheel repair -m ome-metadata/Cargo.toml
rustup target add aarch64-pc-windows-msvc
maturin build --release --out dist --target aarch64-pc-windows-msvc --auditwheel repair -m ome-metadata/Cargo.toml
# Use osxcross, not Zig, for macOS SDK linking.
shopt -s nullglob
sdks=("$HOME"/.osxcross/SDK/MacOSX*.sdk)
if [ "${#sdks[@]}" -ne 1 ] || [ ! -d "${sdks[0]}" ]; then
echo "Expected exactly one macOS SDK under $HOME/.osxcross/SDK" >&2
exit 1
fi
export SDKROOT="$(realpath "${sdks[0]}")"
echo "Using SDKROOT=$SDKROOT"
find_osxcross_tool() {
local arch="$1" tool="$2" candidate
local matches=()
for candidate in "$HOME"/.osxcross/bin/"$arch"-apple-darwin*-"$tool"; do
if [ -x "$candidate" ]; then
matches+=("$candidate")
fi
done
if [ "${#matches[@]}" -ne 1 ]; then
echo "Expected exactly one osxcross $tool for $arch; found ${#matches[@]}" >&2
return 1
fi
printf '%s\n' "${matches[0]}"
}
CARGO_TARGET_X86_64_APPLE_DARWIN_LINKER="$(find_osxcross_tool x86_64 clang)"
export CC_x86_64_apple_darwin="$CARGO_TARGET_X86_64_APPLE_DARWIN_LINKER"
CXX_x86_64_apple_darwin="$(find_osxcross_tool x86_64 clang++)"
# osxcross distributions may call the ARM64 architecture arm64 or aarch64.
arm_arch=arm64
arm_compilers=("$HOME"/.osxcross/bin/arm64-apple-darwin*-clang)
if [ "${#arm_compilers[@]}" -eq 0 ]; then
arm_arch=aarch64
fi
CARGO_TARGET_AARCH64_APPLE_DARWIN_LINKER="$(find_osxcross_tool "$arm_arch" clang)"
export CC_aarch64_apple_darwin="$CARGO_TARGET_AARCH64_APPLE_DARWIN_LINKER"
CXX_aarch64_apple_darwin="$(find_osxcross_tool "$arm_arch" clang++)"
export CARGO_TARGET_X86_64_APPLE_DARWIN_LINKER CXX_x86_64_apple_darwin
export CARGO_TARGET_AARCH64_APPLE_DARWIN_LINKER CXX_aarch64_apple_darwin
"$CC_x86_64_apple_darwin" --version
"$CC_aarch64_apple_darwin" --version
rustup target add x86_64-apple-darwin
MACOSX_DEPLOYMENT_TARGET=10.13 maturin build --release --out dist --target x86_64-apple-darwin --auditwheel repair -m ome-metadata/Cargo.toml
rustup target add aarch64-apple-darwin
MACOSX_DEPLOYMENT_TARGET=11.0 maturin build --release --out dist --target aarch64-apple-darwin --auditwheel repair -m ome-metadata/Cargo.toml
- name: Store cache
uses: actions/cache/save@v4
with:
path: |
~/.cache/pip
~/.cache/pip-wheel
~/.cache/sccache
~/.cache/cargo-xwin
${{ env.CARGO_HOME }}
~/.osxcross
key: cache-ubuntu-maturin-cross-compile
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
env:
GITHUB_WORKFLOW_REF: 1.10.1