GitHub CI: update list of container images
[tinc] / INSTALL.md
1 # Dependencies
2
3 ## Required
4
5 Before you can start compiling tinc from a fresh git clone, you have to install
6 the very latest versions of the following packages:
7
8 - `meson` or `muon` (read below)
9 - `ninja` or `samurai`
10 - `pkgconf` or `pkg-config`
11 - `GCC` or `Clang` (any version with C11 support, although older versions might
12   work)
13 - `OpenSSL`\* (1.1.0+) or `LibreSSL` or `libgcrypt` (not needed if legacy
14   protocol is disabled)
15
16 ### No Python?
17
18 If you're on a constrained system that doesn't have (or cannot run) Python, you
19 can try building tinc with [muon][muon], which is a pure C reimplementation of
20 the same idea. Please note that `meson` is considered to be the main way of
21 building tinc, and `muon` is supported on a best-effort basis.
22
23 [muon]: https://git.sr.ht/~lattis/muon
24
25 ## Optional
26
27 Plus a few optional dependencies. Support for them will be enabled if they're
28 present:
29
30 - `ncurses` or `PDCurses`
31 - `readline`
32 - `zlib`\*
33 - `LZO`\*
34 - `LZ4`\*
35
36 If packages marked by `*` are not available, tinc will fall back to its own
37 vendored copies. This behavior can be disabled by setting the appropriate meson
38 option to `disabled`.
39
40 To build `info` documentation you'll also need these packages:
41
42 - `texinfo` or `makeinfo`
43
44 You might also need some additional command-line utilities to be able to run the
45 integration test suite:
46
47 - `diffutils`
48 - `procps`
49 - `socat`
50 - `netcat`
51
52
53 ## Linux
54
55 Depending on the distribution, one of the following commands can be used to install all dependencies:
56 - Arch Linux: `sudo pacman --needed --sync base-devel meson ninja pkg-config openssl ncurses readline zlib lzo lz4 texinfo diffutils procps socat openbsd-netcat`
57 - Debian: `sudo apt install meson ninja-build pkg-config build-essential libssl-dev libncurses-dev libreadline-dev zlib1g-dev liblzo2-dev liblz4-dev texinfo diffutils procps socat netcat-openbsd`
58 - Alpine Linux: `doas apk add meson ninja pkgconf build-base linux-headers openssl-dev ncurses-dev readline-dev zlib-dev lzo-dev lz4-dev texinfo diffutils procps-ng socat netcat-openbsd`
59 - Fedora: `sudo dnf install meson ninja-build pkgconf-pkg-config @development-tools openssl-devel ncurses-devel readline-devel zlib-devel lzo-devel lz4-devel texinfo diffutils procps-ng socat netcat`
60
61 ## Windows
62
63 You can build tinc using either the native [Windows SDK][sdk-ms] (which comes
64 with Visual Studio), or with the Unix-like [msys2 environment][sdk-msys2].
65 Install either one of them, plus the latest version of [meson][meson-release].
66
67 If you prefer the native SDK, you might want to work on tinc (or build it) under
68 Visual Studio. To do so, follow [these instructions][meson-vs].
69
70 By default, tinc produces a static Windows build, so you don't need to install
71 anything in order to _run_ the compiled binaries.
72
73 [sdk-ms]: https://visualstudio.com/
74 [sdk-msys2]: https://msys2.org/
75 [meson-release]: https://github.com/mesonbuild/meson/releases
76 [meson-vs]: https://mesonbuild.com/Using-with-Visual-Studio.html
77
78 # Building from source
79
80 ## Native
81
82 ### Setup
83
84 Tinc's functionality can vary greatly depending on how you configure it. Have a
85 look at the available options in [`meson_options.txt`](meson_options.txt), or
86 run:
87
88 ```sh
89 meson configure
90 ```
91
92 First you need to create a build directory. If you want the default experience,
93 run:
94
95 ```sh
96 meson setup builddir
97 ```
98
99 or with configuration options (your shell can probably autocomplete them on
100 `Tab`, try it):
101
102 ```sh
103 meson setup builddir -Dprefix=/usr/local -Dbuildtype=release
104 ```
105
106 (For autotools users: this is a rough equivalent of
107 `autoreconf -fsi && ./configure --prefix=/usr/local --with-foobar`).
108
109 This creates a build directory (named `builddir`) with build type set to
110 `release` (which enables compiler optimizations) and path prefix set to
111 `/usr/local`.
112
113 Pass any additional options in the same way. Typically, this is not needed: tinc
114 will autodetect available libraries and adjust its functionality accordingly.
115
116 If you'd like to reconfigure the project after running `setup`, you can either
117 remove the build directory and start anew, or use:
118
119 ```sh
120 meson configure builddir -Dlzo=disabled -Dlz4=enabled
121 ```
122
123 ### Compile
124
125 You then need to build the project:
126
127 ```sh
128 meson compile -C builddir
129 ```
130
131 (For autotools users: this is an equivalent of `make -j$(nproc)`).
132
133 ### Test
134
135 You might want to run the test suite to ensure tinc is working correctly:
136
137 ```sh
138 meson test -C builddir
139 ```
140
141 (For autotools users: this is an equivalent of `make -j$(nproc) test`).
142
143 ### Install
144
145 To install tinc to your system, run:
146
147 ```sh
148 meson install -C builddir
149 ```
150
151 (For autotools users: this is an equivalent of `make install`).
152
153 Please be aware that this is not the best method of installing software because
154 it will not be tracked by your operating system's package manager. You should
155 use packages provided by your operating system, or build your own (this is a
156 large and complicated topic which is out of the scope of this document).
157
158 ### Uninstall
159
160 To uninstall tinc, run:
161
162 ```sh
163 ninja -C builddir uninstall
164 ```
165
166 (For autotools users: this is an equivalent of `make uninstall`).
167
168 ## Cross-compilation
169
170 ### Linux to Linux
171
172 Cross-compilation is easy to do on Debian or its derivatives. Set `$HOST` to
173 your target architecture and install the cross-compilation toolchain and `-dev`
174 versions of all libraries you'd like to link:
175
176 ```sh
177 HOST=armhf
178 dpkg --add-architecture $HOST
179 apt update
180 apt install -y crossbuild-essential-$HOST zlib1g-dev:$HOST …
181 ```
182
183 If you'd like to run tests on emulated hardware, install `qemu-user`:
184
185 ```sh
186 apt install -y qemu-user
187 update-binfmts --enable
188 ```
189
190 Set two environment variables: the C compiler, and pkg-config, and then proceed
191 as usual:
192
193 ```sh
194 export CC=arm-linux-gnueabihf-gcc
195 export PKG_CONFIG=arm-linux-gnueabihf-pkg-config
196 meson setup build --cross-file /dev/null
197 ```
198
199 Or put the names into a [cross file][cross] and pass it to meson:
200
201 ```sh
202 cat >cross-armhf <<EOF
203 [binaries]
204 c = 'arm-linux-gnueabihf-gcc'
205 pkgconfig = 'arm-linux-gnueabihf-pkg-config'
206 EOF
207
208 meson setup build --cross-file cross-armhf
209 ```
210
211 [cross]: https://mesonbuild.com/Cross-compilation.html
212
213 ### Linux to Windows
214
215 Install cross-compilation toolchain:
216
217 ```sh
218 apt install -y mingw-w64 mingw-w64-tools
219 ```
220
221 tinc will use its own vendored libraries, so you don't need to install or build
222 anything manually.
223
224 Prepare the [cross file][cross] to let meson know you're building binaries for a
225 different operating system. Take a look at the [file](.ci/cross/windows/amd64)
226 used by CI for an example, or refer to examples provided by the meson project:
227 [x86][mingw32],[x86_64][mingw64].
228
229 Then build as usual. Because Windows binaries are built with static linkage by
230 default, you might want to enable link-time optimization. It is much slower than
231 building without LTO, but produces binaries that are 80%+ smaller:
232
233 ```sh
234 meson setup build -Dbuildtype=release -Db_lto=true --cross-file cross-windows
235 ninja -C build
236 ```
237
238 [mingw64]: https://github.com/mesonbuild/meson/blob/master/cross/linux-mingw-w64-64bit.txt
239 [mingw32]: https://github.com/mesonbuild/meson/blob/master/cross/linux-mingw-w64-32bit.txt
240
241 ### Linux to Android
242
243 First you need to install [Android NDK][ndk].
244
245 [ndk]: https://developer.android.com/studio/projects/install-ndk
246
247 Prepare a [cross file][cross]. Here's a working example for reference:
248
249 ```ini
250 [host_machine]
251 system     = 'android'
252 cpu_family = 'arm'
253 cpu        = 'aarch64'
254 endian     = 'little'
255
256 [binaries]
257 c = 'aarch64-linux-android24-clang'
258 ```
259
260 Then build as usual:
261
262 ```sh
263 export ANDROID_NDK_ROOT=/tmp/ndk/android-ndk-r24
264 export PATH=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH
265 meson setup android-aarch64 -Dcrypto=nolegacy --cross-file android
266 ninja -C android-aarch64
267 ```
268
269 ### macOS to iOS
270
271 The same instructions should work for iOS. Refer to this [cross file][ios] for
272 an example.
273
274 [ios]: https://github.com/mesonbuild/meson/blob/master/cross/iphone.txt