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

Restructure Java API #1757

Merged
merged 1 commit into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ jobs:
- name: Node.js test
run: CC=gcc CXX=g++ make nodejstest NUM_THREADS=32

- name: Java test
run: CC=gcc CXX=g++ make javatest NUM_THREADS=32

- name: Rust test
run: CC=gcc CXX=g++ make rusttest NUM_THREADS=32

Expand Down Expand Up @@ -109,6 +112,9 @@ jobs:

- name: Node.js test
run: CC=clang-14 CXX=clang++-14 make nodejstest NUM_THREADS=32

- name: Java test
run: CC=clang-14 CXX=clang++-14 make javatest NUM_THREADS=32

msvc-build-test:
name: msvc build & test
Expand Down
19 changes: 3 additions & 16 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,8 @@ scripts/pre-compiled-bins/lib*
scripts/pre-compiled-bins/kuzu*

# Java API
tools/java_api/CMakeFiles/
tools/java_api/Testing/
tools/java_api/testdb/
tools/java_api/testdb/
tools/java_api_falied/
tools/test_java_api/
tools/java_api/cmake_install.cmake
tools/java_api/Notes.txt
tools/java_api/CMakeCache.txt
tools/java_api/CTestTestfile.cmake
tools/java_api/*.log
tools/java_api/build
tools/java_api/test_db/
tools/java_api/*.jar
tools/java_api/*.dylib
tools/java_api/test.java
tools/java_api/*.class
tools/java_api/KuzuNative.h
tools/java_api/error.txt
tools/java_api/Makefile
tools/java_api/*.log
22 changes: 22 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,28 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# Detect OS and architecture, copied from DuckDB
set(OS_NAME "unknown")
set(OS_ARCH "amd64")

string(REGEX MATCH "(arm64|aarch64)" IS_ARM "${CMAKE_SYSTEM_PROCESSOR}")
if(IS_ARM)
set(OS_ARCH "arm64")
elseif(FORCE_32_BIT)
set(OS_ARCH "i386")
endif()

if(APPLE)
set(OS_NAME "osx")
endif()
if(WIN32)
set(OS_NAME "windows")
endif()
if(UNIX AND NOT APPLE)
set(OS_NAME "linux") # sorry BSD
endif()


if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
Expand Down
27 changes: 26 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ nodejs: arrow
cmake $(GENERATOR) $(FORCE_COLOR) $(SANITIZER_FLAG) -DCMAKE_BUILD_TYPE=Release -DBUILD_NODEJS=TRUE ../.. && \
cmake --build . --config Release -- -j $(NUM_THREADS)

java:
$(call mkdirp,build/release) && cd build/release && \
cmake $(GENERATOR) $(FORCE_COLOR) $(SANITIZER_FLAG) -DCMAKE_BUILD_TYPE=Release -DBUILD_JAVA=TRUE ../.. && \
cmake --build . --config Release -- -j $(NUM_THREADS)

test: arrow
$(call mkdirp,build/release) && cd build/release && \
cmake $(GENERATOR) $(FORCE_COLOR) $(SANITIZER_FLAG) -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=TRUE ../.. && \
Expand All @@ -118,6 +123,19 @@ nodejstest: arrow
cd $(ROOT_DIR)/tools/nodejs_api/ && \
npm test

javatest: arrow
ifeq ($(OS),Windows_NT)
$(MAKE) java
$(call mkdirp,tools/java_api/build/test) && cd tools/java_api/ && \
javac -d build/test -cp ".;build/kuzu_java.jar;third_party/junit-platform-console-standalone-1.9.3.jar" -sourcepath src/test/java/com/kuzudb/test/*.java && \
java -jar third_party/junit-platform-console-standalone-1.9.3.jar -cp ".;build/kuzu_java.jar;build/test/" --scan-classpath --include-package=com.kuzudb.java_test --details=verbose
else
$(MAKE) java
$(call mkdirp,tools/java_api/build/test) && cd tools/java_api/ && \
javac -d build/test -cp ".:build/kuzu_java.jar:third_party/junit-platform-console-standalone-1.9.3.jar" -sourcepath src/test/java/com/kuzudb/test/*.java && \
java -jar third_party/junit-platform-console-standalone-1.9.3.jar -cp ".:build/kuzu_java.jar:build/test/" --scan-classpath --include-package=com.kuzudb.java_test --details=verbose
endif

rusttest:
ifeq ($(OS),Windows_NT)
cd $(ROOT_DIR)/tools/rust_api && \
Expand All @@ -137,14 +155,21 @@ else
rm -rf tools/python_api/build
endif

clean-java:
ifeq ($(OS),Windows_NT)
if exist tools\java_api\build rmdir /s /q tools\java_api\build
else
rm -rf tools/java_api/build
endif

clean-external:
ifeq ($(OS),Windows_NT)
if exist external\build rmdir /s /q external\build
else
rm -rf external/build
endif

clean: clean-python-api
clean: clean-python-api clean-java
ifeq ($(OS),Windows_NT)
if exist build rmdir /s /q build
else
Expand Down
3 changes: 2 additions & 1 deletion scripts/dockerized-ci-tests-runner/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ ENV DEBIAN_FRONTEND=noninteractive
# Install dependencies
RUN apt-get update && apt-get install -y --no-install-recommends apt-utils curl ca-certificates apt-transport-https gnupg software-properties-common
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
RUN apt-get update && apt-get install -y g++ gcc clang-14 python3-dev python3-pip python-is-python3 cmake nodejs jq curl sudo git clang-format-11 lsb-release wget lcov libssl-dev libcurl4-openssl-dev rustfmt rustc cargo
RUN apt-get update && apt-get install -y g++ gcc clang-14 python3-dev python3-pip python-is-python3 cmake nodejs jq curl sudo git clang-format-11 lsb-release wget lcov libssl-dev libcurl4-openssl-dev rustfmt rustc cargo openjdk-17-jdk

ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
RUN useradd --create-home runner
USER runner

Expand Down
1 change: 1 addition & 0 deletions third_party/antlr4_runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ if (WIN32)
-DANTLR4CPP_EXPORTS
-DANTLR4CPP_STATIC
)
set_property(TARGET ${ANTLR4_RUNTIME} PROPERTY CXX_STANDARD 17)
endif()


Expand Down
3 changes: 3 additions & 0 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
add_subdirectory(shell)
if(${BUILD_JAVA})
add_subdirectory(java_api)
endif()
if(${BUILD_NODEJS})
add_subdirectory(nodejs_api)
endif()
Expand Down
61 changes: 26 additions & 35 deletions tools/java_api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,38 @@ find_package(JNI REQUIRED)
if (JNI_FOUND)
message (STATUS "JNI_INCLUDE_DIRS=${JNI_INCLUDE_DIRS}")
message (STATUS "JNI_LIBRARIES=${JNI_LIBRARIES}")
else()
message (FATAL_ERROR "Java/JNI not found")
endif()
include(UseJava)

enable_testing()

file(GLOB JAVA_SRC_FILES *.java)
file(GLOB JAVA_SRC_FILES src/main/java/com/kuzudb/*.java)

set(CMAKE_JAVA_COMPILE_FLAGS -source 1.8 -target 1.8 -encoding utf-8)
add_jar(kuzu_java ${JAVA_SRC_FILES})
add_jar(kuzu_java ${JAVA_SRC_FILES}
OUTPUT_DIR "${PROJECT_SOURCE_DIR}/build"
GENERATE_NATIVE_HEADERS kuzu_native_header)
get_target_property(_jarFile kuzu_java JAR_FILE)
get_target_property(_classDir kuzu_java CLASSDIR)

set (_stubDir "${CMAKE_CURRENT_BINARY_DIR}")
add_custom_command(
OUTPUT KuzuNative.h
COMMAND ${Java_JAVAC_EXECUTABLE}
-h .
${JAVA_SRC_FILES}
)

# generate libfoo.jnilib
include_directories(${JNI_INCLUDE_DIRS} ${_classDir} ${_stubDir} ../../src/include)
include_directories(../../third_party/antlr4_cypher/include)
include_directories(../../third_party/antlr4_runtime/src)
include_directories(../../third_party/spdlog)
include_directories(../../third_party/nlohmann_json)
include_directories(../../third_party/pyparse)
include_directories(../../third_party/utf8proc/include)
include_directories(../../third_party/pybind11/include)
include_directories(../../third_party/re2/include)
include_directories(../../third_party/concurrentqueue)

find_library(KUZU NAMES kuzu PATHS ../../build/release/src)

add_library(kuzu_java_native MODULE kuzu_java.cpp KuzuNative.h)
set_target_properties(kuzu_java_native PROPERTIES SUFFIX ".dylib")
target_link_libraries(kuzu_java_native ${JNI_LIBRARIES} ${KUZU})

# add test to run JNIFoo
add_test(NAME Test
COMMAND ${Java_JAVA_EXECUTABLE}
-ea
-Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}
-cp ${_jarFile} tools.java_api.test)

include_directories(${JNI_INCLUDE_DIRS} ${_classDir} ${_stubDir})
add_library(kuzu_java_native SHARED src/jni/kuzu_java.cpp)
target_link_libraries(kuzu_java_native PRIVATE kuzu_native_header kuzu)

string(JOIN "_" LIB_SUFFIX ".so" ${OS_NAME} ${OS_ARCH})
set_target_properties(kuzu_java_native PROPERTIES SUFFIX ${LIB_SUFFIX})
set_target_properties(kuzu_java_native PROPERTIES PREFIX "lib")
set_target_properties(kuzu_java_native
PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/build"
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/build"
ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/build")

add_custom_command(OUTPUT dummy_jar_target
DEPENDS kuzu_java_native kuzu_java
COMMAND ${Java_JAR_EXECUTABLE} uf ${_jarFile} -C
$<TARGET_FILE_DIR:kuzu_java_native> $<TARGET_FILE_NAME:kuzu_java_native>)

add_custom_target(kuzu_java_api ALL DEPENDS dummy_jar_target)
24 changes: 24 additions & 0 deletions tools/java_api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Kùzu Java API

## Requirements
Java 11 or higher

## Build

```
cd ../.. && make java NUM_THREADS=X
```

## Run test

```
cd ../.. && make javatest NUM_THREADS=X
```

## Run `test.java` example

First, build the Java API as described above. Then, run the following command:

```
java -cp ".:build/kuzu_java.jar" test.java
```
Loading
Loading