Commit fc59fce0 authored by Guolin Ke's avatar Guolin Ke
Browse files

[R] update build commands.

parent 3421bc6c
Package: lightgbm Package: lightgbm
Type: Package Type: Package
Title: Light Gradient Boosting Machine Title: Light Gradient Boosting Machine
Version: 2.0.2 Version: 2.0.4
Date: 2017-06-22 Date: 2017-07-14
Author: Guolin Ke <guolin.ke@microsoft.com> Author: Guolin Ke <guolin.ke@microsoft.com>
Maintainer: Guolin Ke <guolin.ke@microsoft.com> Maintainer: Guolin Ke <guolin.ke@microsoft.com>
Description: LightGBM is a gradient boosting framework that uses tree based learning algorithms. Description: LightGBM is a gradient boosting framework that uses tree based learning algorithms.
......
...@@ -14,8 +14,6 @@ Note: 32-bit R/Rtools is not supported. ...@@ -14,8 +14,6 @@ Note: 32-bit R/Rtools is not supported.
Installing [Rtools](https://cran.r-project.org/bin/windows/Rtools/) is mandatory, and only support the 64-bit version. Installing [Rtools](https://cran.r-project.org/bin/windows/Rtools/) is mandatory, and only support the 64-bit version.
[cmake](https://cmake.org/) must be version 3.8 or higher.
The default compiler is Visual Studio (or [MS Build](https://www.visualstudio.com/downloads/#build-tools-for-visual-studio-2017)) in Windows, with an automatic fallback to Rtools or any [MinGW64](https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/) (x86_64-posix-seh) available (this means if you have only Rtools and cmake, it will compile fine). The default compiler is Visual Studio (or [MS Build](https://www.visualstudio.com/downloads/#build-tools-for-visual-studio-2017)) in Windows, with an automatic fallback to Rtools or any [MinGW64](https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/) (x86_64-posix-seh) available (this means if you have only Rtools and cmake, it will compile fine).
To force the usage of Rtools / MinGW, you can set `use_mingw` to `TRUE` in `R-package/src/install.libs.R`. To force the usage of Rtools / MinGW, you can set `use_mingw` to `TRUE` in `R-package/src/install.libs.R`.
...@@ -44,7 +42,7 @@ Or build a self-contained R package which can be installed afterwards: ...@@ -44,7 +42,7 @@ Or build a self-contained R package which can be installed afterwards:
git clone --recursive https://github.com/Microsoft/LightGBM git clone --recursive https://github.com/Microsoft/LightGBM
cd LightGBM/R-package cd LightGBM/R-package
Rscript build_package.R Rscript build_package.R
R CMD INSTALL lightgbm_2.0.2.tar.gz --no-multiarch R CMD INSTALL lightgbm_2.0.4.tar.gz --no-multiarch
``` ```
Note: for the build with Visual Studio/MSBuild in Windows, you should use the Windows CMD or Powershell. Note: for the build with Visual Studio/MSBuild in Windows, you should use the Windows CMD or Powershell.
......
...@@ -18,18 +18,16 @@ if (!use_precompile) { ...@@ -18,18 +18,16 @@ if (!use_precompile) {
unlink("./include", recursive = TRUE) unlink("./include", recursive = TRUE)
unlink("./src", recursive = TRUE) unlink("./src", recursive = TRUE)
unlink("./compute", recursive = TRUE) unlink("./compute", recursive = TRUE)
unlink("./build", recursive = TRUE) unlink("./build", recursive = TRUE)
if (!file.copy("./../../include", "./", overwrite = TRUE, recursive = TRUE)) { if (!file.copy("./../../include", "./", overwrite = TRUE, recursive = TRUE)) {
stop("Cannot find folder LightGBM/include") stop("Cannot find folder LightGBM/include")
} }
if (!file.copy("./../../src", "./", overwrite = TRUE, recursive = TRUE)) { if (!file.copy("./../../src", "./", overwrite = TRUE, recursive = TRUE)) {
stop("Cannot find folder LightGBM/src") stop("Cannot find folder LightGBM/src")
} }
if (use_gpu) { if (!file.copy("./../../compute", "./", overwrite = TRUE, recursive = TRUE)) {
if (!file.copy("./../../compute", "./", overwrite = TRUE, recursive = TRUE)) { print("Cannot find folder LightGBM/compute, disabling GPU build.")
print("Cannot find folder LightGBM/compute, disabling GPU build.") use_gpu <- FALSE
use_gpu <- FALSE
}
} }
if (!file.copy("./../../CMakeLists.txt", "./", overwrite = TRUE, recursive = TRUE)) { if (!file.copy("./../../CMakeLists.txt", "./", overwrite = TRUE, recursive = TRUE)) {
stop("Cannot find file LightGBM/CMakeLists.txt") stop("Cannot find file LightGBM/CMakeLists.txt")
...@@ -42,35 +40,46 @@ if (!use_precompile) { ...@@ -42,35 +40,46 @@ if (!use_precompile) {
setwd(build_dir) setwd(build_dir)
# Prepare installation steps # Prepare installation steps
cmake_base <- "cmake " cmake_cmd <- "cmake "
build_cmd <- "make _lightgbm -j" build_cmd <- "make _lightgbm -j"
lib_folder <- file.path(R_PACKAGE_SOURCE, "src", fsep = "/") lib_folder <- file.path(R_PACKAGE_SOURCE, "src", fsep = "/")
if (use_gpu) {
cmake_cmd <- paste0(cmake_cmd, " -DUSE_GPU=ON ")
}
# Check if Windows installation (for gcc vs Visual Studio) # Check if Windows installation (for gcc vs Visual Studio)
if (WINDOWS) { if (WINDOWS) {
if (use_mingw) { if (use_mingw) {
cmake_cmd <- paste0(cmake_base, " -G \"MinGW Makefiles\" ") cmake_cmd <- paste0(cmake_cmd, " -G \"MinGW Makefiles\" ")
build_cmd <- "mingw32-make.exe _lightgbm -j" build_cmd <- "mingw32-make.exe _lightgbm -j"
system(paste0(cmake_cmd, " ..")) # Must build twice for Windows due sh.exe in Rtools system(paste0(cmake_cmd, " ..")) # Must build twice for Windows due sh.exe in Rtools
} else { } else {
cmake_cmd <- paste0(cmake_base, " -DCMAKE_GENERATOR_PLATFORM=x64 ") try_vs <- 0
tryVS <- system(paste0(cmake_cmd, " ..")) local_vs_def <- ""
if (tryVS == 1) { vs_versions <- c("Visual Studio 15 2017 Win64", "Visual Studio 14 2015 Win64", "Visual Studio 12 2013 Win64")
for(vs in vs_versions){
vs_def <- paste0(" -G \"", vs, "\"")
tmp_cmake_cmd <- paste0(cmake_cmd, vs_def)
try_vs <- system(paste0(tmp_cmake_cmd, " .."))
unlink("./*", recursive = TRUE) # Clean up build directory unlink("./*", recursive = TRUE) # Clean up build directory
cmake_cmd <- paste0(cmake_base, " -G \"MinGW Makefiles\" ") # Switch to MinGW on failure, try build once if (try_vs == 0) {
local_vs_def = vs_def
break
}
}
if (try_vs == 1) {
cmake_cmd <- paste0(cmake_cmd, " -G \"MinGW Makefiles\" ") # Switch to MinGW on failure, try build once
system(paste0(cmake_cmd, " ..")) # Must build twice for Windows due sh.exe in Rtools system(paste0(cmake_cmd, " ..")) # Must build twice for Windows due sh.exe in Rtools
build_cmd <- "mingw32-make.exe _lightgbm -j" build_cmd <- "mingw32-make.exe _lightgbm -j"
} else { } else {
cmake_cmd <- paste0(cmake_cmd, local_vs_def)
build_cmd <- "cmake --build . --target _lightgbm --config Release" build_cmd <- "cmake --build . --target _lightgbm --config Release"
lib_folder <- file.path(R_PACKAGE_SOURCE, "src/Release", fsep = "/") lib_folder <- file.path(R_PACKAGE_SOURCE, "src/Release", fsep = "/")
} }
} }
} }
if (use_gpu) {
cmake_cmd <- paste0(cmake_cmd, " -DUSE_GPU=ON ")
}
# Install # Install
system(paste0(cmake_cmd, " ..")) system(paste0(cmake_cmd, " .."))
system(build_cmd) system(build_cmd)
......
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