From 3e5a42de8b834cb29a33feefa240ede5f255c69f Mon Sep 17 00:00:00 2001 From: Jerry Zhao Date: Tue, 27 Feb 2024 16:30:26 -0800 Subject: [PATCH] Add script to build circt-from-source - from submodule --- .gitmodules | 3 + scripts/build-circt-from-source.sh | 97 ++++++++++++++++++++++++++++++ tools/circt | 1 + 3 files changed, 101 insertions(+) create mode 100755 scripts/build-circt-from-source.sh create mode 160000 tools/circt diff --git a/.gitmodules b/.gitmodules index 4f21369e..3aacc69d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -148,3 +148,6 @@ [submodule "generators/rocket-chip-inclusive-cache"] path = generators/rocket-chip-inclusive-cache url = https://github.com/chipsalliance/rocket-chip-inclusive-cache.git +[submodule "tools/circt"] + path = tools/circt + url = https://github.com/llvm/circt.git diff --git a/scripts/build-circt-from-source.sh b/scripts/build-circt-from-source.sh new file mode 100755 index 00000000..55370536 --- /dev/null +++ b/scripts/build-circt-from-source.sh @@ -0,0 +1,97 @@ +#!/usr/bin/env bash + +# exit script if any command fails +set -e +set -o pipefail + +RDIR=$(git rev-parse --show-toplevel) + +# get helpful utilities +source $RDIR/scripts/utils.sh + +common_setup + +# Allow user to override MAKE +[ -n "${MAKE:+x}" ] || MAKE=$(command -v gnumake || command -v gmake || command -v make) +readonly MAKE + +usage() { + echo "usage: ${0}" + echo "" + echo "Options" + echo " --prefix -p PREFIX : Install destination." + echo " --help -h : Display this message" + exit "$1" +} + +PREFIX="" + +# getopts does not support long options, and is inflexible +while [ "$1" != "" ]; +do + case $1 in + -h | -H | --help | help ) + usage 3 ;; + -p | --prefix ) + shift + PREFIX=$(realpath $1) ;; + * ) + error "invalid option $1" + usage 1 ;; + esac + shift +done + +if [ -z "$PREFIX" ] ; then + error "ERROR: Prefix not given." + exit 1 +fi + + + +echo "Cloning CIRCT submodules" +( + cd $RDIR/tools + git submodule update --init circt + cd circt + git submodule init + git submodule update +) + +echo "Building CIRCT's LLVM/MLIR" +( + cd $RDIR/tools/circt + rm -rf llvm/build + mkdir llvm/build + cd llvm/build + cmake -G Ninja ../llvm \ + -DLLVM_ENABLE_PROJECTS="mlir" \ + -DLLVM_TARGETS_TO_BUILD="host" \ + -DLLVM_ENABLE_ASSERTIONS=ON \ + -DCMAKE_BUILD_TYPE=DEBUG \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + ninja +) + +echo "Building CIRCT" +( + cd $RDIR/tools/circt + rm -rf build + mkdir build + cd build + cmake -G Ninja .. \ + -DMLIR_DIR=../llvm/build/lib/cmake/mlir \ + -DLLVM_DIR=../llvm/build/lib/cmake/llvm \ + -DLLVM_ENABLE_ASSERTIONS=ON \ + -DCMAKE_BUILD_TYPE=DEBUG \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ + -DCMAKE_INSTALL_PREFIX=$PREFIX + ninja +) + +echo "Installing CIRCT to $PREFIX" +( + cd $RDIR/tools/circt/build + ninja install +) + diff --git a/tools/circt b/tools/circt new file mode 160000 index 00000000..9e0c1696 --- /dev/null +++ b/tools/circt @@ -0,0 +1 @@ +Subproject commit 9e0c1696f3caef4059c65774ad6b8efee91d9d9e