[jvm-packages] Another pack of build/CI improvements (#2422)

* [jvm-packages] Fixed compilation on Windows

* [jvm-packages] Build the JNI bindings on Appveyor

* [jvm-packages] Build & test on OS X

* [jvm-packages] Re-applied the CMake build changes reverted by #2395

* Fixed Appveyor JVM build

* Muted Maven on Travis

* Don't link with libawt

* "linux2"->"linux"

Python2.x and 3.X use slightly different values for ``sys.platform``.
This commit is contained in:
Sergei Lebedev 2017-06-21 21:28:35 +02:00 committed by Nan Zhu
parent 46b9889cc5
commit 2cb51f7097
6 changed files with 32 additions and 21 deletions

View File

@ -33,8 +33,6 @@ matrix:
env: TASK=cmake_test
- os: linux
env: TASK=r_test
- os: osx
env: TASK=java_test
- os: osx
env: TASK=python_lightweight_test
- os: osx

View File

@ -96,8 +96,6 @@ if(MSVC)
else()
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR})
#Prevent shared library being called liblibxgboost.so on Linux
set(CMAKE_SHARED_LIBRARY_PREFIX "")
endif()
set(LINK_LIBRARIES dmlccore rabit)
@ -137,11 +135,12 @@ endif()
add_library(objxgboost OBJECT ${SOURCES})
set_target_properties(${objxgboost} PROPERTIES POSITION_INDEPENDENT_CODE 1)
add_library(libxgboost SHARED $<TARGET_OBJECTS:objxgboost> ${CUDA_OBJS})
add_executable(xgboost $<TARGET_OBJECTS:objxgboost> ${CUDA_OBJS})
add_executable(runxgboost $<TARGET_OBJECTS:objxgboost> ${CUDA_OBJS})
set_target_properties(runxgboost PROPERTIES OUTPUT_NAME xgboost)
target_link_libraries(runxgboost ${LINK_LIBRARIES})
add_library(xgboost SHARED $<TARGET_OBJECTS:objxgboost> ${CUDA_OBJS})
target_link_libraries(xgboost ${LINK_LIBRARIES})
target_link_libraries(libxgboost ${LINK_LIBRARIES})
option(JVM_BINDINGS "Build JVM bindings" OFF)
@ -150,11 +149,11 @@ if(JVM_BINDINGS)
include_directories(${JNI_INCLUDE_DIRS} jvm-packages/xgboost4j/src/native)
add_library(libxgboost4j SHARED
add_library(xgboost4j SHARED
$<TARGET_OBJECTS:objxgboost>
${CUDA_OBJS}
jvm-packages/xgboost4j/src/native/xgboost4j.cpp)
target_link_libraries(libxgboost4j
target_link_libraries(xgboost4j
${LINK_LIBRARIES}
${JNI_LIBRARIES})
${JAVA_JVM_LIBRARY})
endif()

View File

@ -1,7 +1,10 @@
environment:
matrix:
- solution_name: C:/projects/xgboost/build2013/xgboost.sln
- solution_name: C:/projects/xgboost/build2015/xgboost.sln
- target: native
solution_name: C:/projects/xgboost/build2013/xgboost.sln
- target: native
solution_name: C:/projects/xgboost/build2015/xgboost.sln
- target: jvm
platform:
- x64
@ -10,6 +13,7 @@ configuration:
- Release
install:
- SET PATH=;%PATH%
- git submodule update --init --recursive
before_build:
@ -19,5 +23,8 @@ before_build:
- cmake .. -G"Visual Studio 12 2013 Win64"
- cd ../build2015
- cmake .. -G"Visual Studio 14 2015 Win64"
build_script:
- msbuild %solution_name%
- cd %APPVEYOR_BUILD_FOLDER%
- if "%target%" == "native" msbuild %solution_name%
- if "%target%" == "jvm" cd jvm-packages && C:\Python36-x64\python create_jni.py

View File

@ -6,7 +6,11 @@ import shutil
import subprocess
import sys
from contextlib import contextmanager
from subprocess import check_output
# Monkey-patch the API inconsistency between Python2.X and 3.X.
if sys.platform.startswith("linux"):
sys.platform = "linux"
CONFIG = {
@ -56,14 +60,18 @@ def cp(source, target):
def normpath(path):
"""Normalize UNIX path to a native path."""
return os.path.join(*path.split("/"))
normalized = os.path.join(*path.split("/"))
if os.path.isabs(path):
return os.path.abspath("/") + normalized
else:
return normalized
if __name__ == "__main__":
if sys.platform == "darwin":
# Enable of your compiler supports OpenMP.
CONFIG["USE_OPENMP"] = "OFF"
os.environ["JAVA_HOME"] = check_output(
os.environ["JAVA_HOME"] = subprocess.check_output(
"/usr/libexec/java_home").strip().decode()
print("building Java wrapper")
@ -88,7 +96,7 @@ if __name__ == "__main__":
library_name = {
"win32": "xgboost4j.dll",
"darwin": "libxgboost4j.dylib",
"linux2": "libxgboost4j.so"
"linux": "libxgboost4j.so"
}[sys.platform]
maybe_makedirs("xgboost4j/src/main/resources/lib")
cp("../lib/" + library_name, "xgboost4j/src/main/resources/lib")

View File

@ -76,7 +76,7 @@ XGB_EXTERN_C int XGBoost4jCallbackDataIterNext(
batch, jenv->GetFieldID(batchClass, "featureValue", "[F"));
XGBoostBatchCSR cbatch;
cbatch.size = jenv->GetArrayLength(joffset) - 1;
cbatch.offset = reinterpret_cast<long *>(
cbatch.offset = reinterpret_cast<jlong *>(
jenv->GetLongArrayElements(joffset, 0));
if (jlabel != nullptr) {
cbatch.label = jenv->GetFloatArrayElements(jlabel, 0);

View File

@ -81,10 +81,9 @@ fi
if [ ${TASK} == "java_test" ]; then
set -e
make jvm-packages
cd jvm-packages
mvn clean install -DskipTests=true
mvn test
mvn -q clean install -DskipTests -Dmaven.test.skip
mvn -q test
fi
if [ ${TASK} == "cmake_test" ]; then