|
| 1 | +# mcpp: GL Runtime Closure Plan |
| 2 | + |
| 3 | +> 状态: active |
| 4 | +> 分支: `codex/gl-runtime-closure-mcpp` |
| 5 | +> PR: pending |
| 6 | +> Last updated: 2026-06-03 |
| 7 | +> 目标: 让 mcpp 以标准工具链方式表达、解析、诊断并注入运行时闭包,使 GLFW/OpenGL 这类通过 `dlopen` 加载的运行库不再依赖用户手写环境变量。 |
| 8 | +
|
| 9 | +## Scope |
| 10 | + |
| 11 | +This repository owns the tool behavior. It should not hard-code one OpenGL |
| 12 | +vendor or one package index workaround. The expected model is closer to |
| 13 | +Conan/vcpkg run environments plus Nix-style runtime closure diagnostics: |
| 14 | + |
| 15 | +- package metadata can declare runtime library directories, `dlopen` library |
| 16 | + names, and required system capabilities; |
| 17 | +- dependency resolution carries runtime requirements separately from compile |
| 18 | + includes and link flags; |
| 19 | +- `mcpp run`, `mcpp test`, `mcpp doctor`, and `mcpp pack` consume the same |
| 20 | + runtime model; |
| 21 | +- missing system capabilities produce actionable errors before a user only sees |
| 22 | + a failed GUI window. |
| 23 | + |
| 24 | +## Current Problem |
| 25 | + |
| 26 | +- `mcpp run` builds the selected binary and executes it directly. |
| 27 | +- Build/link propagation covers link-time shared libraries, but `dlopen` |
| 28 | + libraries such as `libGLX.so.0` and `libGL.so.1` do not appear in `DT_NEEDED`. |
| 29 | +- `mcpp pack` already has runtime closure logic, but it is oriented around |
| 30 | + loader-visible ELF dependencies. GLX/EGL/Mesa/vendor-driver cases need an |
| 31 | + explicit runtime metadata path rather than guessing from one executable. |
| 32 | + |
| 33 | +## Proposed Manifest Surface |
| 34 | + |
| 35 | +Keep compile, link, and runtime requirements separate. Initial names can be |
| 36 | +adjusted during implementation, but the semantics should remain stable: |
| 37 | + |
| 38 | +```toml |
| 39 | +[runtime] |
| 40 | +library_dirs = ["relative/or/generated/runtime/lib"] |
| 41 | +dlopen_libs = ["libGLX.so.0", "libGL.so.1", "libGL.so"] |
| 42 | +capabilities = ["x11.display", "opengl.glx.driver"] |
| 43 | +``` |
| 44 | + |
| 45 | +For package descriptors coming from an index, the same data should be accepted |
| 46 | +from the package `mcpp` table: |
| 47 | + |
| 48 | +```lua |
| 49 | +mcpp = { |
| 50 | + runtime = { |
| 51 | + library_dirs = {"mcpp_generated/runtime/lib"}, |
| 52 | + dlopen_libs = {"libGLX.so.0", "libGL.so.1", "libGL.so"}, |
| 53 | + capabilities = {"x11.display", "opengl.glx.driver"}, |
| 54 | + }, |
| 55 | +} |
| 56 | +``` |
| 57 | + |
| 58 | +Compatibility rule: packages that do not declare runtime metadata keep current |
| 59 | +behavior. |
| 60 | + |
| 61 | +## Implementation Plan |
| 62 | + |
| 63 | +- [x] Create this repository-level plan checkpoint. |
| 64 | +- [x] Add manifest/runtime metadata parsing and validation. |
| 65 | + - Candidate files: `src/manifest.cppm`, manifest tests. |
| 66 | + - Invalid entries should fail early: empty library name, absolute path in |
| 67 | + package metadata unless explicitly allowed, duplicate capability strings. |
| 68 | +- [x] Carry runtime requirements through the resolved package graph. |
| 69 | + - Candidate files: dependency resolution and `PackageRoot`/graph structures. |
| 70 | + - Runtime requirements must not be mixed into public include usage. |
| 71 | +- [x] Teach `mcpp run` and `mcpp test` to build a run environment. |
| 72 | + - Candidate file: `src/cli.cppm`. |
| 73 | + - Done: `mcpp run` consumes resolved runtime library directories. |
| 74 | + - Done: `mcpp test` uses the same runtime environment for test binaries. |
| 75 | + - Linux: prepend resolved runtime directories to `LD_LIBRARY_PATH`. |
| 76 | + - macOS: use `DYLD_LIBRARY_PATH` only for local tool execution where allowed, |
| 77 | + otherwise prefer rpath/install-name behavior. |
| 78 | + - Windows: prepend resolved runtime directories to `PATH`. |
| 79 | +- [ ] Add runtime diagnostics. |
| 80 | + - Candidate commands: `mcpp self doctor`, or a new target-aware runtime |
| 81 | + doctor path if the existing command shape supports it. |
| 82 | + - Diagnostics should list the target, the package that required the runtime |
| 83 | + item, unresolved `dlopen` names, and missing capabilities. |
| 84 | +- [ ] Extend `mcpp pack` to consume runtime metadata. |
| 85 | + - Candidate file: `src/pack/pack.cppm`. |
| 86 | + - `pack` should include declared runtime directories/files when the mode |
| 87 | + requests a runnable bundle. |
| 88 | + - Keep system capabilities explicit; do not silently bundle host GPU drivers |
| 89 | + unless a package declares a redistributable runtime. |
| 90 | +- [x] Add regression coverage with a small `dlopen` fixture. |
| 91 | + - Test should prove that a library loaded only via `dlopen` is found through |
| 92 | + mcpp runtime metadata during `mcpp run`. |
| 93 | + - A second pack-oriented test should prove runtime metadata is represented in |
| 94 | + the bundled executable environment. |
| 95 | +- [ ] Update docs. |
| 96 | + - Candidate files: `docs/02-pack-and-release.md`, |
| 97 | + `docs/05-mcpp-toml.md`, README snippets if needed. |
| 98 | + |
| 99 | +## Verification |
| 100 | + |
| 101 | +- [x] `mcpp build` |
| 102 | +- [x] `mcpp run -- --version` |
| 103 | +- [x] `mcpp test` |
| 104 | +- [ ] `MCPP=<built-mcpp> bash tests/e2e/run_all.sh` |
| 105 | +- [x] Focused runtime metadata e2e for `dlopen` resolution |
| 106 | +- [ ] Focused pack e2e for runtime metadata inclusion |
| 107 | + |
| 108 | +## PR / CI / Merge Notes |
| 109 | + |
| 110 | +- [x] Commit this plan as the first checkpoint. |
| 111 | +- [ ] Open a PR with sanitized paths and no local machine details. |
| 112 | +- [ ] Include a test plan in the PR body. |
| 113 | +- [ ] Wait for Linux/macOS/Windows CI. |
| 114 | +- [ ] Squash merge after required checks pass. |
| 115 | + |
| 116 | +## Cross-Repository Dependencies |
| 117 | + |
| 118 | +- `mcpp-index` can only fully validate `compat.glfw` GLX runtime metadata after |
| 119 | + this repository supports runtime requirements in `mcpp run`. |
| 120 | +- `imgui-m` should not own tool runtime behavior; it only consumes the fixed |
| 121 | + behavior through its minimal window example. |
| 122 | +- `xim-pkgindex` participates only after a released mcpp version is needed by |
| 123 | + xlings or users. |
0 commit comments