Skip to content

Commit

Permalink
Allow libcudfjni to be built as a static library (#10619)
Browse files Browse the repository at this point in the history
This adds the ability for the JNI native libraries to be built as static libraries rather than shared libraries by specifying `-DBUILD_SHARED_LIBS=OFF` when configuring with cmake.  This can be useful for external projects that are leveraging the JNI libraries and would like to use an archive that they can link into their shared library.

Authors:
  - Jason Lowe (https://github.com/jlowe)

Approvers:
  - MithunR (https://github.com/mythrocks)

URL: #10619
  • Loading branch information
jlowe authored Apr 7, 2022
1 parent 018924f commit 26c1810
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
3 changes: 2 additions & 1 deletion java/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2019-2021, NVIDIA CORPORATION.
Copyright (c) 2019-2022, NVIDIA CORPORATION.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -392,6 +392,7 @@
<arg value="-DGPU_ARCHS=${GPU_ARCHS}"/>
<arg value="-DCUDF_JNI_ARROW_STATIC=${CUDF_JNI_ARROW_STATIC}"/>
<arg value="-DCUDF_JNI_LIBCUDF_STATIC=${CUDF_JNI_LIBCUDF_STATIC}"/>
<arg value="-DBUILD_SHARED_LIBS=ON"/>
</exec>
<exec dir="${native.build.path}"
failonerror="true"
Expand Down
28 changes: 21 additions & 7 deletions java/src/main/native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ project(
# * build options ---------------------------------------------------------------------------------

option(USE_NVTX "Build with NVTX support" ON)
option(BUILD_SHARED_LIBS "Build cuDF JNI shared libraries" ON)
option(BUILD_TESTS "Configure CMake to build tests" ON)
option(PER_THREAD_DEFAULT_STREAM "Build with per-thread default stream" OFF)
option(CUDA_STATIC_RUNTIME "Statically link the CUDA runtime" OFF)
Expand All @@ -44,6 +45,7 @@ option(CUDF_JNI_ARROW_STATIC "Statically link Arrow" ON)
option(CUDF_JNI_LIBCUDF_STATIC "Link with libcudf.a" OFF)

message(VERBOSE "CUDF_JNI: Build with NVTX support: ${USE_NVTX}")
message(VERBOSE "CUDF_JNI: Build cuDF JNI shared libraries: ${BUILD_SHARED_LIBS}")
message(VERBOSE "CUDF_JNI: Configure CMake to build tests: ${BUILD_TESTS}")
message(VERBOSE "CUDF_JNI: Build with per-thread default stream: ${PER_THREAD_DEFAULT_STREAM}")
message(VERBOSE "CUDF_JNI: Statically link the CUDA runtime: ${CUDA_STATIC_RUNTIME}")
Expand Down Expand Up @@ -193,7 +195,7 @@ endif()
# * library targets -------------------------------------------------------------------------------

add_library(
cudfjni SHARED
cudfjni
src/Aggregation128UtilsJni.cpp
src/AggregationJni.cpp
src/CudfJni.cpp
Expand All @@ -218,7 +220,7 @@ add_library(
src/check_nvcomp_output_sizes.cu
)

if(CUDF_JNI_LIBCUDF_STATIC)
if(CUDF_JNI_LIBCUDF_STATIC AND BUILD_SHARED_LIBS)
# When linking against libcudf.a, the JNI library will include the old libcudf.so. For
# backwards-compatibility for software that expects to find libcudf.so in the JVM environment
# after cudf has loaded, the JNI code and libcudf.a will be combined into libcudf.so. A stub
Expand Down Expand Up @@ -254,8 +256,15 @@ target_include_directories(
# Override RPATH for cudfjni
set_target_properties(
cudfjni
PROPERTIES BUILD_RPATH "\$ORIGIN" INSTALL_RPATH "\$ORIGIN" # set target compile options
CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON CUDA_STANDARD 17 CUDA_STANDARD_REQUIRED ON
PROPERTIES BUILD_RPATH "\$ORIGIN"
INSTALL_RPATH "\$ORIGIN"
# set target compile options
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
CUDA_STANDARD 17
CUDA_STANDARD_REQUIRED ON
POSITION_INDEPENDENT_CODE ON
INTERFACE_POSITION_INDEPENDENT_CODE ON
)

target_compile_options(
Expand All @@ -269,11 +278,16 @@ target_compile_definitions(
)

if(USE_GDS)
add_library(cufilejni SHARED src/CuFileJni.cpp)
add_library(cufilejni src/CuFileJni.cpp)
set_target_properties(
cufilejni
PROPERTIES BUILD_RPATH "\$ORIGIN" INSTALL_RPATH "\$ORIGIN" # set target compile options
CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON
PROPERTIES BUILD_RPATH "\$ORIGIN"
INSTALL_RPATH "\$ORIGIN"
# set target compile options
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
POSITION_INDEPENDENT_CODE ON
INTERFACE_POSITION_INDEPENDENT_CODE ON
)
target_include_directories(
cufilejni
Expand Down

0 comments on commit 26c1810

Please sign in to comment.