From 3a15a9d5b73dbb3cf84190dba637214943067886 Mon Sep 17 00:00:00 2001 From: Cuiys Date: Mon, 22 Jun 2026 19:41:05 +0800 Subject: [PATCH] fix(python): exclude C++ SDK headers and libs from the wheel (#509) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- CMakeLists.txt | 12 +++++++++--- pyproject.toml | 5 +++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f9ad6bc..25760ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/pyproject.toml b/pyproject.toml index 98fdcff..4f7add5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"