#2020征文-开发板#移植lua到鸿蒙—在鸿蒙上用lua跑hello world 原创 精华

发布于 2020-12-3 21:28
浏览
4收藏


惯例先放hello world

 #2020征文-开发板#移植lua到鸿蒙—在鸿蒙上用lua跑hello world-开源基础软件社区

本项目地址: https://gitee.com/hiharmonica/lua
下载能在鸿蒙上跑的二进制文件


准备环境
1. 安装 docker
2. docker pull ystyle/open-harmony

ps: 本文使用与鸿蒙系统一同编译的方法。 如果自己有本地环境,可以把lua项目放鸿蒙代码目录里(或者使用软接连)

 

下载lua官方代码

mkdir -p ~/code/ohos/
cd ~/code/ohos/
git clone https://github.com/lua/lua.git

编写BUILD.gn文件
因为要与系统一起编译, 为了方便,直接用替换掉示例的方法,这样就只需要写一个BUILD.gn就好了

# Copyright (c) 2020 YSTYLE(lxy5266@live.com)
# 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.

import("//build/lite/config/component/lite_component.gni")
import("//build/lite/ndk/ndk.gni")

static_library("hello_world") {
    sources = [
        "lapi.c",
        "lauxlib.c",
        "lbaselib.c",
        "lcode.c",
        "lcorolib.c",
        "lctype.c",
        "ldblib.c",
        "ldebug.c",
        "ldo.c",
        "ldump.c",
        "lfunc.c",
        "lgc.c",
        "linit.c",
        "liolib.c",
        "llex.c",
        "lmathlib.c",
        "lmem.c",
        "loadlib.c",
        "lobject.c",
        "lopcodes.c",
        "loslib.c",
        "lparser.c",
        "lstate.c",
        "lstring.c",
        "lstrlib.c",
        "ltable.c",
        "ltablib.c",
        "ltests.c",
        "ltm.c",
        "lua.c",
        "lundump.c",
        "lutf8lib.c",
        "lvm.c",
        "lzio.c"
    ]

    include_dirs = [
        "include",
    ]
}

lite_component("camera_app") {
    target_type = "executable"

    features = [
        ":hello_world",
    ]
}

ndk_lib("app_sample") {
    deps = [
        ":hello_world"
    ]
    head_files = [
        "include"
    ]
}

static_library里的source参照lua/makefile

 

编译脚本
创建编译脚本build-ohos.sh文件

cd ~/code/ohos/lua
touch build-ohos.sh
chmod +x build-ohos.sh

文件内容如下

set -e
rm -rf ./out ./bin
docker run --rm -ti \
  -e HARDWARE=ipcamera_hi3516dv300 \
  -v ${PWD}/out:/OpenHarmony/out \
  -v ${PWD}:/OpenHarmony/applications/sample/camera/app \
  ystyle/open-harmony
mkdir -p ./bin
cp ./out/ipcamera_hi3516dv300/bin/camera_app ./bin/lua
tar -zcf lua-5.4.2-ohos.tar.gz ./bin
echo 'build success!'


与鸿蒙一起编译,这里使用我之前的docker镜像

cd ~/code/ohos/lua
./build-ohos.sh
# 看到 ohos ipcamera_hi3516dv300 build success! build success! 就编译成功了。

 

编译后软件在鸿蒙的 ./out/ipcamera_hi3516dv300/bin/camera_app  
脚本会把lua单独打包出来  
单独的lua可执行文件在bin目录 

 

### 演示
 #2020征文-开发板#移植lua到鸿蒙—在鸿蒙上用lua跑hello world-开源基础软件社区

 #2020征文-开发板#移植lua到鸿蒙—在鸿蒙上用lua跑hello world-开源基础软件社区

 #2020征文-开发板#移植lua到鸿蒙—在鸿蒙上用lua跑hello world-开源基础软件社区

 #2020征文-开发板#移植lua到鸿蒙—在鸿蒙上用lua跑hello world-开源基础软件社区

本文链接:https://ystyle.top/2020/11/07/porting-Lua-to-openharmony/
博客内容遵循 知识共享 署名 - 非商业性 - 相同方式共享 4.0协议

©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
已于2020-12-16 21:59:08修改
4
收藏 4
回复
举报
回复
添加资源
添加资源将有机会获得更多曝光,你也可以直接关联已上传资源 去关联
    相关推荐