Skip to content

Commit c362cf0

Browse files
Add relevant info for MacOS building process (#1176)
1 parent eb79b84 commit c362cf0

File tree

2 files changed

+65
-9
lines changed

2 files changed

+65
-9
lines changed

INSTALL.md

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ python3 -m pip install pybind11 lit
3030
```
3131

3232
## macOS / Homebrew
33-
33+
In order to install the dependencies on macOS, you must have Homebrew installed and on your `PATH`.
3434
```shell
3535
brew update
3636
brew install \
@@ -40,19 +40,70 @@ brew install \
4040
fmt \
4141
git \
4242
gmp \
43+
grep \
4344
jemalloc \
45+
libffi
4446
libyaml \
4547
llvm@15 \
4648
maven \
4749
mpfr \
4850
pkg-config \
4951
python3 \
5052
z3
53+
```
54+
55+
To ensure that the backend can use pybind11 correctly, we must create an virtual
56+
environment and install the `pybind11` package:
57+
```shell
58+
python3 -m venv venv
59+
source venv/bin/activate
5160
python3 -m pip install pybind11 lit
5261
```
5362

63+
Guarantee that you have the JDK installed and on your `PATH`:
64+
```shell
65+
export PATH="/opt/homebrew/opt/openjdk/bin:$PATH"
66+
```
67+
68+
Some tests rely on GNU Grep options, which are not available on macOS by
69+
default. To ensure that the tests run correctly, you add the path of
70+
GNU Grep to your `PATH` in your shell profile:
71+
```shell
72+
export PATH=/opt/homebrew/Cellar/grep/3.11/libexec/gnubin/:$PATH
73+
```
74+
5475
# Building
5576

77+
## Environment Variables
78+
79+
If you're building on macOS, type the following command or epermanently
80+
add it your `env` (`.zshrc`, `.bashrc`, etc.), so that the Homebrew
81+
installation of LLVM gets picked up correctly. We recommend adding it to
82+
your shell profile.
83+
```shell
84+
export LLVM_DIR=$($(brew --prefix llvm@15)/bin/llvm-config --cmakedir)
85+
```
86+
87+
If you don't usually use the `clang` from your Homebrew installation as
88+
your default compiler, you can set the following CMake flg to use these
89+
`clang` and `clang++`:
90+
```shell
91+
-DCMAKE_C_COMPILER="$(brew --prefix llvm@15)/bin/clang" \
92+
-DCMAKE_CXX_COMPILER="$(brew --prefix llvm@15)/bin/clang++"
93+
```
94+
Once again, we recommend adding them and other llvm binaries to your
95+
`PATH` in your shell profile:
96+
```shell
97+
export PATH="$(brew --prefix llvm@15)/bin:$PATH"
98+
```
99+
100+
Some tests rely on GNU Grep options, which are not available on macOS by
101+
default. To ensure that the tests run correctly, you can create an alias
102+
for GNU Grep:
103+
```shell
104+
alias grep=ggrep
105+
```
106+
56107
Once the system dependencies have been installed, the backend can be built
57108
locally with:
58109
```shell
@@ -66,12 +117,6 @@ cmake .. \
66117
make -j$(nproc) install
67118
```
68119

69-
If you're building on macOS, add the following option to your CMake invocation
70-
so that the Homebrew installation of LLVM gets picked up correctly.
71-
```shell
72-
-DLLVM_DIR=$($(brew --prefix llvm@15)/bin/llvm-config --cmakedir)
73-
```
74-
75120
Additionally, to build the pattern-matching compiler, run:
76121
```shell
77122
cd matching
@@ -91,7 +136,8 @@ To run the integration tests, run:
91136
```shell
92137
lit test
93138
```
94-
from the root source directory.
139+
from the root source directory. You can use `-v` to see which test is being executed
140+
and the output of failling tests.
95141

96142
There is also a unit test suite for backend internals;
97143
Add the following option to your CMake invocation to enable it:
@@ -113,7 +159,7 @@ and conform to best practices.
113159

114160
```shell
115161
# Ubuntu
116-
apt install shellcheck clang-format-12 iwyu
162+
apt install shellcheck clang-format-15 iwyu
117163

118164
# macOS
119165
brew install shellcheck clang-format iwyu

cmake/FixHomebrew.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,15 @@ if(APPLE)
2020
include_directories(AFTER SYSTEM "${BREW_PREFIX}/include")
2121
link_directories(AFTER "${BREW_PREFIX}/lib")
2222
set(ENV{PKG_CONFIG_PATH} "${BREW_PREFIX}/opt/libffi/lib/pkgconfig")
23+
24+
# Use LLD as the linker
25+
# This is necessary as the default linker used by CMake on macOS is
26+
# ld64, which currently has some incompatibilities with Homebrew and XCode15.
27+
# See: https://github.com/orgs/Homebrew/discussions/4794#discussioncomment-7044468
28+
# Adding this flag avoid the following errors:
29+
# ld: warning: duplicate -rpath ... ignored
30+
# ld: warning: ignoring duplicate libraries ...
31+
add_link_options("-fuse-ld=lld")
32+
2333
endif() # USE_NIX
2434
endif() # APPLE

0 commit comments

Comments
 (0)