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