File tree Expand file tree Collapse file tree 3 files changed +15
-2
lines changed Expand file tree Collapse file tree 3 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ option(SPDL_USE_NPPI "Enable NVIDIA 2D Image And Signal Performance Primitives s
9
9
option (SPDL_LINK_STATIC_NVJPEG "Link nvJPEG and NPPI statically." OFF )
10
10
11
11
option (SPDL_DEBUG_REFCOUNT "Enable debug print for reference counting of AVFrame objects." OFF )
12
+ option (SPDL_IS_GIL_ENABLED "Whether the target Python has the GIL enabled" ON )
12
13
option (SPDL_HOLD_GIL "Hold GIL in IO functions." OFF )
13
14
option (SPDL_BUILD_STUB "Build Python binding stub file" OFF )
14
15
option (SPDL_BUILD_PYTHON_BINDING "Build Python binding" ON )
@@ -63,6 +64,7 @@ endif ()
63
64
add_subdirectory (src )
64
65
65
66
if (SPDL_BUILD_PYTHON_BINDING )
67
+ find_package (Python COMPONENTS Interpreter Development.Module REQUIRED )
66
68
add_subdirectory (third_party/nanobind )
67
69
add_subdirectory (src/binding )
68
70
endif ()
Original file line number Diff line number Diff line change @@ -40,6 +40,13 @@ def _env(var, default=False):
40
40
_SPDL_BUILD_STUB = _env ("SPDL_BUILD_STUB" )
41
41
42
42
43
+ def _is_gil_enabled ():
44
+ try :
45
+ return sys ._is_gil_enabled ()
46
+ except AttributeError :
47
+ return True
48
+
49
+
43
50
def _get_ext_modules ():
44
51
ext_modules = []
45
52
for v in ["4" , "5" , "6" , "7" ]:
@@ -99,6 +106,7 @@ def _b(var):
99
106
f"-DPython_EXECUTABLE={ sys .executable } " ,
100
107
"-DSPDL_BUILD_PYTHON_BINDING=ON" ,
101
108
f"-DSPDL_PYTHON_BINDING_INSTALL_PREFIX={ install_dir } " ,
109
+ f"-DSPDL_IS_GIL_ENABLED={ _b (_is_gil_enabled ())} " ,
102
110
###################################################################
103
111
# Options based on env vars
104
112
###################################################################
Original file line number Diff line number Diff line change @@ -31,6 +31,10 @@ elseif (UNIX)
31
31
set (CMAKE_INSTALL_RPATH $ORIGIN )
32
32
endif ()
33
33
34
+ if (NOT SPDL_IS_GIL_ENABLED )
35
+ set (ft FREE_THREADED )
36
+ endif ()
37
+
34
38
function (add_spdl_extension ffmpeg_version )
35
39
set (name "_spdl_ffmpeg${ffmpeg_version} " )
36
40
message (STATUS "Building ${name} " )
@@ -46,11 +50,10 @@ function(add_spdl_extension ffmpeg_version)
46
50
list (APPEND defs SPDL_HOLD_GIL )
47
51
endif ()
48
52
49
- nanobind_add_module (${name} ${src} )
53
+ nanobind_add_module (${name} ${ft} ${ src} )
50
54
target_compile_definitions (${name} PRIVATE "${defs} " )
51
55
target_link_libraries (${name} PRIVATE "spdl_ffmpeg${ffmpeg_version} " )
52
56
target_include_directories (${name} PRIVATE "${Python_INCLUDE_DIR} " )
53
- target_include_directories (nanobind-static PRIVATE "${Python_INCLUDE_DIR} " )
54
57
55
58
install (
56
59
TARGETS ${name}
You can’t perform that action at this time.
0 commit comments