xref: /kvm-unit-tests/README.macOS.md (revision f01561d3d12c05fc3d952c28e538cc5797670aef)
1# kvm-unit-tests on macOS
2
3The tests can be used to validate TCG or HVF accel on macOS.
4
5## Prerequisites
6
7GNU getopt and coreutils should be installed prior to building and running the
8tests. They're available in [homebrew](https://brew.sh):
9```
10$ brew install coreutils
11$ brew install gnu-getopt
12```
13
14A cross-compiler with ELF support is required to build kvm-unit-tests on macOS.
15
16### Pre-built cross-compiler
17
18Binary packages of ELF cross-compilers for i386 and x86_64 target can be
19installed from homebrew:
20```
21$ brew install i686-elf-gcc
22$ brew install x86_64-elf-gcc
23```
24
25Make enhanced getopt available in the current shell session:
26```
27export PATH="/usr/local/opt/gnu-getopt/bin:$PATH"
28```
29
30Then, 32-bit x86 tests can be built like that:
31```
32$ ./configure \
33  --arch=i386 \
34  --cross-prefix=i686-elf-
35$ make -j $(nproc)
36```
37
3864-bit x86 tests can be built likewise:
39```
40$ ./configure \
41  --arch=x86_64 \
42  --cross-prefix=x86_64-elf-
43$ make -j $(nproc)
44```
45
46Out-of-tree build can be used to make tests for both architectures
47simultaneously in separate build directories.
48
49### Building cross-compiler from source
50
51An alternative is to build cross-compiler toolchain from source using
52crosstool-ng. The latest released version of
53[crosstool-ng](https://github.com/crosstool-ng/crosstool-ng) can be installed
54using homebrew:
55```
56$ brew install crosstool-ng
57```
58
59A case-sensitive APFS/HFS+ volume has to be created using Disk Utility as a
60build and installation directory for the cross-compiler. Please [see Apple
61documentation](https://support.apple.com/guide/disk-utility/dsku19ed921c/mac)
62for details.
63
64Assuming the case-sensitive volume is named /Volumes/BuildTools, the
65cross-compiler can be built and installed there:
66```
67$ X_BUILD_DIR=/Volumes/BuildTools/ct-ng-build
68$ X_INSTALL_DIR=/Volumes/BuildTools/x-tools
69$ mkdir $X_BUILD_DIR
70$ ct-ng -C $X_BUILD_DIR x86_64-unknown-linux-gnu
71$ ct-ng -C $X_BUILD_DIR build CT_PREFIX=$X_INSTALL_DIR
72```
73
74Once compiled, the cross-compiler can be used to build the tests:
75```
76$ ./configure \
77  --arch=x86_64 \
78  --cross-prefix=$X_INSTALL_DIR/x86_64-unknown-linux-gnu/bin/x86_64-unknown-linux-gnu-
79$ make -j $(nproc)
80```
81