• Home
Name Date Size #Lines LOC

..--

DockerfileD03-May-20242.1 KiB5648

README.mdD03-May-20245.1 KiB162123

build-protoc.shD03-May-20249 KiB295222

build-zip.shD03-May-20243.9 KiB12198

pom.xmlD03-May-20245.3 KiB145139

scl-enable-devtoolset.shD03-May-2024211 1410

README.md

1# Build scripts that publish pre-compiled protoc artifacts
2``protoc`` is the compiler for ``.proto`` files. It generates language bindings
3for the messages and/or RPC services from ``.proto`` files.
4
5Because ``protoc`` is a native executable, the scripts under this directory
6build and publish a ``protoc`` executable (a.k.a. artifact) to Maven
7repositories. The artifact can be used by build automation tools so that users
8would not need to compile and install ``protoc`` for their systems.
9
10If you would like us to publish protoc artifact for a new platform, please send
11us a pull request to add support for the new platform. You would need to change
12the following files:
13
14* [build-protoc.sh](build-protoc.sh): script to cross-build the protoc for your
15  platform.
16* [pom.xml](pom.xml): script to upload artifacts to maven.
17* [build-zip.sh](build-zip.sh): script to package published maven artifacts in
18  our release page.
19
20## Maven Location
21The published protoc artifacts are available on Maven here:
22
23    https://repo.maven.apache.org/maven2/com/google/protobuf/protoc/
24
25## Versioning
26The version of the ``protoc`` artifact must be the same as the version of the
27Protobuf project.
28
29## Artifact name
30The name of a published ``protoc`` artifact is in the following format:
31``protoc-<version>-<os>-<arch>.exe``, e.g., ``protoc-3.6.1-linux-x86_64.exe``.
32
33Note that artifacts for linux/macos also have the `.exe` suffix but they are
34not windows binaries.
35
36## System requirement
37Install [Apache Maven](http://maven.apache.org/) if you don't have it.
38
39The scripts only work under Unix-like environments, e.g., Linux, MacOSX, and
40Cygwin or MinGW for Windows. Please see ``README.md`` of the Protobuf project
41for how to set up the build environment.
42
43## Building from a freshly checked-out source
44
45If you just checked out the Protobuf source from github, you need to
46generate the configure script.
47
48Under the protobuf project directory:
49
50
51```
52$ ./autogen.sh
53```
54
55### Build the artifact for each platform
56
57Run the build-protoc.sh script under this protoc-artifacts directory to build the protoc
58artifact for each platform.  For example:
59
60```
61$ cd protoc-artifacts
62$ ./build-protoc.sh linux x86_64 protoc
63```
64
65The above command will produce a `target/linux/x86_64/protoc` binary under the
66protoc-artifacts directory.
67
68For a list of supported platforms, see the comments in the build-protoc.sh
69script. We only use this script to build artifacts on Ubuntu and MacOS (both
70with x86_64, and do cross-compilation for other platforms.
71
72### Tips for building for Linux
73We build on Centos 6.9 to provide a good compatibility for not very new
74systems. We have provided a ``Dockerfile`` under this directory to build the
75environment. It has been tested with Docker 1.6.1.
76
77To build a image:
78
79```
80$ docker build -t protoc-artifacts .
81```
82
83To run the image:
84
85```
86$ docker run -it --rm=true protoc-artifacts bash
87```
88
89To checkout protobuf (run within the container):
90
91```
92$ # Replace v3.5.1 with the version you want
93$ wget -O - https://github.com/protocolbuffers/protobuf/archive/v3.5.1.tar.gz | tar xvzp
94```
95
96### Windows build
97We no longer use scripts in this directory to build windows artifacts. Instead,
98we use Visual Studio 2015 to build our windows release artifacts. See our
99[kokoro windows build scripts here](../kokoro/release/protoc/windows/build.bat).
100
101To upload windows artifacts, copy the built binaries into this directory and
102put it into the target/windows/(x86_64|x86_32) directory the same way as the
103artifacts for other platforms. That will allow the maven script to find and
104upload the artifacts to maven.
105
106## To push artifacts to Maven Central
107Before you can upload artifacts to Maven Central repository, make sure you have
108read [this page](http://central.sonatype.org/pages/apache-maven.html) on how to
109configure GPG and Sonatype account.
110
111Before you do the deployment, make sure you have built the protoc artifacts for
112every supported platform and put them under the target directory. Example
113target directory layout:
114
115    + pom.xml
116    + target
117      + linux
118        + x86_64
119          protoc.exe
120        + x86_32
121          protoc.exe
122        + aarch_64
123          protoc.exe
124        + ppcle_64
125          protoc.exe
126        + s390_64
127          protoc.exe
128      + osx
129        + x86_64
130          protoc.exe
131        + x86_32
132          protoc.exe
133      + windows
134        + x86_64
135          protoc.exe
136        + x86_32
137          protoc.exe
138
139You will need to build the artifacts on multiple machines and gather them
140together into one place.
141
142Use the following command to deploy artifacts for the host platform to a
143staging repository.
144
145```
146$ mvn deploy -P release
147```
148
149It creates a new staging repository. Go to
150https://oss.sonatype.org/#stagingRepositories and find the repository, usually
151in the name like ``comgoogle-123``. Verify that the staging repository has all
152the binaries, close and release this repository.
153
154
155## Tested build environments
156We have successfully built artifacts on the following environments:
157- Linux x86_32 and x86_64:
158  - Centos 6.9 (within Docker 1.6.1)
159  - Ubuntu 14.04.5 64-bit
160- Linux aarch_64: Cross compiled with `g++-aarch64-linux-gnu` on Ubuntu 14.04.5 64-bit
161- Mac OS X x86_32 and x86_64: Mac OS X 10.9.5
162