Debian Codegraph @

script/setup/install-protobuf

raw symbols SCIP
1 #!/usr/bin/env bash
2
3 # Copyright The containerd Authors.
4
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8
9 # http://www.apache.org/licenses/LICENSE-2.0
10
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17
18 #
19 # Downloads and installs protobuf
20 #
21 set -eu -o pipefail
22
23 PROTOBUF_VERSION=3.20.1
24 PROTOBUF_DIR=$(mktemp -d)
25
26 # Use `go tool dist list` for the full list of targets
27 TARGET="$(go env GOOS)-$(go env GOARCH)"
28 TARGET_ORIG=$TARGET
29
30 # Fix up OS/ARCH to get proper download link for https://github.com/protocolbuffers/protobuf/releases
31
32 # Darwin
33 TARGET=${TARGET/darwin-amd64/osx-x86_64}
34 TARGET=${TARGET/darwin-arm64/osx-aarch_64}
35
36 # Windows
37 TARGET=${TARGET/windows-amd64/win64}
38 TARGET=${TARGET/windows-386/win32}
39
40 # Linux
41 TARGET=${TARGET/linux-386/linux-x86_32}
42 TARGET=${TARGET/linux-amd64/linux-x86_64}
43 TARGET=${TARGET/linux-arm64/linux-aarch_64}
44 TARGET=${TARGET/linux-ppc64le/linux-ppcle_64}
45
46 if [[ $TARGET != $TARGET_ORIG ]]
47 then
48 wget -O "$PROTOBUF_DIR/protobuf" "https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOBUF_VERSION/protoc-$PROTOBUF_VERSION-$TARGET.zip"
49 unzip "$PROTOBUF_DIR/protobuf" -d /usr/local
50 else
51 # Build from source
52 wget -O "$PROTOBUF_DIR/protobuf" "https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOBUF_VERSION/protobuf-cpp-$PROTOBUF_VERSION.zip"
53 unzip "$PROTOBUF_DIR/protobuf" -d /usr/src/protobuf
54 cd "/usr/src/protobuf/protobuf-$PROTOBUF_VERSION"
55 ./autogen.sh
56 ./configure --disable-shared
57 make
58 make check
59 make install
60 ldconfig
61 fi
62
63 rm -rf "$PROTOBUF_DIR"
64
65 # Download status.proto. grpc repos' one seems copied from
66 # https://github.com/googleapis/googleapis/blob/master/google/rpc/status.proto,
67 # but we use grpc's since the repos has tags/releases.
68 mkdir -p /usr/local/include/google/rpc
69 curl \
70 -L https://raw.githubusercontent.com/grpc/grpc/v1.45.2/src/proto/grpc/status/status.proto \
71 -o /usr/local/include/google/rpc/status.proto