-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[R] Remove dependency on gendef for Visual Studio builds (fixes #5608) (
#5764) * [R-package] Remove dependency on gendef for Visual Studio builds (fixes #5608) * clarify docs * removed debugging print statement * Make R CMake install more robust * Fix doc format; add ToC * Update build.rst * Fix AppVeyor Co-authored-by: Hyunsu Cho <[email protected]>
- Loading branch information
Showing
10 changed files
with
225 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# [description] | ||
# Create a definition file (.def) from a .dll file, using objdump. This | ||
# is used by FindLibR.cmake when building the R package with MSVC. | ||
# | ||
# [usage] | ||
# | ||
# Rscript make-r-def.R something.dll something.def | ||
# | ||
# [references] | ||
# * https://www.cs.colorado.edu/~main/cs1300/doc/mingwfaq.html | ||
|
||
args <- commandArgs(trailingOnly = TRUE) | ||
|
||
IN_DLL_FILE <- args[[1L]] | ||
OUT_DEF_FILE <- args[[2L]] | ||
DLL_BASE_NAME <- basename(IN_DLL_FILE) | ||
|
||
message(sprintf("Creating '%s' from '%s'", OUT_DEF_FILE, IN_DLL_FILE)) | ||
|
||
# system() will not raise an R exception if the process called | ||
# fails. Wrapping it here to get that behavior. | ||
# | ||
# system() introduces a lot of overhead, at least on Windows, | ||
# so trying processx if it is available | ||
.pipe_shell_command_to_stdout <- function(command, args, out_file) { | ||
has_processx <- suppressMessages({ | ||
suppressWarnings({ | ||
require("processx") # nolint | ||
}) | ||
}) | ||
if (has_processx) { | ||
p <- processx::process$new( | ||
command = command | ||
, args = args | ||
, stdout = out_file | ||
, windows_verbatim_args = FALSE | ||
) | ||
invisible(p$wait()) | ||
} else { | ||
message(paste0( | ||
"Using system2() to run shell commands. Installing " | ||
, "'processx' with install.packages('processx') might " | ||
, "make this faster." | ||
)) | ||
exit_code <- system2( | ||
command = command | ||
, args = shQuote(args) | ||
, stdout = out_file | ||
) | ||
if (exit_code != 0L) { | ||
stop(paste0("Command failed with exit code: ", exit_code)) | ||
} | ||
} | ||
return(invisible(NULL)) | ||
} | ||
|
||
# use objdump to dump all the symbols | ||
OBJDUMP_FILE <- "objdump-out.txt" | ||
.pipe_shell_command_to_stdout( | ||
command = "objdump" | ||
, args = c("-p", IN_DLL_FILE) | ||
, out_file = OBJDUMP_FILE | ||
) | ||
|
||
objdump_results <- readLines(OBJDUMP_FILE) | ||
result <- file.remove(OBJDUMP_FILE) | ||
|
||
# Only one table in the objdump results matters for our purposes, | ||
# see https://www.cs.colorado.edu/~main/cs1300/doc/mingwfaq.html | ||
start_index <- which( | ||
grepl( | ||
pattern = "[Ordinal/Name Pointer] Table" | ||
, x = objdump_results | ||
, fixed = TRUE | ||
) | ||
) | ||
empty_lines <- which(objdump_results == "") | ||
end_of_table <- empty_lines[empty_lines > start_index][1L] | ||
|
||
# Read the contents of the table | ||
exported_symbols <- objdump_results[(start_index + 1L):end_of_table] | ||
exported_symbols <- gsub("\t", "", exported_symbols) | ||
exported_symbols <- gsub(".*\\] ", "", exported_symbols) | ||
exported_symbols <- gsub(" ", "", exported_symbols) | ||
|
||
# Write R.def file | ||
writeLines( | ||
text = c( | ||
paste0("LIBRARY \"", DLL_BASE_NAME, "\"") | ||
, "EXPORTS" | ||
, exported_symbols | ||
) | ||
, con = OUT_DEF_FILE | ||
, sep = "\n" | ||
) | ||
message(sprintf("Successfully created '%s'", OUT_DEF_FILE)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Commands to install the R package as a CMake install target | ||
|
||
function(check_call) | ||
set(cmd COMMAND) | ||
cmake_parse_arguments( | ||
PARSE_ARGV 0 | ||
CALL_ARG "" "" "${cmd}" | ||
) | ||
string(REPLACE ";" " " commands "${CALL_ARG_COMMAND}") | ||
message("Command: ${commands}") | ||
execute_process(COMMAND ${CALL_ARG_COMMAND} | ||
OUTPUT_VARIABLE _out | ||
ERROR_VARIABLE _err | ||
RESULT_VARIABLE _res) | ||
if(NOT "${_res}" EQUAL "0") | ||
message(FATAL_ERROR "out: ${_out}, err: ${_err}, res: ${_res}") | ||
endif() | ||
endfunction() | ||
|
||
# Important paths | ||
set(build_dir "@build_dir@") | ||
set(LIBR_EXECUTABLE "@LIBR_EXECUTABLE@") | ||
|
||
# Back up cmake_install.cmake | ||
file(WRITE "${build_dir}/R-package/src/Makevars" "all:") | ||
file(WRITE "${build_dir}/R-package/src/Makevars.win" "all:") | ||
|
||
# Install dependencies | ||
set(XGB_DEPS_SCRIPT | ||
"deps = setdiff(c('data.table', 'magrittr', 'stringi'), rownames(installed.packages())); if(length(deps)>0) install.packages(deps, repo = 'https://cloud.r-project.org/')") | ||
check_call(COMMAND "${LIBR_EXECUTABLE}" -q -e "${XGB_DEPS_SCRIPT}") | ||
|
||
# Install the XGBoost R package | ||
check_call(COMMAND "${LIBR_EXECUTABLE}" CMD INSTALL --no-multiarch --build "${build_dir}/R-package") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Assembles the R-package files in build_dir; | ||
# if necessary, installs the main R package dependencies; | ||
# runs R CMD INSTALL. | ||
function(setup_rpackage_install_target rlib_target build_dir) | ||
configure_file(${PROJECT_SOURCE_DIR}/cmake/RPackageInstall.cmake.in ${PROJECT_BINARY_DIR}/RPackageInstall.cmake @ONLY) | ||
install( | ||
DIRECTORY "${xgboost_SOURCE_DIR}/R-package" | ||
DESTINATION "${build_dir}" | ||
REGEX "src/*" EXCLUDE | ||
REGEX "R-package/configure" EXCLUDE | ||
) | ||
install(TARGETS ${rlib_target} | ||
LIBRARY DESTINATION "${build_dir}/R-package/src/" | ||
RUNTIME DESTINATION "${build_dir}/R-package/src/") | ||
install(SCRIPT ${PROJECT_BINARY_DIR}/RPackageInstall.cmake) | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters