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 | |
| 10 | ## Versioning |
| 11 | The version of the ``protoc`` artifact must be the same as the version of the |
| 12 | Protobuf project. |
zhangkun83 | 65858d5 | 2015-03-30 10:51:13 -0700 | [diff] [blame] | 13 | |
| 14 | ## Artifact name |
| 15 | The name of a published ``protoc`` artifact is in the following format: |
| 16 | ``protoc-<version>-<os>-<arch>.exe``, e.g., ``protoc-3.0.0-alpha-3-windows-x86_64.exe``. |
| 17 | |
zhangkun83 | f162ee5 | 2015-03-30 11:02:02 -0700 | [diff] [blame] | 18 | ## System requirement |
Kun Zhang | e499956 | 2015-04-01 12:06:24 -0700 | [diff] [blame] | 19 | Install [Apache Maven](http://maven.apache.org/) if you don't have it. |
| 20 | |
| 21 | The scripts only work under Unix-like environments, e.g., Linux, MacOSX, and |
zhangkun83 | f162ee5 | 2015-03-30 11:02:02 -0700 | [diff] [blame] | 22 | Cygwin or MinGW for Windows. Please see ``README.md`` of the Protobuf project |
| 23 | for how to set up the build environment. |
| 24 | |
zhangkun83 | 65858d5 | 2015-03-30 10:51:13 -0700 | [diff] [blame] | 25 | ## To install artifacts locally |
| 26 | The following command will install the ``protoc`` artifact to your local Maven repository. |
| 27 | ``` |
Kun Zhang | e499956 | 2015-04-01 12:06:24 -0700 | [diff] [blame] | 28 | $ mvn install |
zhangkun83 | 65858d5 | 2015-03-30 10:51:13 -0700 | [diff] [blame] | 29 | ``` |
| 30 | |
Kun Zhang | 74c4b64 | 2015-04-01 16:32:21 -0700 | [diff] [blame] | 31 | ## Cross-compilation |
| 32 | The Maven script will try to detect the OS and the architecture from Java |
Kun Zhang | 0556bf4 | 2015-04-02 10:25:13 -0700 | [diff] [blame] | 33 | system properties. It's possible to build a protoc binary for an architecture |
Kun Zhang | 74c4b64 | 2015-04-01 16:32:21 -0700 | [diff] [blame] | 34 | that is different from what Java has detected, as long as you have the proper |
Kun Zhang | b00a5d7 | 2015-04-02 13:14:29 -0700 | [diff] [blame] | 35 | compilers installed. |
| 36 | |
| 37 | You can override the Maven properties ``os.detected.name`` and |
| 38 | ``os.detected.arch`` to force the script to generate binaries for a specific OS |
| 39 | and/or architecture. Valid values are defined as the return values of |
| 40 | ``normalizeOs()`` and ``normalizeArch()`` of ``Detector`` from |
| 41 | [os-maven-plugin](https://github.com/trustin/os-maven-plugin/blob/master/src/main/java/kr/motd/maven/os/Detector.java). |
| 42 | Frequently used values are: |
| 43 | - ``os.detected.name``: ``linux``, ``osx``, ``windows``. |
| 44 | - ``os.detected.arch``: ``x86_32``, ``x86_64`` |
| 45 | |
| 46 | For example, MingGW32 only ships with 32-bit compilers, but you can still build |
| 47 | 32-bit protoc under 64-bit Windows, with the following command: |
Kun Zhang | 74c4b64 | 2015-04-01 16:32:21 -0700 | [diff] [blame] | 48 | ``` |
| 49 | $ mvn install -Dos.detected.arch=x86_32 |
| 50 | ``` |
| 51 | |
zhangkun83 | 65858d5 | 2015-03-30 10:51:13 -0700 | [diff] [blame] | 52 | ## To push artifacts to Maven Central |
Kun Zhang | e499956 | 2015-04-01 12:06:24 -0700 | [diff] [blame] | 53 | Before you can upload artifacts to Maven Central repository, make sure you have |
| 54 | 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] | 55 | configure GPG and Sonatype account. |
zhangkun83 | 65858d5 | 2015-03-30 10:51:13 -0700 | [diff] [blame] | 56 | |
Kun Zhang | c5a2a7c | 2015-04-06 14:31:29 -0700 | [diff] [blame^] | 57 | You need to perform the deployment for every platform that you want to |
| 58 | suppport. DO NOT close the staging repository until you have done the |
| 59 | deployment for all platforms. |
| 60 | |
| 61 | Remove any ``SNAPSHOT`` or ``pre`` suffix from the version string before |
| 62 | deploying. |
| 63 | |
| 64 | Use the following command to deploy artifacts for the host platform to a |
| 65 | staging repository. |
zhangkun83 | 65858d5 | 2015-03-30 10:51:13 -0700 | [diff] [blame] | 66 | ``` |
Kun Zhang | e499956 | 2015-04-01 12:06:24 -0700 | [diff] [blame] | 67 | $ mvn clean deploy -P release |
zhangkun83 | 65858d5 | 2015-03-30 10:51:13 -0700 | [diff] [blame] | 68 | ``` |
Kun Zhang | c5a2a7c | 2015-04-06 14:31:29 -0700 | [diff] [blame^] | 69 | It creates a new staging repository. Go to |
| 70 | https://oss.sonatype.org/#stagingRepositories and find the repository, usually |
| 71 | in the name like ``comgoogle-123``. |
| 72 | |
| 73 | You will want to run this command on a different platform. Remember, in |
| 74 | subsequent deployments you will need to provide the repository name that you |
| 75 | have found in the first deployment so that all artifacts go to the same |
| 76 | repository: |
| 77 | ``` |
| 78 | $ mvn clean deploy -P release -Dstaging.repository=comgoogle-123 |
| 79 | ``` |
| 80 | |
| 81 | A 32-bit artifact can be deployed from a 64-bit host with |
| 82 | ``-Dos.detected.arch=x86_32`` |
| 83 | |
| 84 | When you have done deployment for all platforms, go to |
| 85 | https://oss.sonatype.org/#stagingRepositories, verify that the staging |
| 86 | repository has all the binaries, close and release this repository. |
| 87 | |
| 88 | ### Tips for deploying on Windows |
| 89 | Under Windows the following error may occur: ``gpg: cannot open tty `no tty': |
| 90 | No such file or directory``. This can be fixed by configuring gpg through an |
| 91 | active profile in ``.m2\settings.xml`` where also the Sonatype password is |
| 92 | stored: |
| 93 | ```xml |
| 94 | <settings> |
| 95 | <servers> |
| 96 | <server> |
| 97 | <id>ossrh</id> |
| 98 | <username>[username]</username> |
| 99 | <password>[password]</password> |
| 100 | </server> |
| 101 | </servers> |
| 102 | <profiles> |
| 103 | <profile> |
| 104 | <id>gpg</id> |
| 105 | <properties> |
| 106 | <gpg.executable>gpg</gpg.executable> |
| 107 | <gpg.passphrase>[password]</gpg.passphrase> |
| 108 | </properties> |
| 109 | </profile> |
| 110 | </profiles> |
| 111 | <activeProfiles> |
| 112 | <activeProfile>gpg</activeProfile> |
| 113 | </activeProfiles> |
| 114 | </settings> |
| 115 | ``` |