Skip to content

Commit 1f7a586

Browse files
authored
Improve C# support, set GRPC_CSHARP_VERSION=1.28.1 (#15)
* Update versions * GRPC uses cmake now * linux-headers is necessary as abseil is used as dependency * Use cmake instead of make (deprecated) Signed-off-by: Kraemer, Benjamin <benjamin.kraemer@jungheinrich.de> * Use separate protoc for C# Signed-off-by: Kraemer, Benjamin <benjamin.kraemer@jungheinrich.de> * Improved argument check Signed-off-by: Kraemer, Benjamin <benjamin.kraemer@jungheinrich.de> * Add review comments * Disable unused plugins * Use generic version for copying protoc Signed-off-by: Kraemer, Benjamin <benjamin.kraemer@jungheinrich.de>
1 parent a689380 commit 1f7a586

File tree

2 files changed

+64
-19
lines changed

2 files changed

+64
-19
lines changed

Dockerfile

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,72 @@ ARG ALPINE_VERSION=3.10
22
ARG GO_VERSION=1.13.4
33
ARG GRPC_GATEWAY_VERSION=1.12.2
44
ARG GRPC_JAVA_VERSION=1.26.0
5+
ARG GRPC_CSHARP_VERSION=1.28.1
56
ARG GRPC_VERSION=1.26.0
67
ARG PROTOC_GEN_GO_VERSION=1.3.2
78
ARG PROTOC_GEN_GOGO_VERSION=ba06b47c162d49f2af050fb4c75bcbc86a159d5c
89
ARG PROTOC_GEN_LINT_VERSION=0.2.1
910
ARG UPX_VERSION=3.96
1011

1112

12-
FROM alpine:${ALPINE_VERSION} as protoc_builder
13-
RUN apk add --no-cache build-base curl automake autoconf libtool git zlib-dev
14-
15-
RUN mkdir -p /out
13+
FROM alpine:${ALPINE_VERSION} as protoc_base
14+
RUN apk add --no-cache build-base curl cmake autoconf libtool git zlib-dev linux-headers && \
15+
mkdir -p /out
1616

1717

18+
FROM protoc_base as protoc_builder
1819
ARG GRPC_VERSION
19-
RUN git clone --recursive --depth=1 -b v${GRPC_VERSION} https://github.com/grpc/grpc.git /grpc && \
20+
RUN apk add --no-cache automake && \
21+
git clone --recursive --depth=1 -b v${GRPC_VERSION} https://github.com/grpc/grpc.git /grpc && \
2022
ln -s /grpc/third_party/protobuf /protobuf && \
2123
cd /protobuf && \
2224
./autogen.sh && \
2325
./configure --prefix=/usr --enable-static=no && \
24-
make && \
25-
make check && \
26-
make install && \
27-
make install DESTDIR=/out && \
26+
make -j4 && \
27+
make -j4 check && \
28+
make -j4 install && \
29+
make -j4 install DESTDIR=/out && \
2830
cd /grpc && \
29-
make install-plugins prefix=/out/usr
31+
make -j4 install-plugins prefix=/out/usr
3032

3133
ARG GRPC_JAVA_VERSION
3234
RUN mkdir -p /grpc-java && \
3335
curl -sSL https://api.github.com/repos/grpc/grpc-java/tarball/v${GRPC_JAVA_VERSION} | tar xz --strip 1 -C /grpc-java && \
3436
cd /grpc-java && \
3537
g++ \
3638
-I. -I/protobuf/src \
39+
-I/out/usr/include \
3740
compiler/src/java_plugin/cpp/*.cpp \
38-
-L/protobuf/src/.libs \
41+
-L/out/usr/lib \
42+
-L/out/usr/lib64 \
3943
-lprotoc -lprotobuf -lpthread --std=c++0x -s \
4044
-o protoc-gen-grpc-java && \
41-
install -Ds protoc-gen-grpc-java /out/usr/bin/protoc-gen-grpc-java
45+
install -Ds protoc-gen-grpc-java /out/usr/bin/protoc-gen-grpc-java && \
46+
rm -Rf /grpc-java && \
47+
rm -Rf /grpc
48+
49+
50+
FROM protoc_base AS protoc_cs_builder
51+
ARG GRPC_CSHARP_VERSION
52+
RUN git clone --recursive --depth=1 -b v${GRPC_CSHARP_VERSION} https://github.com/grpc/grpc.git /grpc && \
53+
ln -s /grpc/third_party/protobuf /protobuf && \
54+
mkdir -p /grpc/cmake/build && \
55+
cd /grpc/cmake/build && \
56+
cmake \
57+
-DCMAKE_BUILD_TYPE=Release \
58+
-DgRPC_BUILD_TESTS=OFF \
59+
-gRPC_BUILD_GRPC_CPP_PLUGIN=OFF \
60+
-gRPC_BUILD_GRPC_NODE_PLUGIN=OFF \
61+
-gRPC_BUILD_GRPC_OBJECTIVE_C_PLUGIN=OFF \
62+
-gRPC_BUILD_GRPC_PHP_PLUGIN=OFF \
63+
-gRPC_BUILD_GRPC_PYTHON_PLUGIN=OFF \
64+
-gRPC_BUILD_GRPC_RUBY_PLUGIN=OFF \
65+
-DgRPC_INSTALL=ON \
66+
-DCMAKE_INSTALL_PREFIX=/out/usr \
67+
../.. && \
68+
make -j4 install && \
69+
rm -Rf /grpc
70+
4271

4372
FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} as go_builder
4473
RUN apk add --no-cache build-base curl git
@@ -84,21 +113,27 @@ RUN mkdir -p ${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway && \
84113
install -D $(find ./third_party/googleapis/google/rpc -name '*.proto') -t /out/usr/include/google/rpc
85114

86115

87-
88116
FROM alpine:${ALPINE_VERSION} as packer
89117
RUN apk add --no-cache curl
90118

91119
ARG UPX_VERSION
92120
RUN mkdir -p /upx && curl -sSL https://github.com/upx/upx/releases/download/v${UPX_VERSION}/upx-${UPX_VERSION}-amd64_linux.tar.xz | tar xJ --strip 1 -C /upx && \
93121
install -D /upx/upx /usr/local/bin/upx
94122

123+
# Use all output including headers and protoc from protoc_builder
95124
COPY --from=protoc_builder /out/ /out/
125+
# Use protoc and plugin from protoc_cs_builder
126+
COPY --from=protoc_cs_builder /out/usr/bin/protoc-* /out/usr/bin/protoc-csharp
127+
COPY --from=protoc_cs_builder /out/usr/bin/grpc_csharp_plugin /out/usr/bin/grpc_csharp_plugin
128+
# Integrate all output from go_builder
96129
COPY --from=go_builder /out/ /out/
130+
97131
RUN upx --lzma \
98132
/out/usr/bin/grpc_* \
99133
/out/usr/bin/protoc-gen-*
100134
RUN find /out -name "*.a" -delete -or -name "*.la" -delete
101135

136+
102137
FROM alpine:${ALPINE_VERSION}
103138
LABEL maintainer="The Jaeger Authors"
104139
COPY --from=packer /out/ /

protoc-wrapper

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env bash
22
c_out=""
3+
csharp_out=""
34
includes=()
45
outs=()
56
args=()
@@ -10,6 +11,14 @@ for arg in $@; do
1011
c_out=${arg}
1112
shift
1213
;;
14+
--csharp_out=*)
15+
csharp_out=${arg}
16+
shift
17+
;;
18+
--grpc-csharp_out=*)
19+
csharp_out=${arg}
20+
shift
21+
;;
1322
--*_out=*)
1423
outs+=(${arg})
1524
shift
@@ -31,13 +40,14 @@ fi
3140

3241
protoc_cmd="protoc ${includes[@]} ${outs[@]} ${args[@]}"
3342
protoc_c_cmd="protoc-c ${includes[@]} ${c_out} ${args[@]}"
43+
protoc_csharp_cmd="protoc-csharp ${includes[@]} ${csharp_out} ${args[@]}"
3444

3545
if [ ${c_out} ]; then
36-
if [ ${#outs[@]} -eq 0 ]; then
37-
# only --c_out specified, no need to call `protoc`
38-
exec ${protoc_c_cmd}
39-
fi
4046
${protoc_c_cmd} || exit 1
41-
exec ${protoc_cmd}
4247
fi
43-
exec ${protoc_cmd}
48+
if [ ${csharp_out} ]; then
49+
${protoc_csharp_cmd} || exit 1
50+
fi
51+
if [ ${#outs[@]} -gt 0 ]; then
52+
exec ${protoc_cmd}
53+
fi

0 commit comments

Comments
 (0)