From 2093090575837bb3de192d7e4f9b592e3f5b92f4 Mon Sep 17 00:00:00 2001 From: "A bot of @njzjz" <48687836+njzjz-bot@users.noreply.github.com> Date: Sun, 23 Aug 2026 02:03:11 +0800 Subject: [PATCH 1/3] fix(tf): find external protobuf for TensorFlow 2.21 Backport conda-forge/deepmd-kit-feedstock patch 0001 at d02138263b0b30629fe28c68c8bcecc2b8644513. Agent: ChatGPT Model: GPT-5.6 Sol --- source/cmake/Findtensorflow.cmake | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/source/cmake/Findtensorflow.cmake b/source/cmake/Findtensorflow.cmake index b5b8c92f3d..623c6f0bfc 100644 --- a/source/cmake/Findtensorflow.cmake +++ b/source/cmake/Findtensorflow.cmake @@ -256,15 +256,14 @@ if(NOT TensorFlow_INCLUDE_DIRS_GOOGLE) STATUS "Protobuf headers are not found in the directory of TensorFlow, assuming external protobuf was used to build TensorFlow" ) - if(NOT Protobuf_LIBRARY) - message(FATAL_ERROR "TensorFlow is not linked to protobuf") - endif() - get_filename_component(Protobuf_LIBRARY_DIRECTORY ${Protobuf_LIBRARY} - DIRECTORY) - # assume the include directory is ../include - set(Protobuf_INCLUDE_DIR ${Protobuf_LIBRARY_DIRECTORY}/../include) + # TensorFlow 2.21 packages may not record protobuf as a direct runtime + # dependency. Find the external full protobuf library instead of relying on + # libtensorflow_framework's dependency list, which may also expose only the + # lite library on some platforms. + unset(Protobuf_LIBRARY) find_package(Protobuf REQUIRED) set(TensorFlow_INCLUDE_DIRS_GOOGLE ${Protobuf_INCLUDE_DIRS}) + set(Protobuf_LIBRARY ${Protobuf_LIBRARIES}) endif() list(APPEND TensorFlow_INCLUDE_DIRS ${TensorFlow_INCLUDE_DIRS_GOOGLE}) From 72f40f43d945381e0cef854a49ba48b5a5b81cb1 Mon Sep 17 00:00:00 2001 From: njzjz-bot Date: Mon, 24 Aug 2026 00:12:40 +0800 Subject: [PATCH 2/3] fix(tf): preserve TensorFlow protobuf selection Keep an ldd-discovered protobuf library pinned while using its installation prefix to guide FindProtobuf. Fall back to the normal external package search when TensorFlow exposes no protobuf runtime dependency. Coding-Agent: Codex Codex-Version: codex-cli 0.149.0 Model: gpt-5.6-sol Reasoning-Effort: xhigh --- source/cmake/Findtensorflow.cmake | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/source/cmake/Findtensorflow.cmake b/source/cmake/Findtensorflow.cmake index 623c6f0bfc..0a22d8ad98 100644 --- a/source/cmake/Findtensorflow.cmake +++ b/source/cmake/Findtensorflow.cmake @@ -257,11 +257,31 @@ if(NOT TensorFlow_INCLUDE_DIRS_GOOGLE) "Protobuf headers are not found in the directory of TensorFlow, assuming external protobuf was used to build TensorFlow" ) # TensorFlow 2.21 packages may not record protobuf as a direct runtime - # dependency. Find the external full protobuf library instead of relying on - # libtensorflow_framework's dependency list, which may also expose only the - # lite library on some platforms. - unset(Protobuf_LIBRARY) + # dependency. If the runtime scan found protobuf, preserve that exact library + # and use its installation prefix to guide the header search. Otherwise, allow + # FindProtobuf to locate the external protobuf package normally. + if(Protobuf_LIBRARY) + set(_TensorFlow_PROTOBUF_ROOT_WAS_DEFINED FALSE) + if(DEFINED Protobuf_ROOT) + set(_TensorFlow_PROTOBUF_ROOT_WAS_DEFINED TRUE) + set(_TensorFlow_SAVED_PROTOBUF_ROOT "${Protobuf_ROOT}") + endif() + get_filename_component(_TensorFlow_PROTOBUF_LIBRARY_DIRECTORY + "${Protobuf_LIBRARY}" DIRECTORY) + get_filename_component( + Protobuf_ROOT "${_TensorFlow_PROTOBUF_LIBRARY_DIRECTORY}" DIRECTORY) + endif() find_package(Protobuf REQUIRED) + if(DEFINED _TensorFlow_PROTOBUF_ROOT_WAS_DEFINED) + if(_TensorFlow_PROTOBUF_ROOT_WAS_DEFINED) + set(Protobuf_ROOT "${_TensorFlow_SAVED_PROTOBUF_ROOT}") + else() + unset(Protobuf_ROOT) + endif() + unset(_TensorFlow_PROTOBUF_ROOT_WAS_DEFINED) + unset(_TensorFlow_SAVED_PROTOBUF_ROOT) + unset(_TensorFlow_PROTOBUF_LIBRARY_DIRECTORY) + endif() set(TensorFlow_INCLUDE_DIRS_GOOGLE ${Protobuf_INCLUDE_DIRS}) set(Protobuf_LIBRARY ${Protobuf_LIBRARIES}) endif() From 3499e8a35702c57ded56c1dbfbcb516ae871fae8 Mon Sep 17 00:00:00 2001 From: njzjz-bot Date: Sun, 30 Aug 2026 01:09:36 +0800 Subject: [PATCH 3/3] fix(tf): validate inferred protobuf prefix Verify the inferred protobuf prefix contains the headers before using it, and handle multiarch library directories by checking one additional parent. Leave FindProtobuf on its normal search path when neither layout matches. Coding-Agent: Codex Codex-Version: codex-cli 0.151.0 Model: gpt-5.6-sol Reasoning-Effort: xhigh --- source/cmake/Findtensorflow.cmake | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/source/cmake/Findtensorflow.cmake b/source/cmake/Findtensorflow.cmake index 0a22d8ad98..0995bc664f 100644 --- a/source/cmake/Findtensorflow.cmake +++ b/source/cmake/Findtensorflow.cmake @@ -258,8 +258,10 @@ if(NOT TensorFlow_INCLUDE_DIRS_GOOGLE) ) # TensorFlow 2.21 packages may not record protobuf as a direct runtime # dependency. If the runtime scan found protobuf, preserve that exact library - # and use its installation prefix to guide the header search. Otherwise, allow - # FindProtobuf to locate the external protobuf package normally. + # and use its installation prefix to guide the header search. Check both flat + # /lib and multiarch /lib/ layouts before trusting + # the inferred prefix. Otherwise, allow FindProtobuf to locate the external + # protobuf package normally. if(Protobuf_LIBRARY) set(_TensorFlow_PROTOBUF_ROOT_WAS_DEFINED FALSE) if(DEFINED Protobuf_ROOT) @@ -269,7 +271,17 @@ if(NOT TensorFlow_INCLUDE_DIRS_GOOGLE) get_filename_component(_TensorFlow_PROTOBUF_LIBRARY_DIRECTORY "${Protobuf_LIBRARY}" DIRECTORY) get_filename_component( - Protobuf_ROOT "${_TensorFlow_PROTOBUF_LIBRARY_DIRECTORY}" DIRECTORY) + _TensorFlow_PROTOBUF_PREFIX "${_TensorFlow_PROTOBUF_LIBRARY_DIRECTORY}" + DIRECTORY) + if(NOT EXISTS + "${_TensorFlow_PROTOBUF_PREFIX}/include/google/protobuf/service.h") + get_filename_component(_TensorFlow_PROTOBUF_PREFIX + "${_TensorFlow_PROTOBUF_PREFIX}" DIRECTORY) + endif() + if(EXISTS + "${_TensorFlow_PROTOBUF_PREFIX}/include/google/protobuf/service.h") + set(Protobuf_ROOT "${_TensorFlow_PROTOBUF_PREFIX}") + endif() endif() find_package(Protobuf REQUIRED) if(DEFINED _TensorFlow_PROTOBUF_ROOT_WAS_DEFINED) @@ -281,6 +293,7 @@ if(NOT TensorFlow_INCLUDE_DIRS_GOOGLE) unset(_TensorFlow_PROTOBUF_ROOT_WAS_DEFINED) unset(_TensorFlow_SAVED_PROTOBUF_ROOT) unset(_TensorFlow_PROTOBUF_LIBRARY_DIRECTORY) + unset(_TensorFlow_PROTOBUF_PREFIX) endif() set(TensorFlow_INCLUDE_DIRS_GOOGLE ${Protobuf_INCLUDE_DIRS}) set(Protobuf_LIBRARY ${Protobuf_LIBRARIES})