Skip to content

Commit

Permalink
[jvm-packages] Another pack of build/CI improvements (dmlc#2422)
Browse files Browse the repository at this point in the history
* [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 dmlc#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``.
  • Loading branch information
superbobry authored and CodingCat committed Jun 21, 2017
1 parent 46b9889 commit 2cb51f7
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 21 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 7 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand All @@ -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()
13 changes: 10 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -10,6 +13,7 @@ configuration:
- Release

install:
- SET PATH=;%PATH%
- git submodule update --init --recursive

before_build:
Expand All @@ -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
16 changes: 12 additions & 4 deletions jvm-packages/create_jni.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
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 = {
Expand Down Expand Up @@ -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")
Expand All @@ -88,7 +96,7 @@ def normpath(path):
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")
Expand Down
2 changes: 1 addition & 1 deletion jvm-packages/xgboost4j/src/native/xgboost4j.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions tests/travis/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2cb51f7

Please sign in to comment.