README.md 5.87 KB
Newer Older
1 2 3 4 5 6
# Build scripts that publish pre-compiled protoc artifacts
``protoc`` is the compiler for ``.proto`` files. It generates language bindings
for the messages and/or RPC services from ``.proto`` files.

Because ``protoc`` is a native executable, the scripts under this directory
build and publish a ``protoc`` executable (a.k.a. artifact) to Maven
7 8 9
repositories. The artifact can be used by build automation tools so that users
would not need to compile and install ``protoc`` for their systems.

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
If you would like us to publish protoc artifact for a new platform, please send
us a pull request to add support for the new platform. You would need to change
the following files:

* [build-protoc.sh](build-protoc.sh): script to cross-build the protoc for your
  platform.
* [pom.xml](pom.xml): script to upload artifacts to maven.
* [build-zip.sh](build-zip.sh): script to package published maven artifacts in
  our release page.

## Maven Location
The published protoc artifacts are available on Maven here:

    http://central.maven.org/maven2/com/google/protobuf/protoc/

25 26 27
## Versioning
The version of the ``protoc`` artifact must be the same as the version of the
Protobuf project.
28 29 30

## Artifact name
The name of a published ``protoc`` artifact is in the following format:
31 32 33 34
``protoc-<version>-<os>-<arch>.exe``, e.g., ``protoc-3.6.1-linux-x86_64.exe``.

Note that artifacts for linux/macos also have the `.exe` suffix but they are
not windows binaries.
35

36
## System requirement
Kun Zhang's avatar
Kun Zhang committed
37 38 39
Install [Apache Maven](http://maven.apache.org/) if you don't have it.

The scripts only work under Unix-like environments, e.g., Linux, MacOSX, and
40 41 42
Cygwin or MinGW for Windows. Please see ``README.md`` of the Protobuf project
for how to set up the build environment.

43 44 45
## Building from a freshly checked-out source

If you just checked out the Protobuf source from github, you need to
46
generate the configure script.
47 48 49

Under the protobuf project directory:

50

51
```
52
$ ./autogen.sh
53 54
```

55 56 57 58 59
### Build the artifact for each platform

Run the build-protoc.sh script under this protoc-artifacts directory to build the protoc
artifact for each platform.  For example:

60
```
61 62
$ cd protoc-artifacts
$ ./build-protoc.sh linux x86_64 protoc
63 64
```

65 66
The above command will produce a `target/linux/x86_64/protoc` binary under the
protoc-artifacts directory.
67

68 69 70 71 72 73 74 75 76 77
For a list of supported platforms, see the comments in the build-protoc.sh
script. We only use this script to build artifacts on Ubuntu and MacOS (both
with x86_64, and do cross-compilation for other platforms.

### Tips for building for Linux
We build on Centos 6.9 to provide a good compatibility for not very new
systems. We have provided a ``Dockerfile`` under this directory to build the
environment. It has been tested with Docker 1.6.1.

To build a image:
78

79
```
80
$ docker build -t protoc-artifacts .
81 82
```

83 84 85 86 87 88 89 90 91 92
To run the image:

```
$ docker run -it --rm=true protoc-artifacts bash
```

To checkout protobuf (run within the container):

```
$ # Replace v3.5.1 with the version you want
Feng Xiao's avatar
Feng Xiao committed
93
$ wget -O - https://github.com/protocolbuffers/protobuf/archive/v3.5.1.tar.gz | tar xvzp
94 95 96 97 98 99 100 101 102 103 104 105
```

### Windows build
We no longer use scripts in this directory to build windows artifacts. Instead,
we use Visual Studio 2015 to build our windows release artifacts. See our
[kokoro windows build scripts here](../kokoro/release/protoc/windows/build.bat).

To upload windows artifacts, copy the built binaries into this directory and
put it into the target/windows/(x86_64|x86_32) directory the same way as the
artifacts for other platforms. That will allow the maven script to find and
upload the artifacts to maven.

106
## To push artifacts to Maven Central
Kun Zhang's avatar
Kun Zhang committed
107 108
Before you can upload artifacts to Maven Central repository, make sure you have
read [this page](http://central.sonatype.org/pages/apache-maven.html) on how to
Kun Zhang's avatar
Kun Zhang committed
109
configure GPG and Sonatype account.
110

111 112 113 114 115 116 117 118 119 120 121
Before you do the deployment, make sure you have built the protoc artifacts for
every supported platform and put them under the target directory. Example
target directory layout:

    + pom.xml
    + target
      + linux
        + x86_64
          protoc.exe
        + x86_32
          protoc.exe
122 123
        + aarch_64
          protoc.exe
124 125
        + ppcle_64
          protoc.exe
126 127
        + s390x_64
          protoc.exe
128
      + osx
129 130 131 132 133 134 135 136 137 138 139 140
        + x86_64
          protoc.exe
        + x86_32
          protoc.exe
      + windows
        + x86_64
          protoc.exe
        + x86_32
          protoc.exe

You will need to build the artifacts on multiple machines and gather them
together into one place.
141

142 143
Use the following command to deploy artifacts for the host platform to a
staging repository.
144

145
```
146
$ mvn deploy -P release
147
```
148

149 150
It creates a new staging repository. Go to
https://oss.sonatype.org/#stagingRepositories and find the repository, usually
151 152
in the name like ``comgoogle-123``. Verify that the staging repository has all
the binaries, close and release this repository.
153

154 155 156 157 158
## Upload zip packages to github release page.
After uploading protoc artifacts to Maven Central repository, run the
build-zip.sh script to bulid zip packages for these protoc binaries
and upload these zip packages to the download section of the github
release. For example:
159

160
```
161
$ ./build-zip.sh protoc 3.6.0
162
```
163

164
The above command will create 7 zip files:
165

166
```
167 168 169 170 171
dist/protoc-3.6.0-win32.zip
dist/protoc-3.6.0-osx-x86_32.zip
dist/protoc-3.6.0-osx-x86_64.zip
dist/protoc-3.6.0-linux-x86_32.zip
dist/protoc-3.6.0-linux-x86_64.zip
172
dist/protoc-3.6.0-linux-aarch_64.zip
173
dist/protoc-3.6.0-linux-ppcle_64.zip
174
dist/protoc-3.6.0-linux-s390x_64.zip
175
```
176

177 178 179
Before running the script, make sure the artifacts are accessible from:
http://repo1.maven.org/maven2/com/google/protobuf/protoc/

180
## Tested build environments
181
We have successfully built artifacts on the following environments:
182
- Linux x86_32 and x86_64:
183 184 185
  - Centos 6.9 (within Docker 1.6.1)
  - Ubuntu 14.04.5 64-bit
- Linux aarch_64: Cross compiled with `g++-aarch64-linux-gnu` on Ubuntu 14.04.5 64-bit
Kun Zhang's avatar
Kun Zhang committed
186
- Mac OS X x86_32 and x86_64: Mac OS X 10.9.5