ceph-mirror/cmake/modules
Kefu Chai 91de0e1933 cmake: migrate Python module installation from setup.py to pip
Replace 'setup.py install' with 'pip install --use-pep517' to fix
Cython compilation failures and eliminate deprecation warnings.

Problem Statement:
The build process for Cython modules involves preprocessing .pyx files
(e.g., generating rbd_processed.pyx from rbd.pyx) and then cythonizing
with specific compiler_directives. The previous approach using separate
'setup.py build' and 'setup.py install' commands caused this failure:

```
Error compiling Cython file:
------------------------------------------------------------
...
        """
        name = cstr(name, 'name')
        cdef:
            rados_ioctx_t _ioctx = convert_ioctx(ioctx)
            char *_name = name
            librbd_progress_fn_t _prog_cb = &no_op_progress_callback
                                            ^
------------------------------------------------------------

rbd_processed.pyx:781:44: Cannot assign type 'int (*)(uint64_t, uint64_t, void *) except? -1' to 'librbd_progress_fn_t'. Exception values are incompatible. Suggest adding 'noexcept' to type 'int (uint64_t, uint64_t, void *) except? -1'.
```

This occurs because:
1. 'setup.py build build_ext' successfully preprocesses and cythonizes
   with compiler_directives from setup.py's cythonize() call
2. 'setup.py install' internally triggers a rebuild that:
   - Regenerates the preprocessed .pyx files
   - Re-runs cythonize() through Cython.Distutils.build_ext
   - Does NOT apply the compiler_directives from setup.py
   - Fails on the regenerated files missing required directives

New Options Explained:

`--use-pep517`:
  Addresses deprecation warning:
  ```
    DEPRECATION: Building 'rados' using the legacy setup.py bdist_wheel
    mechanism, which will be removed in a future version. pip 25.3 will
    enforce this behaviour change.
  ```
  Uses the modern PEP 517 build backend which:
  - Performs a single build pass with all compiler_directives applied
  - Prevents the implicit rebuild that caused CompileError
  - Future-proofs against pip 25.3+ which will require this

`--no-build-isolation`:
  Ensures that environment variables set by CMake are respected:
  - CC, LDSHARED (compiler toolchain)
  - CPPFLAGS, LDFLAGS (compilation flags)
  - CYTHON_BUILD_DIR, CEPH_LIBDIR (build paths)

  Without this flag, pip would create an isolated build environment
  that ignores these critical build settings.

`--no-deps`:
  Prevents pip from attempting to install Python dependencies listed
  in setup.py's install_requires. All dependencies are managed by
  CMake and the distribution's package manager, not pip.

`--ignore-installed`:
  Addresses installation error when DESTDIR is set:
  ```
    ERROR: Could not install packages due to an OSError: [Errno 13]
    Permission denied: '/usr/lib/python3/dist-packages/rados-2.0.0.egg-info'

    OSError: [Errno 18] Invalid cross-device link:
    '/usr/lib/python3/dist-packages/rados-2.0.0.egg-info' -> '/tmp/pip-uninstall-...'
  ```
  This error occurs because pip detects an existing system installation
  and tries to uninstall it before installing to DESTDIR. With
  --ignore-installed, pip skips the uninstall step and directly installs
  to the DESTDIR staging directory, which is the correct behavior for
  packaging.

Removed Options:

`--install-layout=deb`:
  This Debian-specific patch to 'setup.py install' is no longer needed.
  Modern pip automatically detects the distribution and uses the correct
  layout (dist-packages on Debian, site-packages on RPM distros).

`--single-version-externally-managed`:
  This option was specific to 'setup.py install' to prevent egg
  installation. With pip, this is handled automatically.

`--record /dev/null`:
  No longer needed as pip manages installation records internally.

`egg_info --egg-base`:
  Not needed with pip as metadata is generated automatically during
  the build process.

Not added option:
`--root-user-action=ignore`: not added
  In this change, we installing a python module using pip with
  `fakeroot` before packaging it. But pip warned:
  ```
  Error: WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behavior with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
  ```
  But we use fakeroot on purpose, this option could have been added  to
  silence this warning. But it is not available in all supported pip
  versions. see
  2e1112a814

New environmental variable:
`DEB_PYTHON_INSTALL_LAYOUT=deb` is conditionally applied when packaging
for debian-derivative distributions. As pip does not support
`--install-layout` option. Since debian patches pip so it installs Python
modules into /usr/local/lib instead of /usr/lib where debian dh_install
helper looks for the content to be packaged, so we have to enforce the
debian layout using the environmental variable.

Working Directory Change:

Changed from `CMAKE_CURRENT_SOURCE_DIR` to `CMAKE_CURRENT_BINARY_DIR` to
keep pip's temporary files and logs in the build directory rather than
polluting the source tree.

Additional Dependencies:

Since the build process uses pip and creates a wheel distribution,
we need to add `pip` and `wheel` Python modules as build dependencies.

Python moduels packaging:

- with `--use-pep517`, pip creates .dist-info directoires as per PEP-517
instead of .egg-info, so we need to package the new metadata directory.

Future Improvements

We considered implementing a custom `build_templates` command or using
setuptools' `sub_commands` mechanism to avoid regenerating `*_processed.pyx`
files on every build (tracking dependencies via file modification times or
hash-based checks). However, to keep `setup.py` simple and maintainable,
we've deferred this optimization for future work. The current solution
using `pip install --use-pep517` ensures correct builds without additional
complexity.

This solution works correctly for both Debian and RPM packaging workflows,
both of which use DESTDIR-based staged installations.

Fixes: 719b749846
Signed-off-by: Kefu Chai <k.chai@proxmox.com>
2026-01-29 08:45:50 +08:00
..
code_tests cmake/.../FindSanitizers: add check for Sanitizers_FIBER_SUPPPORT 2024-02-20 16:20:23 -08:00
FindPython cmake: update FindPython3 module 2023-08-17 10:24:16 +08:00
AddCephTest.cmake Merge pull request #65408 from tchaikov/wip-suppress-asan-warnings 2025-10-21 08:18:45 +08:00
BuildArrow.cmake cmake: BuildArrow.cmake uses bundled thrift if system version < 0.17 2025-10-15 17:08:55 -04:00
BuildBoost.cmake build: Disable FindBoost for Boost's included cmake config 2026-01-14 23:54:08 -05:00
Buildc-ares.cmake cmake: s/c-ares::c-ares/c-ares::cares/ 2022-11-22 01:17:30 +08:00
BuildDPDK.cmake cmake: pass RTE_DEVEL_BUILD=n when building dpdk 2022-03-05 12:57:24 +08:00
BuildFIO.cmake cmake: While building fio headers, reference to macro BITS_PER_LONG defined by the fio's build is not being used in our CMake based system for plugins. 2025-12-17 14:06:05 +05:30
BuildISAL.cmake cmake/modules/BuildISAL.cmake: set no-integrated-as on clang only 2025-03-02 08:48:31 +00:00
BuildISALCrypto.cmake cmake/crypto: use ExternalProject to build isal crypto library 2024-09-05 13:19:21 -04:00
BuildOpentelemetry.cmake cmake: add cmake 4 support 2025-10-20 17:02:57 -04:00
Buildpmdk.cmake cmake: disable LTO when building pmdk 2022-08-04 17:56:48 +08:00
BuildQAT.cmake cmake: WITH_QATLIB/ZIP disabled on aarch64 2024-02-07 11:13:21 -05:00
BuildQATzip.cmake cmake/modules/BuildQATzip: Disable errors 2025-02-20 14:18:12 +00:00
BuildRocksDB.cmake cmake: fix liburing path passed to rocksdb 2026-01-05 15:09:00 +09:00
BuildSPDK.cmake cmake/modules/BuildSPDK.cmake: link whole-archive 2022-01-20 19:39:27 +08:00
Builduadk.cmake uadk: Build with ceph fork (for FORTIFY_SOURCE fix) 2025-09-04 13:27:36 -04:00
BuildUBBD.cmake tools/rbd: add support of new device type for ubbd 2023-05-18 12:35:39 +00:00
Builduring.cmake cmake: bump liburing from 0.7 to 2.5 2024-03-02 12:16:14 +08:00
BuildUtf8proc.cmake cmake: add submodule for utf8proc at v2.2.0 2022-03-14 10:19:02 -04:00
BuildZstd.cmake cmake: allow use libzstd in system 2021-03-31 12:53:39 +08:00
CephCheck_link.c cmake: detect linker support 2019-10-08 21:53:03 +08:00
CephCheck_link.map cmake: detect linker support 2019-10-08 21:53:03 +08:00
CephChecks.cmake cmake: disable deprecated warning when building googletest 2025-04-02 11:35:45 +08:00
CheckCxxAtomic.cmake build: fix atomic linking with LTO on s390x 2022-07-18 15:19:02 -04:00
CheckNasm.cmake cmake: only display the result of checking nasm once 2021-01-04 01:34:46 +08:00
CPM.cmake Add support for Catch2 2025-05-02 10:54:58 -07:00
CTags.cmake Merge pull request #54963 from DimStar77/cmake328 2024-02-17 23:18:23 +08:00
Distutils.cmake cmake: migrate Python module installation from setup.py to pip 2026-01-29 08:45:50 +08:00
Findaio.cmake
FindArrow.cmake cmake: move Arrow targets into find_package modules 2022-03-14 10:19:02 -04:00
Findbabeltrace.cmake
FindBacktrace.cmake
Findblkid.cmake
Findc-ares.cmake cmake: drop c-ares::c-ares alias 2025-06-13 16:23:49 +08:00
Findcap.cmake cmake: find_package(cap) before linking against it 2024-02-11 16:57:38 +08:00
FindCUnit.cmake
FindCython.cmake cmake: drop WITH_PYTHON2 option 2019-12-19 10:58:58 +08:00
FindDAOS.cmake rgw: add DAOS SAL implementation 2022-09-07 12:19:41 -04:00
Finddaxctl.cmake cmake: add findndctl and finddaxctl function 2022-07-12 10:32:57 +08:00
Finddml.cmake Add the support to use DML library for PMEM device. 2022-04-19 14:51:12 +08:00
Finddpdk.cmake cmake: dpdk: only append common dir if it has been found 2022-01-13 14:40:17 +01:00
FindFUSE.cmake cmake: to get the header and library from specified path 2020-05-24 21:40:18 -04:00
FindGMock.cmake cmake: link against gtest in a better way 2018-08-17 15:21:27 +08:00
Findgperftools.cmake cmake: import allocator libraries in a better way 2018-07-26 15:16:48 +08:00
FindGSSApi.cmake auth: Kerberos authentication 2018-12-03 18:55:46 -07:00
FindJeMalloc.cmake cmake: fix a cmake error when with -DALLOCATOR=jemalloc. 2018-08-02 16:38:53 +08:00
Findkeyutils.cmake cmake: extract mount.ceph into src/mount 2018-07-28 16:53:10 +08:00
Findlibcryptsetup.cmake cmake: fix unknown pkg_search_module 2020-12-02 06:18:52 -05:00
Findlibnbd.cmake librbd/migration: add nbd stream 2024-09-06 14:14:12 +02:00
FindLinuxZNS.cmake cmake: detect linux/blk/zoned support 2021-12-25 16:13:47 +08:00
FindLMDB.cmake RGW - Add POSIX Driver 2023-09-14 12:09:40 -04:00
FindLTTngUST.cmake
FindLZ4.cmake cmake: add LZ4::LZ4 target for LZ4 2018-08-06 17:38:07 +08:00
FindMake.cmake cmake: use find_program(REQUIRED) to fail early on missing programs 2025-06-17 17:30:10 +08:00
Findmotr.cmake cmake: find motr libraries and header before using them 2022-08-10 21:15:12 +08:00
Findndctl.cmake cmake: add findndctl and finddaxctl function 2022-07-12 10:32:57 +08:00
Findnl.cmake cmake: rewrite Findgenl to support components argument 2019-06-19 21:21:00 +08:00
FindNUMA.cmake cmake: use NUMA for package name in FindNUMA.cmake 2021-02-14 23:11:33 +08:00
FindOATH.cmake cmake: cmake: oath lives in liboath 2018-06-10 16:21:41 +02:00
FindOpenLDAP.cmake cmake: define OpenLDAP::OpenLDAP library 2021-07-24 19:28:56 +08:00
FindParquet.cmake cmake: move Arrow targets into find_package modules 2022-03-14 10:19:02 -04:00
Findpmdk.cmake cmake: rename a series of pmem libraries to pmdk 2022-06-28 01:16:33 +08:00
FindPython3.cmake cmake: update FindPython3 module 2023-08-17 10:16:45 +08:00
FindQAT.cmake cmake: add WITH_QATLIB to build against qatlib 2024-02-07 10:37:47 -05:00
FindQatDrv.cmake cmake: add WITH_QATLIB to build against qatlib 2024-02-07 10:37:47 -05:00
FindQATzip.cmake cmake: build qatzip from source when WITH_SYSTEM_QATZIP=OFF 2024-02-07 11:12:45 -05:00
FindRabbitMQ.cmake cmake: find_package(RabbitMQ) instead of just checking its header 2019-02-21 19:00:24 +08:00
FindRDKafka.cmake cmake: check version of librdkafka 2019-12-15 22:16:08 +08:00
Findrdmacm.cmake cmake: extract the RDMA libraries interface properties out 2018-06-28 23:26:28 +08:00
FindRocksDB.cmake cmake/FindRocksDB: fix IMPORTED_LOCATION for ROCKSDB_LIBRARIES 2019-03-27 10:18:26 +08:00
FindSanitizers.cmake cmake: quote a list using quotes 2024-03-27 07:35:28 +08:00
Findsnappy.cmake cmake: cleanup snappy related script 2018-08-06 17:16:46 +08:00
FindSQLite3.cmake libcephsqlite: rework architecture and backend 2021-03-19 08:52:55 -07:00
FindStdFilesystem_test.cc cmake: stop detecting <experimental/filesystem> 2021-06-09 23:25:22 +08:00
FindStdFilesystem.cmake cmake: stop detecting <experimental/filesystem> 2021-06-09 23:25:22 +08:00
Findthrift.cmake cmake: Findthrift.cmake parses version string 2025-10-15 17:06:43 -04:00
Findudev.cmake
Finduring.cmake cmake: fix Finduring.cmake 2023-10-20 09:18:30 -04:00
Findutf8proc.cmake cmake: add submodule for utf8proc at v2.2.0 2022-03-14 10:19:02 -04:00
Finduuid.cmake
Findverbs.cmake cmake: extract the RDMA libraries interface properties out 2018-06-28 23:26:28 +08:00
Findxfs.cmake
Findyaml-cpp.cmake jaeger, build/op: add jaeger and it's dependencies as submodules 2020-12-11 07:55:46 +00:00
Findzbd.cmake os/bluestore: Switch from libzbc library to libzbd library 2020-09-06 12:35:05 -04:00
FindZstd.cmake cmake: allow use libzstd in system 2021-03-31 12:53:39 +08:00
GetGitRevisionDescription.cmake cmake: check $top_srcdir/.git directly 2020-04-08 18:03:37 +08:00
GetGitRevisionDescription.cmake.in cmake/modules/GetGitRevisionDescription: update to work with git-worktree 2019-10-07 14:26:07 -05:00
LimitJobs.cmake cmake: Intelligently set job limits for sccache 2024-05-06 14:03:14 -06:00
patch-dpdk-conf.sh cmake: Add dpdk numa support 2019-11-28 20:15:39 +08:00
SIMDExt.cmake crc32c optimized for s390x arch 2024-05-22 19:45:37 +02:00