Skip to content

Commit

Permalink
Merge pull request #19 from isuruf/freethreading
Browse files Browse the repository at this point in the history
Freethreading support
  • Loading branch information
isuruf authored Sep 30, 2024
2 parents e177a58 + cdda4dc commit 6122901
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 34 deletions.
19 changes: 0 additions & 19 deletions .github/workflows/automerge.yml

This file was deleted.

13 changes: 0 additions & 13 deletions .github/workflows/webservices.yml

This file was deleted.

4 changes: 3 additions & 1 deletion recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ source:
sha256: fa48beb9b8d4574482edf19dc8671d4cb78f53c2511047a0e52bb88fbdeb6d0c
folder: python
patches:
- 0001-cython-3.1-fixes.patch
- patches/0001-cython-3.1-fixes.patch
- patches/0002-Another-cython-3.1-fix.patch
- patches/0003-freethreading-support.patch

- url: https://github.com/symengine/symengine/releases/download/v{{ cxx_version }}/symengine-{{ cxx_version }}.tar.gz
sha256: f46bcf037529cd1a422369327bf360ad4c7d2b02d0f607a62a5b09c74a55bb59
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 1e47d959c4edd9c15e1f893a570e4b0082a39501 Mon Sep 17 00:00:00 2001
From: Isuru Fernando <isuruf@gmail.com>
Date: Sun, 29 Sep 2024 16:25:26 -0500
Subject: [PATCH] cython 3.1 fixes
Subject: [PATCH 1/3] cython 3.1 fixes

---
cmake/cython_test.pyx | 3 ---
Expand Down
27 changes: 27 additions & 0 deletions recipe/patches/0002-Another-cython-3.1-fix.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
From 845168d3683f28781b32577abf4f38ed93f0bc79 Mon Sep 17 00:00:00 2001
From: Isuru Fernando <isuruf@gmail.com>
Date: Mon, 30 Sep 2024 11:38:54 -0500
Subject: [PATCH 2/3] Another cython 3.1 fix

---
cmake/cython_test.pyx | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/cmake/cython_test.pyx b/cmake/cython_test.pyx
index cb803c6..47f9847 100644
--- a/cmake/cython_test.pyx
+++ b/cmake/cython_test.pyx
@@ -75,8 +75,8 @@ cdef extern from "<symengine/symbol.h>" namespace "SymEngine":
string get_name() nogil

cdef extern from "<symengine/add.h>" namespace "SymEngine":
- cdef RCP[Basic] add(RCP[Basic] &a, RCP[Basic] &b) nogil except+
- cdef RCP[Basic] sub(RCP[Basic] &a, RCP[Basic] &b) nogil except+
+ cdef RCP[Basic] add(RCP[Basic] &a, RCP[Basic] &b) except+ nogil
+ cdef RCP[Basic] sub(RCP[Basic] &a, RCP[Basic] &b) except+ nogil

cdef cppclass Add(Basic):
void as_two_terms(const Ptr[RCP[Basic]] &a, const Ptr[RCP[Basic]] &b)
--
2.44.0

81 changes: 81 additions & 0 deletions recipe/patches/0003-freethreading-support.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
From 170e7ded46b60ee43ec1e6ee997fd95205cad2f4 Mon Sep 17 00:00:00 2001
From: Isuru Fernando <isuruf@gmail.com>
Date: Mon, 30 Sep 2024 11:39:06 -0500
Subject: [PATCH 3/3] freethreading support

---
cmake/FindPython.cmake | 32 +++++++++++++++++++++++---------
1 file changed, 23 insertions(+), 9 deletions(-)

diff --git a/cmake/FindPython.cmake b/cmake/FindPython.cmake
index f338132..2f54f50 100644
--- a/cmake/FindPython.cmake
+++ b/cmake/FindPython.cmake
@@ -22,26 +22,36 @@ execute_process(
string(STRIP ${PYTHON_LIB_PATH} PYTHON_LIB_PATH)

execute_process(
- COMMAND ${PYTHON_BIN} -c "import sys; print(sys.prefix)"
- OUTPUT_VARIABLE PYTHON_PREFIX_PATH
- )
+ COMMAND ${PYTHON_BIN} -c "import sys; print(sys.prefix)"
+ OUTPUT_VARIABLE PYTHON_PREFIX_PATH
+)

string(STRIP ${PYTHON_PREFIX_PATH} PYTHON_PREFIX_PATH)

execute_process(
- COMMAND ${PYTHON_BIN} -c "import sys; print('%s.%s' % sys.version_info[:2])"
+ COMMAND ${PYTHON_BIN} -c "import sys; print('%s.%s' % sys.version_info[:2])"
OUTPUT_VARIABLE PYTHON_VERSION
- )
+)
string(STRIP ${PYTHON_VERSION} PYTHON_VERSION)
message(STATUS "Python version: ${PYTHON_VERSION}")

string(REPLACE "." "" PYTHON_VERSION_WITHOUT_DOTS ${PYTHON_VERSION})

+execute_process(
+ COMMAND ${PYTHON_BIN} -c "import sysconfig;print(bool(sysconfig.get_config_var('Py_GIL_DISABLED')))"
+ OUTPUT_VARIABLE PY_GIL_DISABLED
+)
+string(STRIP ${PY_GIL_DISABLED} PY_GIL_DISABLED)
+
+if ("${PY_GIL_DISABLED}" STREQUAL "True")
+ set (PY_THREAD "t")
+endif()
+
if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
FIND_LIBRARY(PYTHON_LIBRARY NAMES
- python${PYTHON_VERSION}
+ python${PYTHON_VERSION}${PY_THREAD}
python${PYTHON_VERSION}m
- python${PYTHON_VERSION_WITHOUT_DOTS}
+ python${PYTHON_VERSION_WITHOUT_DOTS}${PY_THREAD}
PATHS ${PYTHON_LIB_PATH} ${PYTHON_PREFIX_PATH}/lib ${PYTHON_PREFIX_PATH}/libs
PATH_SUFFIXES ${CMAKE_LIBRARY_ARCHITECTURE}
NO_DEFAULT_PATH
@@ -51,8 +61,8 @@ endif()

execute_process(
COMMAND ${PYTHON_BIN} -c "from sysconfig import get_paths; print(get_paths()['purelib'])"
- OUTPUT_VARIABLE PYTHON_INSTALL_PATH_tmp
- )
+ OUTPUT_VARIABLE PYTHON_INSTALL_PATH_tmp
+)
string(STRIP ${PYTHON_INSTALL_PATH_tmp} PYTHON_INSTALL_PATH_tmp)
set(PYTHON_INSTALL_PATH ${PYTHON_INSTALL_PATH_tmp}
CACHE BOOL "Python install path")
@@ -129,5 +139,9 @@ macro(ADD_PYTHON_LIBRARY name)
IF(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
target_link_libraries(${name} ${PYTHON_LIBRARY})
set_target_properties(${name} PROPERTIES SUFFIX ".pyd")
+ IF("${PY_GIL_DISABLED}" STREQUAL "True")
+ target_compile_definitions(${name} PRIVATE Py_GIL_DISABLED=1)
+ ENDIF()
ENDIF()
+
endmacro(ADD_PYTHON_LIBRARY)
--
2.44.0

0 comments on commit 6122901

Please sign in to comment.