Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 33 additions & 11 deletions etc/Build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ EOF
numThreads=2
fi
cmakeOptions=()
isNinja=no
cleanBefore=no
depsPrefixesFile=""
compiler=gcc
useBazel=no
noGui=no

_help() {
cat <<EOF
Expand Down Expand Up @@ -54,6 +55,7 @@ OPTIONS:
-keep-log Keep a compile log in build dir
-help Shows this message
-gpu Enable GPU to accelerate the process
-bazel Use Bazel instead of CMake to build
-deps-prefixes-file=FILE File with CMake packages roots,
its content extends -cmake argument.
By default, "openroad_deps_prefixes.txt"
Expand Down Expand Up @@ -97,16 +99,11 @@ while [ "$#" -gt 0 ]; do
;;
-no-gui)
cmakeOptions+=("-DBUILD_GUI=OFF")
noGui=yes
;;
-no-tests)
cmakeOptions+=("-DENABLE_TESTS=OFF")
;;
-ninja)
cmakeOptions+=("-DCMAKE_C_COMPILER_LAUNCHER=ccache")
cmakeOptions+=("-DCMAKE_CXX_COMPILER_LAUNCHER=ccache")
cmakeOptions+=("-GNinja")
isNinja=yes
;;
-cpp20)
cmakeOptions+=("-DCMAKE_CXX_STANDARD=20")
;;
Expand All @@ -125,8 +122,12 @@ while [ "$#" -gt 0 ]; do
cmakeOptions+=("-DCMAKE_EXE_LINKER_FLAGS=-lgcov")
;;
-cmake=*)
read -ra temp_arr <<< "${1#*=}"
cmakeOptions+=("${temp_arr[@]}")
# Use xargs to safely parse the quoted string into array elements without eval
while IFS= read -r arg; do
if [[ -n "$arg" ]]; then
cmakeOptions+=("$arg")
fi
done < <(echo "${1#*=}" | xargs printf '%s\n')
;;
-clean )
cleanBefore=yes
Expand Down Expand Up @@ -155,6 +156,9 @@ while [ "$#" -gt 0 ]; do
-gpu)
cmakeOptions+=("-DGPU=ON")
;;
-bazel)
useBazel=yes
;;
*)
echo "unknown option: ${1}" >&2
_help
Expand All @@ -171,8 +175,11 @@ if [[ -z "$depsPrefixesFile" ]]; then
fi
fi
if [[ -f "$depsPrefixesFile" ]]; then
read -ra newOpts <<< "$(cat "$depsPrefixesFile")"
cmakeOptions+=("${newOpts[@]}")
while IFS= read -r arg; do
if [[ -n "$arg" ]]; then
cmakeOptions+=("$arg")
fi
done < <(xargs printf '%s\n' < "$depsPrefixesFile")
echo "[INFO] Using additional CMake parameters from $depsPrefixesFile"
else
echo "[INFO] Auto-generated prefix file does not exist - CMake will choose the dependencies automatically"
Expand Down Expand Up @@ -333,6 +340,21 @@ echo -e "${GREEN}All pre-compilation checks passed! Proceeding...${NC}\n"
# ==============================================================================

echo "[INFO] Using ${numThreads} threads."
if [[ "$useBazel" == "yes" ]]; then
echo "[INFO] Building with Bazel."
bazel_cmd="bazel"
if command -v bazelisk &> /dev/null; then
bazel_cmd="bazelisk"
fi
bazelArgs=("--config=opt" "--jobs=${numThreads}")
if [[ "$noGui" == "yes" ]]; then
bazelArgs+=("--//:platform=cli")
else
bazelArgs+=("--//:platform=gui")
fi
"${bazel_cmd}" build "${bazelArgs[@]}" //:openroad
exit 0
fi
if [[ "$isNinja" == "yes" ]]; then
cmake "${cmakeOptions[@]}" -B "${buildDir}" .
cd "${buildDir}"
Expand Down
120 changes: 114 additions & 6 deletions etc/DependencyInstaller.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ set -euo pipefail
PREFIX=""
CI="no"
SAVE_DEPS_PREFIXES=""
if [[ "$OSTYPE" == "darwin"* ]]; then
NUM_THREADS=$(sysctl -n hw.logicalcpu)
else
NUM_THREADS=$(nproc)
fi
NUM_THREADS=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 2)
SKIP_SYSTEM_OR_TOOLS="false"
BASE_DIR=$(mktemp -d /tmp/DependencyInstaller-XXXXXX)
CMAKE_PACKAGE_ROOT_ARGS=""
Expand Down Expand Up @@ -76,6 +72,14 @@ FLEX_CHECKSUM="2882e3179748cc9f9c23ec593d6adc8d"
OR_TOOLS_VERSION_BIG="9.14"
OR_TOOLS_VERSION_SMALL="${OR_TOOLS_VERSION_BIG}.6206"
EQUIVALENCE_DEPS="no"
INSTALL_BAZEL="no"
INSTALL_BAZEL_DEV="no"
BAZELISK_VERSION="1.28.1"
BAZELISK_CHECKSUM_AMD64="2dc74b7ad6bdd6b6b08f6802d14fc1fd"
BAZELISK_CHECKSUM_ARM64="94415d08ed2f86a49375f25a7f2f9cca"
BUILDIFIER_VERSION="8.5.1"
BUILDIFIER_CHECKSUM_AMD64="72f5953ab6dcc309a4447c2e2d79c680"
BUILDIFIER_CHECKSUM_ARM64="06f52f0872bde33685c6260110261cf7"
# ... configuration variables will be added here ...

# ==============================================================================
Expand Down Expand Up @@ -784,6 +788,91 @@ _install_or_tools() {
# Each dependency will have its own dedicated function for installation and
# version management. This modular approach makes the script easier to
# maintain and extend.
# ------------------------------------------------------------------------------
# Bazel
# ------------------------------------------------------------------------------
_install_bazel() {
local bazel_prefix=${PREFIX:-"/usr/local"}
log "Checking Bazel (via bazelisk)"
if _command_exists "bazelisk"; then
log "bazelisk already installed, skipping."
INSTALL_SUMMARY+=("Bazel: system=found, required=any, status=skipped")
return
fi
if [[ "$OSTYPE" == "darwin"* ]]; then
_execute "Installing bazelisk via Homebrew..." brew install bazelisk
else
local arch
arch=$(uname -m)
local bazelisk_arch="amd64"
if [[ "${arch}" == "aarch64" ]]; then
bazelisk_arch="arm64"
fi
local bazelisk_checksum="${BAZELISK_CHECKSUM_AMD64}"
if [[ "${bazelisk_arch}" == "arm64" ]]; then
bazelisk_checksum="${BAZELISK_CHECKSUM_ARM64}"
fi
(
cd "${BASE_DIR}"
_execute "Downloading bazelisk v${BAZELISK_VERSION}..." curl -Lo bazelisk \
"https://github.com/bazelbuild/bazelisk/releases/download/v${BAZELISK_VERSION}/bazelisk-linux-${bazelisk_arch}"
_verify_checksum "${bazelisk_checksum}" "bazelisk" || error "Bazelisk checksum failed."
chmod +x bazelisk
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to verify the checksum _verify_checksum

_execute "Installing bazelisk..." mv bazelisk "${bazel_prefix}/bin/bazelisk"
)
# Install xcb libraries needed for GUI support with Bazel builds
if _command_exists "apt-get"; then
_execute "Installing xcb libraries for GUI support..." \
apt-get -y install --no-install-recommends \
libxcb1-dev libxcb-util-dev libxcb-icccm4-dev libxcb-image0-dev \
libxcb-keysyms1-dev libxcb-randr0-dev libxcb-render-util0-dev \
libxcb-xinerama0-dev libxcb-xkb-dev
elif _command_exists "yum"; then
_execute "Installing xcb libraries for GUI support..." \
yum install -y \
libxcb-devel xcb-util-devel xcb-util-image-devel \
xcb-util-keysyms-devel xcb-util-renderutil-devel xcb-util-wm-devel
fi
fi
INSTALL_SUMMARY+=("Bazel: system=none, required=latest, status=installed")
}
Comment on lines +794 to +838
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This function currently only supports installing bazelisk on Linux. On macOS, it will fail because it tries to download a Linux binary. Please add support for macOS, for example by using Homebrew (brew install bazelisk).

_install_bazel() {
    local bazel_prefix=${PREFIX:-/usr/local}
    log "Checking Bazel (via bazelisk)"
    if _command_exists "bazelisk"; then
        log "bazelisk already installed, skipping."
        INSTALL_SUMMARY+=("Bazel: system=found, required=any, status=skipped")
        return
    fi

    if [[ "$(uname -s)" == "Darwin" ]]; then
        if ! _command_exists "brew"; then
            error "Homebrew not found, which is required to install bazelisk on macOS."
        fi
        _execute "Installing bazelisk..." brew install bazelisk
    else
        local arch
        arch=$(uname -m)
        local bazelisk_arch="amd64"
        if [[ "${arch}" == "aarch64" ]]; then
            bazelisk_arch="arm64"
        fi
        (
            cd "${BASE_DIR}"
            _execute "Downloading bazelisk..." curl -Lo bazelisk \
                "https://github.com/bazelbuild/bazelisk/releases/latest/download/bazelisk-linux-${bazelisk_arch}"
            chmod +x bazelisk
            _execute "Installing bazelisk..." mv bazelisk "${bazel_prefix}/bin/bazelisk"
        )
        # Install xcb libraries needed for GUI support with Bazel builds
        if _command_exists "apt-get"; then
            _execute "Installing xcb libraries for GUI support..." \
                apt-get -y install --no-install-recommends \
                libxcb1-dev libxcb-util-dev libxcb-icccm4-dev libxcb-image0-dev \
                libxcb-keysyms1-dev libxcb-randr0-dev libxcb-render-util0-dev \
                libxcb-xinerama0-dev libxcb-xkb-dev
        fi
    fi
    INSTALL_SUMMARY+=("Bazel: system=none, required=latest, status=installed")
}


# ------------------------------------------------------------------------------
# Bazel Dev Tools (buildifier, etc.)
# ------------------------------------------------------------------------------
_install_bazel_dev() {
local bazel_prefix=${PREFIX:-"/usr/local"}
log "Checking Bazel dev tools (buildifier)"
if _command_exists "buildifier"; then
log "buildifier already installed, skipping."
INSTALL_SUMMARY+=("buildifier: system=found, required=any, status=skipped")
return
fi
if [[ "$OSTYPE" == "darwin"* ]]; then
_execute "Installing buildifier via Homebrew..." brew install buildifier
else
local arch
arch=$(uname -m)
local buildifier_arch="amd64"
if [[ "${arch}" == "aarch64" ]]; then
buildifier_arch="arm64"
fi
local buildifier_checksum="${BUILDIFIER_CHECKSUM_AMD64}"
if [[ "${buildifier_arch}" == "arm64" ]]; then
buildifier_checksum="${BUILDIFIER_CHECKSUM_ARM64}"
fi
(
cd "${BASE_DIR}"
_execute "Downloading buildifier v${BUILDIFIER_VERSION}..." curl -Lo buildifier \
"https://github.com/bazelbuild/buildtools/releases/download/v${BUILDIFIER_VERSION}/buildifier-linux-${buildifier_arch}"
_verify_checksum "${buildifier_checksum}" "buildifier" || error "Buildifier checksum failed."
chmod +x buildifier
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to verify the checksum _verify_checksum

_execute "Installing buildifier..." mv buildifier "${bazel_prefix}/bin/buildifier"
)
fi
INSTALL_SUMMARY+=("buildifier: system=none, required=latest, status=installed")
}
Comment on lines +843 to +874
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Similar to _install_bazel, this function only supports Linux. Please add support for macOS. buildifier can be installed with Homebrew (brew install buildifier).

_install_bazel_dev() {
    local bazel_prefix=${PREFIX:-/usr/local}
    log "Checking Bazel dev tools (buildifier)"
    if _command_exists "buildifier"; then
        log "buildifier already installed, skipping."
        INSTALL_SUMMARY+=("buildifier: system=found, required=any, status=skipped")
        return
    fi

    if [[ "$(uname -s)" == "Darwin" ]]; then
        if ! _command_exists "brew"; then
            error "Homebrew not found, which is required to install buildifier on macOS."
        fi
        _execute "Installing buildifier..." brew install buildifier
    else
        local arch
        arch=$(uname -m)
        local buildifier_arch="amd64"
        if [[ "${arch}" == "aarch64" ]]; then
            buildifier_arch="arm64"
        fi
        (
            cd "${BASE_DIR}"
            _execute "Downloading buildifier..." curl -Lo buildifier \
                "https://github.com/bazelbuild/buildtools/releases/latest/download/buildifier-linux-${buildifier_arch}"
            chmod +x buildifier
            _execute "Installing buildifier..." mv buildifier "${bazel_prefix}/bin/buildifier"
        )
    fi
    INSTALL_SUMMARY+=("buildifier: system=none, required=latest, status=installed")
}


_install_common_dev() {
log "Install common development dependencies (-common or -all)"
rm -rf "${BASE_DIR}"
Expand Down Expand Up @@ -1043,6 +1132,8 @@ Options:
-base Install base dependencies using package managers. Requires privileged access.
-common Install common dependencies.
-eqy Install equivalence dependencies (yosys, eqy, sby).
-bazel Download and install bazel (via bazelisk).
-bazel-dev Download and install bazel developer tools (buildifier, etc.).
-prefix=DIR Install common dependencies in a user-specified directory.
-local Install common dependencies in \${HOME}/.local.
-ci Install dependencies required for CI.
Expand All @@ -1068,6 +1159,8 @@ main() {
-base) option="base" ;;
-common) option="common" ;;
-eqy) EQUIVALENCE_DEPS="yes" ;;
-bazel) INSTALL_BAZEL="yes" ;;
-bazel-dev) INSTALL_BAZEL_DEV="yes" ;;
-ci) CI="yes" ;;
-verbose) VERBOSE_MODE="yes" ;;
-local)
Expand Down Expand Up @@ -1113,8 +1206,23 @@ main() {
shift 1
done

if [[ "${option}" == "none" && "${INSTALL_BAZEL}" == "no" && "${INSTALL_BAZEL_DEV}" == "no" ]]; then
error "You must use one of: -all, -base, -common, -bazel, or -bazel-dev."
fi

# -bazel-dev implies -bazel (you need bazelisk to use buildifier)
if [[ "${INSTALL_BAZEL}" == "yes" || "${INSTALL_BAZEL_DEV}" == "yes" ]]; then
_install_bazel
fi

if [[ "${INSTALL_BAZEL_DEV}" == "yes" ]]; then
_install_bazel_dev
fi

if [[ "${option}" == "none" ]]; then
error "You must use one of: -all, -base, or -common."
_print_summary
rm -rf "${BASE_DIR}"
return
fi

OR_TOOLS_PATH=${PREFIX:-"/opt/or-tools"}
Expand Down
Loading