Skip to content

Commit

Permalink
Build for ElectronJS
Browse files Browse the repository at this point in the history
Fixes #2032
  • Loading branch information
Alexandre Lissy committed Apr 10, 2019
1 parent ed7f6bf commit 938698b
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 2 deletions.
4 changes: 2 additions & 2 deletions native_client/javascript/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ configure: deepspeech_wrap.cxx package.json
$(NODE_BUILD_TOOL) configure $(NODE_BUILD_VERBOSE)

build: configure deepspeech_wrap.cxx
AS=$(AS) CC=$(CC) CXX=$(CXX) LD=$(LD) CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(RPATH_NODEJS) $(LDFLAGS)" LIBS=$(LIBS) $(NODE_BUILD_TOOL) $(NODE_PLATFORM_TARGET) $(NODE_ABI_TARGET) rebuild $(NODE_BUILD_VERBOSE)
AS=$(AS) CC=$(CC) CXX=$(CXX) LD=$(LD) CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(RPATH_NODEJS) $(LDFLAGS)" LIBS=$(LIBS) $(NODE_BUILD_TOOL) $(NODE_PLATFORM_TARGET) $(NODE_RUNTIME) $(NODE_ABI_TARGET) $(NODE_DIST_URL) rebuild $(NODE_BUILD_VERBOSE)

copy-deps: build
$(call copy_missing_libs,lib/binding/*/*/*/deepspeech.node,lib/binding/*/*/)

node-wrapper: copy-deps build
$(NODE_BUILD_TOOL) $(NODE_PLATFORM_TARGET) $(NODE_ABI_TARGET) package $(NODE_BUILD_VERBOSE)
$(NODE_BUILD_TOOL) $(NODE_PLATFORM_TARGET) $(NODE_RUNTIME) $(NODE_ABI_TARGET) $(NODE_DIST_URL) package $(NODE_BUILD_VERBOSE)

npm-pack: clean package.json README.md index.js
npm install node-pre-gyp@0.12.x
Expand Down
9 changes: 9 additions & 0 deletions native_client/javascript/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ util.inherits(VersionAction, argparse.Action);

VersionAction.prototype.call = function(parser) {
Ds.printVersions();
let runtime = 'Node';
if (process.versions.electron) {
runtime = 'Electron';
}
console.error('Runtime: ' + runtime);
process.exit(0);
}

Expand Down Expand Up @@ -115,4 +120,8 @@ audioStream.on('finish', () => {
console.log(model.stt(audioBuffer.slice(0, audioBuffer.length / 2), 16000));
const inference_stop = process.hrtime(inference_start);
console.error('Inference took %ds for %ds audio file.', totalTime(inference_stop), audioLength.toPrecision(4));

console.error('process.versions.electron=' + process.versions.electron);

process.exit(0);
});
14 changes: 14 additions & 0 deletions taskcluster/test-electronjs_v4.1-linux-amd64-opt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
build:
template_file: test-linux-opt-base.tyml
docker_image: "ubuntu:16.04"
dependencies:
- "node-package-cpu"
- "test-training_upstream-linux-amd64-py27mu-opt"
system_setup:
>
${nodejs.packages_xenial.prep_10} && ${nodejs.packages_xenial.apt_pinning} && apt-get -qq update && apt-get -qq -y install ${nodejs.packages_xenial.apt}
args:
tests_cmdline: "${system.homedir.linux}/DeepSpeech/ds/tc-electron-tests.sh 10.x 4.1.1"
metadata:
name: "DeepSpeech Linux AMD64 CPU ElectronJS v4.1 tests"
description: "Testing DeepSpeech for Linux/AMD64 on ElectronJS v4.1, CPU only, optimized version"
37 changes: 37 additions & 0 deletions tc-electron-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

set -xe

source $(dirname "$0")/tc-tests-utils.sh

nodever=$1
electronver=$2

if [ -z "${nodever}" ]; then
echo "No node version given, aborting."
exit 1
fi;

if [ -z "${elecronver}" ]; then
echo "No electron version given, aborting."
exit 1
fi;

download_data

node --version
npm --version

NODE_ROOT="${DS_ROOT_TASK}/ds-test/"
export NODE_PATH="${NODE_ROOT}/node_modules/"
export PATH="${NODE_ROOT}:${NODE_PATH}/.bin/:$PATH"

npm install --prefix ${NODE_ROOT} electron@${electronver}

npm install --prefix ${NODE_ROOT} ${DEEPSPEECH_NODEJS}/deepspeech-${DS_VERSION}.tgz

alias deepspeech="${NODE_ROOT}/node_modules/electron/dist/electron ${NODE_ROOT}/node_modules/deepspeech/client.js"

check_runtime_electronjs

run_all_inference_tests
2 changes: 2 additions & 0 deletions tc-node-tests-prod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ npm install ${DEEPSPEECH_NODEJS}/deepspeech-${DS_VERSION}.tgz

export PATH=$HOME/node_modules/.bin/:$PATH

check_runtime_nodejs

run_prod_inference_tests
2 changes: 2 additions & 0 deletions tc-node-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ export PATH="${NODE_ROOT}:${NODE_PATH}/.bin/:$PATH"

npm install --prefix ${NODE_ROOT} ${DEEPSPEECH_NODEJS}/deepspeech-${DS_VERSION}.tgz

check_runtime_nodejs

run_all_inference_tests
33 changes: 33 additions & 0 deletions tc-tests-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ model_source_mmap="$(dirname "${model_source}")/${model_name_mmap}"

SUPPORTED_PYTHON_VERSIONS=${SUPPORTED_PYTHON_VERSIONS:-2.7.15:ucs2 2.7.15:ucs4 3.4.9:ucs4 3.5.6:ucs4 3.6.7:ucs4 3.7.1:ucs4}
SUPPORTED_NODEJS_VERSIONS=${SUPPORTED_NODEJS_VERSIONS:-4.9.1 5.12.0 6.14.4 7.10.1 8.12.0 9.11.2 10.12.0 11.0.0}
SUPPORTED_ELECTRONJS_VERSIONS=${SUPPORTED_ELECTRONJS_VERSIONS:-1.6.18 1.7.16 1.8.8 2.0.18 3.0.16 3.1.8 4.0.3 4.1.4}

strip() {
echo "$(echo $1 | sed -e 's/^[[:space:]]+//' -e 's/[[:space:]]+$//')"
Expand Down Expand Up @@ -284,6 +285,27 @@ check_tensorflow_version()
assert_deepspeech_version "${ds_help}"
}

assert_deepspeech_runtime()
{
local expected_runtime=$1

set +e
local ds_version=$(${DS_BINARY_PREFIX}deepspeech --version 2>&1 1>/dev/null)
set -e

assert_shows_something "${ds_version}" "${expected_runtime}"
}

check_runtime_nodejs()
{
assert_deepspeech_runtime "Runtime: Node"
}

check_runtime_electronjs()
{
assert_deepspeech_runtime "Runtime: Electron"
}

run_tflite_basic_inference_tests()
{
set +e
Expand Down Expand Up @@ -1110,6 +1132,17 @@ do_deepspeech_nodejs_build()
clean node-wrapper
done;

for electron in ${SUPPORTED_ELECTRONJS_VERSIONS}; do
EXTRA_CFLAGS="${EXTRA_LOCAL_CFLAGS}" EXTRA_LDFLAGS="${EXTRA_LOCAL_LDFLAGS}" EXTRA_LIBS="${EXTRA_LOCAL_LIBS}" make -C native_client/javascript \
TARGET=${SYSTEM_TARGET} \
RASPBIAN=${SYSTEM_RASPBIAN} \
TFDIR=${DS_TFDIR} \
NODE_ABI_TARGET=--target=$electron \
NODE_DIST_URL=--disturl=https://atom.io/download/electron \
NODE_RUNTIME=--runtime=electron \
clean node-wrapper
done;

if [ "${rename_to_gpu}" ]; then
make -C native_client/javascript clean npm-pack PROJECT_NAME=deepspeech-gpu
else
Expand Down

0 comments on commit 938698b

Please sign in to comment.