From 5480440e9d397e80d16c09c40a2d52f70e817d4f Mon Sep 17 00:00:00 2001 From: James Lamb Date: Mon, 5 Aug 2024 21:34:53 -0500 Subject: [PATCH] [R-package] [cmake] simplify CMake-based R builds --- R-package/src/install.libs.R | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/R-package/src/install.libs.R b/R-package/src/install.libs.R index f9d4233046db..c622de927ac5 100644 --- a/R-package/src/install.libs.R +++ b/R-package/src/install.libs.R @@ -15,14 +15,8 @@ if (.Machine$sizeof.pointer != 8L) { stop("LightGBM only supports 64-bit R, please check the version of R and Rtools.") } -R_int_UUID <- .Internal(internalsID()) R_ver <- as.double(R.Version()$major) + as.double(R.Version()$minor) / 10.0 -if (!(R_int_UUID == "0310d4b8-ccb1-4bb8-ba94-d36a55f60262" - || R_int_UUID == "2fdf6c18-697a-4ba7-b8ef-11c0d92f1327")) { - warning("Warning: unmatched R_INTERNALS_UUID, may not run normally.") -} - # Get some paths source_dir <- file.path(R_PACKAGE_SOURCE, "src", fsep = "/") build_dir <- file.path(source_dir, "build", fsep = "/") @@ -133,7 +127,13 @@ if (WINDOWS && use_visual_studio) { } # Prepare installation steps -cmake_args <- NULL +cmake_args <- c( + "-D__BUILD_FOR_R=ON" + # pass in R version, to help FindLibR find the R library + , sprintf("-DCMAKE_R_VERSION='%s.%s'", R.Version()[["major"]], R.Version()[["minor"]]) + # ensure CMake build respects how R is configured (`R CMD config SHLIB_EXT`) + , sprintf("-DCMAKE_SHARED_LIBRARY_SUFFIX_CXX='%s'", SHLIB_EXT) +) build_cmd <- "make" build_args <- c("_lightgbm", make_args_from_build_script) lib_folder <- file.path(source_dir, fsep = "/") @@ -174,18 +174,6 @@ windows_makefile_generator <- WINDOWS_BUILD_TOOLS[[windows_toolchain]][["makefil if (use_gpu) { cmake_args <- c(cmake_args, "-DUSE_GPU=ON") } -cmake_args <- c(cmake_args, "-D__BUILD_FOR_R=ON") - -# Pass in R version, used to help find R executable for linking -R_version_string <- paste( - R.Version()[["major"]] - , R.Version()[["minor"]] - , sep = "." -) -r_version_arg <- sprintf("-DCMAKE_R_VERSION='%s'", R_version_string) -# ensure CMake build respects how R is configured (`R CMD config SHLIB_EXT`) -shlib_ext_arg <- sprintf("-DCMAKE_SHARED_LIBRARY_SUFFIX_CXX='%s'", SHLIB_EXT) -cmake_args <- c(cmake_args, r_version_arg, shlib_ext_arg) # the checks below might already run `cmake -G`. If they do, set this flag # to TRUE to avoid re-running it later