Skip to content

Commit

Permalink
pass -j through to install.libs.R
Browse files Browse the repository at this point in the history
  • Loading branch information
jameslamb committed Nov 7, 2021
1 parent 422a30e commit d4a8854
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .ci/test_r_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ cd ${BUILD_DIRECTORY}
PKG_TARBALL="lightgbm_*.tar.gz"
LOG_FILE_NAME="lightgbm.Rcheck/00check.log"
if [[ $R_BUILD_TYPE == "cmake" ]]; then
Rscript build_r.R --skip-install || exit -1
Rscript build_r.R -j2 --skip-install || exit -1
elif [[ $R_BUILD_TYPE == "cran" ]]; then

# on Linux, we recreate configure in CI to test if
Expand Down
4 changes: 2 additions & 2 deletions .ci/test_r_package_windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ if ($env:COMPILER -ne "MSVC") {
if ($env:R_BUILD_TYPE -eq "cmake") {
if ($env:TOOLCHAIN -eq "MINGW") {
Write-Output "Telling R to use MinGW"
$env:BUILD_R_FLAGS = "c('--skip-install', '--use-mingw')"
$env:BUILD_R_FLAGS = "c('--skip-install', '--use-mingw', '-j2')"
} elseif ($env:TOOLCHAIN -eq "MSYS") {
Write-Output "Telling R to use MSYS"
$env:BUILD_R_FLAGS = "c('--skip-install', '--use-msys2')"
$env:BUILD_R_FLAGS = "c('--skip-install', '--use-msys2', '-j2')"
} elseif ($env:TOOLCHAIN -eq "MSVC") {
$env:BUILD_R_FLAGS = "'--skip-install'"
} else {
Expand Down
7 changes: 4 additions & 3 deletions R-package/src/install.libs.R
Original file line number Diff line number Diff line change
@@ -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 Down Expand Up @@ -132,7 +133,7 @@ if (WINDOWS && use_visual_studio) {
# Prepare installation steps
cmake_args <- NULL
build_cmd <- "make"
build_args <- c("_lightgbm", "-j4")
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 +195,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 <- c("_lightgbm", "-j4")
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 +204,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 <- c("_lightgbm", "-j4")
build_args <- c("_lightgbm", make_args_from_build_script)
} else {
build_cmd <- "cmake"
build_args <- c("--build", ".", "--target", "_lightgbm", "--config", "Release")
Expand Down
14 changes: 14 additions & 0 deletions build_r.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,20 @@ if (length(keyword_args) > 0L) {
)
}

# if provided, set '-j' in 'make' commands in install.libs.R
if (length(parsed_args[["make_args"]]) > 0L) {
install_libs_content <- gsub(
pattern = "make_args_from_build_script <- character(0L)"
, replacement = paste0(
"make_args_from_build_script <- c(\""
, paste0(parsed_args[["make_args"]], collapse = "\", \"")
, "\")"
)
, x = install_libs_content
, fixed = TRUE
)
}

# R returns FALSE (not a non-zero exit code) if a file copy operation
# breaks. Let's fix that
.handle_result <- function(res) {
Expand Down

0 comments on commit d4a8854

Please sign in to comment.