Sign in

    moonohos

    HarmonyOS Native module framework for MoonBit: async tasks, platform modules and HAR packaging.

    harmonyos
    native
    ffi
    node-api
    code-generation
    Download zip
    Author
    Version
    0.4.0
    License
    Apache-2.0
    Last updated
    2 days ago
    Downloads
    24

    #MoonOHOS:面向 HarmonyOS 的 MoonBit Native 模块开发框架

    开发者用 MoonBit 编写可复用的 Native 模块;MoonOHOS 负责鸿蒙宿主适配、系统能力扩展、构建与打包,最终以 HAR 形式通过 ArkTS 接口接入应用。ArkTS 负责界面和系统交互,MoonBit 负责检索、解析、计算等业务核心。

    0.4 在 0.3 的接口生成与双 ABI 构建底座之上,新增:

    • 鸿蒙运行时:异步导出在 Node-API 工作线程执行 MoonBit,支持 CancelToken 取消;MoonBit 对象可作为句柄交给 ArkTS,关闭、回收和环境退出时释放。
    • 平台能力:ohos 模块让 MoonBit 直接使用 HiLog、RawFile 和任务取消;第三方 MoonBit 包可按描述文件携带 C 代码进入 HarmonyOS 动态库。
    • 工程分发:moonohos init 生成工程,moonohos har 生成 HAR,独立 Stage 应用通过 file: 依赖即可使用,无需手工拼接 CMake、类型包和库目录。
    • 真实示例:离线文档检索应用,覆盖资源读取、工作线程建索引、取消、离开页面释放和 HAR 消费。

    层次内容文档
    接口生成Int/Double/Bool/String/Bytes/Array/结构体的双向转换,d.ts 生成,清单与 .mbti 核对本文“清单”
    鸿蒙运行时进程门、工作线程任务、取消、句柄生命周期、env cleanup、诊断计数ASYNC-THREADING.md
    平台扩展moonohos.native.json 受控依赖;hilog、rawfile、task 平台包NATIVE-EXTENSIONS.md
    工程分发init、build、har、verify;SHA256 与 ELF 校验本文“命令”

    与 napi-mbt、ohos-rs 的功能对照和借鉴关系见 COMPARISON.md。验证结果见 VALIDATION-0.4.md。

    #环境

    • Windows x64,Moon 0.1.20260920,moonc v0.10.14+7d59c7ec9,Core 0.10.14+7d59c7ec9,async 0.21.0;CLI 由 Moon 调用 MSVC 构建,需要 C++ Build Tools。
    • DevEco Studio 26(HarmonyOS SDK API 26、hvigor、ohpm);目标 ABI arm64-v8a、x86_64。
    • 工具链版本固定,检查不通过时停止,不修改全局开发环境。已在 x86_64 模拟器(API 26)验证,ARM64 真机尚未验证。

    #快速开始

    CLI 和平台模块已发布到 Mooncakes:shop1111/moonohos@0.4.0、shop1111/moonohos_ohos@0.4.0。

    moon install shop1111/moonohos/cmd/moonohos@0.4.0 # 或在源码仓库中 moon build --target native --release cmd/moonohos moonohos init textkit --package alice/textkit moonohos build --config textkit\moonohos.json --sdk 'D:\apps\DevEco Studio\sdk' --out _build/dist moonohos har --dist textkit\_build\dist --module textkit\harmony\textkit --assemble --deveco 'D:\apps\DevEco Studio'

    生成的工程:

    textkit/ moon.work # 工作区;--ohos 时加入本地 ohos 平台模块 moonohos.json # 桥接清单(version 2) core/ # MoonBit 库:同步 greet,异步可取消 count_words(使用 HiLog) harmony/ # Hvigor 工程 textkit/ # HAR 模块:Index.ets 重导出原生模块

    应用接入 HAR:

    {"dependencies": {"@alice/textkit": "file:../textkit/harmony/textkit/build/default/outputs/default/textkit.har"}}

    import textkit, { CancelToken } from '@alice/textkit'; const token: CancelToken = textkit.createCancelToken(); const words: number = await textkit.count_words(longText, token); // 工作线程执行 token.cancel(); // 页面退出时取消

    生成的 core/moon.mod 从 Mooncakes 依赖 shop1111/moonohos_ohos@0.4.0。修改平台模块时可加 --ohos <MoonOHOS/ohos>,让工作区引用本地目录;构建时工作区全部成员被复制到隔离目录,原始文件不被修改。

    #与 0.3 手工接入的对比

    步骤0.30.4
    新建工程手写 MoonBit 模块、清单、DevEco 工程moonohos init
    原生库进入应用复制两个 ABI 的 .so 到 entry/libs/<abi>/moonohos har 放入 HAR 模块
    类型声明复制类型包到 entry/src/main/cpp/types/,手写本地依赖HAR 内置类型包与 ArkTS 门面
    打包分发无--assemble 调用 hvigor 生成 .har
    其他应用复用重复以上复制一行 file: 依赖
    耗时计算只能同步调用,阻塞 UI异步导出 + 取消
    使用系统能力不支持(拒绝所有 Native stub)HiLog、RawFile、任务取消;受控扩展

    #清单 moonohos.json

    version 1 清单保持不变;version 2 增加工作区、句柄、异步和业务错误:

    { "version": 2, "module": "core", "package": "moonohos/search", "nativeModule": "moonsearch", "workspace": "moon.work", "handles": [{"name": "SearchIndex"}], "types": [{"name": "Hit", "fields": [{"name": "path", "type": "String"}, {"name": "score", "type": "Double"}]}], "functions": [ {"name": "build_index", "params": [{"name": "resources", "type": "@rawfile.Manager"}, {"name": "dir", "type": "String"}], "return": "SearchIndex", "async": true, "raises": true}, {"name": "search", "params": [{"name": "index", "type": "SearchIndex"}, {"name": "query", "type": "String"}, {"name": "limit", "type": "Int"}], "return": "Array[Hit]", "async": true} ] }

    MoonBitArkTS说明
    Int / Double / Boolnumber / number / booleanInt 为有限 32 位整数,Double 必须有限
    Unit(返回值)void
    StringstringUTF-16 码元原样复制,支持内嵌 NUL 与未配对代理
    BytesUint8Array只接受普通、未分离 ArrayBuffer 上的视图,复制
    Array[T]Array<T>稠密、非 Sendable,复制
    结构体interface目标包需 pub(all) struct,字段为自有属性,复制
    句柄(handles)带 close()/isClosed() 的对象MoonBit 值保留在原生侧,不复制;不能嵌套在数组或结构体中
    @包.类型(平台适配)如 resourceManager.ResourceManager仅作参数;由描述文件中的适配器获取与释放
    "async": true(..., token?: CancelToken) => Promise<T>工作线程执行
    "raises": true抛出/拒绝 code = ERR_MOONOHOS_BUSINESSMoonBit 函数须声明 raise,消息取错误的 Show 文本

    每个模块还导出 createCancelToken() 和 moonohos_diagnostics()。

    函数必须是所选包公开的普通函数,参数、顺序、返回类型和 raise 与清单一致。每次转换最多嵌套 32 层、1,048,576 个元素/字段、复制 64 MiB,超限抛出 RangeError;缺少参数或类型错误抛出 TypeError。MoonBit panic 会终止进程。不支持泛型、#value 结构体、可选或标记参数、Option、Int64、枚举、类和回调。

    #命令

    & $cli init <dir> [--name <module>] [--package owner/name] [--ohos <path>] [--json] & $cli build --config moonohos.json --sdk <SDK> [--abi arm64-v8a,x86_64] [--out <dir>] [--dry-run] [--cache] [--json] & $cli har --dist <package> --module <HAR module> [--assemble --deveco <DevEco Studio>] [--json] & $cli doctor --sdk <SDK> --json & $cli check | inspect | plan --config moonohos.json --json & $cli verify --out <package> --json

    • build 默认构建两个 ABI,输出目录必须不存在;--dry-run 只验证配置和工具链;--cache 按源码、依赖、清单、编译器、运行时、SDK 与生成器内容计算缓存键,命中前验证整个包,损坏条目改名保留后重建。
    • har 先 verify 包,再把库、类型包、NOTICE、来源记录(moonohos-har.json)和生成的 src/main/ets/generated/Native.ets 写入 HAR 模块;--assemble 依次运行 DevEco 的 ohpm install 与 hvigor assembleHar,报告 .har 的 SHA256。
    • check 严格编译临时包装包;inspect 输出接口摘要;plan 输出有序构建阶段;verify 无需 SDK,核对清单、SHA256、类型包、CMake 导入、ELF64 架构、段和动态依赖。
    • 成功退出 0,参数错误退出 2,诊断或构建失败退出 3;--json 输出单个结构化报告。外部进程以参数数组启动并带超时,阶段日志写入工作目录,分发包不含机器相关日志。

    #产物

    dist/ libs/{arm64-v8a,x86_64}/lib<module>.so types/lib<module>/{index.d.ts,oh-package.json5} cmake/MoonOHOS.cmake manifest.json # moonohos-build-v2:文件 SHA256、导出(async/raises)、句柄、Native 依赖 NOTICE.NativeSDK.txt NOTICE.MoonBit.txt README.md

    编译器只生成 C;MoonOHOS 用同版本运行时源码、生成的适配层、C++ 生命周期运行时和 Native 依赖源码,以 SDK Clang/CMake/Ninja 交叉编译,C++ 标准库静态链接。动态库只允许依赖 libace_napi.z.so、libc/libm/libdl 与清单声明的白名单 NDK 库。

    #离线文档检索示例

    • examples/search/core:MoonBit 检索模块。ASCII 单词与汉字单字/双字分词、倒排索引、BM25 排序、摘要;通过 @rawfile 读取打包文档,@hilog 记录进度,@task 在建索引时检查取消。
    • examples/search/harmony/search:HAR 模块,SearchSession 封装打开、取消、搜索与关闭。
    • examples/search-app:独立 Stage 应用,只依赖 search.har。

    .\scripts\build_search.ps1 # CLI 构建 → HAR → 生成 2000 篇合成文档 → HAP .\scripts\verify_search_device.ps1 # 模拟器上运行脚本化场景两次

    原 examples/harmony 保留为类型转换回归应用。

    #验证

    moon fmt; moon check --target native --deny-warn; moon test --target native --deny-warn; moon info --target native python scripts\verify_containers.py async_core async_bridge.cpp python scripts\verify_cli.py --sdk 'D:\apps\DevEco Studio\sdk' python scripts\verify_integration.py 'D:\apps\DevEco Studio\sdk' .\scripts\verify_init_flow.ps1 .\scripts\verify_device.ps1 -Hdc 'D:\apps\DevEco Studio\sdk\default\openharmony\toolchains\hdc.exe'

    宿主测试在 MSVC AddressSanitizer 下运行实际生成的 MoonBit C 代码和桥接回调,使用 Node-API 替身(async work 在真实线程执行);设备脚本在模拟器上安装应用并读取 HiLog 标记。Windows CI 执行格式、严格检查、测试、接口一致性、CLI 构建、打包、代码量门槛和宿主 ASan;SDK、HAP 与模拟器检查在本机执行。各层证明范围见 VALIDATION-0.4.md。

    #许可

    MoonOHOS 源码使用 Apache-2.0。分发动态库时保留两份 NOTICE,并补充业务库自身的许可证。第三方组件说明见 THIRD_PARTY.md。

    ConfigError

    pub(all) suberror ConfigError {
    Invalid(String)
    } derive(
    Debug
    )

    ConfigError::to_repr

    #deprecated("`ConfigError::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
    fn ConfigError::to_repr(ConfigError) ->
    Repr

    AdapterDef

    pub struct AdapterDef {
    pkg_alias : String
    type_name : String
    pkg : String
    ark_type : String
    ark_import : String
    acquire : String
    release : String
    }

    Adapter bound to the package alias used in moonohos.json.

    AdapterSpec

    pub struct AdapterSpec {
    type_name : String
    ark_type : String
    ark_import : String
    acquire : String
    release : String
    }

    Native argument adapter declared by a platform package.

    BuildStage

    pub struct BuildStage {
    id : String
    description : String
    dependencies : Array[String]
    abi : String?
    outputs : Array[String]
    }

    BuildStage::to_json

    fn BuildStage::to_json(self : BuildStage) -> Json

    Callable

    pub struct Callable {
    name : String
    params : Array[FieldDef]
    result : TypeExpr
    is_async : Bool
    raises : Bool
    }

    Callable::raw_result

    fn Callable::raw_result(self : Callable) -> TypeExpr

    Result type crossing the C boundary: raising functions return a one-element array envelope (empty on error); Unit results use Bool elements.

    Callable::signature

    fn Callable::signature(self : Callable) -> String

    CliOptions

    pub struct CliOptions {
    command : Command
    config : String
    sdk : String?
    abis : Array[String]
    output : String
    json : Bool
    dry_run : Bool
    cache : Bool
    target : String?
    name : String?
    package_name : String?
    ohos : String?
    dist : String?
    module_dir : String?
    deveco : String?
    assemble : Bool
    }

    Command

    pub(all) enum Command {
    Build
    Doctor
    Check
    Inspect
    Plan
    Verify
    Init
    Har
    Help
    Version
    } derive(Eq,
    Debug
    )

    Command::equal

    #deprecated("`Command::equal` is deprecated, use `Eq::equal` instead.")
    fn Command::equal(Command, Command) -> Bool

    Command::not_equal

    #deprecated("`Command::not_equal` is deprecated, use `Eq::not_equal` instead.")
    fn Command::not_equal(x : Command, y : Command) -> Bool

    Command::to_repr

    #deprecated("`Command::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
    fn Command::to_repr(Command) ->
    Repr

    Config

    pub struct Config {
    module_dir : String
    package_name : String
    native_module : String
    functions : Array[Function]
    }

    Config::to_project

    fn Config::to_project(self : Config) -> Project

    ContentFingerprint

    pub struct ContentFingerprint {
    domain : String
    name : String
    digest : String
    }

    ContentFingerprint::to_json

    ConversionLimits

    pub struct ConversionLimits {
    depth : Int
    nodes : Int
    bytes : Int
    }

    ConversionLimits::to_json

    fn ConversionLimits::to_json(self : ConversionLimits) -> Json

    Diagnostic

    pub(all) struct Diagnostic {
    stage : String
    code : String
    message : String
    context : Array[String]
    }

    Diagnostic::render

    fn Diagnostic::render(self : Diagnostic) -> String

    Diagnostic::to_json

    fn Diagnostic::to_json(self : Diagnostic) -> Json

    ElfInfo

    pub struct ElfInfo {
    abi : String
    dependencies : Array[String]
    imports : Array[String]
    exports : Array[String]
    soname : String?
    segments : Array[ElfSegment]
    }

    ElfInfo::to_json

    fn ElfInfo::to_json(self : ElfInfo) -> Json

    ElfSegment

    pub struct ElfSegment {
    offset : Int
    file_size : Int
    memory_size : UInt64
    address : UInt64
    flags : Int
    alignment : UInt64
    }

    ElfSegment::to_json

    fn ElfSegment::to_json(self : ElfSegment) -> Json

    EnvironmentFact

    pub struct EnvironmentFact {
    name : String
    actual : String
    expected : String
    available : Bool
    }

    EnvironmentFact::passed

    fn EnvironmentFact::passed(self : EnvironmentFact) -> Bool

    EnvironmentFact::to_json

    fn EnvironmentFact::to_json(self : EnvironmentFact) -> Json

    FieldDef

    pub struct FieldDef {
    name : String
    kind : TypeExpr
    }

    Function

    pub struct Function {
    name : String
    params : Array[Parameter]
    result : ValueType
    }

    GeneratedArtifacts

    pub struct GeneratedArtifacts {
    wrapper : String
    package_file : String
    header : String
    embed : String
    native : String
    declarations : String
    cmake : String
    }

    InitOptions

    pub(all) struct InitOptions {
    name : String
    package_name : String
    ohos : String?
    }

    Options for moonohos init.

    InterfaceFunction

    pub struct InterfaceFunction {
    name : String
    params : Array[TypeExpr]
    result : TypeExpr
    raises : Bool
    unsupported : String?
    }

    InterfaceRecord

    pub struct InterfaceRecord {
    name : String
    fields : Array[FieldDef]
    unsupported : String?
    }

    InterfaceType

    pub struct InterfaceType {
    name : String
    generic : Bool
    }

    Any declared type name, including abstract type X and external types.

    NativeBuild

    pub(all) struct NativeBuild {
    sources : Array[String]
    include_dirs : Array[String]
    defines : Array[String]
    libraries : Array[String]
    }

    Additional CMake inputs contributed by native dependencies.

    NativeDescriptor

    pub struct NativeDescriptor {
    pkg : String
    sources : Array[String]
    include_dirs : Array[String]
    defines : Array[String]
    libraries : Array[String]
    abis : Array[String]
    adapters : Array[AdapterSpec]
    }

    Controlled description of a MoonBit package that ships C stubs.

    NativeDescriptor::to_json

    fn NativeDescriptor::to_json(self : NativeDescriptor) -> Json

    PackageFile

    pub struct PackageFile {
    path : String
    size : Int
    checksum : String
    }

    PackageFile::to_json

    fn PackageFile::to_json(self : PackageFile) -> Json

    PackageFile::verify

    fn PackageFile::verify(self : PackageFile, data : Bytes) -> Unit raise ConfigError

    PackageInterface

    pub struct PackageInterface {
    functions : Array[InterfaceFunction]
    records : Array[InterfaceRecord]
    types : Array[InterfaceType]
    }

    PackageManifest

    pub struct PackageManifest {
    schema : Int
    module_name : String
    version : String
    abis : Array[String]
    files : Array[PackageFile]
    libraries : Array[String]
    }

    Parameter

    pub struct Parameter {
    name : String
    kind : ValueType
    }

    Project

    pub struct Project {
    version : Int
    module_dir : String
    package_name : String
    native_module : String
    workspace : String?
    records : Array[RecordDef]
    handles : Array[String]
    functions : Array[Callable]
    adapters : Array[AdapterDef]
    }

    Project::build_plan

    fn Project::build_plan(self : Project, abis : Array[String]) -> Json raise ConfigError

    Project::business_adapters

    fn Project::business_adapters(self : Project) -> String raise ConfigError

    Project::business_header

    fn Project::business_header(self : Project) -> String raise ConfigError

    Project::business_wrapper

    fn Project::business_wrapper(self : Project) -> String raise ConfigError

    Generates only business exports; container accessors are added by the backend.

    Project::generate

    fn Project::generate(self : Project) -> GeneratedArtifacts raise ConfigError

    Project::generate_arrays

    fn Project::generate_arrays(self : Project) -> GeneratedArtifacts raise ConfigError

    Project::generation_plan

    fn Project::generation_plan(self : Project) -> Json raise ConfigError

    Project::reachable_types

    fn Project::reachable_types(self : Project) -> Array[TypeExpr] raise ConfigError

    Dependencies precede their users; declaration order is deterministic.

    Project::record_def

    fn Project::record_def(self : Project, name : String) -> RecordDef raise ConfigError

    Project::record_order

    fn Project::record_order(self : Project) -> Array[RecordDef] raise ConfigError

    Project::summary

    fn Project::summary(self : Project) -> Json raise ConfigError

    Project::validate

    fn Project::validate(self : Project) -> Unit raise ConfigError

    Project::verify_interface

    fn Project::verify_interface(self : Project, text : String) -> Unit raise ConfigError

    Project::with_adapters

    fn Project::with_adapters(self : Project, adapters : Array[AdapterDef]) -> Project

    Attaches platform adapters discovered from native dependency descriptors.

    RecordDef

    pub struct RecordDef {
    name : String
    fields : Array[FieldDef]
    }

    Sha256

    pub struct Sha256 {
    state : Array[UInt]
    pending : Array[Byte]
    count : UInt64
    }

    FIPS 180-4 SHA-256. All arithmetic intentionally wraps at 32 bits.

    Sha256::digest

    fn Sha256::digest(self : Sha256) -> String

    Finalization uses a copy; calling digest repeatedly does not mutate state.

    Sha256::new

    fn Sha256::new() -> Sha256

    Sha256::update

    fn Sha256::update(self : Sha256, data : Bytes) -> Unit

    TypeExpr

    pub(all) enum TypeExpr {
    Scalar(ValueType)
    List(TypeExpr)
    Record(String)
    Handle(String)
    External(String, String)
    } derive(Eq,
    Debug
    )

    TypeExpr::ark_name

    fn TypeExpr::ark_name(self : TypeExpr) -> String

    TypeExpr::c_name

    fn TypeExpr::c_name(self : TypeExpr) -> String

    TypeExpr::equal

    #deprecated("`TypeExpr::equal` is deprecated, use `Eq::equal` instead.")
    fn TypeExpr::equal(TypeExpr, TypeExpr) -> Bool

    TypeExpr::is_opaque

    fn TypeExpr::is_opaque(self : TypeExpr) -> Bool

    Handles and adapters cross the bridge by reference and are never copied.

    TypeExpr::is_reference

    fn TypeExpr::is_reference(self : TypeExpr) -> Bool

    TypeExpr::moon_name

    fn TypeExpr::moon_name(self : TypeExpr) -> String

    TypeExpr::not_equal

    #deprecated("`TypeExpr::not_equal` is deprecated, use `Eq::not_equal` instead.")
    fn TypeExpr::not_equal(x : TypeExpr, y : TypeExpr) -> Bool

    TypeExpr::to_repr

    #deprecated("`TypeExpr::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
    fn TypeExpr::to_repr(TypeExpr) ->
    Repr

    TypeExpr::wrapper_name

    fn TypeExpr::wrapper_name(self : TypeExpr) -> String

    ValueType

    pub(all) enum ValueType {
    Int32
    Float64
    Boolean
    Text
    Binary
    Void
    } derive(Eq,
    Debug
    )

    ValueType::ark_name

    fn ValueType::ark_name(self : ValueType) -> String

    ValueType::c_name

    fn ValueType::c_name(self : ValueType) -> String

    ValueType::equal

    #deprecated("`ValueType::equal` is deprecated, use `Eq::equal` instead.")
    fn ValueType::equal(ValueType, ValueType) -> Bool

    ValueType::moon_name

    fn ValueType::moon_name(self : ValueType) -> String

    ValueType::not_equal

    #deprecated("`ValueType::not_equal` is deprecated, use `Eq::not_equal` instead.")
    fn ValueType::not_equal(x : ValueType, y : ValueType) -> Bool

    ValueType::to_repr

    #deprecated("`ValueType::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
    fn ValueType::to_repr(ValueType) ->
    Repr

    abi_triple

    fn abi_triple(abi : String) -> String

    build_stages

    fn build_stages(project : Project, abis : Array[String]) -> Array[BuildStage] raise ConfigError

    c_header

    fn c_header(config : Config) -> String

    cmake_source

    fn cmake_source(config : Config) -> String

    command_name

    fn command_name(command : Command) -> String

    compiler_commands

    fn compiler_commands(plan : String, moon_home : String) -> Array[Array[String]] raise ConfigError

    Selects compiler-only commands; excludes host C compilers and runtime objects.

    content_cache_key

    fn content_cache_key(entries : Array[ContentFingerprint]) -> String raise ConfigError

    conversion_limits

    fn conversion_limits() -> ConversionLimits

    declarations

    fn declarations(config : Config) -> String

    embed_source

    fn embed_source(config : Config) -> String

    empty_native_build

    fn empty_native_build() -> NativeBuild

    environment_fact

    fn environment_fact(name : String, actual : String, expected : String, available : Bool) -> EnvironmentFact

    environment_report

    fn environment_report(facts : Array[EnvironmentFact]) -> Json

    failure_report

    fn failure_report(command : String, diagnostic : Diagnostic, parameter? : Bool) -> Json

    fingerprint

    fn fingerprint(domain : String, name : String, data : Bytes) -> ContentFingerprint

    forbidden_build_hook

    fn forbidden_build_hook(package_file : String) -> String?

    Build hooks and compiler flags that MoonOHOS cannot reproduce for OHOS.

    har_facade

    fn har_facade(module_name : String, declarations : String) -> String

    ArkTS facade re-exporting the native module and every declared interface.

    har_package_manifest

    fn har_package_manifest(text : String, module_name : String) -> String raise ConfigError

    Checks a HAR module and points its native type dependency at the package.

    har_provenance

    fn har_provenance(manifest : PackageManifest, manifest_sha256 : String) -> Json

    Provenance written next to the libraries inside the HAR module.

    identifier

    fn identifier(name : String) -> Bool

    ignored_cache_component

    fn ignored_cache_component(name : String) -> Bool

    init_files

    fn init_files(options : InitOptions) -> Array[(String, String)] raise ConfigError

    Files of a new MoonOHOS project: a MoonBit library, its bridge manifest and a Hvigor project whose HAR module will carry the built libraries.

    inspect_elf

    fn inspect_elf(bytes : Bytes) -> ElfInfo raise ConfigError

    interface_imports

    fn interface_imports(text : String) -> Map[String, String]

    Maps default package aliases (last path segment) to imported packages.

    linked_packages

    fn linked_packages(link_core : Array[String]) -> Array[(String, String)]

    Package directories linked by link-core, in the compiler's order.

    moonohos_version

    fn moonohos_version() -> String

    Generator version recorded in packages, type packages and cache keys.

    native_cmake

    fn native_cmake(target : String, native : NativeBuild) -> String

    CMake for the generated bridge plus sources and NDK libraries contributed by validated native dependency descriptors.

    native_descriptor_file

    fn native_descriptor_file() -> String

    native_source

    fn native_source(config : Config) -> String

    native_stubs

    fn native_stubs(package_file : String) -> Array[String]

    Extracts the native-stub list from moon.pkg or moon.pkg.json.

    package_file

    fn package_file(path : String, data : Bytes) -> PackageFile raise ConfigError

    package_requirements

    fn package_requirements(module_name : String, abis : Array[String]) -> Array[String]

    parse_abis

    fn parse_abis(text : String) -> Array[String] raise ConfigError

    parse_cli

    fn parse_cli(args : Array[String]) -> CliOptions raise ConfigError

    Arguments exclude the executable name. Paths are resolved by the command.

    parse_config

    fn parse_config(text : String) -> Config raise ConfigError

    parse_native_descriptor

    fn parse_native_descriptor(text : String, pkg : String, stubs : Array[String]) -> NativeDescriptor raise ConfigError

    Parses and validates a descriptor against the package's declared stubs.

    parse_package_interface

    fn parse_package_interface(text : String) -> PackageInterface

    Parses selected declarations structurally; unrelated traits remain opaque.

    parse_package_manifest

    fn parse_package_manifest(text : String) -> PackageManifest raise ConfigError

    parse_project

    fn parse_project(text : String) -> Project raise ConfigError

    parse_type_expr

    fn parse_type_expr(text : String, result? : Bool) -> TypeExpr raise ConfigError

    pinned_environment

    fn pinned_environment() -> Array[(String, String)]

    relative_path

    fn relative_path(from : String, to : String) -> String

    Relative path from directory from to to; both absolute with /.

    resolve_adapters

    fn resolve_adapters(project : Project, descriptors : Array[NativeDescriptor], imports : Map[String, String]) -> Array[AdapterDef] raise ConfigError

    Binds @alias.Type parameters to adapters using the target's mbti imports.

    runtime_files

    fn runtime_files() -> Array[String]

    sdk_candidates

    fn sdk_candidates(path : String) -> Array[String]

    sdk_files

    fn sdk_files() -> Array[String]

    seal_manifest

    fn seal_manifest(manifest : Json, files : Array[PackageFile]) -> Json raise ConfigError

    sha256

    fn sha256(data : Bytes) -> String

    signature

    fn signature(fn_ : Function) -> String

    staged_workspace

    fn staged_workspace(count : Int) -> String

    A workspace file for staged members ./m0, ./m1, ...

    success_report

    fn success_report(command : String, result : Json) -> Json

    system_library_allowlist

    fn system_library_allowlist() -> Array[String]

    HarmonyOS NDK libraries that platform packages may link.

    tokenize

    fn tokenize(line : String) -> Array[String] raise ConfigError

    Tokenizes Moon 20260920 dry-run command quoting. Never evaluates a shell.

    valid_module_name

    fn valid_module_name(name : String) -> Bool

    validate_distribution_metadata

    fn validate_distribution_metadata(json : Json) -> Unit raise ConfigError

    validate_har_module

    fn validate_har_module(module_json : String) -> Unit raise ConfigError

    validate_package_path

    fn validate_package_path(path : String) -> Unit raise ConfigError

    validate_stages

    fn validate_stages(stages : Array[BuildStage]) -> Unit raise ConfigError

    verify_import_file

    fn verify_import_file(text : String, manifest : PackageManifest) -> Unit raise ConfigError

    verify_interface

    fn verify_interface(config : Config, text : String) -> Unit raise ConfigError

    verify_library

    fn verify_library(info : ElfInfo, manifest : PackageManifest, abi : String) -> Unit raise ConfigError

    verify_type_package

    fn verify_type_package(text : String, manifest : PackageManifest) -> Unit raise ConfigError

    workspace_members

    fn workspace_members(text : String) -> Array[String] raise ConfigError

    Member directories listed in a moon.work file.

    wrapper_package

    fn wrapper_package(config : Config) -> String

    wrapper_source

    fn wrapper_source(config : Config) -> String