Skip to content

Commit

Permalink
Apply LLVM customizations for Python wheel build (NVIDIA#2504)
Browse files Browse the repository at this point in the history
This PR fixes an LLVM discrepancy in our Docker images vs our Python wheels. This should fix NVIDIA#1421 and NVIDIA#1799 for our Python wheels. (The Docker images were already correct.)
  • Loading branch information
bmhowe23 authored Jan 13, 2025
1 parent da44eda commit e246521
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
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

0 comments on commit e246521

Please # to comment.