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 extensions building #411

Merged
merged 10 commits into from
Jan 28, 2025
Merged

fix extensions building #411

merged 10 commits into from
Jan 28, 2025

Conversation

dkropachev
Copy link
Collaborator

@dkropachev dkropachev commented Jan 23, 2025

By accident @avikivity has found that cassandra.io.libevwrapper is not built properly for fedora:41.
Later @fruch has discovered that on other systems we have similar problems that we failed to spot becasuse setup.py ignores when extension building fails.
To address that this PR introduces CASS_DRIVER_BUILD_EXTENSIONS_ARE_MUST which is False by default.
When it is set, setup.py fails when extension build is failed.

CASS_DRIVER_BUILD_EXTENSIONS_ARE_MUST=yes is added to the CICD, to make it fail, so that we see problem right away.
This PR also addresses all the problems that CASS_DRIVER_BUILD_EXTENSIONS_ARE_MUST uncovered with failed extensions.

pyproject.toml is also introduced to fix building for aarch64 and python 3.13, by some reason cibuildwheel fails to pull all the dependancies in such case.

Fixes following problems:

  1. PyEval_InitThreads got depricated and does not exists in python 3.13:
building 'cassandra.io.libevwrapper' extension
gcc -fno-strict-overflow -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -fcf-protection -fexceptions -fcf-protection -fexceptions -fcf-protection -fexceptions -O3 -fPIC -I/usr/include/libev -I/usr/local/include -I/opt/local/include -I/usr/include/python3.13 -c cassandra/io/libevwrapper.c -o build/temp.linux-x86_64-cpython-313/cassandra/io/libevwrapper.o
cassandra/io/libevwrapper.c: In function ‘PyInit_libevwrapper’:
cassandra/io/libevwrapper.c:668:10: error: implicit declaration of function ‘PyEval_ThreadsInitialized’ [-Wimplicit-function-declaration]
  668 |     if (!PyEval_ThreadsInitialized()) {
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~
cassandra/io/libevwrapper.c:669:9: warning: ‘PyEval_InitThreads’ is deprecated [-Wdeprecated-declarations]
  669 |         PyEval_InitThreads();
      |         ^~~~~~~~~~~~~~~~~~
In file included from /usr/include/python3.13/Python.h:124,
                 from cassandra/io/libevwrapper.c:1:
/usr/include/python3.13/ceval.h:114:37: note: declared here
  114 | Py_DEPRECATED(3.9) PyAPI_FUNC(void) PyEval_InitThreads(void);
      |                                     ^~~~~~~~~~~~~~~~~~
command '/usr/lib64/ccache/gcc' failed with exit code 1
/home/avi/python-driver/setup.py:291: UserWarning: 
  1. Cython fails to convert unicode to 'str':
Error compiling Cython file:
------------------------------------------------------------
...
if metadata_request_timeout is None:
    return stmt
ms = int(metadata_request_timeout / datetime.timedelta(milliseconds=1))
if ms == 0:
    return stmt
return f"{stmt} USING TIMEOUT {ms}ms"
               ^
------------------------------------------------------------
    
cassandra/util.py:1813:11: Cannot convert Unicode string to 'str' implicitly. This is not portable and requires explicit encoding.
  1. Windows builds failures:
    cassandra\c_shard_info.c(3083): error C2065: '__uint128_t': undeclared identifier
    cassandra\c_shard_info.c(3083): error C2146: syntax error: missing ')' before identifier '__pyx_v_biased_token'
    cassandra\c_shard_info.c(3083): error C2059: syntax error: ')'
    cassandra\c_shard_info.c(3083): error C2059: syntax error: ')'
    cassandra\c_shard_info.c(3083): error C2059: syntax error: ')'
  1. Varios macos build failures, one of which:
  ERROR: scylla_driver-3.28.0-cp39-cp39-macosx_14_0_x86_64.whl is not a supported wheel on this platform.
  1. Random crashes, failures or hangups during aarch64 builds

Fixes: #409

Tested

Localy on fedora:41 image

Pre-review checklist

  • I have split my patch into logically separate commits.
  • All commit messages clearly explain what they change and why.
  • I added relevant tests for new features and bug fixes.
  • All commits compile, pass static checks and pass test.
  • PR description sums up the changes and reasons why they should be introduced.
  • I have provided docstrings for the public items that I want to introduce.
  • I have adjusted the documentation in ./docs/source/.
  • I added appropriate Fixes: annotations to PR description.

@dkropachev dkropachev requested review from fruch and Lorak-mmk January 23, 2025 00:59
@dkropachev dkropachev force-pushed the dk/fix-3.13-building branch from 0754abc to 4003ded Compare January 23, 2025 01:00
@dkropachev dkropachev changed the title Dk/fix 3.13 building Fix building on 3.13 Jan 23, 2025
@dkropachev dkropachev marked this pull request as ready for review January 23, 2025 04:21
cassandra/io/libevwrapper.c Outdated Show resolved Hide resolved
cassandra/util.py Outdated Show resolved Hide resolved
@fruch
Copy link

fruch commented Jan 23, 2025

I think something like: #412
would help catching those, and not getting to release with those working as expected

ontop of it some testing should be added to make sure.

@dkropachev dkropachev force-pushed the dk/fix-3.13-building branch 2 times, most recently from 9a8b4dd to 4ac9bf0 Compare January 23, 2025 11:46
@dkropachev
Copy link
Collaborator Author

I think something like: #412 would help catching those, and not getting to release with those working as expected

ontop of it some testing should be added to make sure.

Thanks, I have cherry-picked it.

@dkropachev dkropachev force-pushed the dk/fix-3.13-building branch from f578fb0 to 0c39303 Compare January 23, 2025 13:42
@dkropachev dkropachev changed the title Fix building on 3.13 WIP: Fix building on 3.13 Jan 23, 2025
@dkropachev dkropachev force-pushed the dk/fix-3.13-building branch 3 times, most recently from 14368c1 to a3202b0 Compare January 24, 2025 17:40
@avikivity
Copy link
Member

Great!

@dkropachev dkropachev force-pushed the dk/fix-3.13-building branch from a25ed92 to f7cf0f3 Compare January 26, 2025 11:10
@dkropachev
Copy link
Collaborator Author

Great!

Still working on it, but we are going to be there very soon.

@dkropachev dkropachev force-pushed the dk/fix-3.13-building branch from 54e809c to 94d267e Compare January 26, 2025 11:59
@fruch
Copy link

fruch commented Jan 26, 2025

@dkropachev

I'm trying a fix for windows extensions compilation errors:
47d4409

Anyhow I think the most crucial part from this commit is 8e343d0
that would fix the wheels for python3.13 (and make libev) available

the rest of the change can wait for followup release

@dkropachev dkropachev force-pushed the dk/fix-3.13-building branch 4 times, most recently from 5bc8b19 to ef74fac Compare January 26, 2025 17:47
dkropachev and others added 4 commits January 26, 2025 13:48
PyEval_InitThreads is depricated, since 3.7 it is not necessary to call
it.
On python 3.12 it is not present anymore, which cases build to fail.
Ref: https://docs.python.org/3/c-api/init.html#c.PyEval_InitThreads
Otherwise it fails to convert unicode to 'str':
```
Error compiling Cython file:
------------------------------------------------------------
...
    if metadata_request_timeout is None:
        return stmt
    ms = int(metadata_request_timeout / datetime.timedelta(milliseconds=1))
    if ms == 0:
        return stmt
    return f"{stmt} USING TIMEOUT {ms}ms"
           ^
------------------------------------------------------------

cassandra/util.py:1813:11: Cannot convert Unicode string to 'str' implicitly. This is not portable and requires explicit encoding.
```
We need to see when extension is failed to build on CICD.
Let's introduce CASS_DRIVER_BUILD_EXTENSIONS_ARE_MUST that is False by
default.
When it is set, setup.py fails when building of any extension is failed.
There is a bug in distutils that does not allow it to pick up cython for
python 3.12 and later.
fruch and others added 6 commits January 26, 2025 13:55
move to pyproject.toml that supports PEP517/518
this would help us use isolated build env, and avoid
all the fragile situation we have with Cython installation dependcy
missing in some CI variation
By default docker/setup-qemu-action uses `binmt:master`, which leads to
unstable cicd that hard to debug, randm crashes, bogus errors.
It fixes one of the issue with aarch64 builds.
We use old 20.04, it is time to update it.
Runner os should match cibuildwheels `MACOSX_DEPLOYMENT_TARGET`,
otherwise brew pulls wrong packages that not supported by runner OS.
VSCode cl.exe fails to recognize some of the syntax:
```
    cassandra\c_shard_info.c(3083): error C2065: '__uint128_t': undeclared identifier
    cassandra\c_shard_info.c(3083): error C2146: syntax error: missing ')' before identifier '__pyx_v_biased_token'
    cassandra\c_shard_info.c(3083): error C2059: syntax error: ')'
    cassandra\c_shard_info.c(3083): error C2059: syntax error: ')'
    cassandra\c_shard_info.c(3083): error C2059: syntax error: ')'
```
Let's switch to clang.
@dkropachev dkropachev force-pushed the dk/fix-3.13-building branch from ef74fac to 3a4601a Compare January 26, 2025 18:27
@dkropachev
Copy link
Collaborator Author

@dkropachev

I'm trying a fix for windows extensions compilation errors: 47d4409

Anyhow I think the most crucial part from this commit is 8e343d0 that would fix the wheels for python3.13 (and make libev) available

the rest of the change can wait for followup release

I have fixed all of it, running last lap to make sure it is all ok.

@dkropachev dkropachev changed the title WIP: Fix building on 3.13 fix extensions building Jan 26, 2025
@dkropachev
Copy link
Collaborator Author

dkropachev commented Jan 26, 2025

@fruch , @Lorak-mmk , pipeline is finally green, please take a look, we need to merge it in ASAP.

@roydahan
Copy link
Collaborator

LGTM, but let's let @fruch who is the matter expert to review.

Copy link

@fruch fruch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -100,6 +100,7 @@ jobs:
if: runner.os == 'Windows' && matrix.platform == 'win64'
run: |
echo "CIBW_BUILD=cp*win_amd64" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
echo "CIBW_ENVIRONMENT_WINDOWS= CC=clang CXX=clang++" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should document the clang as the preferred compiler on windows

Copy link

@Lorak-mmk Lorak-mmk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its awesome that you introduced pyproject.toml!

@dkropachev
Copy link
Collaborator Author

Its awesome that you introduced pyproject.toml!

Thanks to @fruch

@dkropachev dkropachev merged commit d02c619 into master Jan 28, 2025
32 checks passed
@avikivity
Copy link
Member

Please emit a new release with Python 3.13 support

@dkropachev
Copy link
Collaborator Author

Please emit a new release with Python 3.13 support

Can you please confirm it works for you.

@avikivity
Copy link
Member

Please emit a new release with Python 3.13 support

Can you please confirm it works for you.

I don't know how to test it. My test involves cqlsh, and I don't know how to tell cqlsh to use a locally compiled driver.

@fruch
Copy link

fruch commented Jan 29, 2025

Please emit a new release with Python 3.13 support

Can you please confirm it works for you.

I don't know how to test it. My test involves cqlsh, and I don't know how to tell cqlsh to use a locally compiled driver.

cqlsh would use the driver installed into scylla-python3, which in turn take it from what installed in dbuild (if it was built with that)

@avikivity
Copy link
Member

Please emit a new release with Python 3.13 support

Can you please confirm it works for you.

I don't know how to test it. My test involves cqlsh, and I don't know how to tell cqlsh to use a locally compiled driver.

cqlsh would use the driver installed into scylla-python3, which in turn take it from what installed in dbuild (if it was built with that)

I don't know how to do any of that.

@dkropachev
Copy link
Collaborator Author

Please emit a new release with Python 3.13 support

Can you please confirm it works for you.

I don't know how to test it. My test involves cqlsh, and I don't know how to tell cqlsh to use a locally compiled driver.

cqlsh would use the driver installed into scylla-python3, which in turn take it from what installed in dbuild (if it was built with that)

I don't know how to do any of that.

Don't mind, I have tested it on fedora:41, it works just fine

@avikivity
Copy link
Member

Please emit a new release with Python 3.13 support

Can you please confirm it works for you.

I don't know how to test it. My test involves cqlsh, and I don't know how to tell cqlsh to use a locally compiled driver.

cqlsh would use the driver installed into scylla-python3, which in turn take it from what installed in dbuild (if it was built with that)

I don't know how to do any of that.

Don't mind, I have tested it on fedora:41, it works just fine

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

libev integration doesn't compile on Python 3.13 / Fedora 41
5 participants