diff --git a/thirdparty/openfst/HPKBUILD b/thirdparty/openfst/HPKBUILD new file mode 100644 index 0000000000000000000000000000000000000000..49c5ef55140cfe5e80ecb72cdb5be0b9a6255c0b --- /dev/null +++ b/thirdparty/openfst/HPKBUILD @@ -0,0 +1,175 @@ +# Contributor: chengkan +# Maintainer: chengkan +pkgname=openfst +pkgver=1.8.2 +pkgrel=0 +pkgdesc="OpenFst is a library for constructing, combining, optimizing, and searching weighted finite-state transducers (FSTs)" +url="https://www.openfst.org/twiki/bin/view/FST/WebHome" +archs=("armeabi-v7a" "arm64-v8a") +license=("Apache-2.0 license") +depends=() +makedepends=() + +source="https://www.openfst.org/twiki/pub/FST/FstDownload/$pkgname-$pkgver.tar.gz" + + +autounpack=true +downloadpackage=true +buildtools="configure" +patchflag=true + +builddir=$pkgname-${pkgver} +packagename=$builddir.tar.gz + +source envset.sh +host= + +unpackageautomake=true + +# automake need to use 1.16.5 version +automakepkgname=automake +automakebuildhostflag=false +automakepkgver=1.16.5 +automakesource="https://ftp.gnu.org/gnu/$automakepkgname/$automakepkgname-$automakepkgver.tar.gz" +automakebuilddir=$automakepkgname-$automakepkgver +automakepackagename=$automakebuilddir.tar.gz +automakepath= + +downloadautomake() { + if [ ! -f "$automakepackagename" ];then + curl -L -f $automakesource > $automakepackagename + if [ "$?" != "0" ];then + echo "download $automakebuilddir fail" + return 1 + fi + fi + return 0 +} + +automakebuildhost() { + if [ $automakebuildhostflag == true ];then + return 0 + fi + + cd $automakebuilddir + mkdir build + + ./configure --prefix=${PWD}/build > `pwd`/build.log 2>&1 + make -j4 VERBOSE=1 >> build.log 2>&1 + make install >> build.log 2>&1 + + $PWD/build/bin/automake --version >> build.log 2>&1 + if [ "$?" != "0" ];then + echo "compile linux automake 1.16.5 fail" + return 1 + fi + automakebuildhostflag=true + automakepath=$PWD/build/bin + cd $OLDPWD + return 0 +} + +prepare() { + downloadautomake + if [ "$?" != "0" ];then + return 1 + fi + + if [ $unpackageautomake == true ];then + tar xvfz $automakepackagename > /dev/null 2>&1 + if [ "$?" != "0" ];then + return 2 + fi + unpackageautomake=false + fi + + automakebuildhost + if [ $automakebuildhostflag == false ];then + return 3 + fi + export AUTOMAKE=$automakepath/automake + + if $patchflag + then + cd $builddir + # 禁止make check阶段进行代码编译 + patch -p1 < `pwd`/../openfst_oh_pkg.patch + # patch只需要打一次,关闭打patch + patchflag=false + cd $OLDPWD + fi + + cp -arf $builddir $builddir-$ARCH-build + if [ $ARCH == "armeabi-v7a" ]; then + setarm32ENV + export LDFLAGS="${OHOS_SDK}/native/llvm/lib/clang/$CLANG_VERSION/lib/arm-linux-ohos/a7_hard_neon-vfpv4/libclang_rt.builtins.a ${LDFLAGS}" + host=arm-linux + elif [ $ARCH == "arm64-v8a" ]; then + setarm64ENV + export LDFLAGS="${OHOS_SDK}/native/llvm/lib/clang/$CLANG_VERSION/lib/aarch64-linux-ohos/libclang_rt.builtins.a ${LDFLAGS}" + host=aarch64-linux + else + echo "$ARCH not support!" + return -1 + fi +} + +build() { + cd $builddir-$ARCH-build + ./configure "$@" --host=$host --enable-static --enable-compact-fsts --enable-compress --enable-const-fsts --enable-far \ + --enable-fsts --enable-grm --enable-linear-fsts --enable-lookahead-fsts --enable-mpdt --enable-ngram-fsts --enable-pdt >> `pwd`/build.log 2>&1 + make -j4 VERBOSE=1 >> `pwd`/build.log 2>&1 + ret=$? + cd $OLDPWD + + return $ret +} + +package() { + cd $builddir-$ARCH-build + make install >> `pwd`/build.log 2>&1 + cd $OLDPWD + + if [ $ARCH == "armeabi-v7a" ]; then + unsetarm32ENV + elif [ $ARCH == "arm64-v8a" ]; then + unsetarm64ENV + else + echo "$ARCH not support!" + fi + + unset AUTOMAKE + unset host + +} + +check() { + if [ $ARCH == "armeabi-v7a" ]; then + cp ${OHOS_SDK}/native/llvm/lib/arm-linux-ohos/libc++_shared.so $builddir-$ARCH-build + elif [ $ARCH == "arm64-v8a" ]; then + cp ${OHOS_SDK}/native/llvm/lib/aarch64-linux-ohos/libc++_shared.so $builddir-$ARCH-build + else + echo "$ARCH not support!" + return -1 + fi + + cd $builddir-$ARCH-build + sed -i 's/algo_test_lexicographic$(EXEEXT): $(algo_test_lexicographic_OBJECTS)/algo_test_lexicographic$(EXEEXT): /' src/test/Makefile + sed -i 's/algo_test_log$(EXEEXT): $(algo_test_log_OBJECTS)/algo_test_log$(EXEEXT): /' src/test/Makefile + sed -i 's/algo_test_minmax$(EXEEXT): $(algo_test_minmax_OBJECTS)/algo_test_minmax$(EXEEXT): /' src/test/Makefile + sed -i 's/algo_test_power$(EXEEXT): $(algo_test_power_OBJECTS)/algo_test_power$(EXEEXT): /' src/test/Makefile + sed -i 's/algo_test_tropical$(EXEEXT): $(algo_test_tropical_OBJECTS)/algo_test_tropical$(EXEEXT): /' src/test/Makefile + sed -i 's/fst_test$(EXEEXT): $(fst_test_OBJECTS)/fst_test$(EXEEXT): /' src/test/Makefile + sed -i 's/weight_test$(EXEEXT): $(weight_test_OBJECTS)/weight_test$(EXEEXT): /' src/test/Makefile + cd $OLDPWD + + echo "The test must be on an OpenHarmony device!" + # real test CMD + # 进入到编译目录的src/test目录下执行 + # make check +} + +# 清理环境 +cleanbuild() { + rm -rf ${PWD}/$automakebuilddir ${PWD}/$builddir ${PWD}/$builddir-${archs[0]}-build ${PWD}/$builddir-${archs[1]}-build #${PWD}/$packagename +} \ No newline at end of file diff --git a/thirdparty/openfst/HPKCHECK b/thirdparty/openfst/HPKCHECK new file mode 100644 index 0000000000000000000000000000000000000000..1f0cf60675ba289ec0fa31d23b43013751f31f58 --- /dev/null +++ b/thirdparty/openfst/HPKCHECK @@ -0,0 +1,27 @@ +# Contributor: chengkan +# Maintainer: chengkan +source HPKBUILD > /dev/null 2>&1 +logfile=${LYCIUM_THIRDPARTY_ROOT}/${pkgname}/${pkgname}_${ARCH}_${OHOS_SDK_VER}_test.log +OLD_LD_LIBRARY_PATH=$LD_LIBRARY_PATH +checkprepare(){ + export LD_LIBRARY_PATH=`pwd`/$builddir-$ARCH-build:$LD_LIBRARY_PATH + +} +openharmonycheck() { + res=0 + cd $builddir-$ARCH-build/src/test + make check >> ${logfile} 2>&1 + res=$? + + if [ $res -ne 0 ] + then + mkdir ${LYCIUM_FAULT_PATH}/${pkgname} + cp -rf *.log ${LYCIUM_FAULT_PATH}/${pkgname}/ + fi + + export LD_LIBRARY_PATH=$OLD_LD_LIBRARY_PATH + unset OLD_LD_LIBRARY_PATH + cd $OLDPWD + + return $res +} diff --git a/thirdparty/openfst/OAT.xml b/thirdparty/openfst/OAT.xml new file mode 100644 index 0000000000000000000000000000000000000000..5eecdd6202e272a5143978ac32f31977d23001c7 --- /dev/null +++ b/thirdparty/openfst/OAT.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/thirdparty/openfst/README.OpenSource b/thirdparty/openfst/README.OpenSource new file mode 100644 index 0000000000000000000000000000000000000000..96a2a1b963d4a2f78611d2311d2849d1bfc1e835 --- /dev/null +++ b/thirdparty/openfst/README.OpenSource @@ -0,0 +1,11 @@ +[ + { + "Name": "openfst", + "License": "Apache-2.0 license", + "License File": "https://www.openfst.org/twiki/bin/view/FST/DistCopying", + "Version Number": "1.8.2", + "Owner": "kanchengc@isoftstone.com", + "Upstream URL": "https://www.openfst.org/twiki/pub/FST/FstDownload/openfst-1.8.2.tar.gz", + "Description": "OpenFst is a library for constructing, combining, optimizing, and searching weighted finite-state transducers (FSTs)." + } +] diff --git a/thirdparty/openfst/README_zh.md b/thirdparty/openfst/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..3520da421ee77a805f71c56872736172acaea8ea --- /dev/null +++ b/thirdparty/openfst/README_zh.md @@ -0,0 +1,17 @@ +# openfst三方库说明 +## 功能简介 +openfst 是一个开源的有限状态转换(FST)库,主要用于构建、操作和分析有限状态自动机和有限状态转换。 +## 使用约束 +- ROM版本:OpenHarmony3.2Release + +- IDE版本:DevEco Studio 3.1 Release + +- SDK:ohos_sdk_public 4.0.8.1 (API Version 10 Release) + +- 三方库版本:1.8.2 + +- 当前适配功能:构建,操作,分析加权有限状态转换(weighted finite-state transducer,WFST),并且支持对输入和输出序列进行操作 + + +## 集成方式 ++ [系统hap包集成](docs/hap_integrate.md) diff --git a/thirdparty/openfst/SHA512SUM b/thirdparty/openfst/SHA512SUM new file mode 100644 index 0000000000000000000000000000000000000000..4da3dbdefe8e3f1d92c5cfe90f6c0bb2779c59ed --- /dev/null +++ b/thirdparty/openfst/SHA512SUM @@ -0,0 +1 @@ +ca7f9f19e24141e1f1d0bbabf43795e6e278bce3887c14261d9ce204a0e01b1588eaf982755a9105247510a19f67da2f566e9b14b1d869497148f95b55606d5c openfst-1.8.2.tar.gz diff --git a/thirdparty/openfst/docs/hap_integrate.md b/thirdparty/openfst/docs/hap_integrate.md new file mode 100644 index 0000000000000000000000000000000000000000..a88f07ae02e3b1f49366a8925dfd878ac86ab0d7 --- /dev/null +++ b/thirdparty/openfst/docs/hap_integrate.md @@ -0,0 +1,97 @@ +# openfst集成到应用hap +本库是在RK3568开发板上基于OpenHarmony3.2 Release版本的镜像验证的,如果是从未使用过RK3568,可以先查看[润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld)。 +## 开发环境 +- ubuntu20.04 +- [OpenHarmony3.2Release镜像](https://gitee.com/link?target=https%3A%2F%2Frepo.huaweicloud.com%2Fopenharmony%2Fos%2F3.2-Release%2Fdayu200_standard_arm32.tar.gz) +- [ohos_sdk_public 4.0.8.1 (API Version 10 Release)](https://gitee.com/link?target=http%3A%2F%2Fdownload.ci.openharmony.cn%2Fversion%2FMaster_Version%2FOpenHarmony_4.0.8.1%2F20230608_091058%2Fversion-Master_Version-OpenHarmony_4.0.8.1-20230608_091058-ohos-sdk-public.tar.gz) +- [DevEco Studio 3.1 Release](https://gitee.com/link?target=https%3A%2F%2Fcontentcenter-vali-drcn.dbankcdn.cn%2Fpvt_2%2FDeveloperAlliance_package_901_9%2F81%2Fv3%2FtgRUB84wR72nTfE8Ir_xMw%2Fdevecostudio-windows-3.1.0.501.zip%3FHW-CC-KV%3DV1%26HW-CC-Date%3D20230621T074329Z%26HW-CC-Expire%3D315360000%26HW-CC-Sign%3D22F6787DF6093ECB4D4E08F9379B114280E1F65DA710599E48EA38CB24F3DBF2) +- [准备三方库构建环境](../../../lycium/README.md#1编译环境准备) +- [准备三方库测试环境](../../../lycium/README.md#3ci环境准备) + +## 编译三方库 +- 下载本仓库 + ``` + git clone https://gitee.com/openharmony-sig/tpc_c_cplusplus.git --depth=1 + ``` +- 三方库目录结构 + ``` + tpc_c_cplusplus/thirdparty/openfst #三方库openfst的目录结构如下 + ├── docs #三方库相关文档的文件夹 + ├── HPKBUILD #构建脚本 + ├── SHA512SUM #三方库校验文件 + ├── README.OpenSource #说明三方库源码的下载地址,版本,license等信息 + ├── openfst_oh_pkg.patch #补丁文件 + ├── OAT.xml #版权校验文件 + ├── HPKCHECK #自动化测试脚本 + ├── README_zh.md + ``` + + +- 在lycium目录下编译三方库 + 编译环境的搭建参考[准备三方库构建环境](../../../lycium/README.md#1编译环境准备) + + ``` + + cd lycium + ./build.sh openfst + ``` +- 三方库头文件及生成的库 + 在lycium目录下会生成usr目录,该目录下存在已编译完成的32位和64位三方库 + + ``` + openfst/arm64-v8a openfst/armeabi-v7a + ``` + +- [测试三方库](#测试三方库) + +## 应用中使用三方库 +- 在IDE的cpp目录下新增thirdparty目录,将编译生成的库拷贝到该目录下,如下图所示 + ![openfst_install](pic/openfst_install.png) +- 在最外层(cpp目录下)CMakeLists.txt中添加如下语句 + ``` + + #将三方库加入到工程 + target_link_libraries(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/openfst/${OHOS_ARCH}/lib/libfst.a + ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/openfst/${OHOS_ARCH}/lib/libfstscript.a + ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/openfst/${OHOS_ARCH}/lib/libfstcompact.a + ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/openfst/${OHOS_ARCH}/lib/libfstcompressscript.a + ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/openfst/${OHOS_ARCH}/lib/libfstconst.a + ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/openfst/${OHOS_ARCH}/lib/libfstfar.a + ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/openfst/${OHOS_ARCH}/lib/libfstfarscript.a + ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/openfst/${OHOS_ARCH}/lib/libfstlinearscript.a + ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/openfst/${OHOS_ARCH}/lib/libfstlookahead.a + ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/openfst/${OHOS_ARCH}/lib/libfstpdtscript.a + ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/openfst/${OHOS_ARCH}/lib/libfstmpdtscript.a + ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/openfst/${OHOS_ARCH}/lib/libfstngram.a) + + #将三方库的头文件加入工程中 + target_include_directories(entry PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/openfst/${OHOS_ARCH}/include) + + ``` + ![openfst_usage](pic/openfst_usage.png) +## 测试三方库 +三方库的测试使用原库自带的测试用例来做测试,[准备三方库测试环境](../../../lycium/README.md#3ci环境准备) + + + +- 将测试资源导入到开发板 +- 设置依赖服务程序路径 +``` +32位系统 +export LD_LIBRARY_PATH=/data/local/tmp/tpc_c_cplusplus/lycium/usr/openfst/armeabi-v7a/lib:/data/local/tmp/tpc_c_cplusplus/thirdparty/openfst/openfst-1.8.2-armeabi-v7a-build + +##64位系统 +export LD_LIBRARY_PATH=/data/local/tmp/tpc_c_cplusplus/lycium/usr/openfst/arm64-v8a/lib:/data/local/tmp/tpc_c_cplusplus/thirdparty/openfst/openfst-1.8.2-arm64-v8a-build +``` +- 进入到构建目录$ARCH-build/src/test下执行 make check 运行测试用例,如下截图(arm64-v8a-build为构建64位的目录,armeabi-v7a-build为构建32位的目录) + + + +![openfst](pic/openfst_test.png) + +## 参考资料 +- [润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld) +- [OpenHarmony三方库地址](https://gitee.com/openharmony-tpc) +- [OpenHarmony知识体系](https://gitee.com/openharmony-sig/knowledge) +- [通过DevEco Studio开发一个NAPI工程](https://gitee.com/openharmony-sig/knowledge_demo_temp/blob/master/docs/napi_study/docs/hello_napi.md) diff --git a/thirdparty/openfst/docs/pic/openfst_install.png b/thirdparty/openfst/docs/pic/openfst_install.png new file mode 100755 index 0000000000000000000000000000000000000000..49fca3506a976226a52890b853162111e152273b Binary files /dev/null and b/thirdparty/openfst/docs/pic/openfst_install.png differ diff --git a/thirdparty/openfst/docs/pic/openfst_test.png b/thirdparty/openfst/docs/pic/openfst_test.png new file mode 100755 index 0000000000000000000000000000000000000000..4f32430910c2968dc26fdea6ac2448d1d55a0ce4 Binary files /dev/null and b/thirdparty/openfst/docs/pic/openfst_test.png differ diff --git a/thirdparty/openfst/docs/pic/openfst_usage.png b/thirdparty/openfst/docs/pic/openfst_usage.png new file mode 100755 index 0000000000000000000000000000000000000000..1a64ae30b7843ed76e2e94a1e1838070b7fe9483 Binary files /dev/null and b/thirdparty/openfst/docs/pic/openfst_usage.png differ diff --git a/thirdparty/openfst/openfst_oh_pkg.patch b/thirdparty/openfst/openfst_oh_pkg.patch new file mode 100644 index 0000000000000000000000000000000000000000..de75ee432255d6f36b9a9662a7fc68654f2e4d9d --- /dev/null +++ b/thirdparty/openfst/openfst_oh_pkg.patch @@ -0,0 +1,63 @@ +diff -rupN openfst-1.8.2/configure openfst-1.8.2_patched/configure +--- openfst-1.8.2/configure 2022-02-04 01:27:24.000000000 +0800 ++++ openfst-1.8.2_patched/configure 2023-07-19 14:28:27.539390345 +0800 +@@ -17978,10 +17978,10 @@ libfstdir=$with_libfstdir + # or when someone does not run `make check`. + if test "$cross_compiling" = yes + then : +- { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +-printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} +-as_fn_error $? "cannot run test program while cross compiling +-See \`config.log' for more details" "$LINENO" 5; } ++# { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 ++#printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} ++#as_fn_error $? "cannot run test program while cross compiling ++#See \`config.log' for more details" "$LINENO" 5; } + else $as_nop + cat confdefs.h - <<_ACEOF >conftest.$ac_ext + /* end confdefs.h. */ +diff -rupN openfst-1.8.2/src/test/Makefile.am openfst-1.8.2_patched/src/test/Makefile.am +--- openfst-1.8.2/src/test/Makefile.am 2022-02-04 00:48:53.000000000 +0800 ++++ openfst-1.8.2_patched/src/test/Makefile.am 2023-07-19 14:28:53.807874051 +0800 +@@ -1,7 +1,9 @@ + AM_CPPFLAGS = -I$(srcdir)/../include $(ICU_CPPFLAGS) + LDADD = ../lib/libfst.la -lm $(DL_LIBS) + +-check_PROGRAMS = fst_test weight_test ++bin_PROGRAMS = fst_test ++ ++bin_PROGRAMS += weight_test + + fst_test_SOURCES = fst_test.cc + +@@ -9,24 +11,24 @@ weight_test_SOURCES = weight_test.cc + + algo_test_SOURCES = algo_test.cc + +-check_PROGRAMS += algo_test_log ++bin_PROGRAMS += algo_test_log + algo_test_log_SOURCES = $(algo_test_SOURCES) + algo_test_log_CPPFLAGS = -DTEST_LOG $(AM_CPPFLAGS) + +-check_PROGRAMS += algo_test_tropical ++bin_PROGRAMS += algo_test_tropical + algo_test_tropical_SOURCES = $(algo_test_SOURCES) + algo_test_tropical_CPPFLAGS = -DTEST_TROPICAL $(AM_CPPFLAGS) + +-check_PROGRAMS += algo_test_minmax ++bin_PROGRAMS += algo_test_minmax + algo_test_minmax_SOURCES = $(algo_test_SOURCES) + algo_test_minmax_CPPFLAGS = -DTEST_MINMAX $(AM_CPPFLAGS) + +-check_PROGRAMS += algo_test_lexicographic ++bin_PROGRAMS += algo_test_lexicographic + algo_test_lexicographic_SOURCES = $(algo_test_SOURCES) + algo_test_lexicographic_CPPFLAGS = -DTEST_LEXICOGRAPHIC $(AM_CPPFLAGS) + +-check_PROGRAMS += algo_test_power ++bin_PROGRAMS += algo_test_power + algo_test_power_SOURCES = $(algo_test_SOURCES) + algo_test_power_CPPFLAGS = -DTEST_POWER $(AM_CPPFLAGS) + +-TESTS = $(check_PROGRAMS) ++TESTS = $(bin_PROGRAMS)