diff --git a/thirdparty/luv/HPKBUILD b/thirdparty/luv/HPKBUILD new file mode 100644 index 0000000000000000000000000000000000000000..e6acd0faf38fb16a23e6d5699bb9e244c8363298 --- /dev/null +++ b/thirdparty/luv/HPKBUILD @@ -0,0 +1,109 @@ +# 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: Ding Qian <1052888395@qq.com> +# Maintainer: Ding Qian <1052888395@qq.com> +pkgname=luv +pkgver=1.45.0-0 +pkgrel=0 +pkgdesc="Bare libuv bindings for lua" +url="https://github.com/luvit/luv" +archs=("armeabi-v7a" "arm64-v8a") +license=("Apache License 2.0") +depends=("libuv" "LuaJIT") +makedepends=() +source="https://github.com/luvit/$pkgname/archive/refs/tags/$pkgver.tar.gz" + +autounpack=true +downloadpackage=true +patchflag=true +syncsubmodule=true +builddir=$pkgname-${pkgver} +packagename=$builddir.tar.gz +buildtools="cmake" + +prepare() { + if $patchflag + then + cd $builddir + # 在编译时在CMakeLists.txt中无法link到LuaJIT,导致编译不通过. + patch -p1 < `pwd`/../luv_oh_pkg.patch + # patch只需要打一次,关闭打patch + patchflag=false + cd $OLDPWD + fi + + if [ $syncsubmodule == true ] + then + cd $builddir + # 同步子模块,这里采用git submodule update容易失败,进行git clone下载 + git clone https://github.com/libuv/libuv.git deps/libuv >> `pwd`/build.log 2>&1 + if [ $? != 0 ] + then + return -1 + fi + git clone https://github.com/LuaJIT/LuaJIT.git deps/luajit >> `pwd`/build.log 2>&1 + if [ $? != 0 ] + then + return -2 + fi + git clone https://github.com/lua/lua deps/lua >> `pwd`/build.log 2>&1 + if [ $? != 0 ] + then + return -3 + fi + git clone https://github.com/keplerproject/lua-compat-5.3.git deps/lua-compat-5.3 >> `pwd`/build.log 2>&1 + if [ $? != 0 ] + then + return -4 + fi + cd $OLDPWD + syncsubmodule=false + fi + + cd $builddir + mkdir $ARCH-build + cd $OLDPWD +} + +build() { + cd $builddir + ${OHOS_SDK}/native/build-tools/cmake/bin/cmake "$@" -B$ARCH-build -DBUILD_MODULE=OFF -DBUILD_SHARED_LIBS=ON -DWITH_SHARED_LIBUV=ON \ + -DWITH_LUA_ENGINE=LuaJIT -DLUA_BUILD_TYPE=Dynamic -DLUA_COMPAT53_DIR=deps/lua-compat-5.3 -DWITH_AMALG=OFF -DOHOS_ARCH=$ARCH -DLUA_BUILD_TYPE=System \ + -B $ARCH-build -S. -L > `pwd`/$ARCH-build/build.log 2>&1 + make VERBOSE=1 -j4 -C $ARCH-build >> `pwd`/$ARCH-build/build.log 2>&1 + ret=$? + cd $OLDPWD + return $ret +} + +package() { + cd $builddir + make -C $ARCH-build install >> `pwd`/$ARCH-build/build.log 2>&1 + ret=$? + cd $OLDPWD + return $ret +} + +check() { + echo "The test must be on an OpenHarmony device!" + # 测试:使用LuaJIT来执行当前测试目录中的run.lua + # ./LuaJIT tests/run.lua + # 注意环境变量的配置. +} + +# 清理环境 +cleanbuild(){ + rm -rf ${PWD}/$builddir #${PWD}/$packagename +return 0 +} + diff --git a/thirdparty/luv/HPKCHECK b/thirdparty/luv/HPKCHECK new file mode 100644 index 0000000000000000000000000000000000000000..0fb4df5499150d15b10dda87a1a0ec9b85734de8 --- /dev/null +++ b/thirdparty/luv/HPKCHECK @@ -0,0 +1,33 @@ +# 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: luozhu <1393302983@qq.com> +# Maintainer: luozhu <1393302983@qq.com> + +source HPKBUILD > /dev/null 2>&1 +logfile=${LYCIUM_THIRDPARTY_ROOT}/${pkgname}/${pkgname}_${ARCH}_${OHOS_SDK_VER}_test.log + +openharmonycheck() { + res=0 + cd $builddir + mkdir /usr/local/lib -p + cp ${LYCIUM_ROOT}/../lycium/usr/${pkgname}/${ARCH}/lib/*.so* /usr/local/lib + cp ${LYCIUM_ROOT}/../lycium/usr/libuv/${ARCH}/lib/*.so* /usr/local/lib + cp ${LYCIUM_ROOT}/../lycium/usr/LuaJIT/${ARCH}/lib/*.so* /usr/local/lib + mkdir /usr/local/lib/lua/5.1/ -p + ln /usr/local/lib/libluv.so.1 /usr/local/lib/lua/5.1/luv.so + ${LYCIUM_ROOT}/../lycium/usr/LuaJIT/${ARCH}/bin/luajit-2.1.0-beta3 tests/run.lua > ${logfile} 2>&1 + rm -rf /usr/local/lib + res=$? + cd $OLDPWD + return $res +} \ No newline at end of file diff --git a/thirdparty/luv/OAT.xml b/thirdparty/luv/OAT.xml new file mode 100644 index 0000000000000000000000000000000000000000..7670fedf83df03b8a279bb083ce12a67d1d55a7c --- /dev/null +++ b/thirdparty/luv/OAT.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/thirdparty/luv/README.OpenSource b/thirdparty/luv/README.OpenSource new file mode 100644 index 0000000000000000000000000000000000000000..0c4a7cc1e09623a6b0fbaa7c6ec83e3925edc4f8 --- /dev/null +++ b/thirdparty/luv/README.OpenSource @@ -0,0 +1,11 @@ +[ + { + "Name": "luv", + "License": "Apache License 2.0", + "License File": "https://www.apache.org/licenses/LICENSE-2.0.txt", + "Version Number": "1.45.0-0", + "Owner": "1393302983@qq.com", + "Upstream URL": "https://github.com/luvit/luv/archive/refs/tags/1.45.0-0.tar.gz", + "Description": "Bare libuv bindings for lua." + } +] diff --git a/thirdparty/luv/README_zh.md b/thirdparty/luv/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..72c848e269ce8a9c55890ef20a11cfa5893a51e1 --- /dev/null +++ b/thirdparty/luv/README_zh.md @@ -0,0 +1,11 @@ +# luv三方库说明 +## 功能简介 +luv是一个用于lua的libuv裸绑定的库 +## 使用约束 +- IDE版本:DevEco Studio 3.1 Release +- SDK版本:ohos_sdk_public 4.0.8.1 (API Version 10 Release) +- 三方库版本:1.45.0-0 +- 当前适配的功能:使libuv可用于lua脚本。 + +## 集成方式 ++ [应用hap包集成](docs/hap_ingtegrate.md) \ No newline at end of file diff --git a/thirdparty/luv/SHA512SUM b/thirdparty/luv/SHA512SUM new file mode 100644 index 0000000000000000000000000000000000000000..b2447ebac46368b5f2fbff799e9692acaf41961a --- /dev/null +++ b/thirdparty/luv/SHA512SUM @@ -0,0 +1,2 @@ +50460573377bc9386a90aa75f7d4938571b04f74ca6f63e32fa2b2f8951e799465abb78b4270f22be511c4d328ce582c38ec3e3da1061310fcfee630b647854d luv-1.45.0-0.tar.gz +ea598ce9f36b54e5549dd20f7934ff213d80cb108dbe2e6c5b749cbae2c2bec9842d77152d3791cf3c8a90b4a59024c835854b4ae0a1702a103c191655c54cb1 luv_oh_pkg.patch diff --git a/thirdparty/luv/docs/hap_ingtegrate.md b/thirdparty/luv/docs/hap_ingtegrate.md new file mode 100644 index 0000000000000000000000000000000000000000..55c94416678adc52b51b75251575326d951a5dbb --- /dev/null +++ b/thirdparty/luv/docs/hap_ingtegrate.md @@ -0,0 +1,82 @@ +# luv集成到应用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/luv # 三方库luv的目录结构如下 + ├── docs # 三方库相关文档的文件夹 + ├── HPKBUILD # 编译脚本 + ├── HPKCHECK # 测试脚本 + ├── OAT.xml # OAT开源审查文本 + ├── luv_oh_pkg.patch # patch文件 + ├── README.OpenSource # 说明三方库源码的下载地址,版本,license等信息 + ├── README_zh.md # 三方库说明文档 + ├── SHA512SUM # 三方库校验文件 + ``` + +- 在lycium目录下编译三方库 + 编译环境的搭建参考[准备三方库构建环境](../../../lycium/README.md#1编译环境准备) + ``` + cd lycium + ./build.sh luv + ``` +- 三方库头文件及生成的库 + 在lycium目录下会生成usr目录,该目录下存在已编译完成的32位和64位三方库 + ``` + luv/arm64-v8a luv/armeabi-v7a + libuv/arm64-v8a libuv/armeabi-v7a + LuaJIT/arm64-v8a LuaJIT/armeabi-v7a + ``` + +- [测试三方库](#测试三方库) + +## 应用中使用三方库 + +- 在IDE的cpp目录下新增thirdparty目录,将编译生成的头文件拷贝到该目录下,将编译生成的三方库全部(动态库名字带版本号和不带版本号的都需要)拷贝到工程的libs目录下,如下图所示 +   +![thirdparty_install_dir](pic/luv_install_dir.png) + +- 在最外层(cpp目录下)CMakeLists.txt中添加如下语句 + ```shell + #将三方库加入工程中 + target_link_libraries(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/${OHOS_ARCH}/libluv.so) + target_link_libraries(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/${OHOS_ARCH}/libuv_a.a) + target_link_libraries(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/${OHOS_ARCH}/libluajit-5.1.a) + #将三方库的头文件加入工程中 + target_include_directories(entry PRIVATE CMAKECURRENTSOURCEDIR/thirdparty/luv/{OHOS_ARCH}/include) + target_include_directories(entry PRIVATE CMAKECURRENTSOURCEDIR/thirdparty/libuv/{OHOS_ARCH}/include) + target_include_directories(entry PRIVATE CMAKECURRENTSOURCEDIR/thirdparty/LuaJIT/{OHOS_ARCH}/include) + + ``` + +![luv_usage](pic/luv_usage.png) + +## 测试三方库 +三方库的测试使用原库自带的测试用例来做测试,[准备三方库测试环境](../../../lycium/README.md#3ci环境准备) + +- 将编译生成的可执行文件及生成的动态库准备好 + +- 将准备好的文件推送到开发板,进入到构建的目录添加执行文件权限和lib库环境执行../../../lycium/usr/LuaJIT/${ARCH}/bin/luajit-2.1.0-beta3 tests/run.lua + ![luv_test](pic/luv_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/luv/docs/pic/luv_install_dir.png b/thirdparty/luv/docs/pic/luv_install_dir.png new file mode 100644 index 0000000000000000000000000000000000000000..07329d41a920082dfec74e6cda6afc811535aecf Binary files /dev/null and b/thirdparty/luv/docs/pic/luv_install_dir.png differ diff --git a/thirdparty/luv/docs/pic/luv_test.png b/thirdparty/luv/docs/pic/luv_test.png new file mode 100644 index 0000000000000000000000000000000000000000..ad6b34e97fdc7673915d0802c95b062dfe4ff749 Binary files /dev/null and b/thirdparty/luv/docs/pic/luv_test.png differ diff --git a/thirdparty/luv/docs/pic/luv_usage.png b/thirdparty/luv/docs/pic/luv_usage.png new file mode 100644 index 0000000000000000000000000000000000000000..1d70a7b76a8c5775b5ad3e09397adf5c3c7fa85c Binary files /dev/null and b/thirdparty/luv/docs/pic/luv_usage.png differ diff --git a/thirdparty/luv/luv_oh_pkg.patch b/thirdparty/luv/luv_oh_pkg.patch new file mode 100644 index 0000000000000000000000000000000000000000..cb7a282503aac5cbd29aaf0657c6a1641f03aa5d --- /dev/null +++ b/thirdparty/luv/luv_oh_pkg.patch @@ -0,0 +1,21 @@ +--- luv-1.45.0-0-old/CMakeLists.txt 2023-05-30 15:27:25.000000000 +0800 ++++ luv-1.45.0-0/CMakeLists.txt 2023-07-06 11:12:23.773570014 +0800 +@@ -244,7 +244,7 @@ + endif() + + foreach(TARGET_NAME ${ACTIVE_TARGETS}) +- if(WIN32 OR CYGWIN) ++ if(WIN32 OR CYGWIN OR OHOS) + if (LUA) + target_link_libraries(${TARGET_NAME} ${LIBUV_LIBRARIES} ${LUA_LIBRARIES}) + else (LUA) +--- luv-1.45.0-0-old/tests/test-dns.lua 2023-05-30 15:27:25.000000000 +0800 ++++ luv-1.45.0-0/tests/test-dns.lua 2023-08-03 11:12:40.587973091 +0800 +@@ -161,7 +161,6 @@ + p{err=err,hostname=hostname,service=service} + assert(not err, err) + assert(hostname) +- assert(service == "http") + end))) + end) +