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