Skip to content

Commit 9efe5d3

Browse files
authored
Merge branch 'main' into export-D103467782
2 parents 9da60dd + fa49f8f commit 9efe5d3

8 files changed

Lines changed: 38 additions & 4 deletions

File tree

.github/workflows/pull.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,8 @@ jobs:
534534
output=$(ls -la cmake-out/test/size_test)
535535
arr=($output)
536536
size=${arr[4]}
537-
# Current CI size: 48008 (gcc9-nopytorch, 2026-03-06)
538-
threshold="48500"
537+
# Current CI size: 52168 (gcc9-nopytorch, 2026-07-06)
538+
threshold="52168"
539539
if [[ "$size" -le "$threshold" ]]; then
540540
echo "Success $size <= $threshold"
541541
else

CMakeLists.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,13 @@ if(NOT PYTHON_EXECUTABLE)
157157
endif()
158158
announce_configured_options(PYTHON_EXECUTABLE)
159159

160+
# pybind11 >=3.0 uses find_package(Python) which looks for Python_EXECUTABLE,
161+
# not the legacy PYTHON_EXECUTABLE variable. Bridge the two so pybind11 picks up
162+
# the interpreter that setup.py (or the user) specified.
163+
if(PYTHON_EXECUTABLE AND NOT Python_EXECUTABLE)
164+
set(Python_EXECUTABLE "${PYTHON_EXECUTABLE}")
165+
endif()
166+
160167
announce_configured_options(CMAKE_CXX_COMPILER_ID)
161168
announce_configured_options(CMAKE_TOOLCHAIN_FILE)
162169
announce_configured_options(BUILD_TESTING)
@@ -260,6 +267,27 @@ endif()
260267

261268
add_subdirectory(third-party)
262269

270+
# On Apple, pybind11 SHARED extension modules must not link libpython directly.
271+
# When python_add_library creates a SHARED library, it links Python::Python (via
272+
# pybind11::embed) which pulls in libpython. This conflicts with pybind11
273+
# >=3.0's multi-phase module init — the duplicate Python runtime causes a GIL
274+
# state crash at import time. This function replaces pybind11::embed with
275+
# pybind11::module (which links Python::Module instead of Python::Python —
276+
# headers and ABI only, no libpython) and adds -undefined dynamic_lookup for
277+
# symbol resolution. No-op on non-Apple platforms.
278+
function(strip_python_lib target)
279+
if(NOT APPLE)
280+
return()
281+
endif()
282+
get_target_property(_libs ${target} LINK_LIBRARIES)
283+
if(_libs)
284+
list(REMOVE_ITEM _libs Python::Python pybind11::embed)
285+
list(APPEND _libs pybind11::module)
286+
set_target_properties(${target} PROPERTIES LINK_LIBRARIES "${_libs}")
287+
endif()
288+
target_link_options(${target} PRIVATE "LINKER:-undefined,dynamic_lookup")
289+
endfunction()
290+
263291
# Size-optimized builds disable exceptions, RTTI, and unwind tables.
264292
# ExecuTorch's runtime uses Result<T>/Error instead of exceptions, so
265293
# -fno-exceptions is safe. Suppressing .eh_frame via -fno-unwind-tables is safe
@@ -1114,6 +1142,7 @@ if(EXECUTORCH_BUILD_PYBIND)
11141142

11151143
# pybind portable_lib
11161144
pybind11_add_module(portable_lib SHARED extension/pybindings/pybindings.cpp)
1145+
strip_python_lib(portable_lib)
11171146
# The actual output file needs a leading underscore so it can coexist with
11181147
# portable_lib.py in the same python package. PyTorch requires C++20, so
11191148
# pybindings must be compiled with C++20.
@@ -1155,6 +1184,7 @@ if(EXECUTORCH_BUILD_PYBIND)
11551184
pybind11_add_module(
11561185
data_loader SHARED extension/pybindings/pybindings_data_loader.cpp
11571186
)
1187+
strip_python_lib(data_loader)
11581188
target_include_directories(data_loader PRIVATE ${_common_include_directories})
11591189
target_compile_options(data_loader PUBLIC ${_pybind_compile_options})
11601190
target_link_libraries(data_loader PRIVATE executorch)

backends/apple/coreml/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ if(EXECUTORCH_BUILD_PYBIND)
175175
executorchcoreml SHARED runtime/inmemoryfs/inmemory_filesystem_py.cpp
176176
runtime/inmemoryfs/inmemory_filesystem_utils.cpp
177177
)
178+
strip_python_lib(executorchcoreml)
178179
target_link_libraries(
179180
executorchcoreml PRIVATE coreml_util coreml_inmemoryfs
180181
nlohmann_json::nlohmann_json

codegen/tools/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
# Create the selective_build pybind11 module
1111
pybind11_add_module(selective_build SHARED selective_build.cpp)
12+
strip_python_lib(selective_build)
1213

1314
# Set the output name to match the module name
1415
set_target_properties(selective_build PROPERTIES OUTPUT_NAME "selective_build")

examples/arm/image_classification_example_vgf/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
# LICENSE file in the root directory of this source tree.
55

66
evaluate == 0.4.6
7-
transformers[torch] == 4.56.1
7+
transformers[torch] == 5.3.0
88
tqdm == 4.67.1

extension/llm/runner/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ if(EXECUTORCH_BUILD_PYBIND)
112112
pybind11_add_module(
113113
_llm_runner SHARED ${CMAKE_CURRENT_SOURCE_DIR}/pybindings.cpp
114114
)
115+
strip_python_lib(_llm_runner)
115116

116117
find_package_torch()
117118
find_library(

extension/training/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ if(EXECUTORCH_BUILD_PYBIND)
6666
_training_lib SHARED
6767
${CMAKE_CURRENT_SOURCE_DIR}/pybindings/_training_lib.cpp
6868
)
69+
strip_python_lib(_training_lib)
6970
set_target_properties(_training_lib PROPERTIES CXX_STANDARD 20)
7071

7172
target_include_directories(_training_lib PRIVATE ${TORCH_INCLUDE_DIRS})

third-party/pybind11

Submodule pybind11 updated 290 files

0 commit comments

Comments
 (0)