/
upb-e4635f223e7d36dfbea3b722a4ca4807a7e882e2.patch
334 lines (316 loc) · 12.5 KB
/
upb-e4635f223e7d36dfbea3b722a4ca4807a7e882e2.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
diff --git a/cmake/make_cmakelists.py b/cmake/make_cmakelists.py
index d64c14f..27813c3 100755
--- a/cmake/make_cmakelists.py
+++ b/cmake/make_cmakelists.py
@@ -39,8 +39,13 @@ import sys
import textwrap
import os
+def MappingThirdPartyDep(dep):
+ if dep.startswith("/third_party/"):
+ return dep[13:]
+ return dep
+
def StripFirstChar(deps):
- return [dep[1:] for dep in deps]
+ return [MappingThirdPartyDep(dep[1:]) for dep in deps]
def IsSourceFile(name):
return name.endswith(".c") or name.endswith(".cc")
@@ -81,11 +86,16 @@ class BuildFileFunctions(object):
if list(filter(IsSourceFile, files)):
# Has sources, make this a normal library.
- self.converter.toplevel += "add_library(%s\n %s)\n" % (
+ output_name = kwargs["name"]
+ if output_name.lower() != "upb":
+ output_name = "upb-" + output_name
+ self.converter.toplevel += "add_library({0}\n {1})\nset_target_properties({0} PROPERTIES OUTPUT_NAME \"{2}\")\n".format(
kwargs["name"],
- "\n ".join(found_files)
+ "\n ".join(found_files),
+ output_name
)
- self._add_deps(kwargs)
+ self.converter.export_targets.append(kwargs["name"])
+ self._add_deps(kwargs, " PUBLIC")
else:
# Header-only library, have to do a couple things differently.
# For some info, see:
@@ -93,6 +103,7 @@ class BuildFileFunctions(object):
self.converter.toplevel += "add_library(%s INTERFACE)\n" % (
kwargs["name"]
)
+ self.converter.export_targets.append(kwargs["name"])
self._add_deps(kwargs, " INTERFACE")
def cc_binary(self, **kwargs):
@@ -249,11 +260,13 @@ class Converter(object):
self.prelude = ""
self.toplevel = ""
self.if_lua = ""
+ self.export_targets = []
def convert(self):
return self.template % {
"prelude": converter.prelude,
"toplevel": converter.toplevel,
+ "export_targets": ' '.join(converter.export_targets),
}
template = textwrap.dedent("""\
@@ -283,6 +296,15 @@ class Converter(object):
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
FORCE)
endif()
+ set(CMAKE_INSTALL_RPATH_USE_LINK_PATH YES)
+ set(CMAKE_BUILD_RPATH_USE_ORIGIN YES)
+ if (UNIX AND NOT APPLE)
+ set(CMAKE_INSTALL_RPATH "$ORIGIN" "$ORIGIN/../lib64" "$ORIGIN/../lib")
+ set(CMAKE_BUILD_RPATH "$ORIGIN" "$ORIGIN/../lib64" "$ORIGIN/../lib")
+ elseif (APPLE)
+ set(CMAKE_INSTALL_RPATH "@loader_path" "@loader_path/../lib64" "@loader_path/../lib")
+ set(CMAKE_BUILD_RPATH "@loader_path" "@loader_path/../lib64" "@loader_path/../lib")
+ endif()
# When using Ninja, compiler output won't be colorized without this.
include(CheckCXXCompilerFlag)
@@ -316,10 +338,181 @@ class Converter(object):
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--build-id")
endif()
+ if (MSVC)
+ add_compile_options(/wd4146 /wd4703 -D_CRT_SECURE_NO_WARNINGS)
+ endif()
+
enable_testing()
+ if (UPB_BUILD_CODEGEN)
+ find_package(absl CONFIG REQUIRED)
+ find_package(protobuf CONFIG REQUIRED)
+ endif()
+
+ add_library(descriptor_upb_proto)
+ set_target_properties(descriptor_upb_proto PROPERTIES OUTPUT_NAME "upb-descriptor_upb_proto")
+
+ file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/_deps/include/upb/third_party/utf8_range")
+ file(COPY ../third_party/utf8_range/utf8_range.h
+ DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/_deps/include/upb/third_party/utf8_range" USE_SOURCE_PERMISSIONS)
+ add_library(utf8_range
+ ../third_party/utf8_range/naive.c
+ ../third_party/utf8_range/range2-neon.c
+ ../third_party/utf8_range/range2-sse.c
+ "${CMAKE_CURRENT_BINARY_DIR}/_deps/include/upb/third_party/utf8_range/utf8_range.h"
+ )
+ set_target_properties(utf8_range PROPERTIES OUTPUT_NAME "upb-utf8_range")
+ target_include_directories(utf8_range PUBLIC
+ "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/_deps/include>"
+ "$<INSTALL_INTERFACE:include>")
+
%(toplevel)s
+ set(UPB_DESCRIPTOR_PROTO "${UPB_HOST_INCLUDE_DIR}/google/protobuf/descriptor.proto")
+ if (UPB_BUILD_CODEGEN)
+ set(UPB_CODEGEN_TARGETS protoc-gen-upb protoc-gen-upbdefs protoc-gen-lua)
+
+ add_executable(protoc-gen-upbdefs
+ ../upbc/common.h
+ ../upbc/common.cc
+ ../upbc/protoc-gen-upbdefs.cc
+ )
+ target_link_libraries(protoc-gen-upbdefs PRIVATE
+ absl::flat_hash_map
+ absl::strings
+ protobuf::libprotobuf
+ protobuf::libprotoc
+ )
+
+ add_executable(protoc-gen-upb
+ ../upbc/common.h
+ ../upbc/common.cc
+ ../upbc/protoc-gen-upb.cc
+ )
+ add_dependencies(protoc-gen-upb mini_table upb)
+ target_link_libraries(protoc-gen-upb PRIVATE
+ mini_table
+ port
+ upb
+ absl::flat_hash_map
+ absl::flat_hash_set
+ absl::strings
+ protobuf::libprotobuf
+ protobuf::libprotoc
+ )
+
+ add_executable(protoc-gen-lua
+ ../upb/bindings/lua/upbc.cc
+ )
+ target_link_libraries(protoc-gen-lua PRIVATE
+ absl::strings
+ protobuf::libprotobuf
+ protobuf::libprotoc
+ )
+
+ set(PROTOC_PROGRAM "\$<TARGET_FILE:protobuf::protoc>")
+ set(PROTOC_GEN_UPB_PROGRAM "\$<TARGET_FILE:protoc-gen-upb>")
+ set(PROTOC_GEN_UPBDEFS_PROGRAM "\$<TARGET_FILE:protoc-gen-upbdefs>")
+ set(PROTOC_GEN_UPBLUA_PROGRAM "\$<TARGET_FILE:protoc-gen-lua>")
+ else()
+ find_program(PROTOC_PROGRAM protoc)
+ find_program(PROTOC_GEN_UPB_PROGRAM protoc-gen-upb)
+ find_program(PROTOC_GEN_UPBDEFS_PROGRAM protoc-gen-upbdefs)
+ find_program(PROTOC_GEN_UPBLUA_PROGRAM protoc-gen-lua)
+ endif()
+
+ set(UPB_DESCRIPTOR_SOURCES
+ "${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/descriptor.upb.h"
+ "${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/descriptor.upb.c"
+ "${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/descriptor.upbdefs.h"
+ "${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/descriptor.upbdefs.c"
+ )
+
+ unset(UPB_DESCRIPTOR_UPB_WELL_KNOWN_TYPES_LUAS)
+ unset(UPB_DESCRIPTOR_UPB_WELL_KNOWN_TYPES_HEADERS)
+ unset(UPB_DESCRIPTOR_UPB_WELL_KNOWN_TYPES_SOURCES)
+ unset(UPB_DESCRIPTOR_UPB_WELL_KNOWN_TYPES_PROTO_FILES)
+ set(UPB_DESCRIPTOR_UPB_WELL_KNOWN_TYPES_PROTO_NAMES any api duration empty
+ field_mask source_context struct timestamp type wrappers)
+ foreach(PROTO_NAME IN LISTS UPB_DESCRIPTOR_UPB_WELL_KNOWN_TYPES_PROTO_NAMES)
+ list(APPEND UPB_DESCRIPTOR_UPB_WELL_KNOWN_TYPES_PROTO_FILES
+ "${UPB_HOST_INCLUDE_DIR}/google/protobuf/${PROTO_NAME}.proto")
+ list(APPEND UPB_DESCRIPTOR_UPB_WELL_KNOWN_TYPES_LUAS
+ "${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/${PROTO_NAME}_pb.lua")
+ list(APPEND UPB_DESCRIPTOR_UPB_WELL_KNOWN_TYPES_HEADERS
+ "${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/${PROTO_NAME}.upb.h"
+ "${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/${PROTO_NAME}.upbdefs.h")
+ list(APPEND UPB_DESCRIPTOR_UPB_WELL_KNOWN_TYPES_SOURCES
+ "${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/${PROTO_NAME}.upb.c"
+ "${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/${PROTO_NAME}.upbdefs.c")
+ endforeach()
+
+ add_custom_command(
+ OUTPUT ${UPB_DESCRIPTOR_SOURCES}
+ "${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/descriptor_pb.lua"
+ ${UPB_DESCRIPTOR_UPB_WELL_KNOWN_TYPES_LUAS}
+ ${UPB_DESCRIPTOR_UPB_WELL_KNOWN_TYPES_HEADERS}
+ ${UPB_DESCRIPTOR_UPB_WELL_KNOWN_TYPES_SOURCES}
+ DEPENDS "${UPB_DESCRIPTOR_PROTO}" ${UPB_DESCRIPTOR_UPB_WELL_KNOWN_TYPES_PROTO_FILES}
+ COMMAND
+ "${PROTOC_PROGRAM}"
+ "-I${UPB_HOST_INCLUDE_DIR}"
+ "--plugin=protoc-gen-upb=${PROTOC_GEN_UPB_PROGRAM}"
+ "--plugin=protoc-gen-upbdefs=${PROTOC_GEN_UPBDEFS_PROGRAM}"
+ "--plugin=protoc-gen-lua=${PROTOC_GEN_UPBLUA_PROGRAM}"
+ "--upb_out=${CMAKE_CURRENT_BINARY_DIR}"
+ "--upbdefs_out=${CMAKE_CURRENT_BINARY_DIR}"
+ "--lua_out=${CMAKE_CURRENT_BINARY_DIR}"
+ "${UPB_DESCRIPTOR_PROTO}" ${UPB_DESCRIPTOR_UPB_WELL_KNOWN_TYPES_PROTO_FILES}
+ )
+
+ target_sources(descriptor_upb_proto PRIVATE ${UPB_DESCRIPTOR_SOURCES})
+ target_link_libraries(descriptor_upb_proto PUBLIC upb)
+
+ add_library(well_known_types ${UPB_DESCRIPTOR_UPB_WELL_KNOWN_TYPES_HEADERS}
+ ${UPB_DESCRIPTOR_UPB_WELL_KNOWN_TYPES_SOURCES})
+ set_target_properties(well_known_types PROPERTIES OUTPUT_NAME "upb-well_known_types")
+ target_link_libraries(well_known_types PUBLIC upb)
+
+ include(GNUInstallDirs)
+ install(
+ DIRECTORY ../upb
+ DESTINATION include
+ FILES_MATCHING
+ PATTERN "*.h"
+ PATTERN "*.hpp"
+ PATTERN "*.inc"
+ PATTERN "*.int.h"
+ )
+ install(
+ FILES
+ "${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/descriptor.upb.h"
+ "${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/descriptor.upbdefs.h"
+ "${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/descriptor_pb.lua"
+ ${UPB_DESCRIPTOR_UPB_WELL_KNOWN_TYPES_LUAS}
+ ${UPB_DESCRIPTOR_UPB_WELL_KNOWN_TYPES_HEADERS}
+ DESTINATION include/google/protobuf
+ )
+ install(
+ FILES
+ "${CMAKE_CURRENT_BINARY_DIR}/_deps/include/upb/third_party/utf8_range/utf8_range.h"
+ DESTINATION include/upb/third_party/utf8_range
+ )
+ install(
+ DIRECTORY ../upb/bindings/lua/
+ DESTINATION share/upb/upb/bindings/lua
+ )
+ target_include_directories(upb PUBLIC $<INSTALL_INTERFACE:include>)
+ install(TARGETS
+ descriptor_upb_proto
+ well_known_types
+ utf8_range
+ %(export_targets)s
+ ${UPB_CODEGEN_TARGETS}
+ EXPORT upb-config
+ )
+ install(EXPORT upb-config NAMESPACE upb:: DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/upb")
+
""")
data = {}
diff --git a/upb/bindings/lua/def.c b/upb/bindings/lua/def.c
index 602dbaf..699c3c2 100644
--- a/upb/bindings/lua/def.c
+++ b/upb/bindings/lua/def.c
@@ -617,7 +617,7 @@ const upb_FileDef* lupb_FileDef_check(lua_State* L, int narg) {
static int lupb_FileDef_Dependency(lua_State* L) {
const upb_FileDef* f = lupb_FileDef_check(L, 1);
- int index = luaL_checkint(L, 2);
+ int index = luaL_checkinteger(L, 2);
const upb_FileDef* dep = upb_FileDef_Dependency(f, index);
lupb_wrapper_pushwrapper(L, 1, dep, LUPB_FILEDEF);
return 1;
@@ -631,7 +631,7 @@ static int lupb_FileDef_DependencyCount(lua_State* L) {
static int lupb_FileDef_enum(lua_State* L) {
const upb_FileDef* f = lupb_FileDef_check(L, 1);
- int index = luaL_checkint(L, 2);
+ int index = luaL_checkinteger(L, 2);
const upb_EnumDef* e = upb_FileDef_TopLevelEnum(f, index);
lupb_wrapper_pushwrapper(L, 1, e, LUPB_ENUMDEF);
return 1;
@@ -645,7 +645,7 @@ static int lupb_FileDef_enumcount(lua_State* L) {
static int lupb_FileDef_msg(lua_State* L) {
const upb_FileDef* f = lupb_FileDef_check(L, 1);
- int index = luaL_checkint(L, 2);
+ int index = luaL_checkinteger(L, 2);
const upb_MessageDef* m = upb_FileDef_TopLevelMessage(f, index);
lupb_wrapper_pushwrapper(L, 1, m, LUPB_MSGDEF);
return 1;
diff --git a/upb/bindings/lua/upb.c b/upb/bindings/lua/upb.c
index 3d59cdd..8e7333e 100644
--- a/upb/bindings/lua/upb.c
+++ b/upb/bindings/lua/upb.c
@@ -61,11 +61,13 @@
/* Lua compatibility code *****************************************************/
/* Shims for upcoming Lua 5.3 functionality. */
+#if LUA_VERSION_NUM < 503
static bool lua_isinteger(lua_State* L, int argn) {
LUPB_UNUSED(L);
LUPB_UNUSED(argn);
return false;
}
+#endif
/* Utility functions **********************************************************/
diff --git a/upb/bindings/lua/upbc.cc b/upb/bindings/lua/upbc.cc
index 78e1473..2d353b0 100644
--- a/upb/bindings/lua/upbc.cc
+++ b/upb/bindings/lua/upbc.cc
@@ -79,7 +79,7 @@ static void PrintString(int max_cols, absl::string_view* str,
} else if (ch == '\'') {
printer->PrintRaw("\\'");
max_cols--;
- } else if (isprint(ch)) {
+ } else if (isprint(static_cast<int>(static_cast<unsigned char>(ch)))) {
printer->WriteRaw(&ch, 1);
max_cols--;
} else {
diff --git a/upb/internal/decode.h b/upb/internal/decode.h
index 708874c..604df7e 100644
--- a/upb/internal/decode.h
+++ b/upb/internal/decode.h
@@ -38,7 +38,7 @@
#include "upb/decode.h"
#include "upb/internal/upb.h"
#include "upb/msg_internal.h"
-#include "third_party/utf8_range/utf8_range.h"
+#include "upb/third_party/utf8_range/utf8_range.h"
/* Must be last. */
#include "upb/port_def.inc"