Skip to content

Commit

Permalink
[ci] fix R-package CI jobs and compatibility with OpenMP 15+ (fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
jameslamb committed Nov 2, 2022
1 parent 0c0eb2a commit d8a6b88
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
6 changes: 3 additions & 3 deletions .ci/test_r_package_windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 $?
Expand Down
19 changes: 18 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
21 changes: 21 additions & 0 deletions R-package/configure
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
19 changes: 19 additions & 0 deletions R-package/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit d8a6b88

Please sign in to comment.