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

Standalone Java bindings #3503

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
Empty file added WORKSPACE
Empty file.
33 changes: 22 additions & 11 deletions native_client/java/.gitignore
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
*.iml
.gradle
/local.properties
/.idea/caches/build_file_checksums.ser
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
.DS_Store
/build
/captures
.externalNativeBuild
#Native libs
libdeepspeech_android/libs/*
!libdeepspeech_android/libs/.gitignore
libdeepspeech_android/*.so

#Gradle
.gradle/

#Make/CMake
Makefile/

#SWIG
jni/*.cpp
jni/*.o

#Collected files by make
build/

#Autogenerated java files by SWIG
libdeepspeech_android/src/main/java/org/deepspeech/libdeepspeech/*.java
!libdeepspeech_android/src/main/java/org/deepspeech/libdeepspeech/DeepSpeechModel.java
!libdeepspeech_android/src/main/java/org/deepspeech/libdeepspeech/DeepSpeechStreamingState.java
29 changes: 0 additions & 29 deletions native_client/java/.idea/codeStyles/Project.xml

This file was deleted.

19 changes: 0 additions & 19 deletions native_client/java/.idea/gradle.xml

This file was deleted.

38 changes: 0 additions & 38 deletions native_client/java/.idea/misc.xml

This file was deleted.

12 changes: 0 additions & 12 deletions native_client/java/.idea/runConfigurations.xml

This file was deleted.

70 changes: 56 additions & 14 deletions native_client/java/Makefile
Original file line number Diff line number Diff line change
@@ -1,31 +1,73 @@
.PHONY: clean apk-clean
.PHONY: clean android-clean jre jre-prepare jre-libdeepspeech-jni jre-gradle jre-collect jre-clean android-prepare

include ../definitions.mk

ARCHS := $(shell grep 'ABI_FILTERS' libdeepspeech/gradle.properties | cut -d'=' -f2 | sed -e 's/;/ /g')
ARCHS := $(shell grep 'ABI_FILTERS' libdeepspeech_android/gradle.properties | cut -d'=' -f2 | sed -e 's/;/ /g')
GRADLE ?= ./gradlew

all: apk
all: android jre
standalone: jre
Copy link
Collaborator

Choose a reason for hiding this comment

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

same


clean: apk-clean
clean: android-clean jre-clean
rm -rf *.java jni/deepspeech_wrap.cpp

apk-clean:
android-clean:
$(GRADLE) clean
rm -rf settings.gradle

libs-clean:
rm -fr libdeepspeech/libs/*/libdeepspeech.so
jre-clean:
rm -f build.gradle
rm -f jni/deepspeech_wrap.cpp jni/deepspeech_wrap.o
rm -rf libdeepspeech_jre/cmake_install.cmake libdeepspeech_jre/CMakeCache.txt libdeepspeech_jre/Makefile libdeepspeech_jre/CMakeFiles/
rm -rf libdeepspeech_jre/build/
rm -rf settings.gradle

libdeepspeech/libs/%/libdeepspeech.so:
-mkdir libdeepspeech/libs/$*/
cp ${TFDIR}/bazel-out/$*-*/bin/native_client/libdeepspeech.so libdeepspeech/libs/$*/
libdeepspeech_jre/libs/%/libdeepspeech.so:
-mkdir libdeepspeech_jre/libs/$*/
cp ${TFDIR}/bazel-out/$*-*/bin/native_client/libdeepspeech.so libdeepspeech_jre/libs/$*/

apk: apk-clean bindings $(patsubst %,libdeepspeech/libs/%/libdeepspeech.so,$(ARCHS))
libdeepspeech_android/libs/%/libdeepspeech.so:
-mkdir libdeepspeech_android/libs/$*/
cp ${TFDIR}/bazel-out/$*-*/bin/native_client/libdeepspeech.so libdeepspeech_android/libs/$*/

android-prepare:
cp build.gradle.android build.gradle
cp libdeepspeech_android/settings.gradle settings.gradle

android: android-prepare android-clean bindings $(patsubst %,libdeepspeech/libs/%/libdeepspeech.so,$(ARCHS))
$(GRADLE) build

jre: jre-prepare jre-collect jre-restore-makefile jre-clean
jre-prepare: $(patsubst %,libdeepspeech_jre/libs/%/libdeepspeech.so,$(ARCHS))
cp Makefile Makefile.original
cp build.gradle.standalone build.gradle
cp libdeepspeech_jre/settings.gradle ./settings.gradle
sed -i 's|__JAVA_HOME__|'${JAVA_HOME}'|g' libdeepspeech_jre/CMakeLists.txt

jre-libdeepspeech-jni: bindings
cd libdeepspeech_jre; \
cmake .; \
$(MAKE)

jre-gradle: jre-libdeepspeech-jni
$(GRADLE) build

maven-bundle: apk
jre-collect: jre-gradle
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why this one?

mkdir -p build
mv libdeepspeech_jre/libdeepspeech-jni.so build/
cp libdeepspeech_jre/libs/x86_64/libdeepspeech.so build/
cp libdeepspeech_jre/build/libs/libdeepspeech_jre.jar build/

jre-restore-makefile:
mv Makefile.original Makefile

maven-bundle: android
$(GRADLE) uploadArchives
$(GRADLE) zipMavenArtifacts

bindings: clean ds-swig
$(DS_SWIG_ENV) swig -c++ -java -package org.deepspeech.libdeepspeech -outdir libdeepspeech/src/main/java/org/deepspeech/libdeepspeech/ -o jni/deepspeech_wrap.cpp jni/deepspeech.i
bindings: ds-swig
mkdir -p ./tmp
$(DS_SWIG_ENV) swig -c++ -java -package org.deepspeech.libdeepspeech -outdir ./tmp -o jni/deepspeech_wrap.cpp jni/deepspeech.i
cp ./tmp/* libdeepspeech_android/src/main/java/org/deepspeech/libdeepspeech/
cp ./tmp/* libdeepspeech_jre/src/main/java/org/deepspeech/libdeepspeech/
rm -rf ./tmp
16 changes: 16 additions & 0 deletions native_client/java/README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
# Java bindings
Full project description and documentation on GitHub: [https://github.com/mozilla/DeepSpeech](https://github.com/mozilla/DeepSpeech).

## Android bindings
For use with Android

``make android``

>Note: The current example app in `./App` is not up to date with the latest changes to the bindings!
Copy link
Collaborator

Choose a reason for hiding this comment

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

what is this ?


## Standalone Java Bindings for DeepSpeech
For use with standalone Java

``make standalone``

### Usage information:
See [standalone.md](standalone.md)
29 changes: 29 additions & 0 deletions native_client/java/build.gradle.standalone
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

repositories {
google()
jcenter()
Copy link
Collaborator

Choose a reason for hiding this comment

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

jcenter() is dying :'(

Copy link
Author

Choose a reason for hiding this comment

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

Not sure what we can do about that. Will need to check out which dependencies are from jcenter, I dont think we have any since the Android stuff is pulled from Google

}
dependencies {
}
}


allprojects {
repositories {
jcenter()
}
}

dependencies {
}

task clean(type: Delete) {
delete rootProject.buildDir
}

ext {
dsVersionString = rootProject.file('../../VERSION').text.trim()
}
Empty file modified native_client/java/gradle.properties
100644 → 100755
Empty file.
Binary file modified native_client/java/gradle/wrapper/gradle-wrapper.jar
100644 → 100755
Binary file not shown.
2 changes: 1 addition & 1 deletion native_client/java/gradle/wrapper/gradle-wrapper.properties
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we avoid updating gradle wrapper? this adds noise and is not really needed

zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
53 changes: 33 additions & 20 deletions native_client/java/gradlew
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
#!/usr/bin/env sh

#
Copy link
Collaborator

Choose a reason for hiding this comment

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

same, avoid updating gradlew for the moment

# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

##############################################################################
##
## Gradle start up script for UN*X
Expand Down Expand Up @@ -28,7 +44,7 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
Expand Down Expand Up @@ -66,6 +82,7 @@ esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar


# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
Expand Down Expand Up @@ -109,10 +126,11 @@ if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`

JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
Expand All @@ -138,19 +156,19 @@ if $cygwin ; then
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
i=`expr $i + 1`
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi

Expand All @@ -159,14 +177,9 @@ save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")
APP_ARGS=`save "$@"`

# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "$@"
Loading