HarmonyOS实战开发-方舟运行时使用指南

方舟编译器简介

方舟编译器(ArkCompiler)是为支持多种编程语言、多种芯片平台的联合编译、运行而设计的统一编译运行时平台。

  • ArkCompiler主要分成两个部分:编译工具链与运行时。 ArkCompiler eTS Runtime主要由四个子系统组成:Core
  • Subsystem、Execution Subsystem、Compiler Subsystem、Runtime subsystem。
  • ArkCompiler 的设计特点:原生支持类型、并发模型优化与并发API、安全。

环境搭建和编译

环境配置

搭建Ubuntu环境

  • 初始环境软件安装(Ubuntu版本推荐18.04或20.04)
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install git-lfs git bison flex gnupg build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses-dev x11proto-core-dev libx11-dev libc++1 lib32z1-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip m4 libtinfo5 bc npm genext2fs liblz4-tool libssl-dev ruby openjdk-8-jre-headless gdb python3-pip libelf-dev libxcursor-dev libxrandr-dev libxinerama-dev

代码编译

注意:下列命令需在源码根目录下执行

1.首次编译:

./build.sh --product-name rk3568

2.首次编译后增量编译方舟运行时:

编译linux-x86版本:

./build.sh --product-name rk3568 --build-target ark_js_host_linux_tools_packages

编译oh-arm64版本:

./build.sh --product-name rk3568 --gn-args use_musl=true --target-cpu arm64 --build-target ark_js_packages

编译oh-arm32版本:

./build.sh --product-name rk3568 --build-target  ark_js_packages

3.首次编译后增量编译方舟前端:

./build.sh --product-name rk3568 --build-target ets_frontend_build

说明:上述编译命令为release版本,编译debug版本需增加编译选项:–gn-args is_debug=true。

方舟相关的二进制文件在如下路径:

out/rk3568/arkcompiler/runtime_core/
out/rk3568/arkcompiler/ets_frontend/
out/rk3568/arkcompiler/ets_runtime/
out/rk3568/clang_x64/arkcompiler/runtime_core/
out/rk3568/clang_x64/arkcompiler/ets_frontend/
out/rk3568/clang_x64/arkcompiler/ets_runtime

开发实例

本章节将介绍基于方舟运行时的开发测试实例。

HelloWorld

运行前准备

  • 编译编译方舟运行时和方舟前端
./build.sh --product-name rk3568 --build-target ark_js_host_linux_tools_packages --build-target ets_frontend_build

运行hello-world.js
新建hello-world.js文件,写入以下源码:

print("Hello World!!!");

运行步骤:

1.通过方舟前端生成hello-world.abc文件,编译命令:

/your_code_path/out/rk3568/clang_x64/arkcompiler/ets_frontend/es2abc hello-world.js

2.执行hello-world.abc文件:

1.设置搜索路径:

export LD_LIBRARY_PATH=/your_code_path/out/rk3568/clang_x64/arkcompiler/ets_runtime:/your_code_path/prebuilts/clang/ohos/linux-x86_64/llvm/lib:/your_code_path/out/rk3568/clang_x64/thirdparty/zlib

2.执行ark_js_vm:

/your_code_p
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值