-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Conversation
@Laurae2 Did you test the build with MinGW ? |
@guolinke It seems to work now. It does not need a separate MinGW, by default it should use Rtools. |
@guolinke In Windows, cmake with Rtools requires to run twice because Rtools has |
@Laurae2 |
@guolinke We already have But in any case, Rtools must be the default choice and VS an optional choice (not the other way around, it makes it unpractical especially for automated installations and future CRAN release). |
@Laurae2 Thanks. I think we can list the installed compilers by using BTW, does these cran test machine have the cmake ? |
R-package/src/install.libs.R
Outdated
cmake_cmd <- paste0(cmake_base, " -DCMAKE_GENERATOR_PLATFORM=x64 ") | ||
tryVS <- system(paste0(cmake_cmd, " ..")) | ||
if (tryVS == 1) { | ||
cmake_cmd <- paste0(cmake_base, " -G \"MinGW Makefiles\" ") # Switch to MinGW on failure, try build once |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is better to remove all cmake caches if last camke is fail. you can delete all contents in build
folder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know where is the build folder in all the folders? I can't seem to get rid of it.
Objective would be:
- try VS build
- if VS build fails, try MinGW build but delete build folder first (I don't know where is the build folder in all the folders)
R-package/src/install.libs.R
Outdated
if (tryVS == 1) { | ||
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 <- "cmake --build . --target _lightgbm --config Release" | ||
lib_folder <- file.path(R_PACKAGE_SOURCE, "src/Release", fsep = "/") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lib_path should change if vs build failed
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 |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
R-package/src/install.libs.R
Outdated
@@ -56,6 +56,7 @@ if (!use_precompile) { | |||
cmake_cmd <- paste0(cmake_base, " -DCMAKE_GENERATOR_PLATFORM=x64 ") | |||
tryVS <- system(paste0(cmake_cmd, " ..")) | |||
if (tryVS == 1) { | |||
system("rm -rf .") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure the rm -rf
can work in windows or not. you can use unlink("./*", recursive = TRUE)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works with your method.
rm rf
works, but I was denied access to remove .
or ..
apparently.
@guolinke CRAN test machines should have For instance, this CRAN package requires |
@guolinke Build passing on my VS+MinGW Windows machine (VS selection) and MinGW Windows machine (VS failed, auto fallback to MinGW) now. |
but getting this error now on my MinGW-only machine:
|
lib_path should change if vs build failed |
@Laurae2 Thanks, can you also update the documents ? |
Success on both machines, using R 3.4.0: VS + MinGW machine: > devtools::install_github("Laurae2/LightGBM@patch-2", subdir = "R-package")
(...)
** building package indices
** testing if installed package can be loaded
Warning: package 'R6' was built under R version 3.4.1
* DONE (lightgbm)
Warning message:
GitHub repo contains submodules, may not function as expected! MinGW-only machine: > devtools::install_github("Laurae2/LightGBM@patch-2", subdir = "R-package")
(...)
** building package indices
** testing if installed package can be loaded
Warning: package 'R6' was built under R version 3.4.1
* DONE (lightgbm)
Warning message:
GitHub repo contains submodules, may not function as expected! |
@guolinke I'll update docs now to change the default to VS and auto fallback to MinGW for Windows. |
R-package/README.md
Outdated
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 Rtools or any [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`. You also can use Visual Studio (or [MS Build](https://www.visualstudio.com/downloads/#build-tools-for-visual-studio-2017)) in Windows. | ||
|
||
For Visual Studio 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/)). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the description in line 19 and 21 should be updated. What do you think ?
Thanks very much. I think now I can merge it. |
* Change VS -> MinGW for CRAN * Documentation to switch to MinGW by default * Force cmake to run twice * Try again dual build for Rtools * Switch to cmake for building twice * Try with Visual Studio as default, MinGW as fallback * Try to remove VS appropriately when failing * Attempt to get rid of build folder first * Switch to unlink from rm rf * Change lib_folder correctly when VS fails * Add README updates from 1c8355c * Update default compiler doc and add GPU online install doc * Better GPU doc
This PR is to help the release of CRAN package of LightGBM.
It removes Visual Studio requirement on Windows. User may still install LightGBM with Visual Studio from GitHub using Laurae2/lgbdl.
MinGW should be the default for the following reasons in Windows:
Updates:
See issue #629.