2020-04-27 07:26:45 +08:00
|
|
|
#!/bin/bash
|
2020-09-17 12:57:46 +08:00
|
|
|
# Configures the project with default options.
|
|
|
|
# LLVM/MLIR should be installed into the build directory first by running
|
|
|
|
# ./build_tools/install_mlir.sh.
|
|
|
|
#
|
|
|
|
# Usage (for in-tree build/ directory):
|
|
|
|
# ./build_tools/cmake_configure.sh [ARGS...]
|
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:26:45 +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
|
|
|
}
|
|
|
|
|
2020-04-27 07:26:45 +08:00
|
|
|
# Setup directories.
|
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-29 11:32:49 +08:00
|
|
|
declare -a extra_opts
|
2020-04-27 07:26:45 +08:00
|
|
|
|
|
|
|
if ! [ -d "$install_mlir/include/mlir" ]; then
|
|
|
|
echo "MLIR install path does not appear valid: $install_mlir"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
mkdir -p "$build_dir"
|
|
|
|
|
|
|
|
# Make sure we are using python3.
|
2020-07-02 12:28:04 +08:00
|
|
|
function probe_python() {
|
|
|
|
local python_exe="$1"
|
|
|
|
local found
|
2020-07-03 01:45:49 +08:00
|
|
|
local command
|
|
|
|
command="import sys
|
2020-07-02 12:28:04 +08:00
|
|
|
if sys.version_info.major >= 3: print(sys.executable)"
|
|
|
|
set +e
|
2020-07-03 01:45:49 +08:00
|
|
|
found="$("$python_exe" -c "$command")"
|
2020-07-02 12:28:04 +08:00
|
|
|
if ! [ -z "$found" ]; then
|
|
|
|
echo "$found"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
python_exe=""
|
|
|
|
for python_candidate in python3 python; do
|
|
|
|
python_exe="$(probe_python "$python_candidate")"
|
2020-07-03 01:45:49 +08:00
|
|
|
if ! [ -z "$python_exe" ]; then
|
|
|
|
break
|
|
|
|
fi
|
2020-07-02 12:28:04 +08:00
|
|
|
done
|
|
|
|
|
2020-04-27 07:26:45 +08:00
|
|
|
echo "Using python: $python_exe"
|
|
|
|
if [ -z "$python_exe" ]; then
|
|
|
|
echo "Could not find python3"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-07-02 12:28:04 +08:00
|
|
|
# Detect windows.
|
|
|
|
if (which cygpath 2>/dev/null); then
|
|
|
|
echo "Using windows path mangling and flags"
|
|
|
|
DEBUG_FLAGS=""
|
|
|
|
function translate_path() {
|
|
|
|
cygpath --windows "$1"
|
|
|
|
}
|
|
|
|
else
|
2020-07-03 01:46:46 +08:00
|
|
|
DEBUG_FLAGS="-g3 -gdwarf-2"
|
2020-07-02 12:28:04 +08:00
|
|
|
function translate_path() {
|
|
|
|
echo "$1"
|
|
|
|
}
|
|
|
|
fi
|
|
|
|
|
2020-07-03 01:45:49 +08:00
|
|
|
# Find llvm-lit.
|
|
|
|
LLVM_LIT=""
|
|
|
|
for candidate_lit in "$build_mlir/bin/llvm-lit" "$build_mlir/bin/llvm-lit.py"
|
|
|
|
do
|
|
|
|
if [ -f "$candidate_lit" ]; then
|
|
|
|
LLVM_LIT="$candidate_lit"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ -z "$LLVM_LIT" ]; then
|
|
|
|
echo "WARNING: Unable to find llvm-lit"
|
|
|
|
fi
|
|
|
|
echo "Using llvm-lit: $LLVM_LIT"
|
|
|
|
|
2020-05-07 14:25:04 +08:00
|
|
|
# Write a .env file for python tooling.
|
2020-09-17 12:57:46 +08:00
|
|
|
function write_env_file() {
|
|
|
|
echo "Updating $build_dir/.env file"
|
2020-12-30 05:03:15 +08:00
|
|
|
echo "PYTHONPATH=\"$(portable_realpath "$build_dir/python"):$(portable_realpath "$install_mlir/python")\"" > "$build_dir/.env"
|
2020-09-17 12:57:46 +08:00
|
|
|
echo "NUMPY_EXPERIMENTAL_ARRAY_FUNCTION=1" >> "$build_dir/.env"
|
|
|
|
if ! cp "$build_dir/.env" "$td/.env"; then
|
|
|
|
echo "WARNING: Failed to write $td/.env"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
write_env_file
|
2020-05-07 14:25:04 +08:00
|
|
|
|
2020-04-27 07:26:45 +08:00
|
|
|
set -x
|
|
|
|
cmake -GNinja \
|
|
|
|
"-H$td" \
|
|
|
|
"-B$build_dir" \
|
2020-05-01 07:00:00 +08:00
|
|
|
"-DCMAKE_BUILD_TYPE=Debug" \
|
2020-11-04 05:46:46 +08:00
|
|
|
"-DNPCOMP_USE_SPLIT_DWARF=ON" \
|
2020-07-02 12:28:04 +08:00
|
|
|
"-DCMAKE_CXX_FLAGS_DEBUG=$DEBUG_FLAGS" \
|
2020-04-27 07:26:45 +08:00
|
|
|
"-DPYTHON_EXECUTABLE=$python_exe" \
|
2021-01-21 10:07:04 +08:00
|
|
|
"-DPython3_EXECUTABLE=$python_exe" \
|
2020-04-27 07:26:45 +08:00
|
|
|
"-DMLIR_DIR=$install_mlir/lib/cmake/mlir" \
|
2020-07-03 01:45:49 +08:00
|
|
|
"-DLLVM_EXTERNAL_LIT=$LLVM_LIT" \
|
2020-06-04 11:37:09 +08:00
|
|
|
"-DLLVM_ENABLE_WARNINGS=ON" \
|
2020-05-12 03:58:42 +08:00
|
|
|
"-DCMAKE_EXPORT_COMPILE_COMMANDS=TRUE" \
|
2020-04-29 11:32:49 +08:00
|
|
|
"${extra_opts[@]}" \
|
2020-04-27 07:26:45 +08:00
|
|
|
"$@"
|