Skip to content

Commit

Permalink
use install.libs.R from master to support newer Visual Studio
Browse files Browse the repository at this point in the history
  • Loading branch information
jameslamb committed Oct 8, 2022
1 parent dd00f22 commit ece95ac
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions R-package/src/install.libs.R
@@ -1,5 +1,6 @@
# User options
use_gpu <- FALSE
make_args_from_build_script <- character(0L)

# For Windows, the package will be built with Visual Studio
# unless you set one of these to TRUE
Expand All @@ -22,6 +23,11 @@ if (!(R_int_UUID == "0310d4b8-ccb1-4bb8-ba94-d36a55f60262"
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 = "/")
inst_dir <- file.path(R_PACKAGE_SOURCE, "inst", fsep = "/")

# system() will not raise an R exception if the process called
# fails. Wrapping it here to get that behavior.
#
Expand All @@ -31,7 +37,7 @@ if (!(R_int_UUID == "0310d4b8-ccb1-4bb8-ba94-d36a55f60262"
on_windows <- .Platform$OS.type == "windows"
has_processx <- suppressMessages({
suppressWarnings({
require("processx") # nolint
require("processx") # nolint: undesirable_function
})
})
if (has_processx && on_windows) {
Expand Down Expand Up @@ -64,7 +70,8 @@ if (!(R_int_UUID == "0310d4b8-ccb1-4bb8-ba94-d36a55f60262"
# try to generate Visual Studio build files
.generate_vs_makefiles <- function(cmake_args) {
vs_versions <- c(
"Visual Studio 16 2019"
"Visual Studio 17 2022"
, "Visual Studio 16 2019"
, "Visual Studio 15 2017"
, "Visual Studio 14 2015"
)
Expand Down Expand Up @@ -94,18 +101,14 @@ if (!(R_int_UUID == "0310d4b8-ccb1-4bb8-ba94-d36a55f60262"

# Move in CMakeLists.txt
write_succeeded <- file.copy(
"../inst/bin/CMakeLists.txt"
file.path(inst_dir, "bin", "CMakeLists.txt")
, "CMakeLists.txt"
, overwrite = TRUE
)
if (!write_succeeded) {
stop("Copying CMakeLists.txt failed")
}

# Get some paths
source_dir <- file.path(R_PACKAGE_SOURCE, "src", fsep = "/")
build_dir <- file.path(source_dir, "build", fsep = "/")

# Prepare building package
dir.create(
build_dir
Expand All @@ -120,7 +123,7 @@ use_visual_studio <- !(use_mingw || use_msys2)
# to create R.def from R.dll
if (WINDOWS && use_visual_studio) {
write_succeeded <- file.copy(
"../../inst/make-r-def.R"
file.path(inst_dir, "make-r-def.R")
, file.path(build_dir, "make-r-def.R")
, overwrite = TRUE
)
Expand All @@ -132,7 +135,7 @@ if (WINDOWS && use_visual_studio) {
# Prepare installation steps
cmake_args <- NULL
build_cmd <- "make"
build_args <- "_lightgbm"
build_args <- c("_lightgbm", make_args_from_build_script)
lib_folder <- file.path(source_dir, fsep = "/")

# add in command-line arguments
Expand Down Expand Up @@ -194,7 +197,7 @@ if (WINDOWS) {
cmake_args <- c(cmake_args, "-G", shQuote(windows_makefile_generator))
.run_shell_command("cmake", c(cmake_args, ".."), strict = FALSE)
build_cmd <- windows_build_tool
build_args <- "_lightgbm"
build_args <- c("_lightgbm", make_args_from_build_script)
} else {
visual_studio_succeeded <- .generate_vs_makefiles(cmake_args)
if (!isTRUE(visual_studio_succeeded)) {
Expand All @@ -203,7 +206,7 @@ if (WINDOWS) {
cmake_args <- c(cmake_args, "-G", shQuote(windows_makefile_generator))
.run_shell_command("cmake", c(cmake_args, ".."), strict = FALSE)
build_cmd <- windows_build_tool
build_args <- "_lightgbm"
build_args <- c("_lightgbm", make_args_from_build_script)
} else {
build_cmd <- "cmake"
build_args <- c("--build", ".", "--target", "_lightgbm", "--config", "Release")
Expand Down

0 comments on commit ece95ac

Please sign in to comment.