8000 Bump Protobuf to 6.31 · pytorch/pytorch@b51e42a · GitHub
[go: up one dir, main page]

Skip to content

Commit b51e42a

Browse files
committed
Bump Protobuf to 6.31
1 parent aac30ef commit b51e42a

File tree

4 files changed

+23
-138
lines changed

4 files changed

+23
-138
lines changed

cmake/Dependencies.cmake

+8-26
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,6 @@ set(CMAKE_INSTALL_RPATH "${_rpath_portable_origin}")
1515
# the rpath (per library?)
1616
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
1717

18-
# UBSAN triggers when compiling protobuf, so we need to disable it.
19-
set(UBSAN_FLAG "-fsanitize=undefined")
20-
21-
macro(disable_ubsan)
22-
if(CMAKE_C_FLAGS MATCHES ${UBSAN_FLAG} OR CMAKE_CXX_FLAGS MATCHES ${UBSAN_FLAG})
23-
set(CAFFE2_UBSAN_ENABLED ON)
24-
string(REPLACE ${UBSAN_FLAG} "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
25-
string(REPLACE ${UBSAN_FLAG} "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
26-
endif()
27-
endmacro()
28-
29-
macro(enable_ubsan)
30-
if(CAFFE2_UBSAN_ENABLED)
31-
set(CMAKE_C_FLAGS "${UBSAN_FLAG} ${CMAKE_C_FLAGS}")
32-
set(CMAKE_CXX_FLAGS "${UBSAN_FLAG} ${CMAKE_CXX_FLAGS}")
33-
endif()
34-
endmacro()
35-
3618
# ---[ CUDA
3719
if(USE_CUDA)
3820
# public/*.cmake uses CAFFE2_USE_*
@@ -103,9 +85,7 @@ endif()
10385

10486
# ---[ Custom Protobuf
10587
if(CAFFE2_CMAKE_BUILDING_WITH_MAIN_REPO AND NOT INTERN_BUILD_MOBILE)
106-
disable_ubsan()
10788
include(${CMAKE_CURRENT_LIST_DIR}/ProtoBuf.cmake)
108-
enable_ubsan()
10989
endif()
11090

11191
if(USE_ASAN OR USE_TSAN)
@@ -546,6 +526,14 @@ if(USE_XNNPACK AND NOT USE_SYSTEM_XNNPACK)
546526
set(XNNPACK_BUILD_WITH_LIBM OFF CACHE BOOL "")
547527
endif()
548528

529+
# Update xnnpack memory target name. It has conflict with ProtoBuf.
530+
if(NOT EXISTS "${XNNPACK_SOURCE_DIR}/CMakeLists.txt.tag")
531+
file(READ "${XNNPACK_SOURCE_DIR}/CMakeLists.txt" FILE_CONTENTS)
532+
string(REPLACE "memory " "xnnpack_memory " FILE_CONTENTS "${FILE_CONTENTS}")
533+
file(WRITE "${XNNPACK_SOURCE_DIR}/CMakeLists.txt" "${FILE_CONTENTS}")
534+
file(WRITE "${XNNPACK_SOURCE_DIR}/CMakeLists.txt.tag" "xnnpack_memory")
535+
endif()
536+
549537
add_subdirectory(
550538
"${XNNPACK_SOURCE_DIR}"
551539
"${CONFU_DEPENDENCIES_BINARY_DIR}/XNNPACK")
@@ -1260,19 +1248,13 @@ endif()
12601248

12611249
# ---[ Onnx
12621250
if(CAFFE2_CMAKE_BUILDING_WITH_MAIN_REPO AND NOT INTERN_DISABLE_ONNX)
1263-
if(EXISTS "${CAFFE2_CUSTOM_PROTOC_EXECUTABLE}")
1264-
set(ONNX_CUSTOM_PROTOC_EXECUTABLE ${CAFFE2_CUSTOM_PROTOC_EXECUTABLE})
1265-
endif()
12661251
set(TEMP_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
12671252
set(BUILD_SHARED_LIBS OFF)
12681253
set(ONNX_USE_MSVC_STATIC_RUNTIME ${CAFFE2_USE_MSVC_STATIC_RUNTIME})
12691254
set(ONNX_USE_LITE_PROTO ${CAFFE2_USE_LITE_PROTO})
12701255
# If linking local protobuf, make sure ONNX has the same protobuf
12711256
# patches as Caffe2 and Caffe proto. This forces some functions to
12721257
# not be inline and instead route back to the statically-linked protobuf.
1273-
if(CAFFE2_LINK_LOCAL_PROTOBUF)
1274-
set(ONNX_PROTO_POST_BUILD_SCRIPT ${PROJECT_SOURCE_DIR}/cmake/ProtoBufPatch.cmake)
1275-
endif()
12761258
if(ONNX_ML)
12771259
add_definitions(-DONNX_ML=1)
12781260
endif()

cmake/ProtoBuf.cmake

+14-34
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@
22
# the standard cmake script with version and python generation support
33
macro(custom_protobuf_find)
44
message(STATUS "Use custom protobuf build.")
5-
option(protobuf_BUILD_TESTS "" OFF)
6-
option(protobuf_BUILD_EXAMPLES "" OFF)
7-
option(protobuf_WITH_ZLIB "" OFF)
5+
set(ABSL_BUILD_TESTING OFF)
6+
set(ABSL_ENABLE_INSTALL OFF)
7+
set(ABSL_PROPAGATE_CXX_STD ON)
8+
set(protobuf_FORCE_FETCH_DEPENDENCIES ON)
9+
set(protobuf_BUILD_TESTS OFF)
10+
set(protobuf_BUILD_EXAMPLES OFF)
11+
set(protobuf_WITH_ZLIB OFF)
12+
set(__caffe2_CMAKE_POSITION_INDEPENDENT_CODE ${CMAKE_POSITION_INDEPENDENT_CODE})
13+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
14+
set(__caffe2_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
15+
set(BUILD_SHARED_LIBS OFF)
816
if(${CAFFE2_LINK_LOCAL_PROTOBUF})
917
# If we are going to link protobuf locally, we will need to turn off
1018
# shared libs build for protobuf.
@@ -18,10 +26,7 @@ macro(custom_protobuf_find)
1826
option(protobuf_MSVC_STATIC_RUNTIME "" ${CAFFE2_USE_MSVC_STATIC_RUNTIME})
1927

2028
if(${CAFFE2_LINK_LOCAL_PROTOBUF})
21-
set(__caffe2_CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ${CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS})
2229
set(__caffe2_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
23-
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS OFF)
24-
set(BUILD_SHARED_LIBS OFF)
2530
if(${COMPILER_SUPPORTS_HIDDEN_VISIBILITY})
2631
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
2732
endif()
@@ -30,9 +35,6 @@ macro(custom_protobuf_find)
3035
endif()
3136
endif()
3237

33-
set(__caffe2_CMAKE_POSITION_INDEPENDENT_CODE ${CMAKE_POSITION_INDEPENDENT_CODE})
34-
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
35-
3638
if(MSVC)
3739
foreach(flag_var
3840
CMAKE_C_FLAGS CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL
@@ -52,35 +54,13 @@ macro(custom_protobuf_find)
5254
endif(MSVC_Z7_OVERRIDE)
5355
endif(MSVC)
5456

55-
if(CMAKE_VERSION VERSION_GREATER_EQUAL "4.0.0")
56-
message(WARNING "Ancient protobuf forces CMake compatibility")
57-
set(CMAKE_POLICY_VERSION_MINIMUM 3.5)
58-
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../third_party/protobuf/cmake)
59-
unset(CMAKE_POLICY_VERSION_MINIMUM)
60-
else()
61-
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../third_party/protobuf/cmake)
62-
endif()
63-
64-
set(CMAKE_POSITION_INDEPENDENT_CODE ${__caffe2_CMAKE_POSITION_INDEPENDENT_CODE})
57+
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../third_party/protobuf)
6558

6659
if(${CAFFE2_LINK_LOCAL_PROTOBUF})
67-
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ${__caffe2_CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS})
68-
set(BUILD_SHARED_LIBS ON)
6960
set(CMAKE_CXX_FLAGS ${__caffe2_CMAKE_CXX_FLAGS})
7061
endif()
71-
72-
# Protobuf "namespaced" target is only added post protobuf 3.5.1. As a
73-
# result, for older versions, we will manually add alias.
74-
if(NOT TARGET protobuf::libprotobuf)
75-
add_library(protobuf::libprotobuf ALIAS libprotobuf)
76-
add_library(protobuf::libprotobuf-lite ALIAS libprotobuf-lite)
77-
# There is link error when cross compiling protoc on mobile:
78-
# https://github.com/protocolbuffers/protobuf/issues/2719
79-
# And protoc is very unlikely needed for mobile builds.
80-
if(NOT (ANDROID OR IOS))
81-
add_executable(protobuf::protoc ALIAS protoc)
82-
endif()
83-
endif()
62+
set(BUILD_SHARED_LIBS ${__caffe2_BUILD_SHARED_LIBS})
63+
set(CMAKE_POSITION_INDEPENDENT_CODE ${__caffe2_CMAKE_POSITION_INDEPENDENT_CODE})
8464
endmacro()
8565

8666
# Main entry for protobuf. If we are building on Android, iOS or we have hard

cmake/ProtoBufPatch.cmake

-77
Original file line numberDiff line numberDiff line change
@@ -4,83 +4,6 @@
44

55
file(READ ${FILENAME} content)
66

7-
if(NOT SYSTEM_PROTOBUF)
8-
# protobuf-3.6.0 pattern
9-
string(
10-
REPLACE
11-
"::google::protobuf::internal::GetEmptyStringAlreadyInited"
12-
"GetEmptyStringAlreadyInited"
13-
content
14-
"${content}")
15-
16-
# protobuf-3.8.0+ pattern
17-
string(
18-
REPLACE
19-
"::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited"
20-
"GetEmptyStringAlreadyInited"
21-
content
22-
"${content}")
23-
24-
string(
25-
REPLACE
26-
"PROTOBUF_CONSTEXPR"
27-
""
28-
content
29-
"${content}")
30-
31-
# https://github.com/protocolbuffers/protobuf/commit/0400cca3236de1ca303af38bf81eab332d042b7c
32-
# changes PROTOBUF_CONSTEXPR to constexpr, which breaks windows
33-
# build.
34-
if(MSVC)
35-
string(
36-
REGEX REPLACE
37-
"static constexpr ([^ ]+) ([^ ]+) ="
38-
"static \\1 const \\2 ="
39-
content
40-
"${content}")
41-
endif()
42-
43-
foreach(ns ${NAMESPACES})
44-
# Insert "const ::std::string& GetEmptyStringAlreadyInited();" within
45-
# the namespace and make sure we only do it once in the file. Unfortunately
46-
# using string(REPLACE ...) doesn't work because it will replace at all
47-
# locations and there might be multiple declarations of the namespace
48-
# depending on how the proto is structured.
49-
set(search "namespace ${ns} {")
50-
string(LENGTH "${search}" search_len)
51-
string(FIND "${content}" "${search}" pos)
52-
if(${pos} GREATER -1)
53-
math(EXPR pos "${pos}+${search_len}")
54-
string(SUBSTRING "${content}" 0 ${pos} content_pre)
55-
string(SUBSTRING "${content}" ${pos} -1 content_post)
56-
string(
57-
CONCAT
58-
content
59-
"${content_pre}"
60-
" const ::std::string& GetEmptyStringAlreadyInited(); "
61-
"${content_post}")
62-
endif()
63-
endforeach()
64-
65-
# The moving constructor is defined in the header file, which will cause
66-
# a lin D9FA k error that claims that the vftable is not found. Luckily, we
67-
# could move the definition into the source file to solve the problem.
68-
list(LENGTH NAMESPACES ns_count)
69-
if("${FILENAME}" MATCHES ".pb.h" AND ns_count EQUAL 1)
70-
string(REPLACE ".pb.h" ".pb.cc" SOURCE_FILENAME ${FILENAME})
71-
file(READ ${SOURCE_FILENAME} content_cc_origin)
72-
73-
string(REGEX MATCHALL "([a-zA-Z_]+)\\([a-zA-Z_]+&& from\\) noexcept[^}]*}" content_cc "${content}")
74-
string(REGEX REPLACE "};" "}\n" content_cc "${content_cc}")
75-
string(REGEX REPLACE "([a-zA-Z_]+)\\([a-zA-Z_]+&& from\\) noexcept" " \\1::\\1(\\1&& from) noexcept" content_cc "${content_cc}")
76-
set(content_cc "${content_cc_origin}\nnamespace ${NAMESPACES} {\n#if LANG_CXX11\n${content_cc}\n#endif\n}")
77-
78-
string(REGEX REPLACE "([a-zA-Z_]+)\\([a-zA-Z_]+&& from\\) noexcept([^}]*)}" "\\1(\\1&& from) noexcept;" content "${content}")
79-
80-
file(WRITE ${SOURCE_FILENAME} "${content_cc}")
81-
endif()
82-
endif(NOT SYSTEM_PROTOBUF)
83-
847
# constexpr int TensorBoundShape_DimType_DimType_ARRAYSIZE = TensorBoundShape_DimType_DimType_MAX + 1;
858
# throws
869
# error: more than one operator "+" matches these operands:

third_party/protobuf

Submodule protobuf updated 4037 files

0 commit comments

Comments
 (0)
0