From d8ebf7efed11254f86eec5bf4f99b9e116a1b3e3 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Thu, 25 Dec 2025 19:53:17 +0100 Subject: [PATCH 1/2] Fix CI and build wheels for more platforms --- .github/workflows/ci-sage-debian.yml | 91 --------------------------- .github/workflows/ci-sage-linux.yml | 89 -------------------------- .github/workflows/ci-sage-macos.yml | 93 ---------------------------- .github/workflows/dist.yml | 80 ++++++++++++++++++++++++ .github/workflows/wheels.yml | 45 -------------- 5 files changed, 80 insertions(+), 318 deletions(-) delete mode 100644 .github/workflows/ci-sage-debian.yml delete mode 100644 .github/workflows/ci-sage-linux.yml delete mode 100644 .github/workflows/ci-sage-macos.yml create mode 100644 .github/workflows/dist.yml delete mode 100644 .github/workflows/wheels.yml diff --git a/.github/workflows/ci-sage-debian.yml b/.github/workflows/ci-sage-debian.yml deleted file mode 100644 index b5e24f9..0000000 --- a/.github/workflows/ci-sage-debian.yml +++ /dev/null @@ -1,91 +0,0 @@ -name: Run Sage CI for Debian stable - -## This GitHub Actions workflow provides: -## -## - portability testing, by building and testing this project on many platforms -## (Linux variants and Cygwin), each with two configurations (installed packages), -## -## - continuous integration, by building and testing other software -## that depends on this project. -## -## It runs on every pull request and push of a tag to the GitHub repository. -## -## The testing can be monitored in the "Actions" tab of the GitHub repository. -## -## After all jobs have finished (or are canceled) and a short delay, -## tar files of all logs are made available as "build artifacts". -## -## This GitHub Actions workflow uses the portability testing framework -## of SageMath (https://www.sagemath.org/). For more information, see -## https://doc.sagemath.org/html/en/developer/portability_testing.html - -## The workflow consists of two jobs: -## -## - First, it builds a source distribution of the project -## and generates a script "update-pkgs.sh". It uploads them -## as a build artifact named upstream. -## -## - Second, it checks out a copy of the SageMath source tree. -## It downloads the upstream artifact and replaces the project's -## package in the SageMath distribution by the newly packaged one -## from the upstream artifact, by running the script "update-pkgs.sh". -## Then it builds a small portion of the Sage distribution. -## -## Many copies of the second step are run in parallel for each of the tested -## systems/configurations. - -on: - # push: - pull_request: - workflow_dispatch: - # Allow to run manually - -env: - # Ubuntu packages to install so that the project's "setup.py sdist" can succeed - DIST_PREREQ: python3-setuptools autoconf - # Name of this project in the Sage distribution - SPKG: primecountpy - # Remove all downstream patches - REMOVE_PATCHES: "*" - -jobs: - - dist: - runs-on: ubuntu-latest - steps: - - name: Check out ${{ env.SPKG }} - uses: actions/checkout@v2 - with: - path: build/pkgs/${{ env.SPKG }}/src - - name: Install prerequisites - run: | - sudo DEBIAN_FRONTEND=noninteractive apt-get update - sudo DEBIAN_FRONTEND=noninteractive apt-get install $DIST_PREREQ - - name: Run make dist, prepare upstream artifact - run: | - (cd build/pkgs/${{ env.SPKG }}/src && python3 setup.py sdist) \ - && mkdir -p upstream && cp build/pkgs/${{ env.SPKG }}/src/dist/*.tar.gz upstream/${{ env.SPKG }}-git.tar.gz \ - && echo "sage-package create ${{ env.SPKG }} --version git --tarball ${{ env.SPKG }}-git.tar.gz --type=standard" > upstream/update-pkgs.sh \ - && if [ -n "${{ env.REMOVE_PATCHES }}" ]; then echo "(cd ../build/pkgs/${{ env.SPKG }}/patches && rm -f ${{ env.REMOVE_PATCHES }}; :)" >> upstream/update-pkgs.sh; fi \ - && ls -l upstream/ - - uses: actions/upload-artifact@v4 - with: - path: upstream - name: upstream - - docker: - uses: sagemath/sage/.github/workflows/docker.yml@develop - with: - tox_system_factors: >- - ["debian-bullseye"] - tox_packages_factors: >- - ["standard"] - # Sage distribution packages to build - targets: SAGE_CHECK=no SAGE_CHECK_PACKAGES=primecount,primecountpy primecount primecountpy - # Standard setting: Test the current beta release of Sage. - sage_repo: sagemath/sage - sage_ref: develop - # To test with a Sage PR, use this: - #sage_ref: refs/pull/PR_NUMBER/merge - upstream_artifact: upstream - needs: [dist] diff --git a/.github/workflows/ci-sage-linux.yml b/.github/workflows/ci-sage-linux.yml deleted file mode 100644 index af4538e..0000000 --- a/.github/workflows/ci-sage-linux.yml +++ /dev/null @@ -1,89 +0,0 @@ -name: Run Sage CI for Linux - -## This GitHub Actions workflow provides: -## -## - portability testing, by building and testing this project on many platforms -## (Linux variants and Cygwin), each with two configurations (installed packages), -## -## - continuous integration, by building and testing other software -## that depends on this project. -## -## It runs on every pull request and push of a tag to the GitHub repository. -## -## The testing can be monitored in the "Actions" tab of the GitHub repository. -## -## After all jobs have finished (or are canceled) and a short delay, -## tar files of all logs are made available as "build artifacts". -## -## This GitHub Actions workflow uses the portability testing framework -## of SageMath (https://www.sagemath.org/). For more information, see -## https://doc.sagemath.org/html/en/developer/portability_testing.html - -## The workflow consists of two jobs: -## -## - First, it builds a source distribution of the project -## and generates a script "update-pkgs.sh". It uploads them -## as a build artifact named upstream. -## -## - Second, it checks out a copy of the SageMath source tree. -## It downloads the upstream artifact and replaces the project's -## package in the SageMath distribution by the newly packaged one -## from the upstream artifact, by running the script "update-pkgs.sh". -## Then it builds a small portion of the Sage distribution. -## -## Many copies of the second step are run in parallel for each of the tested -## systems/configurations. - -on: -# push: - pull_request: - workflow_dispatch: - # Allow to run manually - -env: - # Ubuntu packages to install so that the project's "setup.py sdist" can succeed - DIST_PREREQ: python3-setuptools autoconf - # Name of this project in the Sage distribution - SPKG: primecountpy - # Remove all downstream patches - REMOVE_PATCHES: "*" - -jobs: - - dist: - runs-on: ubuntu-latest - steps: - - name: Check out ${{ env.SPKG }} - uses: actions/checkout@v2 - with: - path: build/pkgs/${{ env.SPKG }}/src - - name: Install prerequisites - run: | - sudo DEBIAN_FRONTEND=noninteractive apt-get update - sudo DEBIAN_FRONTEND=noninteractive apt-get install $DIST_PREREQ - - name: Run make dist, prepare upstream artifact - run: | - (cd build/pkgs/${{ env.SPKG }}/src && python3 setup.py sdist) \ - && mkdir -p upstream && cp build/pkgs/${{ env.SPKG }}/src/dist/*.tar.gz upstream/${{ env.SPKG }}-git.tar.gz \ - && echo "sage-package create ${{ env.SPKG }} --version git --tarball ${{ env.SPKG }}-git.tar.gz --type=standard" > upstream/update-pkgs.sh \ - && if [ -n "${{ env.REMOVE_PATCHES }}" ]; then echo "(cd ../build/pkgs/${{ env.SPKG }}/patches && rm -f ${{ env.REMOVE_PATCHES }}; :)" >> upstream/update-pkgs.sh; fi \ - && ls -l upstream/ - - uses: actions/upload-artifact@v4 - with: - path: upstream - name: upstream - - docker: - uses: sagemath/sage/.github/workflows/docker.yml@develop - with: - tox_packages_factors: >- - ["standard"] - # Sage distribution packages to build - targets: SAGE_CHECK=no SAGE_CHECK_PACKAGES=primecount,primecountpy primecount primecountpy - # Standard setting: Test the current beta release of Sage. - sage_repo: sagemath/sage - sage_ref: develop - # To test with a Sage PR, use this: - #sage_ref: refs/pull/PR_NUMBER/merge - upstream_artifact: upstream - needs: [dist] diff --git a/.github/workflows/ci-sage-macos.yml b/.github/workflows/ci-sage-macos.yml deleted file mode 100644 index 23eaa08..0000000 --- a/.github/workflows/ci-sage-macos.yml +++ /dev/null @@ -1,93 +0,0 @@ -name: Run Sage CI for macOS - -## This GitHub Actions workflow provides: -## -## - portability testing, by building and testing this project on many platforms -## (Linux variants and Cygwin), each with two configurations (installed packages), -## -## - continuous integration, by building and testing other software -## that depends on this project. -## -## It runs on every pull request and push of a tag to the GitHub repository. -## -## The testing can be monitored in the "Actions" tab of the GitHub repository. -## -## After all jobs have finished (or are canceled) and a short delay, -## tar files of all logs are made available as "build artifacts". -## -## This GitHub Actions workflow uses the portability testing framework -## of SageMath (https://www.sagemath.org/). For more information, see -## https://doc.sagemath.org/html/en/developer/portability_testing.html - -## The workflow consists of two jobs: -## -## - First, it builds a source distribution of the project -## and generates a script "update-pkgs.sh". It uploads them -## as a build artifact named upstream. -## -## - Second, it checks out a copy of the SageMath source tree. -## It downloads the upstream artifact and replaces the project's -## package in the SageMath distribution by the newly packaged one -## from the upstream artifact, by running the script "update-pkgs.sh". -## Then it builds a small portion of the Sage distribution. -## -## Many copies of the second step are run in parallel for each of the tested -## systems/configurations. - -on: -# push: - pull_request: - workflow_dispatch: - # Allow to run manually - -env: - # Ubuntu packages to install so that the project's "setup.py sdist" can succeed - DIST_PREREQ: python3-setuptools autoconf - # Name of this project in the Sage distribution - SPKG: primecountpy - # Sage distribution packages to build - TARGETS_PRE: build/make/Makefile - TARGETS: SAGE_CHECK=no SAGE_CHECK_PACKAGES=primecount,primecountpy primecount primecountpy - TARGETS_OPTIONAL: build/make/Makefile - # Standard setting: Test the current beta release of Sage: - SAGE_REPO: sagemath/sage - SAGE_REF: develop - REMOVE_PATCHES: "*" - -jobs: - - dist: - runs-on: ubuntu-latest - steps: - - name: Check out ${{ env.SPKG }} - uses: actions/checkout@v4 - with: - path: build/pkgs/${{ env.SPKG }}/src - - name: Install prerequisites - run: | - sudo DEBIAN_FRONTEND=noninteractive apt-get update - sudo DEBIAN_FRONTEND=noninteractive apt-get install $DIST_PREREQ - - name: Run make dist, prepare upstream artifact - run: | - (cd build/pkgs/${{ env.SPKG }}/src && python3 setup.py sdist) \ - && mkdir -p upstream && cp build/pkgs/${{ env.SPKG }}/src/dist/*.tar.gz upstream/${{ env.SPKG }}-git.tar.gz \ - && echo "sage-package create ${{ env.SPKG }} --version git --tarball ${{ env.SPKG }}-git.tar.gz --type=standard" > upstream/update-pkgs.sh \ - && if [ -n "${{ env.REMOVE_PATCHES }}" ]; then echo "(cd ../build/pkgs/${{ env.SPKG }}/patches && rm -f ${{ env.REMOVE_PATCHES }}; :)" >> upstream/update-pkgs.sh; fi \ - && ls -l upstream/ - - uses: actions/upload-artifact@v2 - with: - path: upstream - name: upstream - - macos: - uses: sagemath/sage/.github/workflows/macos.yml@develop - with: - osversion_xcodeversion_toxenv_tuples: >- - [["latest", "", "homebrew-macos-usrlocal-standard"], - ["latest", "", "conda-forge-macos-standard"]] - # FIXME: duplicated from env.TARGETS - targets: SAGE_CHECK=no SAGE_CHECK_PACKAGES=primecount,primecountpy primecount primecountpy - sage_repo: sagemath/sage - sage_ref: develop - upstream_artifact: upstream - needs: [dist] diff --git a/.github/workflows/dist.yml b/.github/workflows/dist.yml new file mode 100644 index 0000000..29f9f0b --- /dev/null +++ b/.github/workflows/dist.yml @@ -0,0 +1,80 @@ +name: Distributions + +on: + push: + pull_request: + workflow_dispatch: + +concurrency: + # Cancel previous runs of this workflow for the same branch + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + make_sdist: + name: Build sdist + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - uses: astral-sh/setup-uv@v7 + - name: Build sdist + run: uv build --sdist + - uses: actions/upload-artifact@v4 + with: + path: "dist/*.tar.*" + name: release-sdist + + build_wheels: + name: Build wheels on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-latest + - ubuntu-24.04-arm + - windows-latest + - windows-11-arm + - macos-15-intel + - macos-latest + steps: + - uses: actions/checkout@v6 + - uses: astral-sh/setup-uv@v7 + - name: Build wheels + uses: pypa/cibuildwheel@v3.3 + - uses: actions/upload-artifact@v5 + with: + name: release-wheels-${{ matrix.os }} + path: wheelhouse/*.whl + + pypi-publish: + # This needs to be a separate job because pypa/gh-action-pypi-publish cannot run on macOS + # https://github.com/pypa/gh-action-pypi-publish + name: Upload wheels to PyPI + needs: [build_wheels, make_sdist] + runs-on: ubuntu-latest + permissions: + id-token: write + attestations: write + contents: read + steps: + - uses: actions/download-artifact@v6 + with: + pattern: release-* + path: dist + merge-multiple: true + + - name: List files + run: ls -l -R dist + + - name: Generate artifact attestations + uses: actions/attest-build-provenance@v3 + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') + with: + subject-path: "dist/*" + + - name: Publish package distributions to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + verbose: true + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml deleted file mode 100644 index 64ebaf3..0000000 --- a/.github/workflows/wheels.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: Build wheels - -on: - push: - pull_request: - workflow_dispatch: - -jobs: - build_wheels: - name: Build wheels on ${{ matrix.os }} - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, macOS-latest, macos-13] - - steps: - - uses: actions/checkout@v4 - - - name: Build wheels - uses: pypa/cibuildwheel@v2.23.3 - env: - CIBW_BEFORE_ALL: > - cd /tmp/ && - git clone https://github.com/kimwalisch/primecount && - cd primecount && - export CXXFLAGS="-fPIC" && - export LDFLAGS="-fPIC" - - CIBW_BEFORE_BUILD_LINUX: > - cd /tmp/primecount && - cmake . -DWITH_OPENMP=OFF -DCMAKE_VERBOSE_MAKEFILE=TRUE -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=OFF && - make && make install - - CIBW_BEFORE_BUILD_MACOS: > - cd /tmp/primecount && - cmake . -DWITH_OPENMP=OFF -DCMAKE_VERBOSE_MAKEFILE=TRUE -DBUILD_SHARED_LIBS=OFF -DBUILD_STATIC_LIBS=ON && - make && sudo make install - - CIBW_SKIP: pp* - - - uses: actions/upload-artifact@v4 - with: - name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }} - path: ./wheelhouse/*.whl From d4643a954818d4a854f889bdf9d148525276b90b Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Thu, 25 Dec 2025 20:25:48 +0100 Subject: [PATCH 2/2] Compile primecount with `PIC=ON` --- meson.build | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 375ed76..1063278 100644 --- a/meson.build +++ b/meson.build @@ -9,10 +9,17 @@ py_module = import('python') py = py_module.find_installation(pure: false) py_dep = py.dependency() +# CMake subprojects +cmake = import('cmake') + # Compilers cxx = meson.get_compiler('cpp') -primecount_dep = dependency('primecount', required: true) +# Build bundled primecount with PIC so it can link into the Python extension. +primecount_opts = cmake.subproject_options() +primecount_opts.add_cmake_defines({'CMAKE_POSITION_INDEPENDENT_CODE': 'ON'}) +primecount_proj = cmake.subproject('primecount', options: primecount_opts) +primecount_dep = primecount_proj.dependency('libprimecount-static') inc_cysignals = run_command( py, [