# oh_leanclr **Repository Path**: lightsever/oh_leanclr ## Basic Information - **Project Name**: oh_leanclr - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-06-17 - **Last Updated**: 2026-06-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # oh_leanclr [leanclr](https://github.com/focus-creative-games/leanclr) 的 OpenHarmony 移植 —— 一个纯 C++ 实现的 .NET 解释器运行时(AOT + 解释器,无 JIT)。 ## 当前状态(2026-06-17) ### ✅ 已跑通端到端 - 鸿蒙原生构建 lean CLI(ARM64 ELF musl,~1MB) - 上游源码 3 处适配补丁 + 1 处新增 icall 实现(`System.ConsoleDriver`) - 用 lean CLI 跑 `Console.WriteLine("Hello from leanclr!")` 成功 - 预构建产物可直接使用:见 [`dist/`](./dist) ```bash ./dist/lean -l src/libraries/dotnetframework4.x-linux -l dist HelloWorld # 输出:Hello from leanclr! ok! ``` ### ⚠️ 工具链已知缺陷 `dotnet_oh`(来源 [gitee.com/lightsever/install-dotnet-harmonyos](https://gitee.com/lightsever/install-dotnet-harmonyos))仍是开发中版本: - 多线程 GC 有问题 - `throw` 异常路径有缺陷 涉及这两个路径的托管代码可能崩溃,与 leanclr 无关。 ## 构建 lean CLI(鸿蒙原生) ```bash bash scripts/build-ohos.sh Release # 产物:build/lean/Release/bin/lean(或直接用 dist/lean) ``` 环境:clang 15、cmake 4.1.2、HarmonyOS HongMeng Kernel、dotnet_oh 10.0.109。 ## 编 lean CLI 做了哪些调整 相对上游 leanclr 共 **4 处改动**: | # | 文件 | 改动 | 原因 | |---|---|---|---| | 1 | `src/runtime/build_config.h` | 新增 `LEANCLR_PLATFORM_OHOS` 宏 | 识别鸿蒙环境(`__OHOS__` 预定义) | | 2 | `src/runtime/icalls/system_runtime_runtimeimports.cpp:72` | 鸿蒙走 snprintf 回退 | 避开 libc 缺失的 `ecvt` | | 3 | `src/tools/lean/main.cpp:101` | `unwrap()` → `is_ok()` | 修上游 bug,`RtResultVoid` 无 `unwrap()` | | 4 | **新增** `src/runtime/icalls/system_consoleriver.{h,cpp}` | 实现 ConsoleDriver 5 个 icall | 上游仅实现 Windows,非 Win 平台 `Console.WriteLine` 必崩 | 详见 [`doc/build/lean-ohos.md`](./doc/build/lean-ohos.md) 与 [`doc/design/consoleriver-fix.md`](./doc/design/consoleriver-fix.md)。 ## 仓库结构 ``` oh_leanclr/ ├── CLAUDE.md 项目规则 ├── README.md 本文件 ├── dist/ 预构建产物(可直接用) │ ├── lean 鸿蒙原生 lean CLI(ARM64) │ └── HelloWorld.dll 测试 DLL ├── doc/ 所有文档 │ ├── build/ 构建说明 │ ├── usage/ 使用指南 │ ├── design/ 上游 + 修复说明 │ └── plans/ 规划文档 ├── src/ leanclr 源码(含鸿蒙补丁) ├── tests/helloworld/ 端到端测试集(4 个隔离用例) ├── scripts/ 鸿蒙构建脚本 ├── licenses/ ├── build/ 构建中间产物(gitignored) └── temp/ 上游临时克隆(gitignored,仅参考) ``` ## 测试 `tests/helloworld/` 含 4 个测试用例,覆盖:runtime init、字符串、文件 IO、Console.WriteLine。这个测试集是逐步隔离定位 ConsoleDriver icall 缺失 bug 的副产物。详见 [`tests/helloworld/README.md`](./tests/helloworld/README.md)。 ```bash # 跑测试(用 dist/lean) bash tests/helloworld/run.sh # 期望:4 通过, 0 失败 ``` ## 文档入口 - [项目规则](./CLAUDE.md) - [上游 README](./doc/design/upstream-readme.md) - [构建说明(鸿蒙)](./doc/build/lean-ohos.md) - [运行 .NET DLL](./doc/usage/run-dll.md) - [ConsoleDriver 修复](./doc/design/consoleriver-fix.md) - [规划记录](./doc/plans/) ## 已知约束 - 运行时仅支持 .NET Framework 4.x / .NET Standard 2.x BCL ABI - 不提供 corelib/mscorlib 编译环境,仅消费预编译 BCL DLL - 编译托管 DLL 必须用 `csc /nostdlib` 直接引用 leanclr 的 mscorlib(dotnet_oh 不带 net4.x 引用程序集) - 鸿蒙 aligned heap 优化未启用