Repository navigation
321 lines (287 loc) · 11.2 KB
/
Copy path03-macos-linux-build.yml
File metadata and controls
321 lines (287 loc) · 11.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
name: MacOS & Linux Build
on:
workflow_call:
inputs:
platform:
description: 'Platform identifier'
required: true
type: string
os:
description: 'GitHub Actions runner OS'
required: true
type: string
compiler:
description: 'C++ compiler to use (gcc or clang)'
required: false
type: string
default: ''
permissions:
contents: read
jobs:
# Build and test matrix (parallel execution)
build-and-test:
name: Build & Test (${{ inputs.platform }})
runs-on: ${{ inputs.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ${{ inputs.os }}
platform: ${{ inputs.platform }}
arch_flag: "" # Use appropriate architecture
steps:
- name: Checkout code
uses: actions/checkout@v7
with:
submodules: recursive
- name: Setup ccache
uses: hendrikmuhs/ccache-action@v1.2
with:
key: ${{ inputs.platform }}-${{ inputs.os }}-${{ inputs.compiler || 'gcc' }}
max-size: 150M
- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: '3.10'
cache: 'pip'
cache-dependency-path: 'pyproject.toml'
- name: Install Clang
if: inputs.compiler == 'clang' && runner.os == 'Linux'
run: |
sudo apt-get update -y
sudo apt-get install -y clang libomp-dev
shell: bash
- name: Print CPU info
if: runner.os == 'Linux'
run: lscpu
shell: bash
- name: Set up environment variables
run: |
# Set number of processors for parallel builds
if [[ "${{ runner.os }}" == "macOS" ]]; then
NPROC=$(sysctl -n hw.ncpu 2>/dev/null || echo 2)
else
NPROC=$(nproc 2>/dev/null || echo 2)
fi
echo "NPROC=$NPROC" >> $GITHUB_ENV
echo "Using $NPROC parallel jobs for builds"
# Set compiler when clang is requested
if [[ "${{ inputs.compiler }}" == "clang" ]]; then
echo "CC=clang" >> $GITHUB_ENV
echo "CXX=clang++" >> $GITHUB_ENV
fi
# Add Python user base bin to PATH for pip-installed CLI tools
echo "$(python -c 'import site; print(site.USER_BASE)')/bin" >> $GITHUB_PATH
shell: bash
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install \
pybind11==3.0 \
cmake==3.30.0 \
ninja==1.11.1 \
pytest \
pytest-xdist \
scikit-build-core \
setuptools_scm
shell: bash
- name: Check CMake subproject integration
if: matrix.platform == 'linux-x64'
run: |
SMOKE_SOURCE="$RUNNER_TEMP/zvec-subproject-smoke"
SMOKE_BUILD="$RUNNER_TEMP/zvec-subproject-build"
mkdir -p "$SMOKE_SOURCE" "$SMOKE_BUILD"
cp "$GITHUB_WORKSPACE/.github/cmake/subproject-integration/CMakeLists.txt" \
"$SMOKE_SOURCE/CMakeLists.txt"
cmake -S "$SMOKE_SOURCE" -B "$SMOKE_BUILD" -G Ninja \
-DZVEC_SOURCE_DIR="$GITHUB_WORKSPACE" \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_BENCHMARKS=OFF \
-DBUILD_C_BINDINGS=OFF \
-DBUILD_PYTHON_BINDINGS=OFF \
-DENABLE_WERROR=ON \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
shell: bash
- name: Build from source
run: |
cd "$GITHUB_WORKSPACE"
CMAKE_GENERATOR="Ninja" \
CMAKE_BUILD_PARALLEL_LEVEL="$NPROC" \
python -m pip install -v . \
--no-build-isolation \
--config-settings='cmake.define.BUILD_BENCHMARKS=ON' \
--config-settings='cmake.define.ENABLE_WERROR=ON' \
--config-settings='cmake.define.CMAKE_C_COMPILER_LAUNCHER=ccache' \
--config-settings='cmake.define.CMAKE_CXX_COMPILER_LAUNCHER=ccache' \
${{ matrix.arch_flag }}
shell: bash
- name: Run C++ Tests
if: matrix.platform != 'macos-x64'
run: |
cd "$GITHUB_WORKSPACE/build"
cmake --build . --target unittest --parallel $NPROC
shell: bash
- name: Run macOS x64 C++ compatibility tests
if: matrix.platform == 'macos-x64'
run: |
test "$(uname -m)" = "x86_64"
df -h /
cd "$GITHUB_WORKSPACE/build"
test_regex='^(shared_api_test|c_api_test|diskann_.*_test)$'
# Build the same targets CTest will run, including tests added on main.
test_targets=$(ctest --show-only=json-v1 -R "$test_regex" | python -c '
import json
import sys
names = [test["name"] for test in json.load(sys.stdin)["tests"]]
if not names:
sys.exit("No macOS x64 compatibility tests registered")
print(" ".join(names))
')
read -r -a targets <<< "$test_targets"
cmake --build . --target "${targets[@]}" --parallel "$NPROC"
ctest --output-on-failure --no-tests=error -R "$test_regex" --parallel 1
shell: bash
- name: Run Python Tests
if: matrix.platform != 'macos-x64'
run: |
cd "$GITHUB_WORKSPACE"
python -m pytest python/tests/
shell: bash
- name: Run macOS x64 Python compatibility smoke test
if: matrix.platform == 'macos-x64'
run: |
cd "$GITHUB_WORKSPACE"
python -X faulthandler -c \
"import platform, zvec; print('Imported zvec on', platform.machine(), zvec.__version__)"
python -X faulthandler .github/scripts/macos_x64_python_smoke.py
shell: bash
- name: Run required macOS x64 DiskAnn lifecycle tests
if: matrix.platform == 'macos-x64'
run: |
python -m pytest python/tests/test_collection_diskann.py -n 2 -v
shell: bash
- name: Diagnose macOS x64 Python native crash
if: failure() && matrix.platform == 'macos-x64'
run: |
echo "Recent macOS crash reports:"
find "$HOME/Library/Logs/DiagnosticReports" \
-type f -mmin -15 \
\( -name 'Python*.ips' -o -name 'Python*.crash' \) \
-print -exec tail -n 500 {} \; 2>/dev/null || true
echo "Reproducing under LLDB:"
lldb --batch \
-o run \
-k 'thread backtrace all' \
-- "$(command -v python)" -X faulthandler \
"$GITHUB_WORKSPACE/.github/scripts/macos_x64_python_smoke.py"
shell: bash
- name: Run C++ Examples
run: |
cd "$GITHUB_WORKSPACE/examples/c++"
mkdir build && cd build
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
cmake --build . --parallel $NPROC
./db-example
./core-example
./ailego-example
if [[ "${{ runner.os }}" == "macOS" ]]; then
./diskann-core-example
fi
shell: bash
- name: Run C Examples
run: |
cd "$GITHUB_WORKSPACE/examples/c"
mkdir build && cd build
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
cmake --build . --parallel $NPROC
./c_api_basic_example
./c_api_collection_schema_example
./c_api_doc_example
./c_api_field_schema_example
./c_api_index_example
./c_api_optimized_example
shell: bash
# ------------------------------------------------------------------ #
# DiskAnn io_uring round: GitHub-hosted runners are full VMs on
# kernel 6.8+, so raw io_uring syscalls are available and win the
# backend priority (io_uring > libaio > pread). The main test
# rounds above therefore already exercised the io_uring path;
# this step asserts it so a silent probe regression fails CI.
# ------------------------------------------------------------------ #
- name: Verify io_uring backend is active
if: runner.os == 'Linux'
run: |
uname -r
python -c "
import zvec
from zvec.typing import IOBackendType
t = zvec.io_backend_type()
print('Active I/O backend:', t, '-', zvec.io_backend_description())
assert t == IOBackendType.IO_URING, f'expected IO_URING, got {t}'
"
shell: bash
# ------------------------------------------------------------------ #
# DiskAnn libaio round: disable io_uring via sysctl (kernel 6.6+,
# makes io_uring_setup() fail with -EPERM), install libaio, and
# re-run tests so the libaio fallback path is genuinely exercised.
# ------------------------------------------------------------------ #
- name: Install libaio runtime and disable io_uring
if: matrix.platform == 'linux-x64'
run: |
sudo apt-get update -y
# libaio1t64 on Ubuntu 24.04+ (t64 transition), libaio1 on older
sudo apt-get install -y libaio1t64 || sudo apt-get install -y libaio1
echo "=== libaio status (should be present) ==="
dpkg -l | grep -i libaio || true
ldconfig -p | grep libaio || true
sudo sysctl -w kernel.io_uring_disabled=2
python -c "
import zvec
from zvec.typing import IOBackendType
t = zvec.io_backend_type()
print('Active I/O backend:', t)
assert t == IOBackendType.LIBAIO, f'expected LIBAIO, got {t}'
"
shell: bash
- name: Run DiskAnn C++ Tests
if: matrix.platform != 'macos-x64'
run: |
cd "$GITHUB_WORKSPACE/build"
ctest -R diskann --output-on-failure --parallel $NPROC
"$GITHUB_WORKSPACE/examples/c++/build/diskann-core-example"
shell: bash
- name: Run DiskAnn Python Tests (w/ libaio)
if: matrix.platform == 'linux-x64'
run: |
cd "$GITHUB_WORKSPACE"
python -m pytest python/tests/test_collection_diskann.py -v
shell: bash
# ------------------------------------------------------------------ #
# DiskAnn pread round: with io_uring still disabled, remove libaio
# so the final synchronous pread() fallback is exercised too.
# ------------------------------------------------------------------ #
- name: Remove libaio (force pread fallback)
if: matrix.platform == 'linux-x64'
run: |
sudo apt-get remove -y libaio1t64 libaio1 2>/dev/null || \
sudo apt-get remove -y libaio1t64 || \
sudo apt-get remove -y libaio1
python -c "
import zvec
from zvec.typing import IOBackendType
t = zvec.io_backend_type()
print('Active I/O backend:', t)
assert t == IOBackendType.PREAD, f'expected PREAD, got {t}'
"
shell: bash
- name: Run DiskAnn C++ Tests (w/ pread)
if: matrix.platform == 'linux-x64'
run: |
cd "$GITHUB_WORKSPACE/build"
ctest -R diskann --output-on-failure --parallel $NPROC
shell: bash