[R-package] use C++17 in the CRAN package (#5690)

This commit is contained in:
James Lamb 2023-03-06 21:57:18 -06:00 коммит произвёл GitHub
Родитель 709ea4cad3
Коммит 98c1db7794
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
9 изменённых файлов: 56 добавлений и 22 удалений

8
.github/workflows/r_package.yml поставляемый
Просмотреть файл

@ -335,13 +335,7 @@ jobs:
Rscript -e "install.packages(c('R6', 'data.table', 'jsonlite', 'knitr', 'Matrix', 'RhpcBLASctl', 'rmarkdown', 'testthat'), repos = 'https://cran.rstudio.com', Ncpus = parallel::detectCores())"
sh build-cran-package.sh
R CMD check --as-cran --run-donttest lightgbm_*.tar.gz || exit -1
# ignoring the following NOTE:
#
# * checking C++ specification ... NOTE
# Specified C++11: please update to current default of C++17
#
# until it's resolved (see https://github.com/microsoft/LightGBM/pull/5690)
if $(grep -v "C++ specification" "$LOG_FILE_NAME" | grep -v "1 NOTE" | grep -E "NOTE|WARNING|ERROR"); then
if grep -q -E "NOTE|WARNING|ERROR" lightgbm.Rcheck/00check.log; then
echo "NOTEs, WARNINGs, or ERRORs have been found by R CMD check"
exit -1
fi

Просмотреть файл

@ -62,5 +62,5 @@ Imports:
parallel,
utils
SystemRequirements:
C++11
~~CXXSTD~~
RoxygenNote: 7.2.3

8
R-package/configure поставляемый
Просмотреть файл

@ -1735,11 +1735,11 @@ if test -z "${R_HOME}"; then
echo "could not determine R_HOME"
exit 1
fi
CXX11=`"${R_HOME}/bin/R" CMD config CXX11`
CXX11STD=`"${R_HOME}/bin/R" CMD config CXX11STD`
CXX="${CXX11} ${CXX11STD}"
CXX17=`"${R_HOME}/bin/R" CMD config CXX17`
CXX17STD=`"${R_HOME}/bin/R" CMD config CXX17STD`
CXX="${CXX17} ${CXX17STD}"
CPPFLAGS=`"${R_HOME}/bin/R" CMD config CPPFLAGS`
CXXFLAGS=`"${R_HOME}/bin/R" CMD config CXX11FLAGS`
CXXFLAGS=`"${R_HOME}/bin/R" CMD config CXX17FLAGS`
LDFLAGS=`"${R_HOME}/bin/R" CMD config LDFLAGS`
ac_ext=cpp
ac_cpp='$CXXCPP $CPPFLAGS'

Просмотреть файл

@ -20,11 +20,11 @@ if test -z "${R_HOME}"; then
echo "could not determine R_HOME"
exit 1
fi
CXX11=`"${R_HOME}/bin/R" CMD config CXX11`
CXX11STD=`"${R_HOME}/bin/R" CMD config CXX11STD`
CXX="${CXX11} ${CXX11STD}"
CXX17=`"${R_HOME}/bin/R" CMD config CXX17`
CXX17STD=`"${R_HOME}/bin/R" CMD config CXX17STD`
CXX="${CXX17} ${CXX17STD}"
CPPFLAGS=`"${R_HOME}/bin/R" CMD config CPPFLAGS`
CXXFLAGS=`"${R_HOME}/bin/R" CMD config CXX11FLAGS`
CXXFLAGS=`"${R_HOME}/bin/R" CMD config CXX17FLAGS`
LDFLAGS=`"${R_HOME}/bin/R" CMD config LDFLAGS`
AC_LANG(C++)

Просмотреть файл

@ -6,10 +6,31 @@
###########################
R_EXE="${R_HOME}/bin${R_ARCH_BIN}/R"
CXX11=`"${R_EXE}" CMD config CXX11`
CXX11STD=`"${R_EXE}" CMD config CXX11STD`
CXX="${CXX11} ${CXX11STD}"
CXXFLAGS=`"${R_EXE}" CMD config CXX11FLAGS`
# As described in "Using C++ code" in "Writing R Extensions",
# Rtools35 shipped with g++ 4.9, which didn't support C++17.
#
# Testing here for C++17 support, to account for that possibility
# and to continue supporting R 3.6.
#
CXX17=`"${R_EXE}" CMD config CXX17`
CXX17STD=`"${R_EXE}" CMD config CXX17STD`
CXX="${CXX17} ${CXX17STD}"
CXXFLAGS=`"${R_EXE}" CMD config CXX17FLAGS`
CXX_STD="CXX17"
cpp17_supported="yes"
if test "${CXX17}" = "";
then
cpp17_supported="no"
CXX11=`"${R_EXE}" CMD config CXX11`
CXX11STD=`"${R_EXE}" CMD config CXX11STD`
CXX="${CXX11} ${CXX11STD}"
CXXFLAGS=`"${R_EXE}" CMD config CXX11FLAGS`
CXX_STD="CXX11"
fi
echo "checking whether C++17 is supported...${cpp17_supported}"
CPPFLAGS=`"${R_EXE}" CMD config CPPFLAGS`
# LightGBM-specific flags
@ -96,6 +117,9 @@ then
fi
# Generate Makevars.win from Makevars.win.in
sed -e \
"s/@CXX_STD@/$CXX_STD/" \
< src/Makevars.win.in > src/Makevars.win
sed -e \
"s/@LGB_CPPFLAGS@/$LGB_CPPFLAGS/" \
< src/Makevars.win.in > src/Makevars.win

Просмотреть файл

@ -1,4 +1,4 @@
CXX_STD = CXX11
CXX_STD = CXX17
PKGROOT=.

Просмотреть файл

@ -1,4 +1,4 @@
CXX_STD = CXX11
CXX_STD = @CXX_STD@
PKGROOT=.

Просмотреть файл

@ -127,6 +127,16 @@ cd "${TEMP_R_DIR}"
sed -i.bak -e "s/~~VERSION~~/${LGB_VERSION}/" DESCRIPTION
sed -i.bak -e "s/~~DATE~~/${CURRENT_DATE}/" DESCRIPTION
# Rtools35 (used with R 3.6 on Windows) doesn't support C++17
LGB_CXX_STD="C++17"
using_windows_and_r3=$(
Rscript -e 'cat(.Platform$OS.type == "windows" && R.version[["major"]] < 4)'
)
if [[ ${using_windows_and_r3} == "TRUE" ]]; then
LGB_CXX_STD="C++11"
fi
sed -i.bak -e "s/~~CXXSTD~~/${LGB_CXX_STD}/" DESCRIPTION
# Remove 'region', 'endregion', and 'warning' pragmas.
# This won't change the correctness of the code. CRAN does
# not allow you to use compiler flag '-Wno-unknown-pragmas' or

Просмотреть файл

@ -390,6 +390,12 @@ description_contents <- gsub(
, x = description_contents
, fixed = TRUE
)
description_contents <- gsub(
pattern = "~~CXXSTD~~"
, replacement = "C++11"
, x = description_contents
, fixed = TRUE
)
writeLines(description_contents, DESCRIPTION_FILE)
# CMake-based builds can't currently use R's builtin routine registration,