Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor build script enhancements #349

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion cmake/imex.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ if (NOT DEFINED IMEX_INCLUDES)

# TODO: Change to main https://github.com/intel/mlir-extensions when all the
# required functionality is merged.
gc_fetch_content(imex "${IMEX_HASH}" https://github.com/intel/mlir-extensions
set(IMEX_URL https://github.com/intel/mlir-extensions)
gc_fetch_content(imex "${IMEX_HASH}" "${IMEX_URL}"
SET IMEX_CHECK_LLVM_VERSION=ON IMEX_ENABLE_L0_RUNTIME=0
)

Expand Down
48 changes: 33 additions & 15 deletions scripts/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,23 @@ $(basename "$0")
[ -r | --release ] Release build, requires rebuild of LLVM in Release mode, activates 'dev' option
[ -c | --clean ] Delete the build artifacts from the previous build
[ -i | --imex ] Compile with IMEX (used for GPU pipeline)
[ -s | --suffix ] Build dir suffix
[ -v | --llvm ] Build llvm only
[ -h | --help ] Print this message
EOF
}

DYN_LINK=OFF
ENABLE_IMEX=false
for arg in "$@"; do
if [ ! -z "$ASSIGN_NEXT" ]; then
eval "$ASSIGN_NEXT=$arg"
unset ASSIGN_NEXT
continue
fi
case $arg in
-d | --dev)
DEV_BUILD=true
-d | --dev)
DEV_BUILD=true
;;
-i | --imex)
ENABLE_IMEX=true
Expand All @@ -44,12 +51,18 @@ for arg in "$@"; do
-c | --clean)
CLEANUP=true
;;
-s | --suffix)
ASSIGN_NEXT=BUILD_DIR_SFX
;;
-v | --llvm)
LLVM_ONLY=true
;;
-h | --help)
print_usage
exit 0
;;
# -- means the end of the arguments; drop this, and break out of the while loop
*)
*)
echo Unsupported option: $arg
print_usage
exit 1
Expand Down Expand Up @@ -99,6 +112,10 @@ load_llvm() {

build_llvm() {
local llvm_dir="$EXTERNALS_DIR/llvm-project"
LLVM_BUILD_DIR="$llvm_dir/build$BUILD_DIR_SFX"
MLIR_DIR="$LLVM_BUILD_DIR/lib/cmake/mlir"
mkdir -p "$LLVM_BUILD_DIR"

if ! [ -d "$llvm_dir" ]; then
git clone https://github.com/llvm/llvm-project.git
cd "$llvm_dir"
Expand All @@ -111,16 +128,17 @@ build_llvm() {
fi

git checkout ${LLVM_HASH}
[ -z "$CLEANUP" ] || rm -rf build
[ -z "$CLEANUP" ] || rm -rf "$LLVM_BUILD_DIR"

[ "$DYN_LINK" = "OFF" ] && CXX_FLAGS="-fvisibility=hidden"

if [ "$ENABLE_IMEX" = "true" ]; then
# clone IMEX and apply patches
local mlir_ext_dir="$EXTERNALS_DIR/mlir-extensions"
local mlir_ext_dir="$EXTERNALS_DIR/imex-src"
if ! [ -d "$mlir_ext_dir" ]; then
cd "$EXTERNALS_DIR"
git clone https://github.com/intel/mlir-extensions.git
local imex_url="$(grep -F 'set(IMEX_URL ' "$PROJECT_DIR/cmake/imex.cmake" | awk '{print $2}' | tr -d ')')"
git clone "$imex_url" "$mlir_ext_dir"
cd "$mlir_ext_dir"
else
cd "$mlir_ext_dir"
Expand All @@ -134,7 +152,7 @@ build_llvm() {
find "$mlir_ext_dir/build_tools/patches" -name '*.patch' | sort -V | xargs git apply
fi

cmake -G Ninja llvm -B build \
cmake -G Ninja llvm -B "$LLVM_BUILD_DIR" \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DCMAKE_CXX_FLAGS="$CXX_FLAGS" \
-DCMAKE_CXX_FLAGS_DEBUG="-g -O0" \
Expand All @@ -153,9 +171,7 @@ build_llvm() {
-DLLVM_INSTALL_UTILS=ON \
-DLLVM_INSTALL_GTEST=ON \
-DMLIR_ENABLE_BINDINGS_PYTHON=ON
cmake --build build --parallel $MAX_JOBS

MLIR_DIR="$PWD/build/lib/cmake/mlir"
cmake --build "$LLVM_BUILD_DIR" --parallel $MAX_JOBS
}

# MLIR_DIR is set on all passes
Expand All @@ -174,13 +190,14 @@ get_llvm() {
cd "$llvm_dir"
load_llvm
cd "$PROJECT_DIR"
else
else
MLIR_DIR="$llvm_dir/lib/cmake/mlir"
fi
return 0
}

get_llvm
[ -z "$LLVM_ONLY" ] || exit 0

# written in this form to set LIT_PATH in any case
if ! LIT_PATH=$(which lit) && [ -z "$DEV_BUILD" ]; then
Expand All @@ -193,16 +210,17 @@ if [ -z "$DEV_BUILD" ]; then
FETCH_DIR=$PROJECT_DIR/build/_deps
else
FETCH_DIR=$PROJECT_DIR/externals
LIT_PATH=$PROJECT_DIR/externals/llvm-project/build/bin/llvm-lit
LIT_PATH="$LLVM_BUILD_DIR/bin/llvm-lit"
fi

[ -z "$CLEANUP" ] || rm -rf build
cmake -S . -G Ninja -B build \
BUILD_DIR="$PROJECT_DIR/build$BUILD_DIR_SFX"
[ -z "$CLEANUP" ] || rm -rf "$BUILD_DIR"
cmake -S . -G Ninja -B "$BUILD_DIR" \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DMLIR_DIR=$MLIR_DIR \
-DLLVM_EXTERNAL_LIT=$LIT_PATH \
-DFETCHCONTENT_BASE_DIR=$FETCH_DIR \
-DGC_DEV_LINK_LLVM_DYLIB=$DYN_LINK \
-DGC_ENABLE_IMEX=$ENABLE_IMEX

cmake --build build --parallel $MAX_JOBS
cmake --build "$BUILD_DIR" --parallel $MAX_JOBS