Skip to content

Commit 021e509

Browse files
authored
Support FT Python (#436)
1 parent 92cd36e commit 021e509

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

packaging/spdl_io/setup.py

+8
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ def _env(var, default=False):
4242
_SPDL_BUILD_STUB = _env("SPDL_BUILD_STUB")
4343

4444

45+
def _is_gil_enabled():
46+
try:
47+
return sys._is_gil_enabled()
48+
except AttributeError:
49+
return True
50+
51+
4552
def _get_ext_modules():
4653
ext_modules = []
4754
for v in ["4", "5", "6", "7"]:
@@ -101,6 +108,7 @@ def _b(var):
101108
f"-DPython_EXECUTABLE={sys.executable}",
102109
"-DSPDL_BUILD_PYTHON_BINDING=ON",
103110
f"-DSPDL_PYTHON_BINDING_INSTALL_PREFIX={install_dir}",
111+
f"-DSPDL_IS_GIL_ENABLED={_b(_is_gil_enabled())}",
104112
###################################################################
105113
# Options based on env vars
106114
###################################################################

src/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ option(SPDL_USE_NPPI "Enable NVIDIA 2D Image And Signal Performance Primitives s
99
option(SPDL_LINK_STATIC_NVJPEG "Link nvJPEG and NPPI statically." OFF)
1010

1111
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)
1213
option(SPDL_HOLD_GIL "Hold GIL in IO functions." OFF)
1314
option(SPDL_BUILD_STUB "Build Python binding stub file" OFF)
1415
option(SPDL_BUILD_PYTHON_BINDING "Build Python binding" ON)
@@ -64,6 +65,7 @@ endif ()
6465
add_subdirectory(libspdl)
6566

6667
if (SPDL_BUILD_PYTHON_BINDING)
68+
find_package(Python COMPONENTS Interpreter Development.Module REQUIRED)
6769
add_subdirectory(third_party/nanobind)
6870
add_subdirectory(spdl/io/lib)
6971
endif()

src/spdl/io/lib/CMakeLists.txt

+5-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ set(src
3131
io/encoding.cpp
3232
)
3333

34+
if (NOT SPDL_IS_GIL_ENABLED)
35+
set(ft FREE_THREADED)
36+
endif()
37+
3438
function(add_spdl_extension ffmpeg_version)
3539
set(name "_spdl_ffmpeg${ffmpeg_version}")
3640
message(STATUS "Building ${name}")
@@ -46,11 +50,10 @@ function(add_spdl_extension ffmpeg_version)
4650
list(APPEND defs SPDL_HOLD_GIL)
4751
endif ()
4852

49-
nanobind_add_module(${name} ${src})
53+
nanobind_add_module(${name} ${ft} ${src})
5054
target_compile_definitions(${name} PRIVATE "${defs}")
5155
target_link_libraries(${name} PRIVATE "spdl_ffmpeg${ffmpeg_version}")
5256
target_include_directories(${name} PRIVATE "${Python_INCLUDE_DIR}")
53-
target_include_directories(nanobind-static PRIVATE "${Python_INCLUDE_DIR}")
5457

5558
install(
5659
TARGETS ${name}

0 commit comments

Comments
 (0)