Skip to content

Commit

Permalink
add changes from #5503
Browse files Browse the repository at this point in the history
  • Loading branch information
jameslamb committed Oct 10, 2022
1 parent 3be05d4 commit 4498a89
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 10 deletions.
12 changes: 7 additions & 5 deletions .ci/test_r_package_windows.ps1
Expand Up @@ -54,11 +54,13 @@ Remove-From-Path ".*PostgreSQL.*"
Remove-From-Path ".*\\R\\.*"
Remove-From-Path ".*R Client.*"
Remove-From-Path ".*rtools40.*"
Remove-From-Path ".*rtools42.*"
Remove-From-Path ".*shells.*"
Remove-From-Path ".*Strawberry.*"
Remove-From-Path ".*tools.*"

Remove-Item C:\rtools40 -Force -Recurse -ErrorAction Ignore
Remove-Item C:\rtools42 -Force -Recurse -ErrorAction Ignore

# Get details needed for installing R components
#
Expand All @@ -74,11 +76,11 @@ if ($env:R_MAJOR_VERSION -eq "3") {
$env:RTOOLS_EXE_FILE = "rtools35-x86_64.exe"
$env:R_WINDOWS_VERSION = "3.6.3"
} elseif ($env:R_MAJOR_VERSION -eq "4") {
$RTOOLS_INSTALL_PATH = "C:\rtools40"
$RTOOLS_INSTALL_PATH = "C:\rtools42"
$env:RTOOLS_BIN = "$RTOOLS_INSTALL_PATH\usr\bin"
$env:RTOOLS_MINGW_BIN = "$RTOOLS_INSTALL_PATH\mingw64\bin"
$env:RTOOLS_EXE_FILE = "rtools40v2-x86_64.exe"
$env:R_WINDOWS_VERSION = "4.1.3"
$env:RTOOLS_MINGW_BIN = "$RTOOLS_INSTALL_PATH\x86_64-w64-mingw32.static.posix\bin"
$env:RTOOLS_EXE_FILE = "rtools42-5253-5107.exe"
$env:R_WINDOWS_VERSION = "4.2.1"
} else {
Write-Output "[ERROR] Unrecognized R version: $env:R_VERSION"
Check-Output $false
Expand Down Expand Up @@ -147,7 +149,7 @@ Write-Output "Building R package"
# R CMD check is not used for MSVC builds
if ($env:COMPILER -ne "MSVC") {

$PKG_FILE_NAME = "lightgbm_*.tar.gz"
$PKG_FILE_NAME = "lightgbm_$env:LGB_VER.tar.gz"
$LOG_FILE_NAME = "lightgbm.Rcheck/00check.log"

if ($env:R_BUILD_TYPE -eq "cmake") {
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/r_package.yml
Expand Up @@ -83,7 +83,7 @@ jobs:
task: r-package
compiler: MINGW
toolchain: MSYS
r_version: 4.1
r_version: 4.2
build_type: cmake
# Visual Studio 2019
- os: windows-2019
Expand All @@ -97,7 +97,7 @@ jobs:
task: r-package
compiler: MSVC
toolchain: MSVC
r_version: 4.1
r_version: 4.2
build_type: cmake
###############
# CRAN builds #
Expand All @@ -112,7 +112,7 @@ jobs:
task: r-package
compiler: MINGW
toolchain: MSYS
r_version: 4.1
r_version: 4.2
build_type: cran
- os: ubuntu-latest
task: r-package
Expand Down Expand Up @@ -166,6 +166,7 @@ jobs:
shell: pwsh -command ". {0}"
run: |
$env:BUILD_SOURCESDIRECTORY = $env:GITHUB_WORKSPACE
$env:LGB_VER = (Get-Content -TotalCount 1 $env:BUILD_SOURCESDIRECTORY\VERSION.txt).trim().replace('rc', '-')
$env:TOOLCHAIN = "${{ matrix.toolchain }}"
$env:R_VERSION = "${{ matrix.r_version }}"
$env:R_BUILD_TYPE = "${{ matrix.build_type }}"
Expand Down
5 changes: 5 additions & 0 deletions R-package/README.md
Expand Up @@ -94,13 +94,18 @@ After installing `Rtools` and `CMake`, be sure the following paths are added to
- If you have `Rtools` 4.0, example:
- `C:\rtools40\mingw64\bin`
- `C:\rtools40\usr\bin`
- If you have `Rtools` 4.2, example:
- `C:\rtools42\x86_64-w64-mingw32.static.posix\bin`
- `C:\rtools42\usr\bin`
* `CMake`
- example: `C:\Program Files\CMake\bin`
* `R`
- example: `C:\Program Files\R\R-3.6.1\bin`

NOTE: Two `Rtools` paths are required from `Rtools` 4.0 onwards because paths and the list of included software was changed in `Rtools` 4.0.

NOTE: `Rtools42` takes a very different approach to the compiler toolchain than previous releases, and how you install it changes what is required to build packages. See ["Howto: Building R 4.2 and packages on Windows"](https://cran.r-project.org/bin/windows/base/howto-R-4.2.html).

#### Windows Toolchain Options

A "toolchain" refers to the collection of software used to build the library. The R package can be built with three different toolchains.
Expand Down
25 changes: 25 additions & 0 deletions R-package/configure.win
Expand Up @@ -66,6 +66,31 @@ then
LGB_CPPFLAGS="${LGB_CPPFLAGS} -DMM_MALLOC=1"
fi

#############
# INET_PTON #
#############

ac_inet_pton="no"

cat > conftest.cpp <<EOL
#include <ws2tcpip.h>
int main() {
int (*fptr)(int, const char*, void*);
fptr = &inet_pton;
return 0;
}
EOL

${CXX} ${CXXFLAGS} ${CPPFLAGS} -o conftest conftest.cpp 2>/dev/null && ./conftest && ac_inet_pton="yes"
rm -f ./conftest
rm -f ./conftest.cpp
echo "checking whether INET_PTON works...${ac_inet_pton}"

if test "${ac_inet_pton}" = "yes";
then
LGB_CPPFLAGS="${LGB_CPPFLAGS} -DWIN_HAS_INET_PTON=1"
fi

# Generate Makevars.win from Makevars.win.in
sed -e \
"s/@LGB_CPPFLAGS@/$LGB_CPPFLAGS/" \
Expand Down
4 changes: 2 additions & 2 deletions R-package/tests/testthat/test_dataset.R
Expand Up @@ -248,8 +248,8 @@ test_that("lgb.Dataset: Dataset should be able to construct from matrix and retu

test_that("cpp errors should be raised as proper R errors", {
testthat::skip_if(
Sys.getenv("COMPILER", "") == "MSVC" && as.integer(R.Version()[["major"]]) < 4L
, message = "Skipping on R 3.x and Visual Studio"
Sys.getenv("COMPILER", "") == "MSVC"
, message = "Skipping on Visual Studio"
)
data(agaricus.train, package = "lightgbm")
train <- agaricus.train
Expand Down

0 comments on commit 4498a89

Please sign in to comment.