Skip to content

Commit

Permalink
[CI] Test C API demo (#6159)
Browse files Browse the repository at this point in the history
* Fix CMake install config to use dependencies

* [CI] Test C API demo

* Explicitly cast num_feature, to avoid warning in Linux
  • Loading branch information
hcho3 committed Sep 25, 2020
1 parent bd2b1ea commit 2c4dedb
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 4 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,47 @@ jobs:
run: |
cd build
ctest --extra-verbose
c-api-demo:
name: Test installing XGBoost lib + building the C API demo
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest"]
python-version: ["3.8"]
steps:
- uses: actions/checkout@v2
with:
submodules: 'true'
- name: Install system packages
run: |
sudo apt-get install -y --no-install-recommends ninja-build
- uses: conda-incubator/setup-miniconda@v1
with:
auto-update-conda: true
python-version: ${{ matrix.python-version }}
- name: Display Conda env
shell: bash -l {0}
run: |
conda info
conda list
- name: Build and install XGBoost
shell: bash -l {0}
run: |
mkdir build
cd build
cmake .. -DBUILD_STATIC_LIB=ON -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -GNinja
ninja -v install
- name: Build and run C API demo
shell: bash -l {0}
run: |
cd demo/c-api/
mkdir build
cd build
cmake .. -GNinja -DCMAKE_PREFIX_PATH=$CONDA_PREFIX
ninja -v
cd ..
./build/api-demo
test-with-jvm:
name: Test JVM on OS ${{ matrix.os }}
runs-on: ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ install(DIRECTORY ${xgboost_SOURCE_DIR}/include/xgboost
#
# https://github.com/dmlc/xgboost/issues/6085
if (BUILD_STATIC_LIB)
set(INSTALL_TARGETS xgboost runxgboost objxgboost rabit)
set(INSTALL_TARGETS xgboost runxgboost objxgboost rabit dmlc)
else (BUILD_STATIC_LIB)
set(INSTALL_TARGETS xgboost runxgboost)
endif (BUILD_STATIC_LIB)
Expand Down
19 changes: 19 additions & 0 deletions cmake/xgboost-config.cmake.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
@PACKAGE_INIT@

include(CMakeFindDependencyMacro)

set(USE_OPENMP @USE_OPENMP@)
set(USE_CUDA @USE_CUDA@)
set(USE_NCCL @USE_NCCL@)

find_dependency(Threads)
if(USE_OPENMP)
find_dependency(OpenMP)
endif()
if(USE_CUDA)
find_dependency(CUDA)
endif()
if(USE_NCCL)
find_dependency(Nccl)
endif()

if(NOT TARGET xgboost::xgboost)
include(${CMAKE_CURRENT_LIST_DIR}/XGBoostTargets.cmake)
endif()

message(STATUS "Found XGBoost (found version \"${xgboost_VERSION}\")")
5 changes: 3 additions & 2 deletions demo/c-api/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.12)
cmake_minimum_required(VERSION 3.13)
project(api-demo LANGUAGES C CXX VERSION 0.0.1)
find_package(xgboost REQUIRED)
add_executable(api-demo c-api-demo.c)
target_link_libraries(api-demo xgboost::xgboost)
target_link_libraries(api-demo PRIVATE xgboost::xgboost)
2 changes: 1 addition & 1 deletion demo/c-api/c-api-demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ int main(int argc, char** argv) {

bst_ulong num_feature = 0;
safe_xgboost(XGBoosterGetNumFeature(booster, &num_feature));
printf("num_feature: %llu\n", num_feature);
printf("num_feature: %lu\n", (unsigned long)(num_feature));

// predict
bst_ulong out_len = 0;
Expand Down

0 comments on commit 2c4dedb

Please sign in to comment.