Unverified Commit 98c1db77 authored by James Lamb's avatar James Lamb Committed by GitHub
Browse files

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

parent 709ea4ca
...@@ -335,13 +335,7 @@ jobs: ...@@ -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())" 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 sh build-cran-package.sh
R CMD check --as-cran --run-donttest lightgbm_*.tar.gz || exit -1 R CMD check --as-cran --run-donttest lightgbm_*.tar.gz || exit -1
# ignoring the following NOTE: if grep -q -E "NOTE|WARNING|ERROR" lightgbm.Rcheck/00check.log; then
#
# * 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
echo "NOTEs, WARNINGs, or ERRORs have been found by R CMD check" echo "NOTEs, WARNINGs, or ERRORs have been found by R CMD check"
exit -1 exit -1
fi fi
......
...@@ -62,5 +62,5 @@ Imports: ...@@ -62,5 +62,5 @@ Imports:
parallel, parallel,
utils utils
SystemRequirements: SystemRequirements:
C++11 ~~CXXSTD~~
RoxygenNote: 7.2.3 RoxygenNote: 7.2.3
...@@ -1735,11 +1735,11 @@ if test -z "${R_HOME}"; then ...@@ -1735,11 +1735,11 @@ if test -z "${R_HOME}"; then
echo "could not determine R_HOME" echo "could not determine R_HOME"
exit 1 exit 1
fi fi
CXX11=`"${R_HOME}/bin/R" CMD config CXX11` CXX17=`"${R_HOME}/bin/R" CMD config CXX17`
CXX11STD=`"${R_HOME}/bin/R" CMD config CXX11STD` CXX17STD=`"${R_HOME}/bin/R" CMD config CXX17STD`
CXX="${CXX11} ${CXX11STD}" CXX="${CXX17} ${CXX17STD}"
CPPFLAGS=`"${R_HOME}/bin/R" CMD config CPPFLAGS` 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` LDFLAGS=`"${R_HOME}/bin/R" CMD config LDFLAGS`
ac_ext=cpp ac_ext=cpp
ac_cpp='$CXXCPP $CPPFLAGS' ac_cpp='$CXXCPP $CPPFLAGS'
......
...@@ -20,11 +20,11 @@ if test -z "${R_HOME}"; then ...@@ -20,11 +20,11 @@ if test -z "${R_HOME}"; then
echo "could not determine R_HOME" echo "could not determine R_HOME"
exit 1 exit 1
fi fi
CXX11=`"${R_HOME}/bin/R" CMD config CXX11` CXX17=`"${R_HOME}/bin/R" CMD config CXX17`
CXX11STD=`"${R_HOME}/bin/R" CMD config CXX11STD` CXX17STD=`"${R_HOME}/bin/R" CMD config CXX17STD`
CXX="${CXX11} ${CXX11STD}" CXX="${CXX17} ${CXX17STD}"
CPPFLAGS=`"${R_HOME}/bin/R" CMD config CPPFLAGS` 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` LDFLAGS=`"${R_HOME}/bin/R" CMD config LDFLAGS`
AC_LANG(C++) AC_LANG(C++)
......
...@@ -6,10 +6,31 @@ ...@@ -6,10 +6,31 @@
########################### ###########################
R_EXE="${R_HOME}/bin${R_ARCH_BIN}/R" R_EXE="${R_HOME}/bin${R_ARCH_BIN}/R"
CXX11=`"${R_EXE}" CMD config CXX11`
CXX11STD=`"${R_EXE}" CMD config CXX11STD` # As described in "Using C++ code" in "Writing R Extensions",
CXX="${CXX11} ${CXX11STD}" # Rtools35 shipped with g++ 4.9, which didn't support C++17.
CXXFLAGS=`"${R_EXE}" CMD config CXX11FLAGS` #
# 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` CPPFLAGS=`"${R_EXE}" CMD config CPPFLAGS`
# LightGBM-specific flags # LightGBM-specific flags
...@@ -96,6 +117,9 @@ then ...@@ -96,6 +117,9 @@ then
fi fi
# Generate Makevars.win from Makevars.win.in # Generate Makevars.win from Makevars.win.in
sed -e \
"s/@CXX_STD@/$CXX_STD/" \
< src/Makevars.win.in > src/Makevars.win
sed -e \ sed -e \
"s/@LGB_CPPFLAGS@/$LGB_CPPFLAGS/" \ "s/@LGB_CPPFLAGS@/$LGB_CPPFLAGS/" \
< src/Makevars.win.in > src/Makevars.win < src/Makevars.win.in > src/Makevars.win
CXX_STD = CXX11 CXX_STD = CXX17
PKGROOT=. PKGROOT=.
......
CXX_STD = CXX11 CXX_STD = @CXX_STD@
PKGROOT=. PKGROOT=.
......
...@@ -127,6 +127,16 @@ cd "${TEMP_R_DIR}" ...@@ -127,6 +127,16 @@ cd "${TEMP_R_DIR}"
sed -i.bak -e "s/~~VERSION~~/${LGB_VERSION}/" DESCRIPTION sed -i.bak -e "s/~~VERSION~~/${LGB_VERSION}/" DESCRIPTION
sed -i.bak -e "s/~~DATE~~/${CURRENT_DATE}/" 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. # Remove 'region', 'endregion', and 'warning' pragmas.
# This won't change the correctness of the code. CRAN does # This won't change the correctness of the code. CRAN does
# not allow you to use compiler flag '-Wno-unknown-pragmas' or # not allow you to use compiler flag '-Wno-unknown-pragmas' or
......
...@@ -390,6 +390,12 @@ description_contents <- gsub( ...@@ -390,6 +390,12 @@ description_contents <- gsub(
, x = description_contents , x = description_contents
, fixed = TRUE , fixed = TRUE
) )
description_contents <- gsub(
pattern = "~~CXXSTD~~"
, replacement = "C++11"
, x = description_contents
, fixed = TRUE
)
writeLines(description_contents, DESCRIPTION_FILE) writeLines(description_contents, DESCRIPTION_FILE)
# CMake-based builds can't currently use R's builtin routine registration, # CMake-based builds can't currently use R's builtin routine registration,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment