install.md 7.46 KB
Newer Older
Kenton Varda's avatar
Kenton Varda committed
1 2
---
layout: page
Kenton Varda's avatar
Kenton Varda committed
3
title: Installation
Kenton Varda's avatar
Kenton Varda committed
4 5
---

6
# Installation: Tools and C++ Runtime
Kenton Varda's avatar
Kenton Varda committed
7

8 9
The Cap'n Proto tools, including the compiler (which takes `.capnp` files and generates source code
for them), are written in C++.  Therefore, you must install the C++ package even if your actual
10 11 12 13 14 15 16
development language is something else.

This package is licensed under the [MIT License](http://opensource.org/licenses/MIT).

## Caveats

<p style="font-size: 125%; font-weight: bold;">Cap'n Proto is in BETA</p>
17

Kenton Varda's avatar
Kenton Varda committed
18 19
<div style="float: right"><a class="groups_link" style="color: #fff"
href="https://groups.google.com/group/capnproto-announce">Sign Up for Updates</a></div>
Kenton Varda's avatar
Kenton Varda committed
20

21 22 23
As of this writing, Cap'n Proto is in beta.  The serialization layer is close to feature-complete
and we don't anticipate any further changes to the wire format.  That said, if you want to use it,
you should keep in mind some caveats:
Kenton Varda's avatar
Kenton Varda committed
24

Kenton Varda's avatar
Kenton Varda committed
25 26
* **Security:** Cap'n Proto has not yet had a security review.  Although Kenton has a background
  in security and is not aware of any vulnerabilities in the current code, it's likely that there
27 28
  are a few, and [some have been found](https://github.com/sandstorm-io/capnproto/tree/master/security-advisories)
  in the past.  For now, do not accept Cap'n Proto messages from parties you do not trust.
29 30
* **API Stability:** The Cap'n Proto programming interface may still change in ways that break
  existing code.  Such changes are likely to be minor and should not affect the wire format.
Kenton Varda's avatar
Kenton Varda committed
31
* **Performance:** While Cap'n Proto is inherently fast by design, the implementation has not yet
32 33
  undergone serious profiling and optimization.  Currently it only beats Protobufs in realistic-ish
  end-to-end benchmarks by around 2x-5x.  We can do better.
34 35
* **RPC:** The RPC implementation particularly experimental, though it is used heavily by
  [Sandstorm.io](https://sandstorm.io).
36

37 38
If you'd like to hack on Cap'n Proto, you should join the
[discussion group](https://groups.google.com/group/capnproto)!
Kenton Varda's avatar
Kenton Varda committed
39

40
If you'd just like to receive updates as things progress, add yourself to the
41
[announce list](https://groups.google.com/group/capnproto-announce).
Kenton Varda's avatar
Kenton Varda committed
42

43
## Prerequisites
Kenton Varda's avatar
Kenton Varda committed
44

45
### Supported Compilers
Kenton Varda's avatar
Kenton Varda committed
46

47 48
Cap'n Proto makes extensive use of C++11 language features. As a result, it requires a relatively
new version of a well-supported compiler. The minimum versions are:
49

50 51 52
* GCC 4.8
* Clang 3.3
* Visual C++ 2015 (lite mode only)
Kenton Varda's avatar
Kenton Varda committed
53

54 55 56
If your system's default compiler is older that the above, you will need to install a newer
compiler and set the `CXX` environment variable before trying to build Cap'n Proto. For example,
after installing GCC 4.8, you could set `CXX=g++-4.8` to use this compiler.
Kenton Varda's avatar
Kenton Varda committed
57

58
### Supported Operating Systems
Kenton Varda's avatar
Kenton Varda committed
59

60 61
In theory, Cap'n Proto should work on any POSIX platform supporting one of the above compilers,
as well as on Windows. We test every Cap'n Proto release on the following platforms:
62

63 64
* Android
* Linux
65
* Mac OS X
66 67 68 69 70 71 72 73
* Windows - Cygwin
* Windows - MinGW-w64 (lite mode and compiler binary only)
* Windows - Visual C++ (lite mode only)

**Windows users:** As of Visual Studio 2015, Visual C++ still does not support enough of C++11 to
compile Cap'n Proto's reflection or RPC APIs. "Cap'n Proto Lite" omits these features from the
library, giving you only the core serialization based on generated code.

74 75 76
**Mac OS X users:** You must use at least Xcode 5 with the Xcode command-line
tools (Xcode menu > Preferences > Downloads).  Alternatively, the command-line tools
package from [Apple](https://developer.apple.com/downloads/) or compiler builds from
77 78
[Macports](http://www.macports.org/), [Fink](http://www.finkproject.org/), or
[Homebrew](http://brew.sh/) are reported to work.
Kenton Varda's avatar
Kenton Varda committed
79

80
## Installation: Unix
Kenton Varda's avatar
Kenton Varda committed
81

82 83
**From Release Tarball**

Kenton Varda's avatar
Kenton Varda committed
84 85
You may download and install the release version of Cap'n Proto like so:

86
<pre><code>curl -O <a href="https://capnproto.org/capnproto-c++-0.0.0.tar.gz">https://capnproto.org/capnproto-c++-0.0.0.tar.gz</a>
87 88
tar zxf capnproto-c++-0.0.0.tar.gz
cd capnproto-c++-0.0.0
Kenton Varda's avatar
Kenton Varda committed
89 90 91 92 93 94 95 96
./configure
make -j6 check
sudo make install</code></pre>

This will install `capnp`, the Cap'n Proto command-line tool.  It will also install `libcapnp`,
`libcapnpc`, and `libkj` in `/usr/local/lib` and headers in `/usr/local/include/capnp` and
`/usr/local/include/kj`.

97 98 99 100 101 102 103 104 105
**From Package Managers**

Some package managers include Cap'n Proto packages.

Note: These packages are not maintained by us and are sometimes not up to date with the latest Cap'n Proto release.

* Debian / Ubuntu: `apt-get install capnproto`
* Homebrew (OSX): `brew install capnp`

106
**From Git**
Kenton Varda's avatar
Kenton Varda committed
107

108
If you download directly from Git, you will need to have the GNU autotools --
Kenton Varda's avatar
Kenton Varda committed
109 110
[autoconf](http://www.gnu.org/software/autoconf/),
[automake](http://www.gnu.org/software/automake/), and
111
[libtool](http://www.gnu.org/software/libtool/) -- installed.
Kenton Varda's avatar
Kenton Varda committed
112

113
    git clone https://github.com/sandstorm-io/capnproto.git
Kenton Varda's avatar
Kenton Varda committed
114 115 116 117 118 119
    cd capnproto/c++
    autoreconf -i
    ./configure
    make -j6 check
    sudo make install

120
## Installation: Windows
Kenton Varda's avatar
Kenton Varda committed
121

122 123
**From Release Zip**

124
1. Download Cap'n Proto Win32 build:
Kenton Varda's avatar
Kenton Varda committed
125

126
   <pre><a href="https://capnproto.org/capnproto-c++-win32-0.0.0.zip">https://capnproto.org/capnproto-c++-win32-0.0.0.zip</a></pre>
127

128
2. Find `capnp.exe`, `capnpc-c++.exe`, and `capnpc-capnp.exe` under `capnproto-tools-win32-0.0.0` in
129
   the zip and copy them somewhere.
130

131 132
If you don't care about C++ support, you can stop here. The compiler exe can be used with plugins
provided by projects implementing Cap'n Proto in other languages.
Kenton Varda's avatar
Kenton Varda committed
133

134
If you want to use Cap'n Proto in C++ with Visual Studio, do the following:
Kenton Varda's avatar
Kenton Varda committed
135

136
1. Install [CMake](http://www.cmake.org/) version 3.1 or later.
Kenton Varda's avatar
Kenton Varda committed
137

138 139 140
2. Use CMake to generate Visual Studio project files under `capnproto-c++-0.0.0` in the zip file.
   You will need to enable the CMake project options `CAPNP_LITE` and `EXTERNAL_CAPNP`.
   You can use the CMake UI for this or run this shell command:
Kenton Varda's avatar
Kenton Varda committed
141

142
       cmake -G "Visual Studio 14 2015" -DCAPNP_LITE=1 -DEXTERNAL_CAPNP=1
Kenton Varda's avatar
Kenton Varda committed
143

144 145 146
    If the `capnp.exe` and `capnpc-c++.exe` tools are not on your `PATH`, then `CAPNP_EXECUTABLE`
    and `CAPNPC_CXX_EXECUTABLE` will need to be set to their respective locations.

147
3. Open the "Cap'n Proto" solution in Visual Studio.
Kenton Varda's avatar
Kenton Varda committed
148

149 150
4. Adjust the project build options (e.g., choice of C++ runtime library, enable/disable exceptions
   and RTTI) to match the options of the project in which you plan to use Cap'n Proto.
Kenton Varda's avatar
Kenton Varda committed
151

152
5. Build the solution (`ALL_BUILD`).
Kenton Varda's avatar
Kenton Varda committed
153

154
6. Build the `INSTALL` project to copy the compiled libraries and header files into `CMAKE_INSTALL_PREFIX`.
155

156 157 158 159
   Alternatively, find the compiled `.lib` files in the build directory under
   `src/{capnp,kj}/{Debug,Release}` and place them somewhere where your project can link against them.
   Also add the `src` directory to your search path for `#include`s, or copy all the headers to your
   project's include directory.
Kenton Varda's avatar
Kenton Varda committed
160

161
7. Add `#define CAPNP_LITE 1` to either your project's precompiled/shared header or compiler options.
Kenton Varda's avatar
Kenton Varda committed
162

163
**From Git**
Kenton Varda's avatar
Kenton Varda committed
164

165 166 167
If you download directly from Git, you'll need to compile the Cap'n Proto tools (the `.exe`s) using
MinGW-w64. This is easiest to do in Cygwin or on Linux. For example, on Debian or Ubuntu, you can
install MinGW like so:
Kenton Varda's avatar
Kenton Varda committed
168

169
    sudo apt-get install mingw-w64
Kenton Varda's avatar
Kenton Varda committed
170

171 172
You'll first need to install Cap'n Proto on the host system (using the Unix installation
instructions, above). Then, do:
Kenton Varda's avatar
Kenton Varda committed
173

174 175 176 177
    make distclean
    ./configure --host=i686-w64-mingw32 --with-external-capnp \
      --disable-shared CXXFLAGS='-static-libgcc -static-libstdc++'
    make -j6 capnp.exe capnpc-c++.exe capnpc-capnp.exe
Kenton Varda's avatar
Kenton Varda committed
178

179
Now that you have the `exe`s, you can proceed with the usual Windows compilation instructions.