2020-04-27 07:12:27 +08:00
|
|
|
#!/bin/bash
|
2020-09-17 12:57:46 +08:00
|
|
|
# Usage (for in-tree build/ directory):
|
|
|
|
# ./build_tools/install_mlir.sh
|
2021-01-06 06:17:08 +08:00
|
|
|
# For arbitrary build/install directories, set the env variables:
|
|
|
|
# - NPCOMP_BUILD_DIR
|
|
|
|
# - LLVM_BUILD_DIR
|
|
|
|
# - LLVM_INSTALL_DIR
|
2020-04-27 07:12:27 +08:00
|
|
|
set -e
|
2020-12-30 05:03:15 +08:00
|
|
|
|
|
|
|
portable_realpath() {
|
2021-01-06 06:17:08 +08:00
|
|
|
# Create the directory if needed so that the `cd` doesn't fail.
|
|
|
|
mkdir -p $1 && cd $1 && pwd
|
2020-12-30 05:03:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
td="$(portable_realpath $(dirname $0)/..)"
|
|
|
|
build_dir="$(portable_realpath "${NPCOMP_BUILD_DIR:-$td/build}")"
|
2020-10-08 09:31:24 +08:00
|
|
|
build_mlir="${LLVM_BUILD_DIR-$build_dir/build-mlir}"
|
|
|
|
install_mlir="${LLVM_INSTALL_DIR-$build_dir/install-mlir}"
|
2020-04-30 08:05:45 +08:00
|
|
|
|
|
|
|
# Find LLVM source (assumes it is adjacent to this directory).
|
2020-12-30 05:03:15 +08:00
|
|
|
LLVM_SRC_DIR="$(portable_realpath "${LLVM_SRC_DIR:-$td/external/llvm-project}")"
|
2020-04-27 07:12:27 +08:00
|
|
|
|
2020-04-30 08:05:45 +08:00
|
|
|
if ! [ -f "$LLVM_SRC_DIR/llvm/CMakeLists.txt" ]; then
|
2020-04-27 07:12:27 +08:00
|
|
|
echo "Expected LLVM_SRC_DIR variable to be set correctly (got '$LLVM_SRC_DIR')"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
echo "Using LLVM source dir: $LLVM_SRC_DIR"
|
|
|
|
# Setup directories.
|
|
|
|
echo "Building MLIR in $build_mlir"
|
|
|
|
echo "Install MLIR to $install_mlir"
|
|
|
|
mkdir -p "$build_mlir"
|
|
|
|
mkdir -p "$install_mlir"
|
|
|
|
|
|
|
|
echo "Beginning build (commands will echo)"
|
|
|
|
set -x
|
|
|
|
|
2020-10-16 07:25:53 +08:00
|
|
|
function probe_python() {
|
|
|
|
local python_exe="$1"
|
|
|
|
local found
|
|
|
|
local command
|
|
|
|
command="import sys
|
|
|
|
if sys.version_info.major >= 3: print(sys.executable)"
|
|
|
|
found="$("$python_exe" -c "$command")"
|
|
|
|
if ! [ -z "$found" ]; then
|
|
|
|
echo "$found"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
python_exe=""
|
|
|
|
for python_candidate in python3 python; do
|
|
|
|
python_exe="$(probe_python "$python_candidate")"
|
|
|
|
if ! [ -z "$python_exe" ]; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "Using python: $python_exe"
|
|
|
|
if [ -z "$python_exe" ]; then
|
|
|
|
echo "Could not find python3"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-04-27 07:12:27 +08:00
|
|
|
cmake -GNinja \
|
|
|
|
"-H$LLVM_SRC_DIR/llvm" \
|
|
|
|
"-B$build_mlir" \
|
2020-10-08 09:31:24 +08:00
|
|
|
-DCMAKE_EXPORT_COMPILE_COMMANDS=TRUE \
|
2021-01-21 10:07:04 +08:00
|
|
|
"-DPython3_EXECUTABLE=$python_exe" \
|
2020-10-09 09:29:59 +08:00
|
|
|
-DLLVM_BUILD_LLVM_DYLIB=ON \
|
2020-11-09 10:19:36 +08:00
|
|
|
-DLLVM_LINK_LLVM_DYLIB=ON \
|
2020-04-27 07:12:27 +08:00
|
|
|
-DLLVM_INSTALL_UTILS=ON \
|
|
|
|
-DLLVM_ENABLE_PROJECTS=mlir \
|
2021-02-22 05:36:06 +08:00
|
|
|
-DLLVM_TARGETS_TO_BUILD="X86;AArch64" \
|
2020-04-30 08:05:45 +08:00
|
|
|
-DLLVM_INCLUDE_TOOLS=ON \
|
2020-04-27 07:12:27 +08:00
|
|
|
"-DCMAKE_INSTALL_PREFIX=$install_mlir" \
|
|
|
|
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
|
2020-11-04 05:46:46 +08:00
|
|
|
-DLLVM_USE_SPLIT_DWARF=ON \
|
2020-04-27 07:12:27 +08:00
|
|
|
-DLLVM_ENABLE_ASSERTIONS=On \
|
2021-01-23 08:30:23 +08:00
|
|
|
-DMLIR_BINDINGS_PYTHON_ENABLED=ON \
|
|
|
|
"$@"
|
2020-04-27 07:12:27 +08:00
|
|
|
|
|
|
|
cmake --build "$build_mlir" --target install
|