diff --git a/thirdparty/phf/HPKBUILD b/thirdparty/phf/HPKBUILD new file mode 100644 index 0000000000000000000000000000000000000000..d787ebb4b21836528b49852bf843e8a5e96ca8e7 --- /dev/null +++ b/thirdparty/phf/HPKBUILD @@ -0,0 +1,68 @@ +# Contributor: 小肉头君 +# Maintainer: 小肉头君 + +pkgname=phf +pkgver=rel-20190215 +pkgrel=0 +pkgdesc="About Tiny perfect hash library for C, C++, and Lua." +url="https://github.com/wahern/phf" +archs=("armeabi-v7a" "arm64-v8a") +license=("MIT license") +depends=() +makedepends=() +install= +source="https://github.com/wahern/$pkgname/archive/refs/tags/$pkgver.tar.gz" + +autounpack=true +downloadpackage=true +buildtools="make" + +builddir=$pkgname-$pkgver +packagename=$builddir.tar.gz + +cxx= +prepare() { + cp -rf $builddir $builddir-$ARCH-build + if [ $ARCH == "armeabi-v7a" ] + then + cxx=${OHOS_SDK}/native/llvm/bin/arm-linux-ohos-clang++ + fi + if [ $ARCH == "arm64-v8a" ] + then + cxx=${OHOS_SDK}/native/llvm/bin/aarch64-linux-ohos-clang++ + fi +} + +build() { + cd $builddir-$ARCH-build + make CXX=${cxx} -j4 > `pwd`/build.log 2>&1 + # 对最关键一步的退出码进行判断 + ret=$? + cd $OLDPWD + return $ret +} + +# 安装打包 +package() { + cd $builddir-$ARCH-build + # 源库make install强依赖lua,无法在oh环境使用,这里手动copy到usr目录 + mkdir -p $LYCIUM_ROOT/usr/$pkgname/$ARCH/include/ + mkdir -p $LYCIUM_ROOT/usr/$pkgname/$ARCH/lib/ + cp phf.h $LYCIUM_ROOT/usr/$pkgname/$ARCH/include/ + cp libphf.so $LYCIUM_ROOT/usr/$pkgname/$ARCH/lib/ + cd $OLDPWD + unset cxx +} + +# 测试,需要在 ohos 设备上进行 +check() { + echo "The test must be on an OpenHarmony device!" + # real test CMD + # ./phf中间的数字可以随意传,此库是完美hash算法库,传入数据变化,最后生成的报告内容也会变化 + # ./phf 10 20 10 3 -v -n +} + +# 清理环境 +cleanbuild(){ + rm -rf ${PWD}/$builddir $builddir-armeabi-v7a-build $builddir-arm64-v8a-build #${PWD}/$packagename +} \ No newline at end of file diff --git a/thirdparty/phf/README.OpenSource b/thirdparty/phf/README.OpenSource new file mode 100644 index 0000000000000000000000000000000000000000..3b526d0cb57be70e4cc89b3ac3053c1132c250f4 --- /dev/null +++ b/thirdparty/phf/README.OpenSource @@ -0,0 +1,11 @@ +[ + { + "Name": "phf", + "License": "MIT license", + "License File": "LICENSE", + "Version Number": "rel-20190215",: + "Owner": "chenbaodi@huawei.com", + "Upstream URL": "https://github.com/wahern/phf/archive/refs/tags/rel-20190215.tar.gz", + "Description": "Tiny perfect hash library for C, C++, and Lua" + } +] diff --git a/thirdparty/phf/README_zh.md b/thirdparty/phf/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..02c39d1aae6d5d326c37ba1005afc7a429e40ded --- /dev/null +++ b/thirdparty/phf/README_zh.md @@ -0,0 +1,12 @@ +# phf三方库说明 +## 功能简介 +phf是实现完美hash算法的库。 +## 使用约束 +- IDE版本:DevEco Studio 3.1 Beta2 +- SDK版本:ohos_sdk_public 3.2.11.9 (API Version 9 Release) +- 三方库版本:rel-20190215 +- 当前适配的功能:支持完美hash算法 +- [MIT license](https://github.com/wahern/phf/blob/master/LICENSE) + +## 集成方式 ++ [应用hap包集成](docs/hap_integrate.md) diff --git a/thirdparty/phf/SHA512SUM b/thirdparty/phf/SHA512SUM new file mode 100644 index 0000000000000000000000000000000000000000..43782a97dc042df9c645ca7cb3086eb3a73d97cd --- /dev/null +++ b/thirdparty/phf/SHA512SUM @@ -0,0 +1 @@ +fbfd334489e2e6281c07b0f8d2e615c6e51a154dc9243b133af994493cec21b4a21c00f39c6b3cb4cbf19fe1d5da72fbc78ae22d3b64936b1000eab88e26a5d6 phf-rel-20190215.tar.gz diff --git a/thirdparty/phf/docs/hap_integrate.md b/thirdparty/phf/docs/hap_integrate.md new file mode 100644 index 0000000000000000000000000000000000000000..7b792b816eec4a6cdaa64eb9aa084142f60a53a3 --- /dev/null +++ b/thirdparty/phf/docs/hap_integrate.md @@ -0,0 +1,94 @@ +# phf 集成到应用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 3.2.11.9 (API Version 9 Release)](https://gitee.com/link?target=https%3A%2F%2Frepo.huaweicloud.com%2Fopenharmony%2Fos%2F3.2-Release%2Fohos-sdk-windows_linux-public.tar.gz) +- [DevEco Studio 3.1 Beta2](https://gitee.com/link?target=https%3A%2F%2Fcontentcenter-vali-drcn.dbankcdn.cn%2Fpvt_2%2FDeveloperAlliance_package_901_9%2Ff3%2Fv3%2FuJyuq3syQ2ak4hE1QZmAug%2Fdevecostudio-windows-3.1.0.400.zip%3FHW-CC-KV%3DV1%26HW-CC-Date%3D20230408T013335Z%26HW-CC-Expire%3D315360000%26HW-CC-Sign%3D96262721EDC9B34E6F62E66884AB7AE2A94C2A7B8C28D6F7FC891F46EB211A70) +- [准备三方库构建环境](../../../tools/README.md#编译环境准备) +- [准备三方库测试环境](../../../tools/README.md#ci环境准备) + +## 编译三方库 + +- 下载本仓库 + + ```shell + git clone https://gitee.com/openharmony-sig/tpc_c_cplusplus.git --depth=1 + ``` + +- 三方库目录结构 + + ``` + tpc_c_cplusplus/thirdparty/phf #三方库phf的目录结构如下 + ├── docs #三方库相关文档的文件夹 + ├── HPKBUILD #构建脚本 + ├── SHA512SUM #三方库校验文件 + ├── README.OpenSource #说明三方库源码的下载地址,版本,license等信息 + ├── README_zh.md + ``` + +- 将phf拷贝至tools/main目录下 + + ``` + cd tpc_c_cplusplus + cp thirdparty/phf tools/main -rf + ``` + +- 在tools目录下编译三方库 + + 编译环境的搭建参考[准备三方库构建环境](../../../tools/README.md#编译环境准备) + + ``` + cd tools + ./build.sh phf + ``` + +- 三方库头文件及生成的库 + + 在tools目录下会生成usr目录,该目录下存在已编译完成的32位和64位三方库 + + ``` + phf/arm64-v8a phf/armeabi-v7a + ``` + +- [测试三方库](#测试三方库) + +## 应用中使用三方库 + +- 在IDE的cpp目录下新增thirdparty目录,将编译生成的库拷贝到该目录下,如下图所示: + +  ![thirdparty_install_dir](pic/phf_install_dir.png) + +- 拷贝动态库到`\\entry\libs\${OHOS_ARCH}\`目录: + + 动态库需要在`\\entry\libs\${OHOS_ARCH}\`目录,才能集成到hap包中,所以需要将对应的so文件拷贝到对应CPU架构的目录: + +  ![thirdparty_install_dir](pic/phf_install_dir2.png) + +- 在最外层(cpp目录下)CMakeLists.txt中添加如下语句: + + ``` + #将三方库加入工程中,phf是对应的三方库名 + target_link_libraries(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/phf/${OHOS_ARCH}/lib/libphf.so) + #将三方库的头文件加入工程中,phf是对应的三方库名 + target_include_directories(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/phf/${OHOS_ARCH}/include) + ``` + ![phf_usage](pic/phf_usage.png) + +## 测试三方库 + +三方库的测试使用原库自带的可执行文件来做测试 + +进入到构建目录,执行./phf 10 20 10 3 -v -n(arm64-v8a-build为构建64位的目录,armeabi-v7a-build为构建32位的目录) + + ![phf_test](pic/phf_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) \ No newline at end of file diff --git a/thirdparty/phf/docs/pic/phf_install_dir.png b/thirdparty/phf/docs/pic/phf_install_dir.png new file mode 100644 index 0000000000000000000000000000000000000000..d97f6f9610e7ee31f38c6c8b6247f2391de199d7 Binary files /dev/null and b/thirdparty/phf/docs/pic/phf_install_dir.png differ diff --git a/thirdparty/phf/docs/pic/phf_install_dir2.png b/thirdparty/phf/docs/pic/phf_install_dir2.png new file mode 100644 index 0000000000000000000000000000000000000000..89778d0d0b705e68f8df89def43b9c3c50c0e3b9 Binary files /dev/null and b/thirdparty/phf/docs/pic/phf_install_dir2.png differ diff --git a/thirdparty/phf/docs/pic/phf_test.png b/thirdparty/phf/docs/pic/phf_test.png new file mode 100644 index 0000000000000000000000000000000000000000..0c5287a7e32417eaeed6bddfe649e231177847ac Binary files /dev/null and b/thirdparty/phf/docs/pic/phf_test.png differ diff --git a/thirdparty/phf/docs/pic/phf_usage.png b/thirdparty/phf/docs/pic/phf_usage.png new file mode 100644 index 0000000000000000000000000000000000000000..797ae223b14edcf5b94c81a3d7c36c12e23fcb1a Binary files /dev/null and b/thirdparty/phf/docs/pic/phf_usage.png differ