From 39753a38ee8d531f49b73c603db5e23e59699cad Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Thu, 30 Apr 2020 21:27:32 -0700 Subject: [PATCH] Fix nginx build after internal absl change --- Makefile | 16 ++++++++++------ net/grpc/gateway/codec/grpc_web_encoder.cc | 14 +++++++------- net/grpc/gateway/docker/nginx/Dockerfile | 12 +++++++++++- net/grpc/gateway/docker/prereqs/Dockerfile | 1 + 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 63816b9..fd4b162 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,7 @@ PROTOC := $(PROTO_SRC)/protoc GRPC_INC := $(ROOT_DIR)/third_party/grpc/include GRPC_SRC := $(ROOT_DIR)/third_party/grpc GRPC_LIB := $(ROOT_DIR)/third_party/grpc/libs/opt +ABSL_SRC := $(ROOT_DIR)/third_party/grpc/third_party/abseil-cpp all: clean package_static @@ -30,16 +31,19 @@ protos: --cpp_out="$(ROOT_DIR)/google/rpc" NGINX_DIR := third_party/nginx -NGINX_LD_OPT := -L"$(PROTO_LIB)" -L"$(GRPC_LIB)" -lgrpc++ \ --lgrpc -lprotobuf -lpthread -ldl -lrt -lstdc++ -lm +NGINX_LD_OPT := -L"$(PROTO_LIB)" -L"$(GRPC_LIB)" \ +-lgrpc++ -lgrpc -lprotobuf \ +-labsl_str_format_internal -labsl_int128 \ +-lpthread -ldl -lrt -lstdc++ -lm ifeq ($(OS), Darwin) NGINX_LD_OPT := -L"$(PROTO_LIB)" -L"$(GRPC_LIB)" -lgrpc++ \ -lgrpc -lprotobuf -lpthread -lstdc++ -lm endif NGINX_STATIC_LD_OPT := -L"$(PROTO_LIB)" -L"$(GRPC_LIB)" \ --l:libgrpc++.a -l:libgrpc.a -l:libprotobuf.a -lpthread -ldl \ --lrt -lstdc++ -lm +-l:libgrpc++.a -l:libgrpc.a -l:libprotobuf.a \ +-labsl_str_format_internal -labsl_int128 \ +-lpthread -ldl -lrt -lstdc++ -lm ifeq ($(OS), Darwin) NGINX_STATIC_LD_OPT := $(NGINX_LD_OPT) endif @@ -50,7 +54,7 @@ nginx_config: --with-http_ssl_module \ --with-http_v2_module \ --with-cc-opt="-I /usr/local/include -I $(ROOT_DIR) -I $(PROTO_INC) -I $(PROTO_SRC) \ --I $(GRPC_INC) -I $(GRPC_SRC)" \ +-I $(GRPC_INC) -I $(GRPC_SRC) -I $(ABSL_SRC)" \ --with-ld-opt="$(NGINX_LD_OPT)" \ --with-openssl="$(ROOT_DIR)/third_party/openssl" \ --add-module="$(ROOT_DIR)/net/grpc/gateway/nginx" @@ -61,7 +65,7 @@ nginx_config_static: --with-http_ssl_module \ --with-http_v2_module \ --with-cc-opt="-I /usr/local/include -I $(ROOT_DIR) -I $(PROTO_INC) -I $(PROTO_SRC) \ --I $(GRPC_INC) -I $(GRPC_SRC)" \ +-I $(GRPC_INC) -I $(GRPC_SRC) -I $(ABSL_SRC)" \ --with-ld-opt="$(NGINX_STATIC_LD_OPT)" \ --add-module="$(ROOT_DIR)/net/grpc/gateway/nginx" diff --git a/net/grpc/gateway/codec/grpc_web_encoder.cc b/net/grpc/gateway/codec/grpc_web_encoder.cc index 7ebe7e9..e78d251 100644 --- a/net/grpc/gateway/codec/grpc_web_encoder.cc +++ b/net/grpc/gateway/codec/grpc_web_encoder.cc @@ -23,6 +23,7 @@ #include #include "net/grpc/gateway/runtime/types.h" +#include "third_party/absl/strings/str_format.h" #include "third_party/grpc/include/grpcpp/support/byte_buffer.h" #include "third_party/grpc/include/grpcpp/support/slice.h" @@ -79,10 +80,10 @@ void GrpcWebEncoder::EncodeStatus(const grpc::Status& status, // Encodes GRPC status. size_t grpc_status_size = - snprintf(nullptr, 0, kGrpcStatus, status.error_code()); + absl::SNPrintF(nullptr, 0, kGrpcStatus, status.error_code()); grpc_slice grpc_status = grpc_slice_malloc(grpc_status_size + 1); - snprintf(reinterpret_cast(GPR_SLICE_START_PTR(grpc_status)), - grpc_status_size + 1, kGrpcStatus, status.error_code()); + absl::SNPrintF(reinterpret_cast(GPR_SLICE_START_PTR(grpc_status)), + grpc_status_size + 1, kGrpcStatus, status.error_code()); GPR_SLICE_SET_LENGTH(grpc_status, grpc_status_size); buffer.push_back(Slice(grpc_status, Slice::STEAL_REF)); length += grpc_status_size; @@ -90,11 +91,10 @@ void GrpcWebEncoder::EncodeStatus(const grpc::Status& status, // Encodes GRPC message. if (!status.error_message().empty()) { size_t grpc_message_size = - snprintf(nullptr, 0, kGrpcMessage, status.error_message().c_str()); + absl::SNPrintF(nullptr, 0, kGrpcMessage, status.error_message()); grpc_slice grpc_message = grpc_slice_malloc(grpc_message_size + 1); - snprintf(reinterpret_cast(GPR_SLICE_START_PTR(grpc_message)), - grpc_message_size + 1, kGrpcMessage, - status.error_message().c_str()); + absl::SNPrintF(reinterpret_cast(GPR_SLICE_START_PTR(grpc_message)), + grpc_message_size + 1, kGrpcMessage, status.error_message()); GPR_SLICE_SET_LENGTH(grpc_message, grpc_message_size); buffer.push_back(Slice(grpc_message, Slice::STEAL_REF)); length += grpc_message_size; diff --git a/net/grpc/gateway/docker/nginx/Dockerfile b/net/grpc/gateway/docker/nginx/Dockerfile index 8c5ccde..8874732 100644 --- a/net/grpc/gateway/docker/nginx/Dockerfile +++ b/net/grpc/gateway/docker/nginx/Dockerfile @@ -15,10 +15,20 @@ FROM grpcweb/grpc-base RUN apt-get -qq install -y \ - zip + cmake zip WORKDIR /github/grpc-web +RUN cd third_party/grpc/third_party && \ + ln -s ./abseil-cpp/absl absl + +RUN cd third_party/grpc/third_party/abseil-cpp && \ + git remote update && \ + git checkout df3ea78 -b 20200225.1 && \ + cmake . && \ + make && \ + make install + RUN cd ./net/grpc/gateway/examples/echo && \ sed -i 's/localhost:9090/echo-server:9090/g' nginx.conf diff --git a/net/grpc/gateway/docker/prereqs/Dockerfile b/net/grpc/gateway/docker/prereqs/Dockerfile index b05ce97..add3530 100644 --- a/net/grpc/gateway/docker/prereqs/Dockerfile +++ b/net/grpc/gateway/docker/prereqs/Dockerfile @@ -27,6 +27,7 @@ RUN git checkout . && \ git checkout third_party && \ ./scripts/init_submodules.sh +COPY ./Makefile ./Makefile COPY ./javascript ./javascript COPY ./net ./net COPY ./packages ./packages