Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cmake builds with Python 3.12, which deleted the long-deprecated 'distutils' module #13583

Merged
merged 1 commit into from
Sep 4, 2024

Conversation

dconeybe
Copy link
Contributor

@dconeybe dconeybe commented Sep 4, 2024

If performing a cmake build with Python 3.11 or earlier, everything works fine; however, if using Python 3.12 the cmake build fails with ModuleNotFoundError: No module named 'distutils'. This is because the distutils module was deleted in Python 3.12 (see https://peps.python.org/pep-0632/ and https://docs.python.org/3/whatsnew/3.12.html#distutils).

The problem was coming from nanopb which referenced the distutils module in its CMakeLists.txt. The fix was to copy the replacement command that works in Python 3.12, and should work all the way back to Python 3.7 (see nanopb/nanopb#727 and nanopb/nanopb#730). This PR merely tweaks the patching that is already done on nanopb.

Here is what the error looks like, which this PR fixes:

$ PATH="$HOME/.pyenv/versions/3.12.3/bin/python:$PATH" cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -GNinja
...
-- Found PythonInterp: /home/linuxbrew/.linuxbrew/bin/python3 (found suitable version "3.12.3", minimum required is "3.7") 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'distutils'
CMake Error at build/external/src/nanopb/CMakeLists.txt:61 (install):
  install FILES given no DESTINATION!


CMake Error at build/external/src/nanopb/CMakeLists.txt:61 (install):
  install FILES given no DESTINATION!


-- Found Python3: /home/linuxbrew/.linuxbrew/bin/python3.12 (found version "3.12.3") found components: Interpreter 
-- FirebaseSetupPythonInterpreter(FirestoreProtos): Creating Python virtualenv in firebase-ios-sdk/build/Firestore/Protos/pyvenv/FirestoreProtos using /home/linuxbrew/.linuxbrew/bin/python3.12
-- firebase_execute_process(): running command: /home/linuxbrew/.linuxbrew/bin/python3.12 -m venv firebase-ios-sdk/build/Firestore/Protos/pyvenv/FirestoreProtos
-- FirebaseSetupPythonInterpreter(FirestoreProtos): Found Python executable in virtualenv: firebase-ios-sdk/build/Firestore/Protos/pyvenv/FirestoreProtos/bin/python3
-- FirebaseSetupPythonInterpreter(FirestoreProtos): Installing Python dependencies into firebase-ios-sdk/build/Firestore/Protos/pyvenv/FirestoreProtos: six
-- firebase_execute_process(): running command: firebase-ios-sdk/build/Firestore/Protos/pyvenv/FirestoreProtos/bin/python3 -m pip install six
Collecting six
  Using cached six-1.16.0-py2.py3-none-any.whl.metadata (1.8 kB)
Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)
Installing collected packages: six
Successfully installed six-1.16.0

[notice] A new release of pip is available: 24.0 -> 24.2
[notice] To update, run: python3 -m pip install --upgrade pip
-- FirebaseSetupPythonInterpreter(FirestoreCore): Creating Python virtualenv in firebase-ios-sdk/build/Firestore/core/pyvenv/FirestoreCore using /home/linuxbrew/.linuxbrew/bin/python3.12
-- firebase_execute_process(): running command: /home/linuxbrew/.linuxbrew/bin/python3.12 -m venv firebase-ios-sdk/build/Firestore/core/pyvenv/FirestoreCore
-- FirebaseSetupPythonInterpreter(FirestoreCore): Found Python executable in virtualenv: firebase-ios-sdk/build/Firestore/core/pyvenv/FirestoreCore/bin/python3
-- Looking for dispatch_async_f
-- Looking for dispatch_async_f - not found
-- Looking for arc4random
-- Looking for arc4random - found
-- Looking for include file openssl/rand.h
-- Looking for include file openssl/rand.h - found
-- Configuring incomplete, errors occurred!

#no-changelog

@dconeybe dconeybe self-assigned this Sep 4, 2024
@dconeybe dconeybe changed the title Fix cmake build with Python 3.12, which deleted the long-deprecated 'distutils' module Fix cmake builds with Python 3.12, which deleted the long-deprecated 'distutils' module Sep 4, 2024
@dconeybe dconeybe merged commit 3755841 into main Sep 4, 2024
35 checks passed
@dconeybe dconeybe deleted the dconeybe/Python312Fix branch September 4, 2024 18:17
@firebase firebase locked and limited conversation to collaborators Oct 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants