Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Swift language support #219

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ARG debian=buster
ARG go_version
ARG swift_version
ARG grpc_version
ARG grpc_gateway_version
ARG grpc_java_version
Expand Down Expand Up @@ -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

Expand All @@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems as though Apple has an official plugin for this now: https://github.com/apple/swift-protobuf

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not quite the same thing. swift-protobuf is a package that can [de]serialize protobuf-encoded messages. grpc-swift is the grpc runtime, allowing to implement grpc clients and servers in Swift.


WORKDIR /tmp/grpc-swift
RUN make plugins

FROM debian:$debian-slim AS protoc-all

ARG grpc_version
Expand Down Expand Up @@ -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/

Expand All @@ -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
Expand Down
25 changes: 24 additions & 1 deletion all/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand All @@ -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=""
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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`"
;;
Expand Down
2 changes: 1 addition & 1 deletion all/test.sh
Original file line number Diff line number Diff line change
@@ -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}

Expand Down
2 changes: 2 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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} \
Expand Down
2 changes: 2 additions & 0 deletions variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down