https://github.com/keith created https://github.com/llvm/llvm-project/pull/228731
With 23.x we started linking a static libxml in release builds to avoid requiring that to be installed, and the varying names of that library on different linux distros. That broke more than it fixed because the static libxml in our docker images are built targeting ICU, and ICU's shared library version changes quickly, so even between 2 ubuntu versions the binaries will not work. With this change we now build from source in the release build, which is already what windows does, and we disable ICU / iconv since those don't seem vital for the windows manifest use case. This seems easier than building a libxml out of band in our CI images that do the release builds. Fixes https://github.com/llvm/llvm-project/issues/215764 Assisted-By: codex (cherry picked from commit 5ae71ec799917c67e9e72510e68831602fc60699) >From a7c44afc6ec593d8095cbb4fa4443cea0b93c0de Mon Sep 17 00:00:00 2001 From: Keith Smiley <[email protected]> Date: Tue, 22 Sep 2026 11:35:12 -0700 Subject: [PATCH] [cmake] Build libxml from source in release (#221365) With 23.x we started linking a static libxml in release builds to avoid requiring that to be installed, and the varying names of that library on different linux distros. That broke more than it fixed because the static libxml in our docker images are built targeting ICU, and ICU's shared library version changes quickly, so even between 2 ubuntu versions the binaries will not work. With this change we now build from source in the release build, which is already what windows does, and we disable ICU / iconv since those don't seem vital for the windows manifest use case. This seems easier than building a libxml out of band in our CI images that do the release builds. Fixes https://github.com/llvm/llvm-project/issues/215764 Assisted-By: codex (cherry picked from commit 5ae71ec799917c67e9e72510e68831602fc60699) --- .github/workflows/release-binaries.yml | 47 ++++++++++++++++++++++++++ clang/cmake/caches/Release.cmake | 1 + llvm/cmake/modules/FindLibXml2.cmake | 20 +++++++---- 3 files changed, 61 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release-binaries.yml b/.github/workflows/release-binaries.yml index 6d89a03f47e231..2d9b546bb1a161 100644 --- a/.github/workflows/release-binaries.yml +++ b/.github/workflows/release-binaries.yml @@ -258,6 +258,41 @@ jobs: fi echo "build-prefix=$build_prefix" >> $GITHUB_OUTPUT + - name: Build libxml2 (Linux) + if: runner.os == 'Linux' + env: + BUILD_PREFIX: ${{ steps.setup-stage.outputs.build-prefix }} + shell: bash + run: | + libxml2_prefix="$BUILD_PREFIX/libxml2-install" + libxml2_build_dir="$BUILD_PREFIX/libxml2-build" + libxml2_version=2.15.1 + libxml2_archive="libxml2-$libxml2_version.tar.xz" + libxml2_checksum=c008bac08fd5c7b4a87f7b8a71f283fa581d80d80ff8d2efd3b26224c39bc54c + + mkdir -p "$libxml2_build_dir" "$libxml2_prefix" + cd "$libxml2_build_dir" || exit + curl --fail --location --retry 3 \ + "https://download.gnome.org/sources/libxml2/2.15/$libxml2_archive" -o "$libxml2_archive" + echo "$libxml2_checksum $libxml2_archive" | sha256sum --check + tar -xf "$libxml2_archive" + + cmake -G Ninja -S "libxml2-$libxml2_version" -B build \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX="$libxml2_prefix" \ + -DCMAKE_INSTALL_LIBDIR=lib \ + -DBUILD_SHARED_LIBS=OFF \ + -DLIBXML2_WITH_ICU=OFF \ + -DLIBXML2_WITH_ICONV=OFF \ + -DLIBXML2_WITH_MODULES=OFF \ + -DLIBXML2_WITH_PROGRAMS=OFF \ + -DLIBXML2_WITH_TESTS=OFF \ + -DLIBXML2_WITH_ZLIB=ON + cmake --build build --parallel + cmake --install build --component development + + echo "PKG_CONFIG_PATH=$libxml2_prefix/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}" >> "$GITHUB_ENV" + - name: Configure Linux/MacOS id: build if: runner.os != 'Windows' @@ -266,10 +301,22 @@ jobs: TARGET_CMAKE_FLAGS: ${{ needs.prepare.outputs.target-cmake-flags }} shell: bash run: | + libxml2_cmake_flags=() + if [ "$RUNNER_OS" = "Linux" ]; then + libxml2_prefix="$BUILD_PREFIX/libxml2-install" + for stage in "" BOOTSTRAP_ BOOTSTRAP_BOOTSTRAP_; do + libxml2_cmake_flags+=( + "-D${stage}LIBXML2_INCLUDE_DIR=$libxml2_prefix/include/libxml2" + "-D${stage}LIBXML2_LIBRARY=$libxml2_prefix/lib/libxml2.a" + "-D${stage}LIBXML2_STATIC_LIBRARY=$libxml2_prefix/lib/libxml2.a" + ) + done + fi # There were some issues on the ARM64 MacOS runners with trying to build x86 object, # so we need to set some extra cmake flags to disable this. cmake -G Ninja -S llvm -B "$BUILD_PREFIX/build" \ $TARGET_CMAKE_FLAGS \ + "${libxml2_cmake_flags[@]}" \ -C clang/cmake/caches/Release.cmake - name: Build Linux/MacOS diff --git a/clang/cmake/caches/Release.cmake b/clang/cmake/caches/Release.cmake index b0bc3ebfe5cb61..7279923c36b988 100644 --- a/clang/cmake/caches/Release.cmake +++ b/clang/cmake/caches/Release.cmake @@ -173,6 +173,7 @@ set_final_stage_var(CPACK_ARCHIVE_THREADS "0" STRING) set_final_stage_var(LLVM_USE_STATIC_ZSTD "ON" BOOL) if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux") + set_final_stage_var(LLVM_ENABLE_LIBXML2 "FORCE_ON" STRING) set_final_stage_var(LLVM_USE_STATIC_LIBXML2 "ON" BOOL) endif() diff --git a/llvm/cmake/modules/FindLibXml2.cmake b/llvm/cmake/modules/FindLibXml2.cmake index f3f761606260da..f78ff327afc176 100644 --- a/llvm/cmake/modules/FindLibXml2.cmake +++ b/llvm/cmake/modules/FindLibXml2.cmake @@ -75,12 +75,25 @@ find_package_handle_standard_args(LibXml2 ) if(LibXml2_FOUND) + # Static libraries need their transitive dependencies for linking. + set(LIBXML2_STATIC_DEPS) + foreach(lib IN LISTS PC_LIBXML_STATIC_LIBRARIES) + if(NOT lib STREQUAL "xml2") + list(APPEND LIBXML2_STATIC_DEPS ${lib}) + endif() + endforeach() + if(NOT TARGET LibXml2::LibXml2) add_library(LibXml2::LibXml2 UNKNOWN IMPORTED) set_target_properties(LibXml2::LibXml2 PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${LIBXML2_INCLUDE_DIR}" INTERFACE_COMPILE_OPTIONS "${LIBXML2_DEFINITIONS}" IMPORTED_LOCATION "${LIBXML2_LIBRARY}") + # A prefix containing only a static libxml2 also supplies the default target. + if(LIBXML2_LIBRARY STREQUAL LIBXML2_STATIC_LIBRARY) + set_property(TARGET LibXml2::LibXml2 PROPERTY + INTERFACE_LINK_LIBRARIES "${LIBXML2_STATIC_DEPS}") + endif() endif() if(LIBXML2_STATIC_LIBRARY AND NOT TARGET LibXml2::LibXml2Static) add_library(LibXml2::LibXml2Static STATIC IMPORTED) @@ -88,13 +101,6 @@ if(LibXml2_FOUND) INTERFACE_INCLUDE_DIRECTORIES "${LIBXML2_INCLUDE_DIR}" INTERFACE_COMPILE_OPTIONS "${LIBXML2_DEFINITIONS}" IMPORTED_LOCATION "${LIBXML2_STATIC_LIBRARY}") - # Static libraries need their transitive dependencies for linking. - set(LIBXML2_STATIC_DEPS) - foreach(lib IN LISTS PC_LIBXML_STATIC_LIBRARIES) - if(NOT lib STREQUAL "xml2") - list(APPEND LIBXML2_STATIC_DEPS ${lib}) - endif() - endforeach() if(LIBXML2_STATIC_DEPS) set_target_properties(LibXml2::LibXml2Static PROPERTIES INTERFACE_LINK_LIBRARIES "${LIBXML2_STATIC_DEPS}") _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
