Skip to content

Commit 39a6611

Browse files
authored
Merge pull request #10113 from Sahil7741/fix/macos-local-build
build: Improve macOS build and dependency installation
2 parents aec50a4 + 73deb5f commit 39a6611

3 files changed

Lines changed: 88 additions & 8 deletions

File tree

docs/user/Build.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,26 @@ it can be uploaded in the "Relevant log output" section of OpenROAD
9595
[issue forms](https://github.com/The-OpenROAD-Project/OpenROAD-flow-scripts/issues/new/choose).
9696
```
9797

98+
### Only for macOS Setup
99+
100+
On macOS, it is recommended to use a Python virtual environment to isolate dependencies and avoid system conflicts.
101+
102+
1. Create a virtual environment in the OpenROAD directory:
103+
``` shell
104+
python3 -m venv .venv
105+
```
106+
107+
2. Activate the virtual environment:
108+
``` shell
109+
source .venv/bin/activate
110+
```
111+
112+
3. With virtual environment activated, run without `sudo`:
113+
``` shell
114+
./etc/DependencyInstaller.sh -base
115+
./etc/DependencyInstaller.sh -common -local
116+
```
117+
98118
### Install Dependencies
99119

100120
You may follow our helper script to install dependencies as follows:

etc/Build.sh

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ buildDir="build"
1010
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
1111
numThreads=$(nproc --all)
1212
elif [[ "$OSTYPE" == "darwin"* ]]; then
13-
numThreads=$(sysctl -n hw.ncpu)
13+
numThreads=$(sysctl -n hw.logicalcpu)
1414
else
1515
cat << EOF
1616
WARNING: Unsupported OSTYPE: cannot determine number of host CPUs"
@@ -196,8 +196,64 @@ mkdir -p "${buildDir}"
196196
__logging
197197

198198
if [[ "$OSTYPE" == "darwin"* ]]; then
199-
export PATH="$(brew --prefix bison)/bin:$(brew --prefix flex)/bin:$PATH"
200-
export CMAKE_PREFIX_PATH=$(brew --prefix or-tools)
199+
200+
_bison=$(brew --prefix bison 2>/dev/null || true)
201+
_flex=$(brew --prefix flex 2>/dev/null || true)
202+
_ortools=$(brew --prefix or-tools 2>/dev/null || true)
203+
204+
if [[ -z "$_bison" || ! -d "$_bison/bin" ]]; then
205+
echo "[ERROR] bison not found or broken. Run: brew install bison" >&2
206+
exit 1
207+
fi
208+
if [[ -z "$_flex" || ! -d "$_flex/bin" ]]; then
209+
echo "[ERROR] flex not found or broken. Run: brew install flex" >&2
210+
exit 1
211+
fi
212+
if [[ -z "$_ortools" || ! -d "$_ortools/lib" || ! -d "$_ortools/include" ]]; then
213+
echo "[ERROR] or-tools not found or broken. Run: brew install or-tools" >&2
214+
exit 1
215+
fi
216+
217+
export PATH="$_bison/bin:$_flex/bin:$PATH"
218+
export CMAKE_PREFIX_PATH="${_ortools}"
219+
220+
_qt5=$(brew --prefix qt@5 2>/dev/null || true)
221+
if [[ -z "$_qt5" || ! -d "$_qt5/lib" ]]; then
222+
echo "[ERROR] qt@5 not found or broken. Run: brew install qt@5" >&2
223+
exit 1
224+
fi
225+
226+
cmakeOptions+=" -DQt5_DIR=$_qt5/lib/cmake/Qt5"
227+
228+
_tcl8=$(brew --prefix tcl-tk@8 2>/dev/null || true)
229+
if [[ -z "$_tcl8" || ! -d "$_tcl8/lib" || ! -d "$_tcl8/include" ]]; then
230+
echo "[ERROR] tcl-tk@8 not found or broken. Run: brew install tcl-tk@8" >&2
231+
exit 1
232+
fi
233+
234+
cmakeOptions+=" -DTCL_LIBRARY=$_tcl8/lib/libtcl8.6.dylib"
235+
236+
cmakeOptions+=" -DTCL_INCLUDE_PATH=$_tcl8/include"
237+
cmakeOptions+=" -DFLEX_INCLUDE_DIR=$_flex/include"
238+
239+
cmakeOptions+=" -DCMAKE_CXX_FLAGS=-DBOOST_STACKTRACE_GNU_SOURCE_NOT_REQUIRED"
240+
241+
_icu="$(brew --prefix icu4c 2>/dev/null || true)"
242+
if [[ -z "$_icu" || ! -d "$_icu/lib" ]]; then
243+
echo "[ERROR] icu4c not found or broken. Run: brew install icu4c" >&2
244+
exit 1
245+
fi
246+
247+
export LDFLAGS="-L$_icu/lib"
248+
export CPPFLAGS="-I$_icu/include"
249+
export PKG_CONFIG_PATH="$_icu/lib/pkgconfig"
250+
251+
_extra_lib_paths=("$(brew --prefix)/lib")
252+
253+
_joined_paths="$(IFS=:; echo "${_extra_lib_paths[*]}")"
254+
255+
export LIBRARY_PATH="${_joined_paths}${LIBRARY_PATH:+:$LIBRARY_PATH}"
256+
echo "[INFO] General LIBRARY_PATH=$LIBRARY_PATH"
201257
fi
202258

203259
# ==============================================================================

etc/DependencyInstaller.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ set -euo pipefail
1616
PREFIX=""
1717
CI="no"
1818
SAVE_DEPS_PREFIXES=""
19-
NUM_THREADS=$(nproc)
19+
if [[ "$OSTYPE" == "darwin"* ]]; then
20+
NUM_THREADS=$(sysctl -n hw.logicalcpu)
21+
else
22+
NUM_THREADS=$(nproc)
23+
fi
2024
SKIP_SYSTEM_OR_TOOLS="false"
2125
BASE_DIR=$(mktemp -d /tmp/DependencyInstaller-XXXXXX)
2226
CMAKE_PACKAGE_ROOT_ARGS=""
@@ -953,9 +957,9 @@ EOF
953957
exit 1
954958
fi
955959
log "Install darwin base packages using homebrew (-base or -all)"
956-
_execute "Installing Homebrew packages..." brew install bison boost bzip2 cmake eigen flex fmt groff googletest libomp or-tools pandoc pkg-config pyqt python spdlog tcl-tk zlib swig yaml-cpp
957-
_execute "Installing pipx..." brew install pipx
958-
_execute "Installing Python click..." pipx install click
960+
_execute "Installing Homebrew packages..." brew install bison boost bzip2 cmake eigen flex fmt groff googletest icu4c libomp or-tools pandoc pkg-config qt@5 python spdlog tcl-tk@8 zlib swig yaml-cpp
961+
# _execute "Installing pipx..." brew install pipx
962+
_execute "Installing Python click..." pip install click
959963
_execute "Linking libomp..." brew link --force libomp
960964
_execute "Installing lemon-graph..." brew install The-OpenROAD-Project/lemon-graph/lemon-graph
961965
}
@@ -1220,7 +1224,7 @@ main() {
12201224
cat <<EOF
12211225
12221226
To install or run OpenROAD, update your path with:
1223-
export PATH="\$(brew --prefix bison)/bin:\$(brew --prefix flex)/bin:\$(brew --prefix tcl-tk)/bin:\${PATH}"
1227+
export PATH="\$(brew --prefix bison)/bin:\$(brew --prefix flex)/bin:\$(brew --prefix tcl-tk@8)/bin:\${PATH}"
12241228
export CMAKE_PREFIX_PATH=\$(brew --prefix or-tools)
12251229
EOF
12261230
;;

0 commit comments

Comments
 (0)