-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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] Remove dependency on gendef for Visual Studio builds (fixes #5608) #5764
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1c48061
[R-package] Remove dependency on gendef for Visual Studio builds (fix…
jameslamb b638714
clarify docs
jameslamb 177c58d
removed debugging print statement
jameslamb 00e5da0
Make R CMake install more robust
hcho3 0168c4f
Fix doc format; add ToC
hcho3 558f3f1
Update build.rst
hcho3 f1a427c
Fix AppVeyor
hcho3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Previously, CMake would run commands like
R CMD INSTALL
but would not check if the command actually succeeded or not. Now CMake will check the result of the command. This change will help us debug install issues in the coming future.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.
oh great!