fix(python): exclude C++ SDK headers and libs from the wheel (#509)

The wheel shipped ~94 public headers under `include/` and 7 static/shared
libraries under `lib/` (libzvec*.a, libzvec*.dylib). These come from the
`cc_library(PACKED)` install rules, which are meant for a standalone C++
`make install`, not the Python wheel. `_zvec.so` links the zvec libraries
statically (verified via otool: it depends only on system libs), so none of
those `lib/` / `include/` files are used at runtime — they are pure bloat.

Tag the three runtime install rules (_zvec, the DiskANN plugin, the jieba
dict) with `COMPONENT python`, and set `install.components = ["python"]` in
pyproject.toml so scikit-build-core installs only that component into the
wheel. The SDK install rules (default component) are excluded.

The standalone `make install` is unaffected (it still installs every
component).

Verified on macOS arm64: wheel no longer contains any `include/`, `lib/`,
`.a`, or `.h` entries; `import zvec` and `from zvec import Query` still work.
This commit is contained in:
Cuiys
2026-06-22 19:41:05 +08:00
committed by GitHub
parent 0ac294a9fd
commit 3a15a9d5b7
2 changed files with 14 additions and 3 deletions
+9 -3
View File
@@ -171,7 +171,11 @@ if(BUILD_PYTHON_BINDINGS)
endif()
message(STATUS "Zvec install path: ${ZVEC_PY_INSTALL_DIR}")
install(TARGETS _zvec LIBRARY DESTINATION ${ZVEC_PY_INSTALL_DIR})
# COMPONENT python: only these runtime artifacts are pulled into the wheel
# (see install.components in pyproject.toml). The cc_library(PACKED) SDK
# install rules use the default component and are excluded from the wheel.
install(TARGETS _zvec LIBRARY DESTINATION ${ZVEC_PY_INSTALL_DIR}
COMPONENT python)
# DiskAnn ships as a runtime-loaded shared module
# (libzvec_diskann_plugin.so) that is brought online implicitly the
@@ -182,7 +186,8 @@ if(BUILD_PYTHON_BINDINGS)
# The target exists only on platforms where DiskAnn is buildable
# (currently Linux x86_64 with libaio).
if(TARGET core_knn_diskann)
install(TARGETS core_knn_diskann LIBRARY DESTINATION ${ZVEC_PY_INSTALL_DIR})
install(TARGETS core_knn_diskann LIBRARY DESTINATION ${ZVEC_PY_INSTALL_DIR}
COMPONENT python)
endif()
# Bundle cppjieba's dictionary files so the `jieba` FTS tokenizer works
# out of the box. python/zvec/__init__.py resolves this directory via
@@ -192,5 +197,6 @@ if(BUILD_PYTHON_BINDINGS)
install(FILES
"${ZVEC_JIEBA_DICT_SRC}/jieba.dict.utf8"
"${ZVEC_JIEBA_DICT_SRC}/hmm_model.utf8"
DESTINATION ${ZVEC_PY_INSTALL_DIR}/zvec/data/jieba_dict)
DESTINATION ${ZVEC_PY_INSTALL_DIR}/zvec/data/jieba_dict
COMPONENT python)
endif()
+5
View File
@@ -102,6 +102,11 @@ cmake.version = ">=3.26,<4.0"
ninja.version = ">=1.11"
cmake.build-type = "Release"
install.strip = true # Strip symbols in release builds to reduce wheel size
# Only pull the runtime artifacts tagged COMPONENT "python" into the wheel.
# This excludes the C++ SDK install rules (static/shared libs under lib/ and
# public headers under include/) that cc_library(PACKED) registers for a
# standalone `make install`, which would otherwise bloat the wheel.
install.components = ["python"]
# Build directory
build-dir = "build"