From e649fb342273b2a99f13798e237d27ce8737f3e7 Mon Sep 17 00:00:00 2001 From: xuxinguo <554249301@qq.com> Date: Fri, 19 Apr 2024 14:18:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=89=E6=96=B9=E5=BA=93lu?= =?UTF-8?q?a?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xuxinguo --- thirdparty/lua/HPKBUILD | 88 +++++++++++++++++++++++++++ thirdparty/lua/HPKCHECK | 30 +++++++++ thirdparty/lua/OAT.xml | 16 +++++ thirdparty/lua/README.OpenSource | 11 ++++ thirdparty/lua/README_zh.md | 11 ++++ thirdparty/lua/SHA512SUM | 1 + thirdparty/lua/docs/hap_integrate.md | 71 +++++++++++++++++++++ thirdparty/lua/docs/pic/lua_test.png | Bin 0 -> 1974 bytes 8 files changed, 228 insertions(+) create mode 100644 thirdparty/lua/HPKBUILD create mode 100644 thirdparty/lua/HPKCHECK create mode 100644 thirdparty/lua/OAT.xml create mode 100644 thirdparty/lua/README.OpenSource create mode 100644 thirdparty/lua/README_zh.md create mode 100644 thirdparty/lua/SHA512SUM create mode 100644 thirdparty/lua/docs/hap_integrate.md create mode 100644 thirdparty/lua/docs/pic/lua_test.png diff --git a/thirdparty/lua/HPKBUILD b/thirdparty/lua/HPKBUILD new file mode 100644 index 00000000..b760e5de --- /dev/null +++ b/thirdparty/lua/HPKBUILD @@ -0,0 +1,88 @@ +# Copyright (c) 2024 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: xuxingguo <554249301@qq.com> +# Maintainer: xuxingguo <554249301@qq.com> + +pkgname=lua +pkgver=v5.4.6 +pkgrel=0 +pkgdesc="Lua is a powerful, efficient, lightweight, embeddable scripting language." +url="https://www.lua.org" +archs=("armeabi-v7a" "arm64-v8a") +license=("MIT License") +depends=() +makedepends=() +source="https://github.com/lua/$pkgname/archive/refs/tags/$pkgver.tar.gz" + +downloadpackage=true +autounpack=true +buildtools="make" + +builddir=$pkgname-${pkgver:1} +packagename=$builddir.tar.gz + +source envset.sh + +cc= +ar= +ld= +prepare() { + cp -rf $builddir $builddir-$ARCH-build/ + if [ $ARCH == "armeabi-v7a" ];then + setarm32ENV + cc=${OHOS_SDK}/native/llvm/bin/arm-linux-ohos-clang + elif [ $ARCH == "arm64-v8a" ];then + setarm64ENV + cc=${OHOS_SDK}/native/llvm/bin/aarch64-linux-ohos-clang + else + echo "$ARCH not support" + return -1 + fi + + ld=${OHOS_SDK}/native/llvm/bin/ld.lld + ar=${OHOS_SDK}/native/llvm/bin/llvm-ar +} + +build() { + $MAKE CC=${cc} LD=${ld} CFLAGS=-DLUA_USE_LINUX MYLIBS=-ldl -j4 -C $builddir-$ARCH-build VERBOSE=1 > \ + $builddir-$ARCH-build/$buildlog 2>&1 + ret=$? + return $ret +} + +package() { + # lua 5.4.6不支持make install,故需要copy文件 + mkdir -p $LYCIUM_ROOT/usr/$pkgname/$ARCH/include + mkdir -p $LYCIUM_ROOT/usr/$pkgname/$ARCH/lib + mkdir -p $LYCIUM_ROOT/usr/$pkgname/$ARCH/bin + find ./$builddir-$ARCH-build -name '*.so' -exec cp -af {} $LYCIUM_ROOT/usr/$pkgname/$ARCH/lib/ \; + find ./$builddir-$ARCH-build -name 'liblua.a' -exec cp -af {} $LYCIUM_ROOT/usr/$pkgname/$ARCH/lib/ \; + find ./$builddir-$ARCH-build -name 'lua' -exec cp -af {} $LYCIUM_ROOT/usr/$pkgname/$ARCH/bin/ \; + find ./$builddir-$ARCH-build -name 'luac' -exec cp -af {} $LYCIUM_ROOT/usr/$pkgname/$ARCH/bin/ \; + find ./$builddir-$ARCH-build -name '*.h' -exec cp -af {} $LYCIUM_ROOT/usr/$pkgname/$ARCH/include/ \; +} + +recoverpkgbuildenv() { + unset cc ar ld +} + +check() { + echo "The test must be on an OpenHarmony device!" +} + +# 清理环境 +cleanbuild() { + rm -rf $builddir-armeabi-v7a-build $builddir-arm64-v8a-build + rm -rf $builddir # $packagename +} diff --git a/thirdparty/lua/HPKCHECK b/thirdparty/lua/HPKCHECK new file mode 100644 index 00000000..6388a878 --- /dev/null +++ b/thirdparty/lua/HPKCHECK @@ -0,0 +1,30 @@ +# Copyright (c) 2024 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: xuxingguo <554249301@qq.com> +# Maintainer: xuxingguo <554249301@qq.com> + +source HPKBUILD > /dev/null 2>&1 # 导入HPKBUILD文件 +logfile=${LYCIUM_THIRDPARTY_ROOT}/${pkgname}/${pkgname}_${ARCH}_${OHOS_SDK_VER}_test.log + +# 在OH环境执行测试的接口 +openharmonycheck() { + res=0 + cd $builddir + + ${LYCIUM_ROOT}/../lycium/usr/lua/${ARCH}/bin/lua -v > ${logfile} 2>&1 + res=$? + rm -rf /usr/local/lib + cd $OLDPWD + return $res +} \ No newline at end of file diff --git a/thirdparty/lua/OAT.xml b/thirdparty/lua/OAT.xml new file mode 100644 index 00000000..eeb1f946 --- /dev/null +++ b/thirdparty/lua/OAT.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/thirdparty/lua/README.OpenSource b/thirdparty/lua/README.OpenSource new file mode 100644 index 00000000..7ee6d8f4 --- /dev/null +++ b/thirdparty/lua/README.OpenSource @@ -0,0 +1,11 @@ +[ + { + "Name": "lua", + "License": "MIT license", + "License File": "readme.html", + "Version Number": "v5.4.6", + "Owner": "xiafeng@huawei.com", + "Upstream URL": "https://www.lua.org", + "Description": "Lua is a powerful, efficient, lightweight, embeddable scripting language." + } +] \ No newline at end of file diff --git a/thirdparty/lua/README_zh.md b/thirdparty/lua/README_zh.md new file mode 100644 index 00000000..9ee3ab76 --- /dev/null +++ b/thirdparty/lua/README_zh.md @@ -0,0 +1,11 @@ +# lua三方库说明 +## 功能简介 +Lua是一种强大、高效、轻量级、可嵌入的脚本语言。它支持过程编程、面向对象编程、函数式编程、数据驱动编程和数据描述 +## 使用约束 +- IDE版本:DevEco Studio 3.1 Release +- SDK版本:ohos_sdk_public 4.0.8.1 (API Version 10 Release) +- 三方库版本:v5.4.6 +- 当前适配的功能:支持过程编程、面向对象编程、函数式编程、数据驱动编程和数据描述 + +## 集成方式 ++ [应用hap包集成](docs/hap_integrate.md) diff --git a/thirdparty/lua/SHA512SUM b/thirdparty/lua/SHA512SUM new file mode 100644 index 00000000..f41a7025 --- /dev/null +++ b/thirdparty/lua/SHA512SUM @@ -0,0 +1 @@ +6582711740695500cf291a4e32061d74b046839a4128f2c135ceb27929a840ab85429342ef9b5f0221dffa3e7e4955c42fccdfd501822d42291bc9728cb4b4ae lua-5.4.6.tar.gz \ No newline at end of file diff --git a/thirdparty/lua/docs/hap_integrate.md b/thirdparty/lua/docs/hap_integrate.md new file mode 100644 index 00000000..6ea65874 --- /dev/null +++ b/thirdparty/lua/docs/hap_integrate.md @@ -0,0 +1,71 @@ +# lua 集成到应用hap + +本库是在RK3568开发板上基于OpenHarmony3.2 Release版本的镜像验证的,如果是从未使用过RK3568,可以先查看[润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld)。 + +## 开发环境 + +- [开发环境准备](../../../docs/hap_integrate_environment.md) + +## 编译三方库 + +- 下载本仓库 + + ```shell + git clone https://gitee.com/openharmony-sig/tpc_c_cplusplus.git --depth=1 + ``` + +- 三方库目录结构 + + ```shell + tpc_c_cplusplus/thirdparty/lua #三方库lua的目录结构如下 + ├── docs #三方库相关文档的文件夹 + ├── HPKBUILD #构建脚本 + ├── HPKCHECK #测试脚本 + ├── SHA512SUM #三方库校验文件 + ├── README.OpenSource #说明三方库源码的下载地址,版本,license等信息 + ├── README_zh.md #三方库简介 + ``` + +- 在lycium目录下编译三方库 + + 编译环境的搭建参考[准备三方库构建环境](../../../lycium/README.md#1编译环境准备) + + ```shell + cd lycium + ./build.sh lua + ``` + +- 三方库头文件及生成的库 + + 在lycium目录下会生成usr目录,该目录下存在已编译完成的32位和64位三方库 + + ```shell + lua/arm64-v8a lua/armeabi-v7a + ``` + +- [测试三方库](#测试三方库) + +## 应用中使用三方库 + +lua最终生成的是lua可执行文件,无需引入测试编译,引用原生库的测试逻辑即可。 + +## 测试三方库 + +- 将busybox推送到开发板 ,具体步骤如下: + + ```sh + hdc_std.exe file send lua /data/ ## 将测试资源推送到板子 + hdc_std.exe shell ## 进入设备系统 + cd /data + chmod a+x lua ## 设置busybox可执行权限 + ``` + +将lua推送开发板后,可以直接运行lua -v指令并可看到其执行结果,如下图所示: + ![lua_test](pic/lua_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/lua/docs/pic/lua_test.png b/thirdparty/lua/docs/pic/lua_test.png new file mode 100644 index 0000000000000000000000000000000000000000..ec4601e4dc92bfe6f453cf9a40727ab4aed97a00 GIT binary patch literal 1974 zcmb`IYfw{X9>(8X%EclCvq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