Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[R-package] Fallback to MinGW when VS build fails #664

Merged
merged 15 commits into from
Jul 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions R-package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,22 @@ 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.

[cmake](https://cmake.org/) must be version 3.8 or higher.
[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. You also can use [MinGW64](https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/) (x86_64-posix-seh) to compile by setting `use_mingw` to `TRUE` in `R-package/src/install.libs.R`. For MinGW users who wants to install online, please check the end of this document for installation using a helper package ([Laurae2/lgbdl](https://github.com/Laurae2/lgbdl/)).
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).

It is recommended to use *Visual Studio* for its better multi-threading efficency in Windows for many core systems. For very simple systems (dual core computers or worse), MinGW64 is recommended for maximum performance. If you do not know what to choose, it is recommended to use [Visual Studio](https://www.visualstudio.com/downloads/#build-tools-for-visual-studio-2017).
To force the usage of Rtools / MinGW, you can set `use_mingw` to `TRUE` in `R-package/src/install.libs.R`.

#### Mac OS X Preparation
For users who wants to install online with GPU or want to choose a specific compiler, please check the end of this document for installation using a helper package ([Laurae2/lgbdl](https://github.com/Laurae2/lgbdl/)).

It is recommended to use *Visual Studio* for its better multi-threading efficency in Windows for many core systems. For very simple systems (dual core computers or worse), MinGW64 is recommended for maximum performance. If you do not know what to choose, it is recommended to use [Visual Studio](https://www.visualstudio.com/downloads/#build-tools-for-visual-studio-2017), the default compiler.

Gcc with OpenMP support must be installed first. Refer to [wiki](https://github.com/Microsoft/LightGBM/wiki/Installation-Guide#osx) for installing gcc with OpenMP support.
#### Mac OS X Preparation

gcc with OpenMP support must be installed first. Refer to [wiki](https://github.com/Microsoft/LightGBM/wiki/Installation-Guide#osx) for installing gcc with OpenMP support.

### Install

Install LightGBM R-package with the following command:

```sh
Expand Down Expand Up @@ -53,7 +57,7 @@ You can also install directly from R using the repository with `devtools`:

```r
library(devtools)
options(devtools.install.args = "--no-multiarch")
options(devtools.install.args = "--no-multiarch") # if you have 64-bit R only, you can skip this
install_github("Microsoft/LightGBM", subdir = "R-package")
```

Expand Down Expand Up @@ -93,13 +97,12 @@ In addition, if you are using a Visual Studio precompiled DLL, assuming you do n

Once you have all this setup, you can use `lgb.dl` from `lgbdl` package to install LightGBM from repository.

For instance, you can install the R package from LightGBM master commit of GitHub using the following from R:
For instance, you can install the R package from LightGBM master commit of GitHub with Visual Studio using the following from R:

```r
lgb.dl(commit = "master",
compiler = "gcc",
repo = "https://github.com/Microsoft/LightGBM",
cores = 4)
compiler = "vs",
repo = "https://github.com/Microsoft/LightGBM")
```

You may also install using a precompiled dll/lib using the following from R:
Expand All @@ -110,6 +113,15 @@ lgb.dl(commit = "master",
repo = "https://github.com/Microsoft/LightGBM")
```

You may also install online using a LightGBM with proper GPU support using Visual Studio (as an example here) using the following from R:

```r
lgb.dl(commit = "master",
compiler = "vs", # Remove this for MinGW + GPU installation
repo = "https://github.com/Microsoft/LightGBM",
use_gpu = TRUE)
```

For more details about options, please check [Laurae2/lgbdl](https://github.com/Laurae2/lgbdl/) R-package.

Examples
Expand Down
23 changes: 16 additions & 7 deletions R-package/src/install.libs.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,28 @@ if (!use_precompile) {
setwd(build_dir)

# Prepare installation steps
cmake_cmd <- "cmake "
build_cmd <- "make _lightgbm -j4"
cmake_base <- "cmake "
build_cmd <- "make _lightgbm -j"
lib_folder <- file.path(R_PACKAGE_SOURCE, "src", fsep = "/")

# Check if Windows installation (for gcc vs Visual Studio)
if (WINDOWS) {
if (use_mingw) {
cmake_cmd <- paste0(cmake_cmd, " -G \"MinGW Makefiles\" ")
build_cmd <- "mingw32-make.exe _lightgbm -j4"
cmake_cmd <- paste0(cmake_base, " -G \"MinGW Makefiles\" ")
build_cmd <- "mingw32-make.exe _lightgbm -j"
system(paste0(cmake_cmd, " ..")) # Must build twice for Windows due sh.exe in Rtools
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It that okay for double cmake for vs ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double cmake for VS does not cause issues.

This is the message printed when using twice cmake with VS: CMake does not need to re-run because C:/tmp/RtmpygCFH6/devtools19ad439764e21/Laurae2-LightGBM-ed00f7b/R-package/src/build/CMakeFiles/generate.stamp is up-to-date.

} else {
cmake_cmd <- paste0(cmake_cmd, " -DCMAKE_GENERATOR_PLATFORM=x64 ")
build_cmd <- "cmake --build . --target _lightgbm --config Release"
lib_folder <- file.path(R_PACKAGE_SOURCE, "src/Release", fsep = "/")
cmake_cmd <- paste0(cmake_base, " -DCMAKE_GENERATOR_PLATFORM=x64 ")
tryVS <- system(paste0(cmake_cmd, " .."))
if (tryVS == 1) {
unlink("./*", recursive = TRUE) # Clean up build directory
cmake_cmd <- paste0(cmake_base, " -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
build_cmd <- "mingw32-make.exe _lightgbm -j"
} else {
build_cmd <- "cmake --build . --target _lightgbm --config Release"
lib_folder <- file.path(R_PACKAGE_SOURCE, "src/Release", fsep = "/")
}
}
}

Expand Down