Skip to content
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-package] [ci] Added Windows CI for R package #6

Closed
wants to merge 64 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
19ed854
first test of appveyor
jameslamb Mar 21, 2020
16476da
strings are strings
jameslamb Mar 21, 2020
f7573f0
lil bit of build script
jameslamb Mar 21, 2020
311d3d8
fixing paths
jameslamb Mar 21, 2020
c422b15
removed unnecessary file
jameslamb Mar 21, 2020
b2fce60
updated CRAN URL
jameslamb Mar 21, 2020
b973b7d
added a lot more printing
jameslamb Mar 21, 2020
a8873f6
fixing paths
jameslamb Mar 21, 2020
952ca55
more stuff
jameslamb Mar 21, 2020
b4cf398
fixed paths
jameslamb Mar 21, 2020
cc6d02b
more stuff
jameslamb Mar 21, 2020
adfb832
more path guessing
jameslamb Mar 21, 2020
92b0032
even more paths
jameslamb Mar 22, 2020
8d77941
more stuff
jameslamb Mar 22, 2020
b7e2abe
moar logz
jameslamb Mar 22, 2020
12fb638
and now for something totally different
jameslamb Mar 22, 2020
1091504
please work
jameslamb Mar 22, 2020
96dcc18
ok could be a thing
jameslamb Mar 22, 2020
97d9913
changing directories
jameslamb Mar 22, 2020
6ed498d
we might be in business
jameslamb Mar 22, 2020
b275d22
fixed install syntax
jameslamb Mar 22, 2020
f701325
tryinv mingw
jameslamb Mar 22, 2020
618086a
more mingw
jameslamb Mar 22, 2020
90f91e5
ignore Suggests check
jameslamb Mar 22, 2020
2f4979a
trying Azure DevOps
jameslamb Mar 22, 2020
3b07c7b
just run bare minimum for Azure DevOps
jameslamb Mar 22, 2020
2d17cae
fixed build dir thing
jameslamb Mar 22, 2020
2e9fe09
trying to set libPaths
jameslamb Mar 22, 2020
855cdc9
more testing
jameslamb Mar 22, 2020
6d8878b
trying R 3.6.3
jameslamb Mar 22, 2020
c854fe3
R 3.6.3
jameslamb Mar 22, 2020
86f4eec
this feels right
jameslamb Mar 22, 2020
8b12858
still messing around with libraries
jameslamb Mar 22, 2020
dc50ad5
more paths
jameslamb Mar 22, 2020
065df95
removed duplication in Windows testing code
jameslamb Mar 22, 2020
432df25
simpler
jameslamb Mar 22, 2020
6e73047
fixed conda stuff
jameslamb Mar 22, 2020
fec3de7
more conda stuff
jameslamb Mar 22, 2020
9b90d84
more fixes
jameslamb Mar 22, 2020
c305e9d
fixed testing script
jameslamb Mar 22, 2020
c70e352
moved AppVeyor setup to the top
jameslamb Mar 22, 2020
517e519
commenting
jameslamb Mar 22, 2020
56bf28a
ch-ch-ch-ch-chaaaanges
jameslamb Mar 22, 2020
f439ba2
paths
jameslamb Mar 22, 2020
2923111
plz work
jameslamb Mar 22, 2020
65915a1
fixed conda stuff in Windows CI
jameslamb Mar 22, 2020
f18399d
uncommented stuff to test a full build
jameslamb Mar 23, 2020
1de8f6c
fixed quotes and removed some unnecessary stuff
jameslamb Mar 23, 2020
a912213
added install.libs.R change
jameslamb Mar 23, 2020
290e5b7
quotes are impoortant
jameslamb Mar 23, 2020
2565df7
added commented-out stuff back in
jameslamb Mar 23, 2020
cd89065
added Windows script, download retries, and MSVC linking
jameslamb Mar 24, 2020
fbf494c
minor fixes
jameslamb Mar 25, 2020
244a14a
cleaned up debugging code in FindLibR
jameslamb Mar 29, 2020
42609cd
cleaned up debugging code and moved R first in CI
jameslamb Mar 29, 2020
2804d45
fixed vsts-ci indentation
jameslamb Mar 31, 2020
af3c004
cut documentation stuff out of MSVC build
jameslamb Mar 31, 2020
1c498d0
fix R CMD check for Azure
jameslamb Mar 31, 2020
9e6aa49
misc whitespace changes
jameslamb Mar 31, 2020
76d264d
merge in #2962
jameslamb Apr 2, 2020
51f37e9
Cleanup MissingType enum constants (#2931)
AlbertoEAF Apr 2, 2020
cc6a2f5
replace built-in assert with own CHECK macro (#2938)
StrikerRUS Apr 3, 2020
01359ab
Merge branch 'master' into ci/r-windows-ci
jameslamb Apr 4, 2020
d100027
Added echoing of build logs from R CMD check
jameslamb Apr 4, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 2.3.2.{build}
version: 2.3.2.{build}

image: Visual Studio 2015
platform: x64
Expand All @@ -7,6 +7,9 @@ configuration: # a trick to construct a build matrix with multiple Python versi

environment:
matrix:
- COMPILER: MINGW
TASK: r-package
R_WINDOWS_VERSION: 3.6.3
- COMPILER: MSVC
TASK: python
- COMPILER: MINGW
Expand Down
94 changes: 94 additions & 0 deletions .ci/test_r_package_windows.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Download a file and retry upon failure. This looks like
# an infinite loop but CI-level timeouts will kill it
function Download-File-With-Retries {
param(
[string]$url,
[string]$destfile
)
do {
Write-Output "Downloading '${url}'"
sleep 5;
(New-Object System.Net.WebClient).DownloadFile($url, $destfile)
} while(!$?);
}

$env:R_LIB_PATH = "C:/RLibrary"
$env:PATH = "$env:R_LIB_PATH/Rtools/bin;" + "$env:R_LIB_PATH/R/bin/x64;" + "$env:R_LIB_PATH/miktex/texmfs/install/miktex/bin/x64;" + $env:PATH
$env:BINPREF = "C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/"
$env:CRAN_MIRROR = "https://cloud.r-project.org/"

cd $env:BUILD_SOURCESDIRECTORY
tzutil /s "GMT Standard Time"
[Void][System.IO.Directory]::CreateDirectory($env:R_LIB_PATH)

if ($env:COMPILER -eq "MINGW") {
Write-Output "Telling R to use MinGW"
$install_libs = "$env:BUILD_SOURCESDIRECTORY\R-package\src\install.libs.R"
((Get-Content -path $install_libs -Raw) -replace 'use_mingw <- FALSE','use_mingw <- TRUE') | Set-Content -Path $install_libs
}

# set up R if it doesn't exist yet
if (!(Get-Command R.exe -errorAction SilentlyContinue)) {

Write-Output "Downloading R and Rtools"

# download R and RTools
Download-File-With-Retries -url "https://cloud.r-project.org/bin/windows/base/old/$env:R_WINDOWS_VERSION/R-$env:R_WINDOWS_VERSION-win.exe" -destfile "R-win.exe"
Download-File-With-Retries -url "https://cloud.r-project.org/bin/windows/Rtools/Rtools35.exe" -destfile "Rtools.exe"

# Install R
Write-Output "Installing R"
Start-Process -FilePath R-win.exe -NoNewWindow -Wait -ArgumentList "/VERYSILENT /DIR=$env:R_LIB_PATH/R /COMPONENTS=main,x64" ; Check-Output $?
Write-Output "Done installing R"

Write-Output "Installing Rtools"
Start-Process -FilePath Rtools.exe -NoNewWindow -Wait -ArgumentList "/VERYSILENT /DIR=$env:R_LIB_PATH/Rtools" ; Check-Output $?
Write-Output "Done installing Rtools"

# download Miktex
Write-Output "Downloading MiKTeX"
Download-File-With-Retries -url "https://miktex.org/download/win/miktexsetup-x64.zip" -destfile "miktexsetup-x64.zip"
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::ExtractToDirectory("miktexsetup-x64.zip", "miktex")
Write-Output "Setting up MiKTeX"
.\miktex\miktexsetup.exe --local-package-repository=./miktex/download --package-set=essential --quiet download ; Check-Output $?
Write-Output "Installing MiKTeX"
.\miktex\download\miktexsetup.exe --portable="$env:R_LIB_PATH/miktex" --quiet install ; Check-Output $?
Write-Output "Done installing R, Rtools, and MiKTeX"
}

initexmf --set-config-value [MPM]AutoInstall=1
conda install -y --no-deps pandoc

Add-Content .Renviron "R_LIBS=$env:R_LIB_PATH"

Write-Output "Installing dependencies"
$packages = "c('data.table', 'jsonlite', 'Matrix', 'R6', 'testthat'), dependencies = c('Imports', 'Depends', 'LinkingTo')"
Rscript --vanilla -e "install.packages($packages, repos = '$env:CRAN_MIRROR', pkgType = 'binary', lib = '$env:R_LIB_PATH', install.packages.check.source = 'no')" ; Check-Output $?

Write-Output "Building R package"
Rscript build_r.R --skip-install ; Check-Output $?

$PKG_FILE_NAME = Get-Item *.tar.gz
$LOG_FILE_NAME = "lightgbm.Rcheck/00check.log"

$env:_R_CHECK_FORCE_SUGGESTS_=0
if ($env:AZURE -eq "true") {
Write-Output "Running R CMD check without checking documentation"
R.exe CMD check --no-multiarch --no-manual --ignore-vignettes ${PKG_FILE_NAME} ; Check-Output $?
} else {
Write-Output "Running R CMD check as CRAN"
R.exe CMD check --no-multiarch --as-cran ${PKG_FILE_NAME} ; Check-Output $?
}

Write-Output "R CMD check build logs:"
Get-Content -Path $env:BUILD_SOURCESDIRECTORY\lightgbm.Rcheck\00install.out

Write-Output "Looking for issues with R CMD check results"
if (Get-Content "$LOG_FILE_NAME" | Select-String -Pattern "WARNING" -Quiet) {
echo "WARNINGS have been found by R CMD check!"
Check-Output $False
}

Write-Output "No issues were found checking the R package"
Exit 0
5 changes: 5 additions & 0 deletions .ci/test_windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ if (Test-Path env:APPVEYOR) {
$env:BUILD_SOURCESDIRECTORY = $env:APPVEYOR_BUILD_FOLDER
}

if ($env:TASK -eq "r-package") {
& $env:BUILD_SOURCESDIRECTORY\.ci\test_r_package_windows.ps1 ; Check-Output $?
Exit 0
}

# setup for Python
conda init powershell
conda activate
Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ before_install:
- if [[ $TRAVIS_OS_NAME == "osx" ]]; then
export OS_NAME="macos";
export COMPILER="gcc";
export R_MAC_VERSION=3.6.1;
export R_MAC_VERSION=3.6.3;
else
export OS_NAME="linux";
export COMPILER="clang";
export R_TRAVIS_LINUX_VERSION=3.6.1-3bionic;
export R_TRAVIS_LINUX_VERSION=3.6.3-1bionic;
fi
- export CONDA="$HOME/miniconda"
- export PATH="$CONDA/bin:$PATH"
Expand Down
13 changes: 8 additions & 5 deletions .vsts-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
strategy:
maxParallel: 6
matrix:
r_package:
TASK: r-package
regular:
TASK: regular
sdist:
Expand All @@ -42,8 +44,6 @@ jobs:
TASK: gpu
METHOD: source
PYTHON_VERSION: 3.6
r_package:
TASK: r-package
steps:
- script: |
echo "##vso[task.setvariable variable=HOME_DIRECTORY]$AGENT_HOMEDIRECTORY"
Expand Down Expand Up @@ -78,6 +78,8 @@ jobs:
strategy:
maxParallel: 3
matrix:
r_package:
TASK: r-package
regular:
TASK: regular
PYTHON_VERSION: 3.6
Expand All @@ -86,8 +88,6 @@ jobs:
PYTHON_VERSION: 3.5
bdist:
TASK: bdist
r_package:
TASK: r-package
steps:
- script: |
echo "##vso[task.setvariable variable=HOME_DIRECTORY]$AGENT_HOMEDIRECTORY"
Expand All @@ -99,7 +99,7 @@ jobs:
echo "##vso[task.setvariable variable=CONDA]$CONDA"
echo "##vso[task.prependpath]$CONDA/bin"
echo "##vso[task.setvariable variable=JAVA_HOME]$JAVA_HOME_8_X64"
echo "##vso[task.setvariable variable=R_MAC_VERSION]3.6.1"
echo "##vso[task.setvariable variable=R_MAC_VERSION]3.6.3"
displayName: 'Set variables'
- bash: $(Build.SourcesDirectory)/.ci/setup.sh
displayName: Setup
Expand All @@ -119,6 +119,9 @@ jobs:
strategy:
maxParallel: 3
matrix:
rpkg:
TASK: r-package
R_WINDOWS_VERSION: 3.6.3
regular:
TASK: regular
PYTHON_VERSION: 3.7
Expand Down
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,16 @@ if(WIN32 AND (MINGW OR CYGWIN))
endif()

if(BUILD_FOR_R)
if(MSVC)
# https://docs.microsoft.com/en-us/cpp/build/reference/link-input-files?redirectedfrom=MSDN&view=vs-2019
set_property(
TARGET _lightgbm
PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreadedDLL"
)
TARGET_LINK_LIBRARIES(_lightgbm ${CMAKE_CURRENT_BINARY_DIR}/R.lib)
else()
TARGET_LINK_LIBRARIES(_lightgbm ${LIBR_CORE_LIBRARY})
endif()
endif(BUILD_FOR_R)

install(TARGETS lightgbm _lightgbm
Expand Down
34 changes: 15 additions & 19 deletions R-package/src/cmake/modules/FindLibR.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# LIBR_HOME
# LIBR_EXECUTABLE
# LIBR_INCLUDE_DIRS
# LIBR_LIB_DIR
# LIBR_CORE_LIBRARY
# and a CMake function to create R.lib for MSVC

Expand All @@ -36,8 +35,8 @@ function(create_rlib_for_msvc)
message(FATAL_ERROR "create_rlib_for_msvc() can only be used with MSVC")
endif()

if(NOT EXISTS "${LIBR_LIB_DIR}")
message(FATAL_ERROR "LIBR_LIB_DIR, '${LIBR_LIB_DIR}', not found")
if(NOT EXISTS "${LIBR_CORE_LIBRARY}")
message(FATAL_ERROR "LIBR_CORE_LIBRARY, '${LIBR_CORE_LIBRARY}', not found")
endif()

find_program(GENDEF_EXE gendef)
Expand All @@ -50,7 +49,7 @@ function(create_rlib_for_msvc)

# extract symbols from R.dll into R.def and R.lib import library
execute_process(COMMAND ${GENDEF_EXE}
"-" "${LIBR_LIB_DIR}/R.dll"
"-" "${LIBR_CORE_LIBRARY}"
OUTPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/R.def"
)
execute_process(COMMAND ${DLLTOOL_EXE}
Expand Down Expand Up @@ -168,23 +167,21 @@ execute_process(
OUTPUT_VARIABLE LIBR_INCLUDE_DIRS
)

# ask R for the lib dir
execute_process(
COMMAND ${LIBR_EXECUTABLE} "--slave" "--vanilla" "-e" "cat(normalizePath(R.home('lib'), winslash='/'))"
OUTPUT_VARIABLE LIBR_LIB_DIR
)

# look for the core R library
find_library(
LIBR_CORE_LIBRARY
NAMES R
HINTS "${CMAKE_CURRENT_BINARY_DIR}" "${LIBR_LIB_DIR}" "${LIBR_HOME}/bin" "${LIBR_LIBRARIES}"
)

set(LIBR_HOME ${LIBR_HOME} CACHE PATH "R home directory")
set(LIBR_EXECUTABLE ${LIBR_EXECUTABLE} CACHE PATH "R executable")
set(LIBR_INCLUDE_DIRS ${LIBR_INCLUDE_DIRS} CACHE PATH "R include directory")
set(LIBR_LIB_DIR ${LIBR_LIB_DIR} CACHE PATH "R shared libraries directory")

# look for the core R library
if(WIN32)
set(LIBR_CORE_LIBRARY ${LIBR_HOME}/bin/${R_ARCH}/R.dll)
else()
find_library(
LIBR_CORE_LIBRARY
NAMES R
HINTS "${CMAKE_CURRENT_BINARY_DIR}" "${LIBR_HOME}/lib" "${LIBR_HOME}/bin/${R_ARCH}" "${LIBR_HOME}/bin" "${LIBR_LIBRARIES}"
)
endif()

set(LIBR_CORE_LIBRARY ${LIBR_CORE_LIBRARY} CACHE PATH "R core shared library")

if(WIN32 AND MSVC)
Expand All @@ -203,6 +200,5 @@ find_package_handle_standard_args(LibR DEFAULT_MSG
LIBR_HOME
LIBR_EXECUTABLE
LIBR_INCLUDE_DIRS
LIBR_LIB_DIR
LIBR_CORE_LIBRARY
)
1 change: 1 addition & 0 deletions R-package/src/install.libs.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ if (!use_precompile) {
# Check if Windows installation (for gcc vs Visual Studio)
if (WINDOWS) {
if (use_mingw) {
print("Trying to build with MinGW")
cmake_cmd <- paste0(cmake_cmd, " -G \"MinGW Makefiles\" ")
build_cmd <- "mingw32-make.exe _lightgbm"
system(paste0(cmake_cmd, " ..")) # Must build twice for Windows due sh.exe in Rtools
Expand Down
16 changes: 7 additions & 9 deletions include/LightGBM/tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,11 @@ class Tree {

inline int NumericalDecision(double fval, int node) const {
uint8_t missing_type = GetMissingType(decision_type_[node]);
if (std::isnan(fval)) {
if (missing_type != 2) {
fval = 0.0f;
}
if (std::isnan(fval) && missing_type != MissingType::NaN) {
fval = 0.0f;
}
if ((missing_type == 1 && IsZero(fval))
|| (missing_type == 2 && std::isnan(fval))) {
if ((missing_type == MissingType::Zero && IsZero(fval))
|| (missing_type == MissingType::NaN && std::isnan(fval))) {
if (GetDecisionType(decision_type_[node], kDefaultLeftMask)) {
return left_child_[node];
} else {
Expand All @@ -279,8 +277,8 @@ class Tree {

inline int NumericalDecisionInner(uint32_t fval, int node, uint32_t default_bin, uint32_t max_bin) const {
uint8_t missing_type = GetMissingType(decision_type_[node]);
if ((missing_type == 1 && fval == default_bin)
|| (missing_type == 2 && fval == max_bin)) {
if ((missing_type == MissingType::Zero && fval == default_bin)
|| (missing_type == MissingType::NaN && fval == max_bin)) {
if (GetDecisionType(decision_type_[node], kDefaultLeftMask)) {
return left_child_[node];
} else {
Expand All @@ -301,7 +299,7 @@ class Tree {
return right_child_[node];;
} else if (std::isnan(fval)) {
// NaN is always in the right
if (missing_type == 2) {
if (missing_type == MissingType::NaN) {
return right_child_[node];
}
int_fval = 0;
Expand Down
13 changes: 6 additions & 7 deletions src/io/json11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@
*/
#include <LightGBM/utils/json11.h>

#include <limits>
#ifndef LGB_R_BUILD
#include <cassert>
#endif
#include <LightGBM/utils/log.h>

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <limits>

namespace json11 {

Expand All @@ -39,6 +38,8 @@ using std::make_shared;
using std::initializer_list;
using std::move;

using LightGBM::Log;

/* Helper for representing null - just a do-nothing struct, plus comparison
* operators so the helpers in JsonValue work. We can't use nullptr_t because
* it may not be orderable.
Expand Down Expand Up @@ -626,9 +627,7 @@ struct JsonParser final {
* the input and return res. If not, flag an error.
*/
Json expect(const string &expected, Json res) {
#ifndef LGB_R_BUILD
assert(i != 0);
#endif
CHECK_NE(i, 0)
i--;
if (str.compare(i, expected.length(), expected) == 0) {
i += expected.length();
Expand Down
Loading