zhangkun83 | 65858d5 | 2015-03-30 10:51:13 -0700 | [diff] [blame] | 1 | # Build scripts that publish pre-compiled protoc artifacts |
| 2 | ``protoc`` is the compiler for ``.proto`` files. It generates language bindings |
| 3 | for the messages and/or RPC services from ``.proto`` files. |
| 4 | |
| 5 | Because ``protoc`` is a native executable, the scripts under this directory |
| 6 | build and publish a ``protoc`` executable (a.k.a. artifact) to Maven |
zhangkun83 | 9f4d9c6 | 2015-03-30 10:57:00 -0700 | [diff] [blame] | 7 | repositories. The artifact can be used by build automation tools so that users |
| 8 | would not need to compile and install ``protoc`` for their systems. |
| 9 | |
Feng Xiao | 6fa17eb | 2018-07-13 12:28:17 -0700 | [diff] [blame] | 10 | If you would like us to publish protoc artifact for a new platform, please send |
| 11 | us a pull request to add support for the new platform. You would need to change |
| 12 | the 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 |
| 21 | The published protoc artifacts are available on Maven here: |
| 22 | |
| 23 | http://central.maven.org/maven2/com/google/protobuf/protoc/ |
| 24 | |
zhangkun83 | 9f4d9c6 | 2015-03-30 10:57:00 -0700 | [diff] [blame] | 25 | ## Versioning |
| 26 | The version of the ``protoc`` artifact must be the same as the version of the |
| 27 | Protobuf project. |
zhangkun83 | 65858d5 | 2015-03-30 10:51:13 -0700 | [diff] [blame] | 28 | |
| 29 | ## Artifact name |
| 30 | The name of a published ``protoc`` artifact is in the following format: |
Feng Xiao | 6fa17eb | 2018-07-13 12:28:17 -0700 | [diff] [blame] | 31 | ``protoc-<version>-<os>-<arch>.exe``, e.g., ``protoc-3.6.1-linux-x86_64.exe``. |
| 32 | |
| 33 | Note that artifacts for linux/macos also have the `.exe` suffix but they are |
| 34 | not windows binaries. |
zhangkun83 | 65858d5 | 2015-03-30 10:51:13 -0700 | [diff] [blame] | 35 | |
zhangkun83 | f162ee5 | 2015-03-30 11:02:02 -0700 | [diff] [blame] | 36 | ## System requirement |
Kun Zhang | e499956 | 2015-04-01 12:06:24 -0700 | [diff] [blame] | 37 | Install [Apache Maven](http://maven.apache.org/) if you don't have it. |
| 38 | |
| 39 | The scripts only work under Unix-like environments, e.g., Linux, MacOSX, and |
zhangkun83 | f162ee5 | 2015-03-30 11:02:02 -0700 | [diff] [blame] | 40 | Cygwin or MinGW for Windows. Please see ``README.md`` of the Protobuf project |
| 41 | for how to set up the build environment. |
| 42 | |
Kun Zhang | 28cb77f | 2016-05-11 16:18:26 -0700 | [diff] [blame] | 43 | ## Building from a freshly checked-out source |
| 44 | |
| 45 | If you just checked out the Protobuf source from github, you need to |
Jisi Liu | ce7e502 | 2016-05-12 17:55:29 -0700 | [diff] [blame] | 46 | generate the configure script. |
Kun Zhang | 28cb77f | 2016-05-11 16:18:26 -0700 | [diff] [blame] | 47 | |
| 48 | Under the protobuf project directory: |
| 49 | |
Feng Xiao | 6fa17eb | 2018-07-13 12:28:17 -0700 | [diff] [blame] | 50 | |
Kun Zhang | 28cb77f | 2016-05-11 16:18:26 -0700 | [diff] [blame] | 51 | ``` |
Feng Xiao | 6fa17eb | 2018-07-13 12:28:17 -0700 | [diff] [blame] | 52 | $ ./autogen.sh |
Kun Zhang | 28cb77f | 2016-05-11 16:18:26 -0700 | [diff] [blame] | 53 | ``` |
| 54 | |
Feng Xiao | 6fa17eb | 2018-07-13 12:28:17 -0700 | [diff] [blame] | 55 | ### Build the artifact for each platform |
| 56 | |
| 57 | Run the build-protoc.sh script under this protoc-artifacts directory to build the protoc |
| 58 | artifact for each platform. For example: |
| 59 | |
zhangkun83 | 65858d5 | 2015-03-30 10:51:13 -0700 | [diff] [blame] | 60 | ``` |
Feng Xiao | 6fa17eb | 2018-07-13 12:28:17 -0700 | [diff] [blame] | 61 | $ cd protoc-artifacts |
| 62 | $ ./build-protoc.sh linux x86_64 protoc |
zhangkun83 | 65858d5 | 2015-03-30 10:51:13 -0700 | [diff] [blame] | 63 | ``` |
| 64 | |
Feng Xiao | 6fa17eb | 2018-07-13 12:28:17 -0700 | [diff] [blame] | 65 | The above command will produce a `target/linux/x86_64/protoc` binary under the |
| 66 | protoc-artifacts directory. |
Kun Zhang | b00a5d7 | 2015-04-02 13:14:29 -0700 | [diff] [blame] | 67 | |
Feng Xiao | 6fa17eb | 2018-07-13 12:28:17 -0700 | [diff] [blame] | 68 | For a list of supported platforms, see the comments in the build-protoc.sh |
| 69 | script. We only use this script to build artifacts on Ubuntu and MacOS (both |
| 70 | with x86_64, and do cross-compilation for other platforms. |
Kun Zhang | b00a5d7 | 2015-04-02 13:14:29 -0700 | [diff] [blame] | 71 | |
Feng Xiao | 6fa17eb | 2018-07-13 12:28:17 -0700 | [diff] [blame] | 72 | ### Tips for building for Linux |
| 73 | We build on Centos 6.9 to provide a good compatibility for not very new |
| 74 | systems. We have provided a ``Dockerfile`` under this directory to build the |
| 75 | environment. It has been tested with Docker 1.6.1. |
| 76 | |
| 77 | To build a image: |
| 78 | |
Kun Zhang | 74c4b64 | 2015-04-01 16:32:21 -0700 | [diff] [blame] | 79 | ``` |
Feng Xiao | 6fa17eb | 2018-07-13 12:28:17 -0700 | [diff] [blame] | 80 | $ docker build -t protoc-artifacts . |
Kun Zhang | 74c4b64 | 2015-04-01 16:32:21 -0700 | [diff] [blame] | 81 | ``` |
| 82 | |
Feng Xiao | 6fa17eb | 2018-07-13 12:28:17 -0700 | [diff] [blame] | 83 | To run the image: |
| 84 | |
| 85 | ``` |
| 86 | $ docker run -it --rm=true protoc-artifacts bash |
| 87 | ``` |
| 88 | |
| 89 | To checkout protobuf (run within the container): |
| 90 | |
| 91 | ``` |
| 92 | $ # Replace v3.5.1 with the version you want |
Feng Xiao | afe98de | 2018-08-22 11:55:30 -0700 | [diff] [blame] | 93 | $ wget -O - https://github.com/protocolbuffers/protobuf/archive/v3.5.1.tar.gz | tar xvzp |
Feng Xiao | 6fa17eb | 2018-07-13 12:28:17 -0700 | [diff] [blame] | 94 | ``` |
| 95 | |
| 96 | ### Windows build |
| 97 | We no longer use scripts in this directory to build windows artifacts. Instead, |
| 98 | we 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 | |
| 101 | To upload windows artifacts, copy the built binaries into this directory and |
| 102 | put it into the target/windows/(x86_64|x86_32) directory the same way as the |
| 103 | artifacts for other platforms. That will allow the maven script to find and |
| 104 | upload the artifacts to maven. |
| 105 | |
zhangkun83 | 65858d5 | 2015-03-30 10:51:13 -0700 | [diff] [blame] | 106 | ## To push artifacts to Maven Central |
Kun Zhang | e499956 | 2015-04-01 12:06:24 -0700 | [diff] [blame] | 107 | Before you can upload artifacts to Maven Central repository, make sure you have |
| 108 | read [this page](http://central.sonatype.org/pages/apache-maven.html) on how to |
Kun Zhang | 0556bf4 | 2015-04-02 10:25:13 -0700 | [diff] [blame] | 109 | configure GPG and Sonatype account. |
zhangkun83 | 65858d5 | 2015-03-30 10:51:13 -0700 | [diff] [blame] | 110 | |
Feng Xiao | 6fa17eb | 2018-07-13 12:28:17 -0700 | [diff] [blame] | 111 | Before you do the deployment, make sure you have built the protoc artifacts for |
| 112 | every supported platform and put them under the target directory. Example |
| 113 | target directory layout: |
Kun Zhang | c5a2a7c | 2015-04-06 14:31:29 -0700 | [diff] [blame] | 114 | |
Feng Xiao | 6fa17eb | 2018-07-13 12:28:17 -0700 | [diff] [blame] | 115 | + pom.xml |
| 116 | + target |
| 117 | + linux |
| 118 | + x86_64 |
| 119 | protoc.exe |
| 120 | + x86_32 |
| 121 | protoc.exe |
Adam Cozzette | 90e2c29 | 2018-07-30 09:30:08 -0700 | [diff] [blame] | 122 | + aarch_64 |
| 123 | protoc.exe |
Adam Cozzette | 0255797 | 2019-01-30 11:22:36 -0800 | [diff] [blame] | 124 | + ppcle_64 |
| 125 | protoc.exe |
Adam Cozzette | 90e2c29 | 2018-07-30 09:30:08 -0700 | [diff] [blame] | 126 | + osx |
Feng Xiao | 6fa17eb | 2018-07-13 12:28:17 -0700 | [diff] [blame] | 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 | |
| 137 | You will need to build the artifacts on multiple machines and gather them |
| 138 | together into one place. |
Kun Zhang | 28cb77f | 2016-05-11 16:18:26 -0700 | [diff] [blame] | 139 | |
Kun Zhang | c5a2a7c | 2015-04-06 14:31:29 -0700 | [diff] [blame] | 140 | Use the following command to deploy artifacts for the host platform to a |
| 141 | staging repository. |
Feng Xiao | 6fa17eb | 2018-07-13 12:28:17 -0700 | [diff] [blame] | 142 | |
zhangkun83 | 65858d5 | 2015-03-30 10:51:13 -0700 | [diff] [blame] | 143 | ``` |
Adam Cozzette | 90e2c29 | 2018-07-30 09:30:08 -0700 | [diff] [blame] | 144 | $ mvn deploy -P release |
zhangkun83 | 65858d5 | 2015-03-30 10:51:13 -0700 | [diff] [blame] | 145 | ``` |
Feng Xiao | 6fa17eb | 2018-07-13 12:28:17 -0700 | [diff] [blame] | 146 | |
Kun Zhang | c5a2a7c | 2015-04-06 14:31:29 -0700 | [diff] [blame] | 147 | It creates a new staging repository. Go to |
| 148 | https://oss.sonatype.org/#stagingRepositories and find the repository, usually |
Feng Xiao | 6fa17eb | 2018-07-13 12:28:17 -0700 | [diff] [blame] | 149 | in the name like ``comgoogle-123``. Verify that the staging repository has all |
| 150 | the binaries, close and release this repository. |
Kun Zhang | c5a2a7c | 2015-04-06 14:31:29 -0700 | [diff] [blame] | 151 | |
Feng Xiao | b553b87 | 2016-07-25 14:55:36 -0700 | [diff] [blame] | 152 | ## Upload zip packages to github release page. |
| 153 | After uploading protoc artifacts to Maven Central repository, run the |
| 154 | build-zip.sh script to bulid zip packages for these protoc binaries |
| 155 | and upload these zip packages to the download section of the github |
| 156 | release. For example: |
Feng Xiao | 6fa17eb | 2018-07-13 12:28:17 -0700 | [diff] [blame] | 157 | |
Feng Xiao | b553b87 | 2016-07-25 14:55:36 -0700 | [diff] [blame] | 158 | ``` |
Adam Cozzette | 377f64f | 2018-07-27 16:36:41 -0700 | [diff] [blame] | 159 | $ ./build-zip.sh protoc 3.6.0 |
Feng Xiao | b553b87 | 2016-07-25 14:55:36 -0700 | [diff] [blame] | 160 | ``` |
Feng Xiao | 6fa17eb | 2018-07-13 12:28:17 -0700 | [diff] [blame] | 161 | |
Adam Cozzette | 377f64f | 2018-07-27 16:36:41 -0700 | [diff] [blame] | 162 | The above command will create 7 zip files: |
Feng Xiao | 6fa17eb | 2018-07-13 12:28:17 -0700 | [diff] [blame] | 163 | |
Feng Xiao | b553b87 | 2016-07-25 14:55:36 -0700 | [diff] [blame] | 164 | ``` |
nashimus | 1f7837a | 2018-07-06 20:03:25 -0600 | [diff] [blame] | 165 | dist/protoc-3.6.0-win32.zip |
| 166 | dist/protoc-3.6.0-osx-x86_32.zip |
| 167 | dist/protoc-3.6.0-osx-x86_64.zip |
| 168 | dist/protoc-3.6.0-linux-x86_32.zip |
| 169 | dist/protoc-3.6.0-linux-x86_64.zip |
Adam Cozzette | 377f64f | 2018-07-27 16:36:41 -0700 | [diff] [blame] | 170 | dist/protoc-3.6.0-linux-aarch_64.zip |
nashimus | 1f7837a | 2018-07-06 20:03:25 -0600 | [diff] [blame] | 171 | dist/protoc-3.6.0-linux-ppcle_64.zip |
Feng Xiao | b553b87 | 2016-07-25 14:55:36 -0700 | [diff] [blame] | 172 | ``` |
Feng Xiao | 6fa17eb | 2018-07-13 12:28:17 -0700 | [diff] [blame] | 173 | |
Feng Xiao | b553b87 | 2016-07-25 14:55:36 -0700 | [diff] [blame] | 174 | Before running the script, make sure the artifacts are accessible from: |
| 175 | http://repo1.maven.org/maven2/com/google/protobuf/protoc/ |
| 176 | |
Feng Xiao | 6fa17eb | 2018-07-13 12:28:17 -0700 | [diff] [blame] | 177 | ## Tested build environments |
Dongjoon Hyun | 7b08d49 | 2016-01-11 14:52:01 -0800 | [diff] [blame] | 178 | We have successfully built artifacts on the following environments: |
Kun Zhang | 2aaf5c6 | 2015-05-11 17:13:59 -0700 | [diff] [blame] | 179 | - Linux x86_32 and x86_64: |
Feng Xiao | 6fa17eb | 2018-07-13 12:28:17 -0700 | [diff] [blame] | 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 |
Kun Zhang | 90a7ed6 | 2015-04-16 17:30:07 -0700 | [diff] [blame] | 183 | - Mac OS X x86_32 and x86_64: Mac OS X 10.9.5 |