Skip to content

refactor(app)!: ncnn 插件拆仓为独立包(github.com/hhoao/ncnn) - #2

Merged
hhoao merged 5 commits into
mainfrom
feat/ncnn-package-extraction
Sep 11, 2026
Merged

hhoao merged 5 commits into
mainfrom
feat/ncnn-package-extraction

Conversation

@hhoao

@hhoao hhoao commented Sep 11, 2026

Copy link
Copy Markdown
Owner

Summary

  • 将 huji-app/packages/huji_ncnn 拆出为独立 pub 包 ncnn(https://github.com/hhoao/ncnn),本分支以 git submodule 接入(huji-app/packages/ncnn,pin d9092fa,CI 绿)
  • 包 API 泛化:版本化 C 选项结构体、输出 blob 自动发现(pnnx/onnx2ncnn 两种 param 格式)、多输出 + shape 查询 + 容量重试、hn_extract_f32 浮点输入、YOLO classify/detect 纯 Dart 工具、ultralytics metadata 解析(类名 + imgsz)
  • app 层引擎/helper 迁入包内;app 保留 predictor/pool/selector 等业务层
  • 设计文档:docs/superpowers/specs/2026-09-10-ncnn-package-extraction-design.md,实施计划:docs/superpowers/plans/2026-09-10-ncnn-package-extraction.md

验收

  • flutter test 207/207(含真实 native GPU 推理 golden 测试)
  • parity:4/4 模型 vs fp32 ONNX 导出 max diff 6.3e-07,argmax 全同
  • --ncnn-selftest:Vulkan(RTX 4060)+ 强制 CPU 双路 ALL OK
  • AppImage 含 libncnn_plugin.so + libncnn.so.1 + 4 组模型,干净机器 ldd 可解析(修复了 SONAME 打包 bug)
  • flutter analyze 0 错误(117 条预存在 info,比基线少 2)

注意事项

  • 环境变量改名(旧名本地 shell/脚本会静默失效):HUJI_NCNN_LIB_DIR→NCNN_DART_LIB_DIR、HUJI_NCNN_ENABLE_GPU_IN_TESTS→NCNN_ENABLE_GPU_IN_TESTS、HUJI_NCNN_STRICT_GOLDENS→NCNN_STRICT_GOLDENS
  • macos/Podfile.lock 中 ncnn 条目 checksum 对应旧 podspec 版本,下次 macOS pod install 会自动重写(非阻塞)
  • 包发布 pub.dev 0.1.0 在后续单独进行(Task 13)

🤖 Generated with Claude Code

hhoao and others added 3 commits September 11, 2026 00:17
…ji_ncnn)

- Replace huji-app/packages/huji_ncnn with a git submodule of
  github.com/hhoao/ncnn (package:ncnn); pin efff93d.
- Delete app-side ncnn_inference_engine.dart / ncnn_helper_process.dart
  and the package-level tests that migrated with the package
  (ncnn_plugin_test, ncnn_real_frame_test, ncnn_stale_marker_test);
  NcnnInferenceEngine/NcnnHelperProcess now come from package:ncnn.
- NcnnModelPredictor wires NcnnInferenceEngine(onLog: AppLogger().i)
  and passes NcnnOptions.yolo(warmupWidth/Height: imgsz) parsed from
  the newly bundled ultralytics metadata.yaml (falls back to const
  NcnnOptions.yolo()).
- New slim test bootstrap pins the built plugin dir via
  NcnnRuntime.overrideLibraryDirectory (app build + package example
  build); native-dependent tests skip cleanly without a build.
- Rename huji_ncnn references across pubspec, scripts, workflows,
  generated plugin files, Podfile.lock (hand-edited, SHA-1 of the new
  podspec); env vars HUJI_NCNN_* -> NCNN_*.

Co-Authored-By: Claude <noreply@anthropic.com>
The ncnn package's linux bundling installed the real ncnn shared lib
under its versioned file name; the plugin's DT_NEEDED (libncnn.so.1)
then failed to resolve on machines without the build tree (masked by
the plugin's absolute dev RUNPATH, and previously in AppImages by
linuxdeploy deploying libncnn.so.1 from the old libhuji_ncnn_plugin
name). Pull the fix so the Flutter bundle — and the AppImage built
from it — is self-contained.

Co-Authored-By: Claude <noreply@anthropic.com>
…odfile.lock order, bump ncnn pin

Co-Authored-By: Claude <noreply@anthropic.com>
hhoao added a commit to hhoao/ncnn that referenced this pull request Sep 11, 2026
…duct name collision

The pod is named 'ncnn', so the pod target's own build product is
${PODS_CONFIGURATION_BUILD_DIR}/ncnn/ncnn.framework while CocoaPods
stages the vendored ncnn xcframework slices into
${PODS_CONFIGURATION_BUILD_DIR}/XCFrameworkIntermediates/ncnn/.
Both directories end up in the app target's FRAMEWORK_SEARCH_PATHS and
the link line contains -framework ncnn — ld resolves the flag against
the pod-product dir (sorted first) and picks the shim-only framework,
leaving every ncnn:: C++ symbol undefined at app link time.

The prepare_command now renames the vendored bundle (and inner binary;
the ar symbol table is unaffected by a rename) to ncnn_static(.xc).framework,
so the aggregate OTHER_LDFLAGS become -framework ncnn (shim product) +
-framework ncnn_static (real library) with no ambiguity. Verified against
CocoaPods 1.15 locally: generated xcconfigs, copy-xcframeworks script and
staged headers all point at the renamed bundle, and the staged fat ar
archive still exports Net::load_param / get_gpu_count / GpuInfo::* /
Mat::from_pixels.

iOS follow-up: vendored plain .framework bundles are never staged into
XCFrameworkIntermediates, so HEADER_SEARCH_PATHS now points directly at
the renamed bundle's Headers via $(PODS_TARGET_SRCROOT).

Pre-migration (pod 'huji_ncnn') there was no collision — see hhoao/huji#2.

Co-Authored-By: Claude <noreply@anthropic.com>
hhoao and others added 2 commits September 11, 2026 10:44
…name fixes macOS link

Bumps ncnn to daf3faf: the vendored ncnn(.xc)framework is renamed to
ncnn_static in the podspec prepare_command so -framework ncnn no longer
collides with the pod target's own product dir (root cause of the
'Undefined symbols for architecture arm64' failure in the macOS job).

Co-Authored-By: Claude <noreply@anthropic.com>
… VM segfault

The package migration replaced the app's engine wrapper with
package:ncnn's NcnnInferenceEngine but dropped the wiring of its
gpuDeviceProbe through GpuDeviceSelector. The default probe calls
NcnnRuntime.gpuDevices directly with no FLUTTER_TEST guard, so in the
flutter_test VM ncnn's Vulkan init actually runs (on macOS CI it now
loads MoltenVK — previously impossible, hence green before) and
flutter_tester segfaults at test teardown:

  unhandled error during finalization of test:
  TestDeviceException(Shell subprocess crashed with segmentation fault.)

(4 occurrences in the macOS integration step; only 6/19 tests ran and
the step exited 1 even though every started test passed.)

Restore the pre-migration behavior: gpuDeviceProbe:
() async => GpuDeviceSelector.devices. Its FLUTTER_TEST probe guard
keeps the test VM on CPU (NCNN_ENABLE_GPU_IN_TESTS=1 to override).

Co-Authored-By: Claude <noreply@anthropic.com>
@hhoao
hhoao merged commit 504bf72 into main Sep 11, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant