Skip to content

feat: support injecting gl/sharp native .node via env vars - #858

Open
looopmax wants to merge 2 commits into
cocos:mainfrom
looopmax:feat/native-module-node-injection
Open

feat: support injecting gl/sharp native .node via env vars#858
looopmax wants to merge 2 commits into
cocos:mainfrom
looopmax:feat/native-module-node-injection

Conversation

@looopmax

Copy link
Copy Markdown

背景

cocos-cli 的 gl(webgl.node) / sharp(sharp-*.node) 原生二进制与宿主(如 PinK 编辑器)Electron 的 ABI 可能不匹配,导致加载失败。

改动

  • gl / sharp 加载点支持通过 COCOS_CLI_GL_NODE / COCOS_CLI_SHARP_NODE 环境变量指定外部 .node 文件(patch-package 补丁,走仓库既有补丁机制)
  • 未设置环境变量时回退到内置二进制,行为不变
  • 加载器在消费环境变量时输出 [cocos-cli] gl/sharp: loading native binding from ... 关键日志
  • 新增 patches/sharp+0.32.6.patchpatches/gl+9.0.0-rc.9.patch 补充 native-gl.js 环境变量支持
  • 新增 docs/dev/native-modules-injection.md 环境变量契约文档
  • .gitignore 忽略 perf/ 目录

环境变量契约

变量 含义
COCOS_CLI_GL_NODE gl (webgl.node) 路径
COCOS_CLI_SHARP_NODE sharp (sharp-*.node) 路径

配合 PinK 侧 PR(CocosMainService 启动 utility process 时传入)实现 ABI 适配。

@looopmax
looopmax force-pushed the feat/native-module-node-injection branch from a3ec537 to 68660c5 Compare August 14, 2026 03:55
- gl (webgl.node) / sharp (sharp-*.node) loaders now honor COCOS_CLI_GL_NODE / COCOS_CLI_SHARP_NODE env vars to load an external .node binary, for hosts (e.g. PinK editor) whose Electron ABI mismatches the bundled binaries

- Falls back to bundled binaries when env vars are unset; loaders log at consumption time

- Add patches/sharp+0.32.6.patch; extend gl patch with native-gl.js env var support

- Add docs/dev/native-modules-injection.md documenting the env var contract

- Ignore perf/ directory in .gitignore
@looopmax
looopmax force-pushed the feat/native-module-node-injection branch from 68660c5 to f225e09 Compare August 14, 2026 03:59
@wuzhiming
wuzhiming self-requested a review August 14, 2026 04:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants