blob: 88f183aff199787cffda75fdcb6c0f9da67f3144 [file] [log] [blame] [view]
zhangkun8365858d52015-03-30 10:51:13 -07001# 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
zhangkun839f4d9c62015-03-30 10:57:00 -07007repositories. The artifact can be used by build automation tools so that users
8would not need to compile and install ``protoc`` for their systems.
9
Feng Xiao6fa17eb2018-07-13 12:28:17 -070010If 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 http://central.maven.org/maven2/com/google/protobuf/protoc/
24
zhangkun839f4d9c62015-03-30 10:57:00 -070025## Versioning
26The version of the ``protoc`` artifact must be the same as the version of the
27Protobuf project.
zhangkun8365858d52015-03-30 10:51:13 -070028
29## Artifact name
30The name of a published ``protoc`` artifact is in the following format:
Feng Xiao6fa17eb2018-07-13 12:28:17 -070031``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.
zhangkun8365858d52015-03-30 10:51:13 -070035
zhangkun83f162ee52015-03-30 11:02:02 -070036## System requirement
Kun Zhange4999562015-04-01 12:06:24 -070037Install [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
zhangkun83f162ee52015-03-30 11:02:02 -070040Cygwin or MinGW for Windows. Please see ``README.md`` of the Protobuf project
41for how to set up the build environment.
42
Kun Zhang28cb77f2016-05-11 16:18:26 -070043## Building from a freshly checked-out source
44
45If you just checked out the Protobuf source from github, you need to
Jisi Liuce7e5022016-05-12 17:55:29 -070046generate the configure script.
Kun Zhang28cb77f2016-05-11 16:18:26 -070047
48Under the protobuf project directory:
49
Feng Xiao6fa17eb2018-07-13 12:28:17 -070050
Kun Zhang28cb77f2016-05-11 16:18:26 -070051```
Feng Xiao6fa17eb2018-07-13 12:28:17 -070052$ ./autogen.sh
Kun Zhang28cb77f2016-05-11 16:18:26 -070053```
54
Feng Xiao6fa17eb2018-07-13 12:28:17 -070055### 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
zhangkun8365858d52015-03-30 10:51:13 -070060```
Feng Xiao6fa17eb2018-07-13 12:28:17 -070061$ cd protoc-artifacts
62$ ./build-protoc.sh linux x86_64 protoc
zhangkun8365858d52015-03-30 10:51:13 -070063```
64
Feng Xiao6fa17eb2018-07-13 12:28:17 -070065The above command will produce a `target/linux/x86_64/protoc` binary under the
66protoc-artifacts directory.
Kun Zhangb00a5d72015-04-02 13:14:29 -070067
Feng Xiao6fa17eb2018-07-13 12:28:17 -070068For 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.
Kun Zhangb00a5d72015-04-02 13:14:29 -070071
Feng Xiao6fa17eb2018-07-13 12:28:17 -070072### 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
Kun Zhang74c4b642015-04-01 16:32:21 -070079```
Feng Xiao6fa17eb2018-07-13 12:28:17 -070080$ docker build -t protoc-artifacts .
Kun Zhang74c4b642015-04-01 16:32:21 -070081```
82
Feng Xiao6fa17eb2018-07-13 12:28:17 -070083To 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
Feng Xiaoafe98de2018-08-22 11:55:30 -070093$ wget -O - https://github.com/protocolbuffers/protobuf/archive/v3.5.1.tar.gz | tar xvzp
Feng Xiao6fa17eb2018-07-13 12:28:17 -070094```
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
zhangkun8365858d52015-03-30 10:51:13 -0700106## To push artifacts to Maven Central
Kun Zhange4999562015-04-01 12:06:24 -0700107Before 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
Kun Zhang0556bf42015-04-02 10:25:13 -0700109configure GPG and Sonatype account.
zhangkun8365858d52015-03-30 10:51:13 -0700110
Feng Xiao6fa17eb2018-07-13 12:28:17 -0700111Before 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:
Kun Zhangc5a2a7c2015-04-06 14:31:29 -0700114
Feng Xiao6fa17eb2018-07-13 12:28:17 -0700115 + pom.xml
116 + target
117 + linux
118 + x86_64
119 protoc.exe
120 + x86_32
121 protoc.exe
Adam Cozzette90e2c292018-07-30 09:30:08 -0700122 + aarch_64
123 protoc.exe
Adam Cozzette02557972019-01-30 11:22:36 -0800124 + ppcle_64
125 protoc.exe
Adam Cozzette90e2c292018-07-30 09:30:08 -0700126 + osx
Feng Xiao6fa17eb2018-07-13 12:28:17 -0700127 + x86_64
128 protoc.exe
129 + x86_32
130 protoc.exe
131 + windows
132 + x86_64
133 protoc.exe
134 + x86_32
135 protoc.exe
136
137You will need to build the artifacts on multiple machines and gather them
138together into one place.
Kun Zhang28cb77f2016-05-11 16:18:26 -0700139
Kun Zhangc5a2a7c2015-04-06 14:31:29 -0700140Use the following command to deploy artifacts for the host platform to a
141staging repository.
Feng Xiao6fa17eb2018-07-13 12:28:17 -0700142
zhangkun8365858d52015-03-30 10:51:13 -0700143```
Adam Cozzette90e2c292018-07-30 09:30:08 -0700144$ mvn deploy -P release
zhangkun8365858d52015-03-30 10:51:13 -0700145```
Feng Xiao6fa17eb2018-07-13 12:28:17 -0700146
Kun Zhangc5a2a7c2015-04-06 14:31:29 -0700147It creates a new staging repository. Go to
148https://oss.sonatype.org/#stagingRepositories and find the repository, usually
Feng Xiao6fa17eb2018-07-13 12:28:17 -0700149in the name like ``comgoogle-123``. Verify that the staging repository has all
150the binaries, close and release this repository.
Kun Zhangc5a2a7c2015-04-06 14:31:29 -0700151
Feng Xiaob553b872016-07-25 14:55:36 -0700152## Upload zip packages to github release page.
153After uploading protoc artifacts to Maven Central repository, run the
154build-zip.sh script to bulid zip packages for these protoc binaries
155and upload these zip packages to the download section of the github
156release. For example:
Feng Xiao6fa17eb2018-07-13 12:28:17 -0700157
Feng Xiaob553b872016-07-25 14:55:36 -0700158```
Adam Cozzette377f64f2018-07-27 16:36:41 -0700159$ ./build-zip.sh protoc 3.6.0
Feng Xiaob553b872016-07-25 14:55:36 -0700160```
Feng Xiao6fa17eb2018-07-13 12:28:17 -0700161
Adam Cozzette377f64f2018-07-27 16:36:41 -0700162The above command will create 7 zip files:
Feng Xiao6fa17eb2018-07-13 12:28:17 -0700163
Feng Xiaob553b872016-07-25 14:55:36 -0700164```
nashimus1f7837a2018-07-06 20:03:25 -0600165dist/protoc-3.6.0-win32.zip
166dist/protoc-3.6.0-osx-x86_32.zip
167dist/protoc-3.6.0-osx-x86_64.zip
168dist/protoc-3.6.0-linux-x86_32.zip
169dist/protoc-3.6.0-linux-x86_64.zip
Adam Cozzette377f64f2018-07-27 16:36:41 -0700170dist/protoc-3.6.0-linux-aarch_64.zip
nashimus1f7837a2018-07-06 20:03:25 -0600171dist/protoc-3.6.0-linux-ppcle_64.zip
Feng Xiaob553b872016-07-25 14:55:36 -0700172```
Feng Xiao6fa17eb2018-07-13 12:28:17 -0700173
Feng Xiaob553b872016-07-25 14:55:36 -0700174Before running the script, make sure the artifacts are accessible from:
175http://repo1.maven.org/maven2/com/google/protobuf/protoc/
176
Feng Xiao6fa17eb2018-07-13 12:28:17 -0700177## Tested build environments
Dongjoon Hyun7b08d492016-01-11 14:52:01 -0800178We have successfully built artifacts on the following environments:
Kun Zhang2aaf5c62015-05-11 17:13:59 -0700179- Linux x86_32 and x86_64:
Feng Xiao6fa17eb2018-07-13 12:28:17 -0700180 - Centos 6.9 (within Docker 1.6.1)
181 - Ubuntu 14.04.5 64-bit
182- Linux aarch_64: Cross compiled with `g++-aarch64-linux-gnu` on Ubuntu 14.04.5 64-bit
Kun Zhang90a7ed62015-04-16 17:30:07 -0700183- Mac OS X x86_32 and x86_64: Mac OS X 10.9.5