diff --git a/Dockerfile b/Dockerfile index f7c92df8..cc1836ae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,6 @@ ARG debian=buster ARG go_version +ARG swift_version ARG grpc_version ARG grpc_gateway_version ARG grpc_java_version @@ -89,8 +90,8 @@ RUN go get -u github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc RUN go get -u github.com/micro/micro/cmd/protoc-gen-micro -RUN go get -d github.com/envoyproxy/protoc-gen-validate -RUN make -C /go/src/github.com/envoyproxy/protoc-gen-validate/ build +# RUN go get -d github.com/envoyproxy/protoc-gen-validate +# RUN make -C /go/src/github.com/envoyproxy/protoc-gen-validate/ build RUN go get -u github.com/mwitkow/go-proto-validators/protoc-gen-govalidators @@ -112,6 +113,16 @@ RUN curl -sSL https://github.com/grpc/grpc-web/releases/download/${grpc_web_vers -o /tmp/grpc_web_plugin && \ chmod +x /tmp/grpc_web_plugin +FROM swift:$swift_version AS build-swift + +ARG grpc_swift_version + +WORKDIR /tmp +RUN git clone --depth 1 -b $grpc_swift_version https://github.com/grpc/grpc-swift.git + +WORKDIR /tmp/grpc-swift +RUN make plugins + FROM debian:$debian-slim AS protoc-all ARG grpc_version @@ -153,6 +164,10 @@ COPY --from=build /tmp/grpc/bazel-bin/external/com_google_protobuf/ /usr/local/b COPY --from=build /tmp/grpc/bazel-bin/src/compiler/ /usr/local/bin/ # Copy protoc java plugin COPY --from=build /tmp/grpc-java/bazel-bin/compiler/ /usr/local/bin/ +# Copy protoc swift plugin +COPY --from=build-swift /tmp/grpc-swift/protoc-gen-swift /usr/local/bin/ +COPY --from=build-swift /tmp/grpc-swift/protoc-gen-grpc-swift /usr/local/bin/ +COPY --from=build-swift /usr/lib/swift/linux/* /usr/lib/swift/linux/ # Copy grpc_cli COPY --from=build /tmp/grpc/bazel-bin/test/cpp/util/ /usr/local/bin/ @@ -164,7 +179,7 @@ COPY --from=build /tmp/protoc-gen-scala /usr/local/bin/ COPY --from=build /go/pkg/mod/github.com/grpc-ecosystem/grpc-gateway/v2@v${grpc_gateway_version}/protoc-gen-openapiv2/options /opt/include/protoc-gen-openapiv2/options/ -COPY --from=build /go/src/github.com/envoyproxy/protoc-gen-validate/ /opt/include/ +# COPY --from=build /go/src/github.com/envoyproxy/protoc-gen-validate/ /opt/include/ COPY --from=build /go/src/github.com/mwitkow/go-proto-validators/ /opt/include/github.com/mwitkow/go-proto-validators/ ADD all/entrypoint.sh /usr/local/bin diff --git a/all/entrypoint.sh b/all/entrypoint.sh index 30b2b482..13533cb1 100755 --- a/all/entrypoint.sh +++ b/all/entrypoint.sh @@ -31,6 +31,8 @@ printUsage() { as surrounding comments." echo " --descr-filename The filename for the descriptor proto when used with -l descriptor_set. Default to descriptor_set.pb" echo " --csharp_opt The options to pass to protoc to customize the csharp code generation." + echo " --swift_opt The options to pass to protoc to customize the swift code generation." + echo " --grpc_swift_opt The options to pass to protoc to customize the swift grpc code generation." echo " --scala_opt The options to pass to protoc to customize the scala code generation." echo " --with-swagger-json-names Use with --with-gateway flag. Generated swagger file will use JSON names instead of protobuf names. (deprecated. Please use --with-openapi-json-names)" @@ -49,7 +51,7 @@ GEN_RBI=false GEN_TYPESCRIPT=false LINT=false LINT_CHECKS="" -SUPPORTED_LANGUAGES=("go" "ruby" "csharp" "java" "python" "objc" "gogo" "php" "node" "web" "cpp" "descriptor_set" "scala") +SUPPORTED_LANGUAGES=("go" "ruby" "csharp" "java" "python" "objc" "swift" "gogo" "php" "node" "web" "cpp" "descriptor_set" "scala") EXTRA_INCLUDES="" OUT_DIR="" GO_SOURCE_RELATIVE="" @@ -62,6 +64,8 @@ DESCR_INCLUDE_IMPORTS=false DESCR_INCLUDE_SOURCE_INFO=false DESCR_FILENAME="descriptor_set.pb" CSHARP_OPT="" +SWIFT_OPT="" +GRPC_SWIFT_OPT="" SCALA_OPT="" OPENAPI_JSON=false JS_OUT="import_style=commonjs" @@ -193,6 +197,16 @@ while test $# -gt 0; do CSHARP_OPT=$1 shift ;; + --swift_opt) + shift + SWIFT_OPT=$1 + shift + ;; + --grpc_swift_opt) + shift + GRPC_SWIFT_OPT=$1 + shift + ;; --scala_opt) shift SCALA_OPT=$1 @@ -369,6 +383,15 @@ plugins=grpc+embedded\ GEN_STRING="$GEN_STRING --csharp_opt=$CSHARP_OPT" fi ;; + "swift") + GEN_STRING="--grpc-swift_out=$OUT_DIR --swift_out=$OUT_DIR" + if [[ ! -z $SWIFT_OPT ]]; then + GEN_STRING="$GEN_STRING --swift_opt=$SWIFT_OPT" + fi + if [[ ! -z $GRPC_SWIFT_OPT ]]; then + GEN_STRING="$GEN_STRING --grpc-swift_opt=$GRPC_SWIFT_OPT" + fi + ;; *) GEN_STRING="--grpc_out=$OUT_DIR --${GEN_LANG}_out=$OUT_DIR --plugin=protoc-gen-grpc=`which grpc_${PLUGIN_LANG}_plugin`" ;; diff --git a/all/test.sh b/all/test.sh index 3da11b58..79a85593 100755 --- a/all/test.sh +++ b/all/test.sh @@ -1,6 +1,6 @@ #!/bin/bash -e -LANGS=("go" "ruby" "csharp" "java" "python" "objc" "node" "gogo" "php" "cpp" "descriptor_set" "web") +LANGS=("go" "ruby" "csharp" "java" "python" "objc" "swift" "node" "gogo" "php" "cpp" "descriptor_set" "web") CONTAINER=${CONTAINER} diff --git a/build.sh b/build.sh index 0295a390..e602dc83 100755 --- a/build.sh +++ b/build.sh @@ -10,6 +10,8 @@ for build in ${BUILDS[@]}; do --build-arg grpc_version=${GRPC_VERSION} \ --build-arg grpc_java_version=${GRPC_JAVA_VERSION} \ --build-arg grpc_web_version=${GRPC_WEB_VERSION} \ + --build-arg grpc_swift_version=${GRPC_SWIFT_VERSION} \ + --build-arg swift_version=${SWIFT_VERSION} \ --build-arg grpc_gateway_version=${GRPC_GATEWAY_VERSION} \ --build-arg go_version=${GO_VERSION} \ --build-arg uber_prototool_version=${UBER_PROTOTOOL_VERSION} \ diff --git a/variables.sh b/variables.sh index 9aa34d79..bf39fa2d 100755 --- a/variables.sh +++ b/variables.sh @@ -10,6 +10,8 @@ GO_VERSION=${GO_VERSION:-1.14} GRPC_VERSION=${GRPC_VERSION:-1.37} GRPC_JAVA_VERSION=${GRPC_JAVA_VERSION:-1.37} GRPC_WEB_VERSION=${GRPC_WEB_VERSION:-1.2.1} +GRPC_SWIFT_VERSION=${GRPC_SWIFT_VERSION:-1.4.2} +SWIFT_VERSION=${SWIFT_VERSION:-5.5.0} GRPC_GATEWAY_VERSION=${GRPC_GATEWAY_VERSION:-2.0.1} UBER_PROTOTOOL_VERSION=${UBER_PROTOTOOL_VERSION:-1.3.0} SCALA_PB_VERSION=${SCALA_PB_VERSION:-0.11.0}