diff --git a/thirdparty/libevent/HPKBUILD b/thirdparty/libevent/HPKBUILD index 82ef82bd0f4748252a3b11d7871af9c6e7b8ad18..b5f5517f85a4c1efc8fdbf0754bb7436d466ca92 100644 --- a/thirdparty/libevent/HPKBUILD +++ b/thirdparty/libevent/HPKBUILD @@ -1,26 +1,73 @@ -# Contributor: Chen Xu -# Maintainer: Chen Xu +# Copyright (c) 2023 Huawei Device Co., Ltd. +# 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 +# +# http://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. + +# Contributor: Jeff Han +# Maintainer: Jeff Han + pkgname=libevent -pkgver=release-2.1.12-stable +pkgver=2.1.12 pkgrel=0 -pkgdesc="libevent is meant to replace the event loop found in event driven network servers. An application just needs to call event_dispatch() and then add or remove events dynamically without having to change the event loop." +pkgdesc="I/O" url="https://libevent.org/" -archs=("armeabi-v7a" "arm64-v8a") -license=("BSD-style license") -depends=("openssl") +archs=("armeabi-v7a" "arm64-v8a" "x86_64") +license=("Apache-2.0") +depends=(openssl) makedepends=() -source="https://github.com/$pkgname/$pkgname/archive/refs/tags/$pkgver.tar.gz" + +source="https://master.dl.sourceforge.net/project/libevent.mirror/release-2.1.12-stable/release-2.1.12-stable.zip?viasf=1" autounpack=true downloadpackage=true +buildtools="cmake" + +builddir=libevent-libevent-4f12382 +packagename=release-2.1.12-stable.zip +patchflag=true -builddir=$pkgname-${pkgver} -packagename=$builddir.tar.gz +source envset.sh +host= prepare() { + if $patchflag + then + cd $builddir + # 屏蔽测试bug + #patch -p1 < `pwd`/../openssl_oh_test.patch + # patch只需要打一次,关闭打patch + patchflag=false + cd $OLDPWD + fi mkdir -p $builddir/$ARCH-build + if [ $ARCH == "armeabi-v7a" ] + then + setarm32ENV + host=linux-generic32 + elif [ $ARCH == "arm64-v8a" ] + then + setarm64ENV + host=linux-aarch64 + elif [ $ARCH == "x86_64" ] + then + setx86_64ENV + host=linux-x86_64 + else + echo "${ARCH} not support" + return -1 + fi + } +#参数1 build() { cd $builddir ${OHOS_SDK}/native/build-tools/cmake/bin/cmake "$@" -DOHOS_ARCH=$ARCH \ @@ -32,17 +79,41 @@ build() { return $ret } + package() { - cd $builddir - make -C $ARCH-build install VERBOSE=1 >> `pwd`/$ARCH-build/build.log 2>&1 + cd $builddir/$ARCH-build + make install >> `pwd`/build.log 2>&1 cd $OLDPWD } check() { + cd $builddir/$ARCH-build + make depend >> `pwd`/build.log 2>&1 + cd $OLDPWD + unset host + if [ $ARCH == "armeabi-v7a" ] + then + unsetarm32ENV + elif [ $ARCH == "arm64-v8a" ] + then + unsetarm64ENV + elif [ $ARCH == "x86_64" ] + then + setx86_64ENV + else + echo "${ARCH} not support" + return -1 + fi echo "The test must be on an OpenHarmony device!" + # real test CMD + # 将编译目录加到 LD_LIBRARY_PATH 环境变量 + # make test + # make test TESTS=test_shlibload V=1 运行指定测试用例 + # 32 个用例错误判定为误报, 不同系统错误描述不同(实际为正常) + # 8 个 dlopen 用例错误(尽量避开使用dlopen加载动态库), 进程退出时 signal 11. 系在特定平台,使用方法问题 典型问题,采用patch规避 } # 清理环境 cleanbuild() { - rm -rf ${PWD}/$builddir # ${PWD}/$packagename + rm -rf ${PWD}/$builddir #${PWD}/$packagename } diff --git a/thirdparty/libevent/HPKCHECK b/thirdparty/libevent/HPKCHECK new file mode 100644 index 0000000000000000000000000000000000000000..56e50f7d2f640f85a81d1ce35bd9020a6743f3f3 --- /dev/null +++ b/thirdparty/libevent/HPKCHECK @@ -0,0 +1,27 @@ +# This is an example HPKCHECK file. Use this as a start to creating your own, +# and remove these comments. + +# Contributor: Your Name +# Maintainer: Your Name + +source HPKBUILD > /dev/null 2>&1 # 导入HPKBUILD文件 +logfile=${LYCIUM_THIRDPARTY_ROOT}/${pkgname}/${pkgname}_${ARCH}_${OHOS_SDK_VER}_test.log + +# 测试前的准备, 如果不需要可以不写。 +checkprepare(){ + return 0 +} + +# 在OH环境执行测试的接口 +openharmonycheck() { + res=0 # 记录返回值 + cd ${builddir}/test # 进入到测试目录 + #gcc -I$tmppath/$ARCH/include -L$tmppath/$ARCH/lib -levent-2.1 -lbevent_core-2.1 -levent_extra-2.1 -lbevent_openssl-2.1 -levent_pthreads-2.1 -levent *.c + #gcc -I${LYCIUM_THIRDPARTY_ROOT}/${pkgname}/${builddir}/include -I${LYCIUM_THIRDPARTY_ROOT}/${pkgname}/${builddir} -I${LYCIUM_THIRDPARTY_ROOT}/${pkgname}/${builddir}/test -L$tmppath/$ARCH/lib *.c -levent-2.1 -lbevent_core-2.1 -levent_extra-2.1 -lbevent_openssl-2.1 -levent_pthreads-2.1 -levent + ./test.sh > ${logfile} 2>&1 # 执行测试命令并将测试结果导出到${logfile},测试命令根据每个库的真实情况填写 + ./rpcgen_wrapper.sh >> ${logfile} 2>&1 # 执行测试命令并将测试结果导出到${logfile},测试命令根据每个库的真实情况填写 + res=$? # 记录测试结果返回值 + cd $OLDPWD # 返回上一次目录 + + return $res # 返回测试值 +} diff --git a/thirdparty/libevent/OAT.xml b/thirdparty/libevent/OAT.xml new file mode 100644 index 0000000000000000000000000000000000000000..5663c536ddecb545bb824af7a320605c8072e4f4 --- /dev/null +++ b/thirdparty/libevent/OAT.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/thirdparty/libevent/README.OpenSource b/thirdparty/libevent/README.OpenSource new file mode 100644 index 0000000000000000000000000000000000000000..b3e2bb2468b2af94abab027854c0ac3638790b35 --- /dev/null +++ b/thirdparty/libevent/README.OpenSource @@ -0,0 +1,11 @@ +[ + { + "Name": "libevent", + "License": "the 3-clause (or "modified") BSD license" "Apache-2.0", + "License File": "LICENSE", + "Version Number": "libevent-2.1.12", + "Owner": "guowenkai@h-partners.com", + "Upstream URL": "https://github.com/libevent/libevent/releases/tag/release-2.1.12-stable", + "Description": ""Libevent supports /dev/poll, kqueue(2), event ports, POSIX select(2), Windows select(), poll(2), and epoll(4). Libevent additionally provides a sophisticated framework for buffered network IO, with support for sockets, filters, rate-limiting, SSL, zero-copy file transmission, and IOCP. Libevent includes support for several useful protocols, including DNS, HTTP, and a minimal RPC framework. + } +] diff --git a/thirdparty/libevent/README_zh.md b/thirdparty/libevent/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..720d68bcb83aaa1ba633f9643985c015ad655509 --- /dev/null +++ b/thirdparty/libevent/README_zh.md @@ -0,0 +1,16 @@ +# libevent三方库说明 +## 功能简介 + + Libevent支持devpoll、kqueue(2个)、事件端口、POSIX select(2个)、Windows select(2个)、poll(2个)和epoll(4个)。Libevent还为缓冲网络IO提供了一个完善的框架,支持套接字、过滤器、速率限制、SSL、零拷贝文件传输和IOCP。 + + ## 使用约束 +- IDE版本:DevEco Studio 4.1.3.313 +- SDK版本:ohos_sdk_public 4.1.0.36 (API Version 11 Release) +- 三方库版本:libevent-2.1.12 +- 当前适配的功能:支持devpoll、kqueue(2个)、事件端口、POSIX select(2个)、Windows select(2个)、poll(2个)、epoll(4个)、套接字、过滤器、速率限制、SSL、零拷贝文件传输和IOCP + + ## 集成方式 +[应用包hap集成](docs/hap_integrate.md) + + + diff --git a/thirdparty/libevent/SHA512SUM b/thirdparty/libevent/SHA512SUM index 5faf7a6c93e108a6b980d4536fb42f194246c96a..bf9321236c1a73601a19b037c151d48863af8ce3 100644 --- a/thirdparty/libevent/SHA512SUM +++ b/thirdparty/libevent/SHA512SUM @@ -1 +1 @@ -5d6c6f0072f69a68b190772d4c973ce8f33961912032cdc104ad0854c0950f9d7e28bc274ca9df23897937f0cd8e45d1f214543d80ec271c5a6678814a7f195e libevent-release-2.1.12-stable.tar.gz +04e18796815c67ed4784d8aaa0c49cc4a94502ba5bc839b29a8be755735a102090ec6f3cc0b72809c8fed59de985dcf650a58be00a0312728e91caaa5ea63984 release-2.1.12-stable.zip diff --git a/thirdparty/libevent/docs/hap_integrate.md b/thirdparty/libevent/docs/hap_integrate.md new file mode 100644 index 0000000000000000000000000000000000000000..e1996139b32acd76edd3e3fa50252bf7b6267723 --- /dev/null +++ b/thirdparty/libevent/docs/hap_integrate.md @@ -0,0 +1,82 @@ +# libevent集成到应用hap + +本库是在HUAWEI Mate 60上基于OpenHarmony4.1 Release版本的镜像验证的。 + +## 开发环境 + +- [开发环境准备](../../../docs/hap_integrate_environment.md) + +## 编译三方库 + +- 下载本仓库 + + ```shell + git clone https://gitee.com/openharmony-sig/tpc_c_cplusplus.git --depth=1 + ``` + +- 三方库目录结构 + + ```shell + tpc_c_cplusplus/thirdparty/libevent #三方库libevent的目录结构如下 + ├── docs #三方库相关文档的文件夹 + ├── HPKBUILD #构建脚本 + ├── HPKCHECK #测试脚本 + ├── SHA512SUM #三方库校验文件 + ├── README.OpenSource #说明三方库源码的下载地址,版本、license等信息 + ├── README_zh.md + ``` + +- 在lycium目录下编译三方库 + + 编译环境的搭建参考[准备三方库构建环境](../../../lycium/README.md#1编译环境准备) + + ```shell + cd lycium + ./build.sh libevent + ``` + +- 三方库头文件及生成的库 + + 在lycium目录下会生成usr目录,该目录下存在已编译完成的32位和64位三方库 + + ```shell + libevent/arm64-v8a libevent/armeabi-v7a + ``` + +- [测试三方库](#测试三方库) + +## 应用中使用三方库 + +- 需要将libcups.so相关目录拷贝到entry/libs目录下 +- ![thirdparty_install_dir](pic/cups_so_usage_for_ide.png) + +- 在IDE的cpp目录下新增thirdparty目录,将编译生成的库拷贝到该目录下,如下图所示 + + ![thirdparty_install_dir](pic/cups_usage_for_ide.png) + +- 在最外层(cpp目录下)CMakeLists.txt中添加如下语句 + + ```cmake + #将三方库的头文件加入工程中 + target_include_directories(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libevent/${OHOS_ARCH}/include) + target_link_libraries(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/${OHOS_ARCH}/lib/libevent.so) + ``` + + +## 测试三方库 + +三方库的测试使用原库自带的测试用例来做测试,[准备三方库测试环境](../../../lycium/README.md#3ci环境准备) + + + +进入到对应版本build构建目录下的test目录,根据测试平台使用clang命令生产相应的二进制文件,执行如下命令 ./tests.sh + + ![cups_test](pic/test.png) + + ![cups_test](pic/test_result.png) + +## 参考资料 + +- [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/libevent/docs/pic/cups_so_usage_for_ide.png b/thirdparty/libevent/docs/pic/cups_so_usage_for_ide.png new file mode 100644 index 0000000000000000000000000000000000000000..ab2d401a5c0ad47ca190ff5047eea12c9aa24ef3 Binary files /dev/null and b/thirdparty/libevent/docs/pic/cups_so_usage_for_ide.png differ diff --git a/thirdparty/libevent/docs/pic/cups_usage_for_ide.png b/thirdparty/libevent/docs/pic/cups_usage_for_ide.png new file mode 100644 index 0000000000000000000000000000000000000000..f43710affc6764097d18ecd8b6317b121bd8fd2a Binary files /dev/null and b/thirdparty/libevent/docs/pic/cups_usage_for_ide.png differ diff --git a/thirdparty/libevent/docs/pic/test.png b/thirdparty/libevent/docs/pic/test.png new file mode 100644 index 0000000000000000000000000000000000000000..b49141507d8a319d6811fa74b0d843acb9854591 Binary files /dev/null and b/thirdparty/libevent/docs/pic/test.png differ diff --git a/thirdparty/libevent/docs/pic/test_result.png b/thirdparty/libevent/docs/pic/test_result.png new file mode 100644 index 0000000000000000000000000000000000000000..343ba176e3cd61f4ded1990c14811ef113e47055 Binary files /dev/null and b/thirdparty/libevent/docs/pic/test_result.png differ