Skip to content

Commit debefd5

Browse files
authored
perf: stable and extensible build with cbw (#138)
- change scikit-build-core cmake settings to define for extensibility - add cache steps in CI - ignore pypy build Signed-off-by: l.feng <43399351+msclock@users.noreply.github.com>
1 parent d00ed05 commit debefd5

4 files changed

Lines changed: 57 additions & 27 deletions

File tree

.github/workflows/reuseable_cibuildwheel.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ on:
1414

1515
jobs:
1616
build_wheels:
17-
name: On ${{ matrix.os }}, with ${{ matrix.arch }}, build ${{ matrix.build }} wheels
17+
name: ${{ matrix.os }}, ${{ matrix.arch }}, ${{ matrix.build }} wheels
1818
runs-on: ${{ matrix.os }}
1919

2020
strategy:
@@ -48,6 +48,15 @@ jobs:
4848
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
4949
if: runner.os == 'Linux' && inputs.extra && contains(matrix.qemu_arch, matrix.arch)
5050

51+
- name: Cache
52+
uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4
53+
with:
54+
path: |
55+
~/.cache/vcpkg
56+
~/AppData/Local/vcpkg
57+
key: cache-${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.build }}-${{ hashFiles('vcpkg.json') }}
58+
restore-keys: cache-${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.build }}-${{ hashFiles('vcpkg.json') }}
59+
5160
- name: Build wheels
5261
if: >
5362
inputs.auto && !contains(matrix.qemu_arch, matrix.arch) ||
@@ -56,6 +65,11 @@ jobs:
5665
env:
5766
CIBW_ARCHS: ${{ matrix.arch }}
5867
CIBW_BUILD: '*${{ matrix.build }}*'
68+
CIBW_BEFORE_ALL_LINUX: >
69+
mkdir -p ~/.cache || true &&
70+
mkdir -p /host/home/runner/.cache/vcpkg || true &&
71+
ln -s /host/home/runner/.cache/vcpkg ~/.cache/vcpkg || true &&
72+
git config --global --add safe.directory ~/.cache/vcpkg/projects/ss-pybind11 || true
5973
6074
- name: Upload wheels
6175
if: >

pyproject.toml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,28 +56,29 @@ cmake.verbose = false
5656
logging.level = "DEBUG"
5757
metadata.version.provider = "scikit_build_core.metadata.setuptools_scm"
5858
sdist.include = ["src/ss_pybind11/_version.py"]
59-
cmake.args = [
60-
"-DBUILD_TESTING=OFF",
61-
"-DCMAKE_BUILD_TYPE=Release",
62-
"-DVCPKG_INSTALL_REPORT_FAILURE=ON",
63-
"-DVCPKG_INSTALL_OPTIONS=--allow-unsupported",
64-
"-DCMAKE_TOOLCHAIN_FILE=cmake/vcpkg/vcpkg.toolchain.cmake",
65-
"-DVCPKG_OVERLAY_TRIPLETS=cmake/vcpkg/triplets",
66-
"-DVCPKG_OVERLAY_PORTS=cmake/vcpkg/ports",
67-
]
59+
60+
[tool.scikit-build.cmake.define]
61+
BUILD_TESTING="OFF"
62+
CMAKE_BUILD_TYPE="Release"
63+
VCPKG_INSTALL_REPORT_FAILURE="ON"
64+
VCPKG_INSTALL_OPTIONS="--allow-unsupported"
65+
CMAKE_TOOLCHAIN_FILE="cmake/vcpkg/vcpkg.toolchain.cmake"
66+
VCPKG_OVERLAY_TRIPLETS="cmake/vcpkg/triplets"
67+
VCPKG_OVERLAY_PORTS="cmake/vcpkg/ports"
6868

6969
[tool.setuptools_scm]
7070
write_to = "src/ss_pybind11/_version.py"
7171

7272
[tool.cibuildwheel]
7373
build-verbosity = 1
74+
skip = "pp*"
7475
test-command = "pytest {project}/tests"
7576
test-extras = ["test"]
7677
test-skip = ["*-win_arm64", "*-macosx_universal2:arm64"]
7778

7879
[tool.cibuildwheel.linux]
7980
before-build = [
80-
'yum install zip -y || apk add zip || true',
81+
'yum install zip perl-IPC-Cmd -y || apk add zip || true',
8182
'apt update && apt install zip pkg-config -y || true',
8283
'pip install cmake ninja',
8384
'cmake --version',

template/[% if repo_platform == 'github' %].github[% endif %]/workflows/reuseable_cibuildwheel.yml renamed to template/[% if repo_platform == 'github' %].github[% endif %]/workflows/reuseable_cibuildwheel.yml.jinja

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ on:
1414

1515
jobs:
1616
build_wheels:
17-
name: On ${{ matrix.os }}, with ${{ matrix.arch }}, build ${{ matrix.build }} wheels
18-
runs-on: ${{ matrix.os }}
17+
name: {{ '${{ matrix.os }}, ${{ matrix.arch }}, ${{ matrix.build }} wheels' }}
18+
runs-on: {{ '${{ matrix.os }}' }}
1919

2020
strategy:
2121
matrix:
@@ -42,26 +42,40 @@ jobs:
4242
if: runner.os == 'Windows' && inputs.auto && !contains(matrix.qemu_arch, matrix.arch)
4343
uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1
4444
with:
45-
arch: ${{ matrix.arch }}
45+
arch: {{ '${{ matrix.arch }}' }}
4646

4747
- name: Set up QEMU
4848
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
4949
if: runner.os == 'Linux' && inputs.extra && contains(matrix.qemu_arch, matrix.arch)
5050

51+
- name: Cache
52+
uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4
53+
with:
54+
path: |
55+
~/.cache/vcpkg
56+
~/AppData/Local/vcpkg
57+
key: {{ 'cache-${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.build }}-${{ hashFiles(\'vcpkg.json\') }}' }}
58+
restore-keys: {{ 'cache-${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.build }}-${{ hashFiles(\'vcpkg.json\') }}' }}
59+
5160
- name: Build wheels
5261
if: >
5362
inputs.auto && !contains(matrix.qemu_arch, matrix.arch) ||
5463
inputs.extra && contains(matrix.qemu_arch, matrix.arch)
5564
uses: pypa/cibuildwheel@6cccd09a31908ffd175b012fb8bf4e1dbda3bc6c # v2.23.0
5665
env:
57-
CIBW_ARCHS: ${{ matrix.arch }}
58-
CIBW_BUILD: '*${{ matrix.build }}*'
66+
CIBW_ARCHS: {{ '${{ matrix.arch }}' }}
67+
CIBW_BUILD: {{ '\'*${{ matrix.build }}*\'' }}
68+
CIBW_BEFORE_ALL_LINUX: >
69+
mkdir -p ~/.cache || true &&
70+
mkdir -p /host/home/runner/.cache/vcpkg || true &&
71+
ln -s /host/home/runner/.cache/vcpkg ~/.cache/vcpkg || true &&
72+
git config --global --add safe.directory ~/.cache/vcpkg/projects/{{ repo_name }} || true
5973

6074
- name: Upload wheels
6175
if: >
6276
inputs.auto && !contains(matrix.qemu_arch, matrix.arch) ||
6377
inputs.extra && contains(matrix.qemu_arch, matrix.arch)
6478
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4
6579
with:
66-
name: cibw-${{ matrix.os }}-${{ matrix.build }}-${{ matrix.arch }}
80+
name: {{ 'cibw-${{ matrix.os }}-${{ matrix.build }}-${{ matrix.arch }}' }}
6781
path: wheelhouse/*.whl

template/pyproject.toml.jinja

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,28 +109,29 @@ cmake.verbose = false
109109
logging.level = "DEBUG"
110110
metadata.version.provider = "scikit_build_core.metadata.setuptools_scm"
111111
sdist.include = ["src/{{ module_name }}/_version.py"]
112-
cmake.args = [
113-
"-DBUILD_TESTING=OFF",
114-
"-DCMAKE_BUILD_TYPE=Release",
115-
"-DVCPKG_INSTALL_REPORT_FAILURE=ON",
116-
"-DVCPKG_INSTALL_OPTIONS=--allow-unsupported",
117-
"-DCMAKE_TOOLCHAIN_FILE=cmake/vcpkg/vcpkg.toolchain.cmake",
118-
"-DVCPKG_OVERLAY_TRIPLETS=cmake/vcpkg/triplets",
119-
"-DVCPKG_OVERLAY_PORTS=cmake/vcpkg/ports",
120-
]
112+
113+
[tool.scikit-build.cmake.define]
114+
BUILD_TESTING="OFF"
115+
CMAKE_BUILD_TYPE="Release"
116+
VCPKG_INSTALL_REPORT_FAILURE="ON"
117+
VCPKG_INSTALL_OPTIONS="--allow-unsupported"
118+
CMAKE_TOOLCHAIN_FILE="cmake/vcpkg/vcpkg.toolchain.cmake"
119+
VCPKG_OVERLAY_TRIPLETS="cmake/vcpkg/triplets"
120+
VCPKG_OVERLAY_PORTS="cmake/vcpkg/ports"
121121

122122
[tool.setuptools_scm]
123123
write_to = "src/{{ module_name }}/_version.py"
124124

125125
[tool.cibuildwheel]
126126
build-verbosity = 1
127+
skip = "pp*"
127128
test-command = "pytest {project}/tests"
128129
test-extras = ["test"]
129130
test-skip = ["*-win_arm64", "*-macosx_universal2:arm64"]
130131

131132
[tool.cibuildwheel.linux]
132133
before-build = [
133-
'yum install zip -y || apk add zip || true',
134+
'yum install zip perl-IPC-Cmd -y || apk add zip || true',
134135
'apt update && apt install zip pkg-config -y || true',
135136
'pip install cmake ninja',
136137
'cmake --version',

0 commit comments

Comments
 (0)