diff --git a/upbc/BUILD b/upbc/BUILD index 309d363319..419ada371a 100644 --- a/upbc/BUILD +++ b/upbc/BUILD @@ -104,7 +104,6 @@ cc_binary( "//:message_accessors", "//:mini_table", "//:port", - "//upbc:upbdev", ], ) @@ -206,6 +205,21 @@ bootstrap_cc_library( ], ) +cc_library( + name = "upbdev_ffi_headers", + srcs = [ + "upbdev.h", + ], + copts = ["-DUPB_BUILD_API"], + visibility = ["//visibility:public"], + deps = [ + ":upbdev", + "//:base", + "//:mem", + "//:port", + ], +) + cc_library( name = "upbdev", srcs = [ @@ -217,7 +231,7 @@ cc_library( "upbdev.h", ], copts = UPB_DEFAULT_COPTS, - visibility = ["//visibility:public"], + visibility = ["//visibility:private"], deps = [ ":code_generator_request_upb_proto", ":code_generator_request_upb_proto_reflection", @@ -232,6 +246,21 @@ cc_library( ], ) +cc_binary( + name = "lib/libupbdev.so", + linkshared = 1, + visibility = ["//visibility:private"], + deps = [ + ":upbdev", + ], +) + +cc_library( + name = "libupbdev", + srcs = [":lib/libupbdev.so"], + visibility = ["//visibility:public"], +) + bootstrap_cc_binary( name = "protoc-gen-upb", srcs = ["protoc-gen-upb.cc"], diff --git a/upbc/upbc_so.c b/upbc/upbc_so.c index 9854babb2a..8858242f73 100644 --- a/upbc/upbc_so.c +++ b/upbc/upbc_so.c @@ -36,7 +36,6 @@ #include "upb/message/accessors.h" #include "upb/message/message.h" #include "upb/mini_table/decode.h" -#include "upbc/upbdev.h" // Must be last. #include "upb/port/def.inc" diff --git a/upbc/upbdev.c b/upbc/upbdev.c index 1ac30eab64..a88fedb252 100644 --- a/upbc/upbdev.c +++ b/upbc/upbdev.c @@ -92,10 +92,9 @@ upb_StringView upbdev_ProcessInput(const char* buf, size_t size, const upbc_CodeGeneratorRequest* outer_request = upbc_MakeCodeGeneratorRequest(inner_request, arena, status); - if (upb_Status_IsOk(status)) - out = upbc_JsonEncode(outer_request, arena, status); + if (!upb_Status_IsOk(status)) return out; - return out; + return upbc_JsonEncode(outer_request, arena, status); } upb_StringView upbdev_ProcessOutput(const char* buf, size_t size, @@ -126,3 +125,7 @@ void upbdev_ProcessStdout(const char* buf, size_t size, upb_Arena* arena, } } } + +upb_Arena* upbdev_Arena_New() { return upb_Arena_New(); } + +void upbdev_Status_Clear(upb_Status* status) { upb_Status_Clear(status); } diff --git a/upbc/upbdev.h b/upbc/upbdev.h index b8c6b2deab..d6e8d62761 100644 --- a/upbc/upbdev.h +++ b/upbc/upbdev.h @@ -54,6 +54,11 @@ UPB_API upb_StringView upbdev_ProcessOutput(const char* buf, size_t size, UPB_API void upbdev_ProcessStdout(const char* buf, size_t size, upb_Arena* arena, upb_Status* status); +// The following wrappers allow the protoc plugins to call the above functions +// without pulling in the entire pb_runtime library. +UPB_API upb_Arena* upbdev_Arena_New(); +UPB_API void upbdev_Status_Clear(upb_Status* status); + #ifdef __cplusplus } /* extern "C" */ #endif