Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
tianlh
LightGBM-DCU
Commits
da9bb5fd
Unverified
Commit
da9bb5fd
authored
May 01, 2024
by
James Lamb
Committed by
GitHub
May 01, 2024
Browse files
[R-package] always name the shared library 'lightgbm', not 'lib_lightgbm' (#6432)
parent
d7fcb3c2
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
18 additions
and
61 deletions
+18
-61
CMakeLists.txt
CMakeLists.txt
+12
-1
R-package/NAMESPACE
R-package/NAMESPACE
+1
-1
R-package/R/lightgbm.R
R-package/R/lightgbm.R
+1
-1
R-package/src/install.libs.R
R-package/src/install.libs.R
+3
-3
build-cran-package.sh
build-cran-package.sh
+1
-19
build_r.R
build_r.R
+0
-36
No files found.
CMakeLists.txt
View file @
da9bb5fd
...
...
@@ -461,11 +461,22 @@ if(BUILD_STATIC_LIB)
else
()
add_library
(
_lightgbm SHARED
)
endif
()
# R expects libraries of the form <project>.{dll,dylib,so}, not lib_<project>.{dll,dylib,so}
if
(
__BUILD_FOR_R
)
set_target_properties
(
_lightgbm
PROPERTIES
PREFIX
""
OUTPUT_NAME
"lightgbm"
)
endif
()
# LightGBM headers include openmp, cuda, R etc. headers,
# thus PUBLIC is required for building _lightgbm_swig target.
target_link_libraries
(
_lightgbm PUBLIC lightgbm_capi_objs lightgbm_objs
)
if
(
MSVC
)
if
(
MSVC
AND NOT __BUILD_FOR_R
)
set_target_properties
(
_lightgbm PROPERTIES OUTPUT_NAME
"lib_lightgbm"
)
endif
()
...
...
R-package/NAMESPACE
View file @
da9bb5fd
...
...
@@ -62,4 +62,4 @@ importFrom(parallel,detectCores)
importFrom(stats,quantile)
importFrom(utils,modifyList)
importFrom(utils,read.delim)
useDynLib(
lib_
lightgbm , .registration = TRUE)
useDynLib(lightgbm , .registration = TRUE)
R-package/R/lightgbm.R
View file @
da9bb5fd
...
...
@@ -325,7 +325,7 @@ NULL
#' @import methods
#' @importFrom Matrix Matrix
#' @importFrom R6 R6Class
#' @useDynLib
lib_
lightgbm , .registration = TRUE
#' @useDynLib lightgbm , .registration = TRUE
NULL
# Suppress false positive warnings from R CMD CHECK about
...
...
R-package/src/install.libs.R
View file @
da9bb5fd
...
...
@@ -227,9 +227,9 @@ if (!makefiles_already_generated) {
}
# build the library
message
(
"Building
lib_
lightgbm"
)
message
(
paste0
(
"Building lightgbm"
,
SHLIB_EXT
)
)
.run_shell_command
(
build_cmd
,
build_args
)
src
<-
file.path
(
lib_folder
,
paste0
(
"
lib_
lightgbm"
,
SHLIB_EXT
),
fsep
=
"/"
)
src
<-
file.path
(
lib_folder
,
paste0
(
"lightgbm"
,
SHLIB_EXT
),
fsep
=
"/"
)
# Packages with install.libs.R need to copy some artifacts into the
# expected places in the package structure.
...
...
@@ -247,7 +247,7 @@ if (file.exists(src)) {
}
}
else
{
stop
(
paste0
(
"Cannot find
lib_
lightgbm"
,
SHLIB_EXT
))
stop
(
paste0
(
"Cannot find lightgbm"
,
SHLIB_EXT
))
}
# clean up the "build" directory
...
...
build-cran-package.sh
View file @
da9bb5fd
...
...
@@ -165,23 +165,6 @@ cd "${TEMP_R_DIR}"
-e
's/\.\..*fast_double_parser\.h/LightGBM\/fast_double_parser\.h/'
\
src/include/LightGBM/utils/common.h
# When building an R package with 'configure', it seems
# you're guaranteed to get a shared library called
# <packagename>.so/dll/dylib. The package source code expects
# 'lib_lightgbm.so', not 'lightgbm.so', to comply with the way
# this project has historically handled installation
echo
"Changing lib_lightgbm to lightgbm"
for
file
in
R/
*
.R
;
do
sed
\
-i
.bak
\
-e
's/lib_lightgbm/lightgbm/'
\
"
${
file
}
"
done
sed
\
-i
.bak
\
-e
's/lib_lightgbm/lightgbm/'
\
NAMESPACE
# 'processx' is listed as a 'Suggests' dependency in DESCRIPTION
# because it is used in install.libs.R, a file that is not
# included in the CRAN distribution of the package
...
...
@@ -191,8 +174,7 @@ cd "${TEMP_R_DIR}"
DESCRIPTION
echo
"Cleaning sed backup files"
rm
R/
*
.R.bak
rm
NAMESPACE.bak
rm
*
.bak
cd
"
${
ORIG_WD
}
"
...
...
build_r.R
View file @
da9bb5fd
...
...
@@ -398,42 +398,6 @@ description_contents <- gsub(
)
writeLines
(
description_contents
,
DESCRIPTION_FILE
)
# CMake-based builds can't currently use R's builtin routine registration,
# so have to update NAMESPACE manually, with a statement like this:
#
# useDynLib(lib_lightgbm, LGBM_DatasetCreateFromFile_R, ...)
#
# See https://cran.r-project.org/doc/manuals/r-release/R-exts.html#useDynLib for
# documentation of this approach, where the NAMESPACE file uses a statement like
# useDynLib(foo, myRoutine, myOtherRoutine)
NAMESPACE_FILE
<-
file.path
(
TEMP_R_DIR
,
"NAMESPACE"
)
namespace_contents
<-
readLines
(
NAMESPACE_FILE
)
dynlib_line
<-
grep
(
pattern
=
"^useDynLib"
,
x
=
namespace_contents
)
c_api_contents
<-
readLines
(
file.path
(
TEMP_SOURCE_DIR
,
"src"
,
"lightgbm_R.h"
))
c_api_contents
<-
c_api_contents
[
startsWith
(
c_api_contents
,
"LIGHTGBM_C_EXPORT"
)]
c_api_contents
<-
gsub
(
pattern
=
"LIGHTGBM_C_EXPORT SEXP "
,
replacement
=
""
,
x
=
c_api_contents
,
fixed
=
TRUE
)
c_api_symbols
<-
gsub
(
pattern
=
"\\(.*"
,
replacement
=
""
,
x
=
c_api_contents
)
dynlib_statement
<-
paste0
(
"useDynLib(lib_lightgbm, "
,
toString
(
c_api_symbols
)
,
")"
)
namespace_contents
[
dynlib_line
]
<-
dynlib_statement
writeLines
(
namespace_contents
,
NAMESPACE_FILE
)
# NOTE: --keep-empty-dirs is necessary to keep the deep paths expected
# by CMake while also meeting the CRAN req to create object files
# on demand
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment