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

Apply LLVM customizations for Python wheel build #2504

Merged
merged 2 commits into from
Jan 13, 2025
Merged
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
2 changes: 2 additions & 0 deletions docker/build/devdeps.manylinux.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ RUN curl -L https://github.com/Kitware/CMake/releases/download/v3.26.4/cmake-3.2
# Build the the LLVM libraries and compiler toolchain needed to build CUDA-Q.
ADD ./scripts/build_llvm.sh /scripts/build_llvm.sh
ADD ./cmake/caches/LLVM.cmake /cmake/caches/LLVM.cmake
ADD ./tpls/customizations/llvm/ /tpls/customizations/llvm/
RUN LLVM_PROJECTS='clang;mlir' LLVM_SOURCE=/llvm-project \
LLVM_CMAKE_CACHE=/cmake/caches/LLVM.cmake \
LLVM_CMAKE_PATCHES=/tpls/customizations/llvm \
bash /scripts/build_llvm.sh -c Release -v
# No clean up of the build or source directory,
# since we need to re-build llvm for each python version to get the bindings.
Expand Down
41 changes: 24 additions & 17 deletions scripts/build_llvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,26 +93,33 @@ if [ ! -d "$LLVM_SOURCE" ] || [ -z "$(ls -A "$LLVM_SOURCE"/* 2> /dev/null)" ]; t
llvm_repo="$(git config --file=.gitmodules submodule.tpls/llvm.url)"
llvm_commit="$(git submodule | grep tpls/llvm | cut -c2- | cut -d ' ' -f1)"
git clone --filter=tree:0 "$llvm_repo" "$LLVM_SOURCE"
cd "$LLVM_SOURCE" && git checkout $llvm_commit
fi

LLVM_CMAKE_PATCHES=${LLVM_CMAKE_PATCHES:-"$this_file_dir/../tpls/customizations/llvm"}
if [ -d "$LLVM_CMAKE_PATCHES" ]; then
echo "Applying LLVM patches in $LLVM_CMAKE_PATCHES..."
for patch in `find "$LLVM_CMAKE_PATCHES"/* -maxdepth 0 -type f -name '*.diff'`; do
# Check if patch is already applied.
git apply "$patch" --ignore-whitespace --reverse --check 2>/dev/null
# Always apply LLVM patches if patch directory exists; patches will be skipped
# if they were already applied previously.
LLVM_CMAKE_PATCHES=${LLVM_CMAKE_PATCHES:-"$this_file_dir/../tpls/customizations/llvm"}
if [ -d "$LLVM_CMAKE_PATCHES" ]; then
cd "$LLVM_SOURCE" && git checkout $llvm_commit
echo "Applying LLVM patches in $LLVM_CMAKE_PATCHES..."
for patch in `find "$LLVM_CMAKE_PATCHES"/* -maxdepth 0 -type f -name '*.diff'`; do
# Check if patch is already applied.
git apply "$patch" --ignore-whitespace --reverse --check 2>/dev/null
if [ ! 0 -eq $? ]; then
# If the patch is not yet applied, apply the patch.
git apply "$patch" --ignore-whitespace
if [ ! 0 -eq $? ]; then
# If the patch is not yet applied, apply the patch.
git apply "$patch" --ignore-whitespace
if [ ! 0 -eq $? ]; then
echo "Applying patch $patch failed. Please update patch."
(return 0 2>/dev/null) && return 1 || exit 1
else
echo "Applied patch $patch."
fi
echo "Applying patch $patch failed. Please update patch."
(return 0 2>/dev/null) && return 1 || exit 1
else
echo "Applied patch $patch."
fi
done
fi
else
echo "Skipping $patch because it has already been applied."
fi
done
else
echo "LLVM patch directory not found. You must apply LLVM patches via the LLVM_CMAKE_PATCHES environment variable."
(return 0 2>/dev/null) && return 1 || exit 1
fi

llvm_build_dir="$LLVM_SOURCE/${LLVM_BUILD_FOLDER:-build}"
Expand Down
Loading