Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-4456

Use Hatch CMake Plugin

    • Type: Icon: Task Task
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Python Drivers

      Context

      In PYTHON-4451 we switch from using setuptools as the PEP 517 build backend to using Hatch, but still use setuptools to build the C extensions. There is an experimental Hatch plugin for scikit-build-core, that will eventually move to its own plugin. At that point we can switch to using CMake and scikit-build-core to build the C extensions, and migrate off of setuptools entirely.

      This will enable us to use a widely supported build system, and even let us build C extensions for PyPy.

      I did some experimentation and the following CMakelists.txt will build our C extension:

      cmake_minimum_required(VERSION 3.18...3.22)
      
      project(pymongo LANGUAGES C)
      
      find_package(Python COMPONENTS Interpreter Development.Module REQUIRED)
      
      Python_add_library(_cbson MODULE bson/_cbsonmodule.c bson/buffer.c bson/time64.c WITH_SOABI)
      include_directories(bson)
      Python_add_library(_cmessage MODULE pymongo/_cmessagemodule.c bson/_cbsonmodule.c bson/buffer.c bson/time64.c WITH_SOABI)
      
      install(TARGETS _cbson LIBRARY DESTINATION bson)
      install(TARGETS _cmessage LIBRARY DESTINATION pymongo)
      

      Definition of done

      Replace the custom build step introduced in PYTHON-4451 with the CMake plugin.

      Pitfalls

      We may want to do some manual testing or add new test cases to ensure there are no regressions from switching the C extension build system.

            Assignee:
            Unassigned Unassigned
            Reporter:
            steve.silvester@mongodb.com Steve Silvester
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: