Unverified Commit 49677098 authored by Guolin Ke's avatar Guolin Ke Committed by GitHub
Browse files

fix R build for version 3.5 and above (#1346)

parent fb55d72f
...@@ -13,6 +13,7 @@ OPTION(USE_OPENMP "Enable OpenMP" ON) ...@@ -13,6 +13,7 @@ OPTION(USE_OPENMP "Enable OpenMP" ON)
OPTION(USE_GPU "Enable GPU-acclerated training (EXPERIMENTAL)" OFF) OPTION(USE_GPU "Enable GPU-acclerated training (EXPERIMENTAL)" OFF)
OPTION(USE_SWIG "Enable SWIG to generate Java API" OFF) OPTION(USE_SWIG "Enable SWIG to generate Java API" OFF)
OPTION(USE_HDFS "Enable HDFS support (EXPERIMENTAL)" OFF) OPTION(USE_HDFS "Enable HDFS support (EXPERIMENTAL)" OFF)
OPTION(USE_R35 "Set to ON if your R version is not smaller than 3.5" OFF)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.8.2") if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.8.2")
...@@ -49,6 +50,10 @@ if(USE_SWIG) ...@@ -49,6 +50,10 @@ if(USE_SWIG)
include_directories($ENV{JAVA_HOME}/include/linux) include_directories($ENV{JAVA_HOME}/include/linux)
endif(USE_SWIG) endif(USE_SWIG)
if(USE_R35)
ADD_DEFINITIONS(-DR_VER_ABOVE_35)
endif()
if(USE_MPI) if(USE_MPI)
find_package(MPI REQUIRED) find_package(MPI REQUIRED)
ADD_DEFINITIONS(-DUSE_MPI) ADD_DEFINITIONS(-DUSE_MPI)
......
...@@ -61,7 +61,7 @@ options(devtools.install.args = "--no-multiarch") # if you have 64-bit R only, y ...@@ -61,7 +61,7 @@ options(devtools.install.args = "--no-multiarch") # if you have 64-bit R only, y
install_github("Microsoft/LightGBM", subdir = "R-package") install_github("Microsoft/LightGBM", subdir = "R-package")
``` ```
If you are using a precompiled dll/lib locally, you can move the dll/lib into LightGBM root folder, modify `LightGBM/R-package/src/install.libs.R`'s 2nd line (change `use_precompile <- FALSE` to `use_precompile <- TRUE`), and install R-package as usual. If you are using a precompiled dll/lib locally, you can move the dll/lib into LightGBM root folder, modify `LightGBM/R-package/src/install.libs.R`'s 2nd line (change `use_precompile <- FALSE` to `use_precompile <- TRUE`), and install R-package as usual. ** NOTE: If your R version is not smaller than 3.5.0, you should set `DUSE_R35=ON` in cmake options when build precompiled dll/lib **.
When your package installation is done, you can check quickly if your LightGBM R package is working by running the following: When your package installation is done, you can check quickly if your LightGBM R package is working by running the following:
......
...@@ -7,6 +7,13 @@ if (.Machine$sizeof.pointer != 8){ ...@@ -7,6 +7,13 @@ if (.Machine$sizeof.pointer != 8){
stop("Only support 64-bit R, please check your the version of your R and Rtools.") stop("Only support 64-bit R, please check your the version of your R and Rtools.")
} }
R_int_UUID <- .Internal(internalsID())
R_ver <- as.double(R.Version()$major) + as.double(R.Version()$minor)/10
if (!(R_int_UUID == "0310d4b8-ccb1-4bb8-ba94-d36a55f60262"
|| R_int_UUID == "2fdf6c18-697a-4ba7-b8ef-11c0d92f1327")){
print("Warning: unmatched R_INTERNALS_UUID, may cannot run normally.")
}
# Check for precompilation # Check for precompilation
if (!use_precompile) { if (!use_precompile) {
...@@ -47,6 +54,9 @@ if (!use_precompile) { ...@@ -47,6 +54,9 @@ if (!use_precompile) {
if (use_gpu) { if (use_gpu) {
cmake_cmd <- paste0(cmake_cmd, " -DUSE_GPU=ON ") cmake_cmd <- paste0(cmake_cmd, " -DUSE_GPU=ON ")
} }
if (R_ver >= 3.5) {
cmake_cmd <- paste0(cmake_cmd, " -DUSE_R35=ON ")
}
# Check if Windows installation (for gcc vs Visual Studio) # Check if Windows installation (for gcc vs Visual Studio)
if (WINDOWS) { if (WINDOWS) {
......
...@@ -9,6 +9,36 @@ ...@@ -9,6 +9,36 @@
#include <cstdint> #include <cstdint>
#define TYPE_BITS 5 #define TYPE_BITS 5
// use .Internal(internalsID()) to uuid
#define R_INTERNALS_UUID "2fdf6c18-697a-4ba7-b8ef-11c0d92f1327"
#ifdef R_VER_ABOVE_35
#define NAMED_BITS 16
struct lgbm_sxpinfo {
unsigned int type : 5;
unsigned int scalar : 1;
unsigned int obj : 1;
unsigned int alt : 1;
unsigned int gp : 16;
unsigned int mark : 1;
unsigned int debug : 1;
unsigned int trace : 1;
unsigned int spare : 1;
unsigned int gcgen : 1;
unsigned int gccls : 3;
unsigned int named : NAMED_BITS;
unsigned int extra : 32 - NAMED_BITS;
};
// 64bit pointer
#if INTPTR_MAX == INT64_MAX
typedef ptrdiff_t R_xlen_t;
#else
typedef int R_xlen_t;
#endif
#else
struct lgbm_sxpinfo { struct lgbm_sxpinfo {
unsigned int type : 5; unsigned int type : 5;
unsigned int obj : 1; unsigned int obj : 1;
...@@ -22,6 +52,9 @@ struct lgbm_sxpinfo { ...@@ -22,6 +52,9 @@ struct lgbm_sxpinfo {
unsigned int gccls : 3; unsigned int gccls : 3;
}; };
typedef int R_xlen_t;
#endif
struct lgbm_primsxp { struct lgbm_primsxp {
int offset; int offset;
}; };
...@@ -71,8 +104,8 @@ typedef struct LGBM_SER { ...@@ -71,8 +104,8 @@ typedef struct LGBM_SER {
} LGBM_SER, *LGBM_SE; } LGBM_SER, *LGBM_SE;
struct lgbm_vecsxp { struct lgbm_vecsxp {
int length; R_xlen_t length;
int truelength; R_xlen_t truelength;
}; };
typedef struct VECTOR_SER { typedef struct VECTOR_SER {
...@@ -96,7 +129,6 @@ typedef union { VECTOR_SER s; double align; } SEXPREC_ALIGN; ...@@ -96,7 +129,6 @@ typedef union { VECTOR_SER s; double align; } SEXPREC_ALIGN;
#define R_IS_NULL(x) ((*(LGBM_SE)(x)).sxpinfo.type == 0) #define R_IS_NULL(x) ((*(LGBM_SE)(x)).sxpinfo.type == 0)
// 64bit pointer // 64bit pointer
#if INTPTR_MAX == INT64_MAX #if INTPTR_MAX == INT64_MAX
......
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