-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feat][Java] Initialize the JAVA SDK: add INFO implementation (#212)
--------- Co-authored-by: Weibin Zeng <[email protected]>
- Loading branch information
Showing
33 changed files
with
3,043 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
name: GraphAr Java CI | ||
|
||
on: | ||
# Trigger the workflow on push or pull request, | ||
# but only for the main branch | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- 'cpp/include/**' | ||
- 'java/**' | ||
- '.github/workflows/java.yml' | ||
pull_request: | ||
branches: | ||
- main | ||
paths: | ||
- 'cpp/include/**' | ||
- 'java/**' | ||
- '.github/workflows/java.yml' | ||
|
||
concurrency: | ||
group: ${{ github.repository }}-${{ github.event.number || github.head_ref || github.sha }}-${{ github.workflow }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
GraphAr-java: | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
submodules: true | ||
|
||
# install GrahpAr C++ library first | ||
- name: Cache for ccache | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.ccache | ||
key: ${{ matrix.os }}-build-ccache-${{ hashFiles('**/git-modules.txt') }} | ||
restore-keys: | | ||
${{ matrix.os }}-build-ccache- | ||
- name: Install dependencies | ||
run: | | ||
sudo apt-get update -y | ||
sudo apt-get install ccache libcurl4-openssl-dev -y | ||
sudo apt-get install llvm-11 clang-11 lld-11 libclang-11-dev libz-dev -y | ||
- name: Build and Install cpp | ||
run: | | ||
mkdir build | ||
pushd build | ||
cmake ../cpp | ||
make -j$(nproc) | ||
sudo make install | ||
popd | ||
- name: Run test | ||
run: | | ||
export JAVA_HOME=${JAVA_HOME_11_X64} | ||
export LLVM11_HOME=/usr/lib/llvm-11 | ||
pushd java | ||
mvn test | ||
popd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.idea | ||
dependency-reduced-pom.xml | ||
target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
cmake_minimum_required(VERSION 3.1) | ||
project(gar-java) | ||
|
||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -g -std=c++17 -Wall") | ||
|
||
file(GLOB SOURCES "target/generated-sources/annotations/*.cc" "target/generated-test-sources/test-annotations/*.cc") | ||
|
||
set(LIBNAME "gar-jni") | ||
|
||
set(JAVA_AWT_LIBRARY NotNeeded) | ||
set(JAVA_AWT_INCLUDE_PATH NotNeeded) | ||
find_package(JNI REQUIRED) | ||
include_directories(SYSTEM ${JAVA_INCLUDE_PATH}) | ||
include_directories(SYSTEM ${JAVA_INCLUDE_PATH2}) | ||
|
||
include_directories("src/main/native") | ||
include_directories("src/test/native") | ||
|
||
find_package(gar REQUIRED) | ||
|
||
add_library(${LIBNAME} SHARED ${SOURCES}) | ||
target_link_libraries(${LIBNAME} ${CMAKE_JNI_LINKER_FLAGS} gar) | ||
|
||
set_target_properties(${LIBNAME} PROPERTIES LINKER_LANGUAGE CXX) | ||
|
||
add_custom_command(TARGET ${LIBNAME} | ||
POST_BUILD | ||
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${LIBNAME}> "${CMAKE_CURRENT_SOURCE_DIR}/target/classes/") | ||
|
||
add_custom_command(TARGET ${LIBNAME} | ||
POST_BUILD | ||
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_SOURCE_DIR}/target/native/bitcode | ||
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_OBJECTS:${LIBNAME}> ${CMAKE_CURRENT_SOURCE_DIR}/target/native/bitcode COMMAND_EXPAND_LISTS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# [WIP] GraphAr Java | ||
|
||
This directory contains the code and build system for the GraphAr Java library which powered by [Alibaba-FastFFI](https://github.com/alibaba/fastFFI). | ||
|
||
## Dependencies | ||
|
||
### Java | ||
|
||
- JDK 8 or higher | ||
- Maven | ||
|
||
### C++ | ||
|
||
- CMake 3.5 or higher | ||
- [GraphAr C++ library](../cpp/README.md) | ||
- LLVM 11 | ||
|
||
Tips: | ||
- To install GraphAr C++ library, you can refer to our [C++ CI](../.github/workflows/ci.yml) on Ubuntu and CentOS; | ||
- To install LLVM 11, you can refer to our [Java CI](../.github/workflows/java.yml) on Ubuntu or compile from source with [this script](https://github.com/alibaba/fastFFI/blob/main/docker/install-llvm11.sh). | ||
|
||
## Build, Test and Install | ||
|
||
Only support installing from source currently, but we will support installing from Maven in the future. | ||
|
||
```shell | ||
git clone https://github.com/alibaba/GraphAr.git | ||
cd GraphAr | ||
git submodule update --init | ||
# Install GraphAr C++ first ... | ||
cd java | ||
export LLVM11_HOME=<path-to-LLVM11-home> # In Ubuntu, it is at /usr/lib/llvm-11 | ||
mvn clean install | ||
``` | ||
|
||
## How to use | ||
|
||
We will provide JavaDoc after we finished. Basically, Java's API are same as C++ library's. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<project name="llvm4jni"> | ||
<target name="make"> | ||
<echo message="Make native code" level="info"/> | ||
|
||
<mkdir dir="${project.build.directory}/native"/> | ||
|
||
<property environment="env"/> | ||
<fail unless="env.LLVM11_HOME" message="LLVM11_HOME not set."/> | ||
|
||
<condition property="platform" value="linux64"><os family="unix" arch="amd64" /> | ||
</condition> | ||
|
||
<condition property="platform" value="mac"><os family="mac" arch="x86_64" /> | ||
</condition> | ||
|
||
<fail unless="platform" message="Not a supported platform."/> | ||
|
||
<echo message="Native Library Name: ${native.library.name}" level="info"/> | ||
|
||
<exec executable="cmake" dir="${project.build.directory}/native" failonerror="true"> | ||
<arg line="-DCMAKE_AR="${env.LLVM11_HOME}/bin/llvm-ar" -DCMAKE_RANLIB="${env.LLVM11_HOME}/bin/llvm-ranlib" -DCMAKE_C_COMPILER="${env.LLVM11_HOME}/bin/clang" -DCMAKE_CXX_COMPILER="${env.LLVM11_HOME}/bin/clang++" -DCMAKE_CXX_FLAGS="-flto -fforce-emit-vtables" ${basedir}"/> | ||
</exec> | ||
|
||
<exec executable="make" dir="${project.build.directory}/native" failonerror="true"> | ||
<arg line="VERBOSE=1"/> | ||
</exec> | ||
</target> | ||
|
||
<target name="link-llvm-bitcode" depends="make"> | ||
<echo message="Link bitcode" level="info"/> | ||
|
||
<exec executable="sh" dir="${project.build.directory}/native" failonerror="true"> | ||
<arg line="-c '${env.LLVM11_HOME}/bin/llvm-link ./bitcode/* -o ${native.library.name}.bc'" /> | ||
</exec> | ||
|
||
<exec executable="cp" dir="${project.build.directory}/native" failonerror="true"> | ||
<arg line="${native.library.name}.bc ${project.build.directory}/classes"/> | ||
</exec> | ||
</target> | ||
|
||
<target name="run-llvm4jni" depends="link-llvm-bitcode"> | ||
<echo message="Run LLVM4JNI" level="info"/> | ||
|
||
<mkdir dir="${project.build.directory}/llvm4jni-output"/> | ||
|
||
<condition property="native.library.file" value="lib${native.library.name}.so"><os family="unix" arch="amd64" /> | ||
</condition> | ||
|
||
<condition property="native.library.file" value="lib${native.library.name}.dylib"><os family="mac" arch="x86_64" /> | ||
</condition> | ||
|
||
<java classname="com.alibaba.fastffi.llvm4jni.Main" | ||
fork="true" failonerror="true"> | ||
<arg value="-cp" /> | ||
<arg value="${project.build.directory}/classes" /> | ||
<arg value="-bc" /> | ||
<arg value="${project.build.directory}/native/${native.library.name}.bc" /> | ||
<!-- | ||
<arg value="-lib" /> | ||
<arg value="${project.build.directory}/native/${native.library.file}" /> | ||
--> | ||
<arg value="-output" /> | ||
<arg value="${project.build.directory}/llvm4jni-output" /> | ||
<arg value="-v" /> | ||
<arg value="INFO" /> | ||
<jvmarg value="-Dllvm4jni.supportIndirectCall=simple" /> | ||
<jvmarg value="-Dllvm4jni.supportLocalConstant=true" /> | ||
<jvmarg value="-Dllvm4jni.maximumBytecodeSize=128" /> | ||
<classpath> | ||
<pathelement path="${compile_classpath}"/> | ||
</classpath> | ||
</java> | ||
</target> | ||
</project> |
Oops, something went wrong.