install.md 7.35 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
* GCC 4.8
* Clang 3.3
52
* Visual C++ 2015
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
* Windows - Cygwin
67 68
* Windows - MinGW-w64
* Windows - Visual C++
69

70 71 72 73
**Windows users:** Cap'n Proto requires Visual Studio 2015 Update 3 or newer. All runtime features
of Cap'n Proto -- including serialization and RPC -- are now supported. (It is still not possible to
compile the code generator tool, capnp.exe, using Visual Studio; however, a precompiled copy built
with MinGW is provided in the release zip for your convenience.)
74

75 76 77
**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
78 79
[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
80

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

83 84
**From Release Tarball**

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

87
<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>
88 89
tar zxf capnproto-c++-0.0.0.tar.gz
cd capnproto-c++-0.0.0
Kenton Varda's avatar
Kenton Varda committed
90 91 92 93 94 95 96 97
./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`.

98 99 100 101 102 103 104 105 106
**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`

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

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

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

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

123 124
**From Release Zip**

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

127
   <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>
128

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

132 133
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
134

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

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

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

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

145 146 147
    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.

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

150 151
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
152

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

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

157 158 159 160
   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
161

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

164 165 166
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
167

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

170 171
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
172

173 174 175 176
    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
177

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