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

[Feat][Java] Initialize JAVA SDK: add INFO implementation #212

Merged
merged 16 commits into from
Aug 16, 2023
Merged
106 changes: 106 additions & 0 deletions .github/workflows/java.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: GraphAr Java CI

on:
# Trigger the workflow on push or pull request,
# but only for the main branch
push:
branches:
- main
paths:
- 'java/**'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include cpp/src/** since the cpp may affect java

- '.github/workflows/java.yml'
pull_request:
branches:
- main
paths:
- 'java/**'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Diito

- '.github/workflows/java.yml'

concurrency:
group: ${{ github.repository }}-${{ github.event.number || github.head_ref || github.sha }}-${{ github.workflow }}
cancel-in-progress: true

env:
LLVM11_HOME: /opt/llvm11.0.0
LLVM_VER: 11.0.0

jobs:
GraphAr-java:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
with:
submodules: true

- name: Install llvm-11
run: |
bash ${GITHUB_WORKSPACE}/java/install-llvm11.sh


# 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: |

# install the latest arrow deb to test arrow
wget -c https://apache.jfrog.io/artifactory/arrow/"$(lsb_release --id --short | tr 'A-Z' 'a-z')"/apache-arrow-apt-source-latest-$(lsb_release --codename --short).deb \
-P /tmp/
sudo apt-get install -y -V /tmp/apache-arrow-apt-source-latest-"$(lsb_release --codename --short)".deb
sudo apt-get update -y
sudo apt-get install -y libarrow-dev
sudo apt-get install -y libboost-graph-dev ccache libcurl4-openssl-dev

- name: CMake
run: |
mkdir build
pushd build
cmake ../cpp
popd

- name: Build GraphAr
run: |
pushd build
make -j$(nproc)
sudo make install
popd

# Install Java dependencies
- uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '8'
java-package: 'jdk'
cache: 'maven'
server-id: ossrh
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
gpg-private-key: ${{ secrets.OSSRH_MAVEN_GPG_PRIVATE_KEY }}
gpg-passphrase: MAVEN_GPG_PASSPHRASE

- name: Set up Maven
uses: stCarolas/setup-maven@master
with:
maven-version: 3.8.4

- name: Check environment
run: |
export PATH=$LLVM11_HOME/bin:$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH

- name: Install fastFFI
run: |
git clone https://github.com/alibaba/fastffi
pushd fastffi
mvn clean install
popd

- name: Run test
run: |
pushd java
mvn test
popd
2 changes: 2 additions & 0 deletions java/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea
target
33 changes: 33 additions & 0 deletions java/CMakeLists.txt
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)
1 change: 1 addition & 0 deletions java/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Coming soon
74 changes: 74 additions & 0 deletions java/build.xml
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=&quot;${env.LLVM11_HOME}/bin/llvm-ar&quot; -DCMAKE_RANLIB=&quot;${env.LLVM11_HOME}/bin/llvm-ranlib&quot; -DCMAKE_C_COMPILER=&quot;${env.LLVM11_HOME}/bin/clang&quot; -DCMAKE_CXX_COMPILER=&quot;${env.LLVM11_HOME}/bin/clang++&quot; -DCMAKE_CXX_FLAGS=&quot;-flto -fforce-emit-vtables&quot; ${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>
27 changes: 27 additions & 0 deletions java/install-llvm11.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this file since we don't need to build llvm from the source


workdir=/tmp/install-llvm
mkdir -p $workdir

mkdir -p $LLVM11_HOME/include/binutils
curl -L --output $LLVM11_HOME/include/binutils/plugin-api.h \
https://raw.githubusercontent.com/bminor/binutils-gdb/binutils-2_37-branch/include/plugin-api.h

cd $workdir
curl -L -O https://github.com/llvm/llvm-project/releases/download/llvmorg-$LLVM_VER/llvm-project-$LLVM_VER.tar.xz
tar xf llvm-project-$LLVM_VER.tar.xz
cd llvm-project-$LLVM_VER
mkdir build
cd build
cmake ../llvm -DLLVM_ENABLE_PROJECTS="clang;llvm;lld" \
-DLLVM_ENABLE_TERMINFO=OFF \
-DLLVM_TARGETS_TO_BUILD=X86 \
-DCMAKE_BUILD_TYPE=MinSizeRel \
-DCMAKE_INSTALL_PREFIX=$LLVM11_HOME \
-DLLVM_BINUTILS_INCDIR=$LLVM11_HOME/include/binutils \
-DCMAKE_CXX_FLAGS_MINSIZEREL="-Os -DNDEBUG -static-libgcc -static-libstdc++ -s"
make install -j`nproc`

# cleanup
cd /
rm -rf $workdir
Loading