From fa4a9778961ee8042ecdbda08e4f48896c773791 Mon Sep 17 00:00:00 2001 From: shoumikhin Date: Wed, 5 Aug 2026 09:29:51 -0700 Subject: [PATCH] Update [ghstack-poisoned] --- devtools/etdump/CMakeLists.txt | 24 ++++++++++++++++++++++- setup.py | 21 ++++++++++++++++++++ tools/cmake/executorch-wheel-config.cmake | 3 +++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/devtools/etdump/CMakeLists.txt b/devtools/etdump/CMakeLists.txt index fe754d8129a..43ee4bddf13 100644 --- a/devtools/etdump/CMakeLists.txt +++ b/devtools/etdump/CMakeLists.txt @@ -39,8 +39,19 @@ add_custom_command( COMMENT "Generating etdump headers" ) +# The profiler is reachable from both the Python extension and a standalone C++ +# application, and each one linking it statically would keep its own tracing state. +# Build it shared for the wheel, where both are loaded into one process, and keep it +# static everywhere else so no other build changes. +if(EXECUTORCH_BUILD_SHARED) + set(_etdump_library_type SHARED) +else() + set(_etdump_library_type STATIC) +endif() + add_library( etdump + ${_etdump_library_type} ${_schema_outputs} ${CMAKE_CURRENT_SOURCE_DIR}/etdump_flatcc.cpp ${CMAKE_CURRENT_SOURCE_DIR}/emitter.cpp @@ -49,7 +60,9 @@ add_library( ${CMAKE_CURRENT_SOURCE_DIR}/data_sinks/file_data_sink.cpp ${CMAKE_CURRENT_SOURCE_DIR}/data_sinks/file_data_sink.h ) -target_link_libraries(etdump PUBLIC flatccrt) +# Private, not public: the flatbuffer runtime is an implementation detail and the wheel +# does not ship it, so exposing it would make the shipped header unlinkable. +target_link_libraries(etdump PRIVATE flatccrt) # As with bundled_program, avoid the whole-archive of the `executorch` target so # the primitive operator registrations are not duplicated alongside the copy # already inside libexecutorch.so. @@ -58,6 +71,15 @@ if(EXECUTORCH_BUILD_SHARED) else() target_link_libraries(etdump PRIVATE executorch) endif() +if(EXECUTORCH_BUILD_SHARED) + set_target_properties( + etdump + PROPERTIES OUTPUT_NAME executorch_etdump + VERSION "${PROJECT_VERSION}" + SOVERSION "${PROJECT_VERSION_MAJOR}" + ) +endif() + target_include_directories( etdump PUBLIC ${DEVTOOLS_INCLUDE_DIR} diff --git a/setup.py b/setup.py index edd46a69f56..340bb9fb8a9 100644 --- a/setup.py +++ b/setup.py @@ -941,6 +941,7 @@ def run(self): "extension/named_data_map/", "extension/tensor/", "extension/threadpool/", + "devtools/etdump/", ]: src_list = Path(include_dir).rglob("*.h") for src in src_list: @@ -1282,6 +1283,26 @@ def run(self): # noqa C901 dst=f"executorch/lib/libexecutorch.so.{get_runtime_soname_major()}", dependent_cmake_flags=["EXECUTORCH_BUILD_SHARED"], ), + # Install the profiler next to it. Keeping it separate lets a C++ + # application link it without pulling in the Python extension, which + # is where it was only reachable before. + BuiltFile( + src_dir="%CMAKE_CACHE_DIR%/devtools/etdump/", + src_name=( + f"libexecutorch_etdump.so.{get_runtime_soname_major()}.*" + ), + dst=( + "executorch/lib/libexecutorch_etdump.so." + f"{get_runtime_soname_major()}" + ), + # The target only exists when the developer tools are built, so + # packaging has to require that too or a shared build without them + # looks for a file that was never built. + dependent_cmake_flags=[ + "EXECUTORCH_BUILD_SHARED", + "EXECUTORCH_BUILD_DEVTOOLS", + ], + ), # Install the shared thread pool next to it. It is a separate # library so that a process has one pool rather than one per # component that uses it. diff --git a/tools/cmake/executorch-wheel-config.cmake b/tools/cmake/executorch-wheel-config.cmake index 566cf06c6ea..1e126fe2fd3 100644 --- a/tools/cmake/executorch-wheel-config.cmake +++ b/tools/cmake/executorch-wheel-config.cmake @@ -356,6 +356,9 @@ executorch_define_component(threadpool executorch_threadpool) # to be defined here or a consumer following the documentation gets a bare name that CMake hands # to the linker as a literal flag. executorch_define_component(kernels_optimized executorch_kernels_optimized) +# The profiler. A C++ application could not record timing data from an installed package before, +# because the implementation shipped only inside the Python extension. +executorch_define_component(etdump executorch_etdump) # A consumer that links the thread pool has to see the same switch a source build sets, or the # parallel helpers in the runtime headers compile their serial fallback instead and the library