Skip to content

Commit fd00e82

Browse files
committed
Update build for FT Python
1 parent 3f24c5a commit fd00e82

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
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)
@@ -63,6 +64,7 @@ endif ()
6364
add_subdirectory(src)
6465

6566
if (SPDL_BUILD_PYTHON_BINDING)
67+
find_package(Python COMPONENTS Interpreter Development.Module REQUIRED)
6668
add_subdirectory(third_party/nanobind)
6769
add_subdirectory(src/binding)
6870
endif()

setup.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ def _env(var, default=False):
4040
_SPDL_BUILD_STUB = _env("SPDL_BUILD_STUB")
4141

4242

43+
def _is_gil_enabled():
44+
try:
45+
return sys._is_gil_enabled()
46+
except AttributeError:
47+
return True
48+
49+
4350
def _get_ext_modules():
4451
ext_modules = []
4552
for v in ["4", "5", "6", "7"]:
@@ -99,6 +106,7 @@ def _b(var):
99106
f"-DPython_EXECUTABLE={sys.executable}",
100107
"-DSPDL_BUILD_PYTHON_BINDING=ON",
101108
f"-DSPDL_PYTHON_BINDING_INSTALL_PREFIX={install_dir}",
109+
f"-DSPDL_IS_GIL_ENABLED={_b(_is_gil_enabled())}",
102110
###################################################################
103111
# Options based on env vars
104112
###################################################################

src/binding/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ elseif (UNIX)
3131
set(CMAKE_INSTALL_RPATH $ORIGIN)
3232
endif ()
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)