From d8a6b8871b990950ab37cfa96d83e3bfc87680ba Mon Sep 17 00:00:00 2001 From: James Lamb Date: Wed, 2 Nov 2022 16:38:52 -0500 Subject: [PATCH] [ci] fix R-package CI jobs and compatibility with OpenMP 15+ (fixes #5549, #5562) (#5563) --- .ci/test_r_package_windows.ps1 | 6 +++--- CMakeLists.txt | 19 ++++++++++++++++++- R-package/configure | 21 +++++++++++++++++++++ R-package/configure.ac | 19 +++++++++++++++++++ 4 files changed, 61 insertions(+), 4 deletions(-) diff --git a/.ci/test_r_package_windows.ps1 b/.ci/test_r_package_windows.ps1 index 891c7cbd36e1..fc6fbc9ee4f3 100644 --- a/.ci/test_r_package_windows.ps1 +++ b/.ci/test_r_package_windows.ps1 @@ -132,13 +132,13 @@ Run-R-Code-Redirect-Stderr "options(install.packages.check.source = 'no'); insta # # MiKTeX always needs to be built to test a CRAN package. if (($env:COMPILER -eq "MINGW") -or ($env:R_BUILD_TYPE -eq "cran")) { - Download-File-With-Retries "https://github.com/microsoft/LightGBM/releases/download/v2.0.12/miktexsetup-4.0-x64.zip" -destfile "miktexsetup-x64.zip" + Download-File-With-Retries "https://github.com/microsoft/LightGBM/releases/download/v2.0.12/miktexsetup-5.2.0-x64.zip" -destfile "miktexsetup-x64.zip" Add-Type -AssemblyName System.IO.Compression.FileSystem [System.IO.Compression.ZipFile]::ExtractToDirectory("miktexsetup-x64.zip", "miktex") Write-Output "Setting up MiKTeX" - .\miktex\miktexsetup.exe --remote-package-repository="$env:CTAN_PACKAGE_ARCHIVE" --local-package-repository=./miktex/download --package-set=essential --quiet download ; Check-Output $? + .\miktex\miktexsetup_standalone.exe --remote-package-repository="$env:CTAN_PACKAGE_ARCHIVE" --local-package-repository=./miktex/download --package-set=essential --quiet download ; Check-Output $? Write-Output "Installing MiKTeX" - .\miktex\download\miktexsetup.exe --remote-package-repository="$env:CTAN_PACKAGE_ARCHIVE" --portable="$env:R_LIB_PATH/miktex" --quiet install ; Check-Output $? + .\miktex\download\miktexsetup_standalone.exe --remote-package-repository="$env:CTAN_PACKAGE_ARCHIVE" --portable="$env:R_LIB_PATH/miktex" --quiet install ; Check-Output $? Write-Output "Done installing MiKTeX" Run-R-Code-Redirect-Stderr "result <- processx::run(command = 'initexmf', args = c('--set-config-value', '[MPM]AutoInstall=1'), echo = TRUE, windows_verbatim_args = TRUE, error_on_status = TRUE)" ; Check-Output $? diff --git a/CMakeLists.txt b/CMakeLists.txt index c3a16000c20f..f126d659fee2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -142,7 +142,24 @@ if(USE_CUDA OR USE_CUDA_EXP) endif() if(USE_OPENMP) - find_package(OpenMP REQUIRED) + if(APPLE) + find_package(OpenMP) + if(NOT OpenMP_FOUND) + # libomp 15.0+ from brew is keg-only, so have to search in other locations. + # See https://github.com/Homebrew/homebrew-core/issues/112107#issuecomment-1278042927. + execute_process(COMMAND brew --prefix libomp + OUTPUT_VARIABLE HOMEBREW_LIBOMP_PREFIX + OUTPUT_STRIP_TRAILING_WHITESPACE) + set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp -I${HOMEBREW_LIBOMP_PREFIX}/include") + set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -I${HOMEBREW_LIBOMP_PREFIX}/include") + set(OpenMP_C_LIB_NAMES omp) + set(OpenMP_CXX_LIB_NAMES omp) + set(OpenMP_omp_LIBRARY ${HOMEBREW_LIBOMP_PREFIX}/lib/libomp.dylib) + find_package(OpenMP REQUIRED) + endif() + else() + find_package(OpenMP REQUIRED) + endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") endif() diff --git a/R-package/configure b/R-package/configure index 5bb4a1973ef6..75f6cf608746 100755 --- a/R-package/configure +++ b/R-package/configure @@ -1800,6 +1800,27 @@ if test `uname -s` = "Darwin" then OPENMP_CXXFLAGS='-Xclang -fopenmp' OPENMP_LIB='-lomp' + + # libomp 15.0+ from brew is keg-only (i.e. not symlinked into the standard paths search by the linker), + # so need to search in other locations. + # See https://github.com/Homebrew/homebrew-core/issues/112107#issuecomment-1278042927. + # + # If Homebrew is found and libomp was installed with it, this code adds the necessary + # flags for the compiler to find libomp headers and for the linker to find libomp.dylib. + HOMEBREW_LIBOMP_PREFIX="" + if command -v brew &> /dev/null; then + ac_brew_openmp=no + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether OpenMP was installed via Homebrew" >&5 +$as_echo_n "checking whether OpenMP was installed via Homebrew... " >&6; } + brew --prefix libomp &>/dev/null && ac_brew_openmp=yes + { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${ac_brew_openmp}" >&5 +$as_echo "${ac_brew_openmp}" >&6; } + if test "${ac_brew_openmp}" = yes; then + HOMEBREW_LIBOMP_PREFIX=`brew --prefix libomp` + OPENMP_CXXFLAGS="${OPENMP_CXXFLAGS} -I${HOMEBREW_LIBOMP_PREFIX}/include" + OPENMP_LIB="${OPENMP_LIB} -L${HOMEBREW_LIBOMP_PREFIX}/lib" + fi + fi ac_pkg_openmp=no { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether OpenMP will work in a package" >&5 $as_echo_n "checking whether OpenMP will work in a package... " >&6; } diff --git a/R-package/configure.ac b/R-package/configure.ac index 3d7dcc28faae..b0fe727967fb 100644 --- a/R-package/configure.ac +++ b/R-package/configure.ac @@ -104,6 +104,25 @@ if test `uname -s` = "Darwin" then OPENMP_CXXFLAGS='-Xclang -fopenmp' OPENMP_LIB='-lomp' + + # libomp 15.0+ from brew is keg-only (i.e. not symlinked into the standard paths search by the linker), + # so need to search in other locations. + # See https://github.com/Homebrew/homebrew-core/issues/112107#issuecomment-1278042927. + # + # If Homebrew is found and libomp was installed with it, this code adds the necessary + # flags for the compiler to find libomp headers and for the linker to find libomp.dylib. + HOMEBREW_LIBOMP_PREFIX="" + if command -v brew &> /dev/null; then + ac_brew_openmp=no + AC_MSG_CHECKING([whether OpenMP was installed via Homebrew]) + brew --prefix libomp &>/dev/null && ac_brew_openmp=yes + AC_MSG_RESULT([${ac_brew_openmp}]) + if test "${ac_brew_openmp}" = yes; then + HOMEBREW_LIBOMP_PREFIX=`brew --prefix libomp` + OPENMP_CXXFLAGS="${OPENMP_CXXFLAGS} -I${HOMEBREW_LIBOMP_PREFIX}/include" + OPENMP_LIB="${OPENMP_LIB} -L${HOMEBREW_LIBOMP_PREFIX}/lib" + fi + fi ac_pkg_openmp=no AC_MSG_CHECKING([whether OpenMP will work in a package]) AC_LANG_CONFTEST(