diff --git a/.github/workflows/build_wheel.yml b/.github/workflows/build_wheel.yml index bc4f6683..d27abd6a 100644 --- a/.github/workflows/build_wheel.yml +++ b/.github/workflows/build_wheel.yml @@ -19,13 +19,51 @@ jobs: matrix: os: [ubuntu-latest, macos-latest, windows-latest] + env: + # Job level so that the build and the statistics step talk to the same + # sccache server configured for the GitHub Actions cache + SCCACHE_GHA_ENABLED: "true" + steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v7 + - uses: mozilla-actions/sccache-action@v0.0.11 + with: + version: "v0.18.0" + + # Without an MSVC environment scikit-build-core falls back to the Visual + # Studio generator on Windows, and MSBuild ignores the compiler launcher + - uses: TheMrMilchmann/setup-msvc-dev@v4.1.0 + if: runner.os == 'Windows' + with: + arch: x64 + + # Linux wheels build inside a manylinux container, which needs its own + # sccache binary and the cache credentials the action exported; its + # statistics are printed after each wheel since the host cannot see them. - name: Build wheels - run: pipx run cibuildwheel==3.4.0 + env: + CIBW_ENVIRONMENT_WINDOWS: CMAKE_GENERATOR=Ninja + CIBW_REPAIR_WHEEL_COMMAND_LINUX: >- + auditwheel repair -w {dest_dir} {wheel} && sccache --show-stats + CIBW_CONFIG_SETTINGS: >- + cmake.define.CMAKE_C_COMPILER_LAUNCHER=sccache + cmake.define.CMAKE_CXX_COMPILER_LAUNCHER=sccache + cmake.define.CMAKE_DISABLE_PRECOMPILE_HEADERS=ON + CIBW_ENVIRONMENT_PASS_LINUX: >- + SCCACHE_GHA_ENABLED ACTIONS_RESULTS_URL ACTIONS_RUNTIME_TOKEN + ACTIONS_CACHE_SERVICE_V2 + CIBW_BEFORE_ALL_LINUX: >- + curl -sSL https://github.com/mozilla/sccache/releases/download/v0.18.0/sccache-v0.18.0-x86_64-unknown-linux-musl.tar.gz + | tar -xz -C /usr/local/bin --strip-components=1 --wildcards '*/sccache' + && chmod +x /usr/local/bin/sccache + run: pipx run cibuildwheel==4.3.0 - - uses: actions/upload-artifact@v4 + - name: Compiler cache statistics + if: runner.os != 'Linux' + run: sccache --show-stats + + - uses: actions/upload-artifact@v7 with: name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }} path: ./wheelhouse/*.whl @@ -34,12 +72,12 @@ jobs: name: Build source distribution runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v7 - name: Build sdist run: pipx run build --sdist - - uses: actions/upload-artifact@v4 + - uses: actions/upload-artifact@v7 with: name: cibw-sdist path: dist/*.tar.gz @@ -54,7 +92,7 @@ jobs: # or, alternatively, upload to PyPI on every tag starting with 'v' (remove on: release above to use this) # if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') steps: - - uses: actions/download-artifact@v4 + - uses: actions/download-artifact@v8 with: # unpacks all CIBW artifacts into dist/ pattern: cibw-* diff --git a/.github/workflows/build_windows.yml b/.github/workflows/build_windows.yml index 5078cf5e..1a562f39 100644 --- a/.github/workflows/build_windows.yml +++ b/.github/workflows/build_windows.yml @@ -9,25 +9,42 @@ jobs: build: runs-on: windows-latest + env: + # sccache keeps compiled objects in the GitHub Actions cache, so later + # runs only recompile the translation units a change affects + SCCACHE_GHA_ENABLED: "true" + steps: - uses: actions/checkout@v6 - - uses: actions/setup-python@v5 + - uses: actions/setup-python@v7 with: python-version: "3.12" - name: Install Python dependencies run: python -m pip install ninja numpy matplotlib pytest pytest-check boost-histogram - # Puts cl.exe on the path so that CMake can use the Ninja generator - - uses: ilammy/msvc-dev-cmd@v1 + # Puts cl.exe on the path so that CMake can use the Ninja generator. + # Pinned to a release tag: the v4 ref of this action is a branch. + - uses: TheMrMilchmann/setup-msvc-dev@v4.1.0 + with: + arch: x64 + - uses: mozilla-actions/sccache-action@v0.0.11 + with: + version: "v0.18.0" + + # Precompiled headers are disabled: sccache cannot cache MSVC + # compilations that use one - name: Configure - run: cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DAARE_TESTS=ON -DAARE_PYTHON_BINDINGS=ON -DAARE_WARNINGS_AS_ERRORS=ON + run: cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DAARE_TESTS=ON -DAARE_PYTHON_BINDINGS=ON -DAARE_WARNINGS_AS_ERRORS=ON -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache -DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON - name: Build run: cmake --build build + - name: Compiler cache statistics + run: sccache --show-stats + - name: C++ unit tests run: ctest --test-dir build --output-on-failure -j4 diff --git a/.github/workflows/build_with_docs.yml b/.github/workflows/build_with_docs.yml index bbae4f9b..9e2dc872 100644 --- a/.github/workflows/build_with_docs.yml +++ b/.github/workflows/build_with_docs.yml @@ -27,15 +27,19 @@ jobs: runs-on: ${{ matrix.platform }} + env: + # sccache keeps compiled objects in the GitHub Actions cache + SCCACHE_GHA_ENABLED: "true" + defaults: run: shell: "bash -l {0}" steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v7 - name: Get conda - uses: conda-incubator/setup-miniconda@v3 + uses: conda-incubator/setup-miniconda@v4 with: python-version: ${{ matrix.python-version }} environment-file: etc/dev-env.yml @@ -43,14 +47,23 @@ jobs: channels: conda-forge conda-remove-defaults: "true" + - uses: mozilla-actions/sccache-action@v0.0.11 + with: + version: "v0.18.0" + + # Precompiled headers are disabled because sccache does not cache + # compilations that use one - name: Build library and docs run: | mkdir build cd build - cmake .. -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DAARE_SYSTEM_LIBRARIES=ON -DAARE_PYTHON_BINDINGS=ON -DAARE_DOCS=ON -DAARE_TESTS=ON -DAARE_WARNINGS_AS_ERRORS=ON + cmake .. -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DAARE_SYSTEM_LIBRARIES=ON -DAARE_PYTHON_BINDINGS=ON -DAARE_DOCS=ON -DAARE_TESTS=ON -DAARE_WARNINGS_AS_ERRORS=ON -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache -DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON make -j 4 make docs + - name: Compiler cache statistics + run: sccache --show-stats + - name: C++ unit tests working-directory: ${{github.workspace}}/build run: ctest -C ${{env.BUILD_TYPE}} -j4 @@ -63,7 +76,7 @@ jobs: - name: Upload static files as artifact if: matrix.platform == 'ubuntu-latest' id: deployment - uses: actions/upload-pages-artifact@v3 + uses: actions/upload-pages-artifact@v5 with: path: build/docs/html/ deploy: @@ -76,7 +89,7 @@ jobs: steps: - name: Deploy to GitHub Pages id: deployment - uses: actions/deploy-pages@v4 + uses: actions/deploy-pages@v5 diff --git a/conda-recipe/meta.yaml b/conda-recipe/meta.yaml index d2d39b53..2e2264af 100644 --- a/conda-recipe/meta.yaml +++ b/conda-recipe/meta.yaml @@ -26,7 +26,7 @@ requirements: - python - pip - numpy >=2.1 - - scikit-build-core >=0.11 + - scikit-build-core >=1.0 - pybind11 >=3.0.3 - matplotlib # needed in host to solve the environment for run diff --git a/pyproject.toml b/pyproject.toml index 16636a01..e1176dcd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,11 +1,12 @@ -[tool.scikit-build.metadata.version] +[[tool.dynamic-metadata]] +field = "version" provider = "scikit_build_core.metadata.regex" input = "VERSION" regex = '^(?P\d+(?:\.\d+)*(?:[\.\+\w]+)?)$' -result = "{version}" +result = "{version}" [build-system] -requires = ["scikit-build-core>=0.11", "pybind11", "numpy"] +requires = ["scikit-build-core>=1.0", "pybind11", "numpy"] build-backend = "scikit_build_core.build" [project] @@ -34,6 +35,9 @@ build = "cp{312,313,314}-win_amd64" [tool.scikit-build] build.verbose = true +# A fixed build directory keeps the absolute paths of the compiled sources +# stable between runs, which sccache needs for a cache hit +build-dir = "build/{wheel_tag}" cmake.build-type = "Release" install.components = ["python"]