readcon-core 0.14.6

An oxidized single and multiple CON file reader and writer with FFI bindings for ergonomic C/C++ usage.
Documentation
name: Python wheels

on:
  push:
    tags:
      - 'v*'
  pull_request:
    paths:
      - 'src/**'
      - 'Cargo.toml'
      - 'Cargo.lock'
      - 'pyproject.toml'
      - 'pyproject.chemfiles.toml'
      - '.github/workflows/python_wheels.yml'
  workflow_dispatch:

concurrency:
  group: python-wheels-${{ github.ref }}
  cancel-in-progress: ${{ !startsWith(github.ref, 'refs/tags/') }}

permissions:
  contents: read

env:
  CARGO_HTTP_MULTIPLEXING: "false"
  CARGO_NET_RETRY: "10"
  CARGO_HTTP_TIMEOUT: "120"
  CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER: "cc"

jobs:
  # Lean `readcon` + chemfiles-linked `readcon-chemfiles` (separate PyPI names,
  # same extension module `readcon`). Matrix is the usual dual-distribution pattern.
  sdist:
    name: Build sdist (${{ matrix.variant }})
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        include:
          - variant: default
            pyproject: pyproject.toml
          - variant: chemfiles
            pyproject: pyproject.chemfiles.toml
    steps:
      - uses: actions/checkout@v6

      - name: Select pyproject for variant
        shell: bash
        run: |
          if [ "${{ matrix.pyproject }}" != "pyproject.toml" ]; then
            cp "${{ matrix.pyproject }}" pyproject.toml
          fi
          head -15 pyproject.toml

      - name: Build sdist
        uses: PyO3/maturin-action@v1
        with:
          command: sdist
          args: --out dist

      - name: Validate sdist
        run: pipx run twine check --strict dist/*

      - uses: actions/upload-artifact@v4
        with:
          name: sdist-${{ matrix.variant }}
          path: dist/*.tar.gz
          if-no-files-found: error

  wheels:
    name: Wheel ${{ matrix.variant }} (${{ matrix.os }}, ${{ matrix.target }})
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      # Explicit rows only (no axis × include cartesian product).
      matrix:
        include:
          # Native-arch runners only (featomic / metatomic build-wheels.yml).
          # Do not cross-compile macOS x86_64 on Apple silicon.
          - variant: default
            os: ubuntu-24.04
            target: x86_64
            pyproject: pyproject.toml
            features: python
          - variant: default
            os: ubuntu-24.04-arm
            target: aarch64
            pyproject: pyproject.toml
            features: python
          - variant: default
            os: macos-15-intel
            target: x86_64
            pyproject: pyproject.toml
            features: python
          - variant: default
            os: macos-15
            target: aarch64
            pyproject: pyproject.toml
            features: python
          - variant: default
            os: windows-2022
            target: x86_64
            pyproject: pyproject.toml
            features: python
          - variant: chemfiles
            os: ubuntu-24.04
            target: x86_64
            pyproject: pyproject.chemfiles.toml
            features: python,chemfiles-from-sources
          - variant: chemfiles
            os: ubuntu-24.04-arm
            target: aarch64
            pyproject: pyproject.chemfiles.toml
            features: python,chemfiles-from-sources
          - variant: chemfiles
            os: macos-15-intel
            target: x86_64
            pyproject: pyproject.chemfiles.toml
            features: python,chemfiles
          - variant: chemfiles
            os: macos-15
            target: aarch64
            pyproject: pyproject.chemfiles.toml
            features: python,chemfiles
          # Official prebuilt libchemfiles for x86_64-pc-windows-msvc.
          # Do not use chemfiles-from-sources here (vendored zlib/CMake).
          - variant: chemfiles
            os: windows-2022
            target: x86_64
            pyproject: pyproject.chemfiles.toml
            features: python,chemfiles
    steps:
      - uses: actions/checkout@v6

      # BFD is the stable manylinux linker. Apple clang rejects -fuse-ld=bfd.
      - name: Linux BFD linker
        if: runner.os == 'Linux'
        run: echo "RUSTFLAGS=-C link-arg=-fuse-ld=bfd" >> "$GITHUB_ENV"

      # chemfiles-sys 0.10.41 builds vendored zlib. cmake-rs 0.1.58 ignores
      # CMAKE_ARGS, so CHFL_SYSTEM_ZLIB never reached CMake. Old zconf.h does
      # `#define fdopen ...` unless HAVE_UNISTD_H; that breaks the MacOSX SDK
      # stdio.h. CFLAGS is forwarded by cmake-rs via the cc crate.
      - name: macOS chemfiles zlib vs SDK
        if: runner.os == 'macOS' && matrix.variant == 'chemfiles'
        run: |
          echo "CFLAGS=-DHAVE_UNISTD_H -DHAVE_FDOPEN" >> "$GITHUB_ENV"
          echo "CXXFLAGS=-DHAVE_UNISTD_H -DHAVE_FDOPEN" >> "$GITHUB_ENV"

      - uses: actions/setup-python@v5
        with:
          python-version: '3.12'

      - name: Select pyproject for variant
        shell: bash
        run: |
          if [ "${{ matrix.pyproject }}" != "pyproject.toml" ]; then
            cp "${{ matrix.pyproject }}" pyproject.toml
          fi
          echo "Building features=${{ matrix.features }} from:"
          head -20 pyproject.toml

      - name: Build wheels
        id: build1
        continue-on-error: true
        env:
          RUSTFLAGS: ${{ runner.os == 'Linux' && '-C link-arg=-fuse-ld=bfd' || '' }}
          CFLAGS: ${{ (runner.os == 'macOS' && matrix.variant == 'chemfiles') && '-DHAVE_UNISTD_H -DHAVE_FDOPEN' || '' }}
          CXXFLAGS: ${{ (runner.os == 'macOS' && matrix.variant == 'chemfiles') && '-DHAVE_UNISTD_H -DHAVE_FDOPEN' || '' }}
        uses: PyO3/maturin-action@v1
        with:
          target: ${{ matrix.target }}
          args: --release --out dist --features ${{ matrix.features }} --find-interpreter
          manylinux: auto
          docker-options: >-
            -e CARGO_HTTP_MULTIPLEXING=false
            -e CARGO_NET_RETRY=10
            -e CARGO_HTTP_TIMEOUT=120
            -e CMAKE_POLICY_VERSION_MINIMUM=3.5

      - name: Build wheels (retry)
        if: steps.build1.outcome == 'failure'
        env:
          RUSTFLAGS: ${{ runner.os == 'Linux' && '-C link-arg=-fuse-ld=bfd' || '' }}
          CFLAGS: ${{ (runner.os == 'macOS' && matrix.variant == 'chemfiles') && '-DHAVE_UNISTD_H -DHAVE_FDOPEN' || '' }}
          CXXFLAGS: ${{ (runner.os == 'macOS' && matrix.variant == 'chemfiles') && '-DHAVE_UNISTD_H -DHAVE_FDOPEN' || '' }}
        uses: PyO3/maturin-action@v1
        with:
          target: ${{ matrix.target }}
          args: --release --out dist --features ${{ matrix.features }} --find-interpreter
          manylinux: auto
          docker-options: >-
            -e CARGO_HTTP_MULTIPLEXING=false
            -e CARGO_NET_RETRY=10
            -e CARGO_HTTP_TIMEOUT=120
            -e CMAKE_POLICY_VERSION_MINIMUM=3.5

      - name: Validate wheels
        if: matrix.target != 'aarch64' || runner.os != 'Linux'
        run: pipx run twine check --strict dist/*

      - uses: actions/upload-artifact@v4
        with:
          name: wheels-${{ matrix.variant }}-${{ matrix.os }}-${{ matrix.target }}
          path: dist/*.whl
          if-no-files-found: error

  # Same shape as metatomic/featomic merge-and-release: attach whatever
  # built to the GitHub Release, then (separately) try PyPI OIDC.
  github-release:
    name: Attach wheels to GitHub Release
    needs: [sdist, wheels]
    if: ${{ always() && startsWith(github.ref, 'refs/tags/v') && needs.sdist.result == 'success' }}
    runs-on: ubuntu-24.04
    permissions:
      contents: write
    steps:
      - uses: actions/download-artifact@v4
        with:
          pattern: '{sdist-*,wheels-*}'
          merge-multiple: true
          path: dist/
      - name: Upload to GitHub Release
        uses: softprops/action-gh-release@v2
        with:
          files: dist/*
          fail_on_unmatched_files: false

  publish:
    name: Publish to PyPI
    needs: [sdist, wheels]
    runs-on: ubuntu-latest
    if: ${{ always() && startsWith(github.ref, 'refs/tags/v') && needs.sdist.result == 'success' }}
    environment:
      name: pypi
      url: https://pypi.org/p/readcon
    permissions:
      id-token: write
    steps:
      - uses: actions/download-artifact@v4
        with:
          pattern: '{sdist-*,wheels-*}'
          merge-multiple: true
          path: dist/

      - name: List artifacts
        run: |
          ls -la dist/
          echo "--- expected packages: readcon (lean) and readcon-chemfiles (full) ---"
          ls dist/*.whl dist/*.tar.gz | sed 's|.*/||' | sort -u

      # Trusted publishers must be configured on PyPI for *both* project names
      # `readcon` and `readcon-chemfiles` (same workflow + environment `pypi`).
      - name: Publish to PyPI
        uses: pypa/gh-action-pypi-publish@release/v1
        with:
          skip-existing: true