惯例先放hello world

#2020征文-开发板#移植lua到鸿蒙—在鸿蒙上用lua跑hello world_lua

本项目地址: ​​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:///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


编译脚本

创建编译脚本文件

cd ~/code/ohos/lua
touch
chmod +x

文件内容如下

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
./
# 看到 ohos ipcamera_hi3516dv300 build success! build success! 就编译成功了。


编译后软件在鸿蒙的 ./out/ipcamera_hi3516dv300/bin/camera_app  

脚本会把lua单独打包出来  

单独的lua可执行文件在bin目录


 文章后续内容和附件可以点击下面的原文链接前往学习

原文链接:   ​​https://harmonyos.51cto.com/posts/1970#bkwz​


​想了解更多内容,请访问:​

​51CTO和华为官方合作共建的鸿蒙技术社区​

​https://harmonyos.51cto.com/#bkwz​


#2020征文-开发板#移植lua到鸿蒙—在鸿蒙上用lua跑hello world_lua_02