diff --git a/docker/build/devdeps.manylinux.Dockerfile b/docker/build/devdeps.manylinux.Dockerfile index 01506eb3fe..bdc97881d7 100644 --- a/docker/build/devdeps.manylinux.Dockerfile +++ b/docker/build/devdeps.manylinux.Dockerfile @@ -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. diff --git a/scripts/build_llvm.sh b/scripts/build_llvm.sh index 751c163c50..07b4573508 100644 --- a/scripts/build_llvm.sh +++ b/scripts/build_llvm.sh @@ -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}"