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 http://central.maven.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 + osx 127 + 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. 139 140Use the following command to deploy artifacts for the host platform to a 141staging repository. 142 143``` 144$ mvn deploy -P release 145``` 146 147It creates a new staging repository. Go to 148https://oss.sonatype.org/#stagingRepositories and find the repository, usually 149in the name like ``comgoogle-123``. Verify that the staging repository has all 150the binaries, close and release this repository. 151 152## 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: 157 158``` 159$ ./build-zip.sh protoc 3.6.0 160``` 161 162The above command will create 7 zip files: 163 164``` 165dist/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 170dist/protoc-3.6.0-linux-aarch_64.zip 171dist/protoc-3.6.0-linux-ppcle_64.zip 172``` 173 174Before running the script, make sure the artifacts are accessible from: 175http://repo1.maven.org/maven2/com/google/protobuf/protoc/ 176 177## Tested build environments 178We have successfully built artifacts on the following environments: 179- Linux x86_32 and x86_64: 180 - 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 183- Mac OS X x86_32 and x86_64: Mac OS X 10.9.5 184