Skip to content

Commit c5bee46

Browse files
authored
Add imgui module package
Add the independent imgui 0.0.1 module package descriptor, docs, smoke test, and mcpp 0.0.45 CI validation.
1 parent 338c859 commit c5bee46

4 files changed

Lines changed: 184 additions & 10 deletions

File tree

.github/workflows/validate.yml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ jobs:
5353
uses: actions/cache@v4
5454
with:
5555
path: ~/.mcpp/registry
56-
key: mcpp-registry-${{ runner.os }}-0.0.41-${{ hashFiles('pkgs/**/*.lua', 'tests/smoke_compat_*.sh', '.github/workflows/validate.yml') }}
56+
key: mcpp-registry-${{ runner.os }}-0.0.45-${{ hashFiles('pkgs/**/*.lua', 'tests/*.sh', '.github/workflows/validate.yml') }}
5757
restore-keys: |
58-
mcpp-registry-${{ runner.os }}-0.0.41-
58+
mcpp-registry-${{ runner.os }}-0.0.45-
5959
- name: Download mcpp
6060
env:
61-
MCPP_VERSION: "0.0.41"
61+
MCPP_VERSION: "0.0.45"
6262
run: |
6363
curl -L -fsS -o mcpp.tar.gz \
6464
"https://github.com/mcpp-community/mcpp/releases/download/v${MCPP_VERSION}/mcpp-${MCPP_VERSION}-linux-x86_64.tar.gz"
@@ -79,6 +79,7 @@ jobs:
7979
timeout 1800 bash tests/smoke_compat_imgui.sh
8080
timeout 1800 bash tests/smoke_compat_archive.sh
8181
timeout 1800 bash tests/smoke_compat_imgui_window.sh
82+
timeout 1800 bash tests/smoke_imgui_module.sh
8283
8384
smoke-portable:
8485
name: smoke-${{ matrix.platform }}
@@ -90,14 +91,14 @@ jobs:
9091
include:
9192
- platform: macos
9293
os: macos-15
93-
archive: mcpp-0.0.41-macosx-arm64.tar.gz
94-
root: mcpp-0.0.41-macosx-arm64
94+
archive: mcpp-0.0.45-macosx-arm64.tar.gz
95+
root: mcpp-0.0.45-macosx-arm64
9596
mcpp: bin/mcpp
9697
xlings: registry/bin/xlings
9798
- platform: windows
9899
os: windows-latest
99-
archive: mcpp-0.0.41-windows-x86_64.zip
100-
root: mcpp-0.0.41-windows-x86_64
100+
archive: mcpp-0.0.45-windows-x86_64.zip
101+
root: mcpp-0.0.45-windows-x86_64
101102
mcpp: bin/mcpp.exe
102103
xlings: registry/bin/xlings.exe
103104
steps:
@@ -106,13 +107,13 @@ jobs:
106107
uses: actions/cache@v4
107108
with:
108109
path: ~/.mcpp/registry
109-
key: mcpp-registry-${{ runner.os }}-0.0.41-${{ hashFiles('pkgs/**/*.lua', 'tests/smoke_compat_*.sh', '.github/workflows/validate.yml') }}
110+
key: mcpp-registry-${{ runner.os }}-0.0.45-${{ hashFiles('pkgs/**/*.lua', 'tests/*.sh', '.github/workflows/validate.yml') }}
110111
restore-keys: |
111-
mcpp-registry-${{ runner.os }}-0.0.41-
112+
mcpp-registry-${{ runner.os }}-0.0.45-
112113
- name: Download mcpp
113114
shell: bash
114115
env:
115-
MCPP_VERSION: "0.0.41"
116+
MCPP_VERSION: "0.0.45"
116117
MCPP_ARCHIVE: ${{ matrix.archive }}
117118
MCPP_ROOT: ${{ matrix.root }}
118119
run: |

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ mcpp build # 自动拉取源码 + 构建
2424
| `mcpplibs.xpkg` | 0.0.40 | xpkg V1 规范的 C++23 参考实现 — `import mcpplibs.xpkg;` | [openxlings/libxpkg](https://github.com/openxlings/libxpkg) |
2525
| `mcpplibs.templates` | 0.0.1 | 最小化模块库模板 — `import mcpplibs.templates;` | [mcpplibs/templates](https://github.com/mcpplibs/templates) |
2626

27+
### 独立模块化库
28+
29+
| 包名 | 版本 | 简介 | 仓库 |
30+
|------|------|------|------|
31+
| `imgui` | 0.0.1 | Dear ImGui C++23 模块封装 — `import imgui.core;` / `import imgui.backend.glfw_opengl3;` | [mcpplibs/imgui-m](https://github.com/mcpplibs/imgui-m) |
32+
2733
### 第三方 C/C++ 库
2834

2935
| 包名 | 版本 | 简介 |
@@ -68,6 +74,12 @@ mcpplibs.xpkg
6874
└── mcpplibs.capi.lua
6975
└── lua ← 同上
7076
77+
imgui
78+
├── compat.imgui
79+
├── compat.glfw
80+
│ └── compat.opengl
81+
└── compat.opengl ← 消费者只需要 import imgui.* 模块
82+
7183
libarchive
7284
├── zlib
7385
├── bzip2
@@ -109,6 +121,7 @@ mcpp 0.0.3+ 的 transitive walker 自动沿链路传播头文件和依赖,消费
109121
MCPP=/path/to/mcpp tests/smoke_compat_core.sh
110122
MCPP=/path/to/mcpp tests/smoke_compat_imgui.sh
111123
MCPP=/path/to/mcpp tests/smoke_compat_archive.sh
124+
MCPP=/path/to/mcpp tests/smoke_imgui_module.sh
112125
```
113126

114127
该脚本会通过当前 checkout 作为本地 path index 创建临时 mcpp 项目,验证:
@@ -117,6 +130,8 @@ MCPP=/path/to/mcpp tests/smoke_compat_archive.sh
117130
`#include <...>` API 构建并运行最小用例
118131
- `compat.opengl`/`compat.khrplatform` 能提供 GLFW/OpenGL 常见头文件闭包
119132
- `compat.imgui@1.92.8` core 能构建并运行一个 headless ImGui frame
133+
- `imgui@0.0.1` 模块包能通过 `[dependencies] imgui = "0.0.1"` 构建并运行
134+
`import imgui.core;` / `import imgui.backend.glfw_opengl3;` 最小用例
120135
- `compat.glfw@3.4` 能构建、运行 `glfwInit()` smoke,并链接 X11 扩展 runtime `.so`
121136
- `compat.xau@1.0.12`/`compat.xdmcp@1.1.5` 能构建、运行并链接 runtime `.so`
122137
- `compat.xcb@1.17.0` 能构建、运行并链接 `libxcb.so`

pkgs/i/imgui.lua

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
-- Form A descriptor: the public imgui module package ships its own
2+
-- mcpp.toml. mcpp's default lookup finds <verdir>/*/mcpp.toml inside
3+
-- the GitHub source tarball wrap.
4+
--
5+
package = {
6+
spec = "1",
7+
name = "imgui",
8+
namespace = "",
9+
description = "C++23 module package for Dear ImGui core and GLFW/OpenGL3 backends",
10+
licenses = {"MIT"},
11+
repo = "https://github.com/mcpplibs/imgui-m",
12+
type = "package",
13+
14+
xpm = {
15+
linux = {
16+
["0.0.1"] = {
17+
url = "https://github.com/mcpplibs/imgui-m/archive/refs/tags/0.0.1.tar.gz",
18+
sha256 = "b87188bd2ca7d8010a695d5ebfccd76eb3e28b3e002885207493225057f5e190",
19+
},
20+
},
21+
macosx = {
22+
["0.0.1"] = {
23+
url = "https://github.com/mcpplibs/imgui-m/archive/refs/tags/0.0.1.tar.gz",
24+
sha256 = "b87188bd2ca7d8010a695d5ebfccd76eb3e28b3e002885207493225057f5e190",
25+
},
26+
},
27+
windows = {
28+
["0.0.1"] = {
29+
url = "https://github.com/mcpplibs/imgui-m/archive/refs/tags/0.0.1.tar.gz",
30+
sha256 = "b87188bd2ca7d8010a695d5ebfccd76eb3e28b3e002885207493225057f5e190",
31+
},
32+
},
33+
},
34+
35+
-- (no `mcpp` field -- default lookup will find <verdir>/*/mcpp.toml)
36+
}

tests/smoke_imgui_module.sh

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!/usr/bin/env bash
2+
# Smoke-test the public imgui module package through this checkout as a local
3+
# mcpp path index. This validates user-facing import-only consumption.
4+
set -euo pipefail
5+
6+
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
7+
MCPP_BIN="${MCPP:-}"
8+
if [[ -z "$MCPP_BIN" ]]; then
9+
MCPP_BIN="$(command -v mcpp || true)"
10+
fi
11+
if [[ -z "$MCPP_BIN" || ! -x "$MCPP_BIN" ]]; then
12+
echo "FATAL: set MCPP=/path/to/mcpp or put mcpp on PATH" >&2
13+
exit 1
14+
fi
15+
16+
TMP="$(mktemp -d)"
17+
if [[ "${MCPP_INDEX_KEEP_SMOKE_TMP:-0}" == "1" ]]; then
18+
echo "KEEP: $TMP"
19+
else
20+
trap 'rm -rf "$TMP"' EXIT
21+
fi
22+
23+
if [[ -n "${MCPP_INDEX_SMOKE_MCPP_HOME:-}" ]]; then
24+
export MCPP_HOME="$MCPP_INDEX_SMOKE_MCPP_HOME"
25+
else
26+
export MCPP_HOME="$TMP/mcpp-home"
27+
fi
28+
mkdir -p "$MCPP_HOME/registry/data/xpkgs"
29+
30+
USER_MCPP="${HOME}/.mcpp"
31+
link_xpkgs() {
32+
local src="$1"
33+
[[ -d "$src" ]] || return 0
34+
find "$src" -mindepth 1 -maxdepth 1 -type d | while read -r pkg; do
35+
ln -s "$pkg" "$MCPP_HOME/registry/data/xpkgs/$(basename "$pkg")" 2>/dev/null || true
36+
done
37+
}
38+
link_xpkgs "${MCPP_INDEX_SMOKE_XPKGS_DIR:-}"
39+
link_xpkgs "$USER_MCPP/registry/data/xpkgs"
40+
if [[ -d "$USER_MCPP/registry/data/xim-pkgindex" ]]; then
41+
mkdir -p "$MCPP_HOME/registry/data/xim-pkgindex"
42+
cp -a "$USER_MCPP/registry/data/xim-pkgindex/." "$MCPP_HOME/registry/data/xim-pkgindex/" 2>/dev/null || true
43+
rm -f "$MCPP_HOME/registry/data/xim-pkgindex/.xlings-index-cache.json"
44+
fi
45+
if [[ -d "$USER_MCPP/registry/bin" ]]; then
46+
mkdir -p "$MCPP_HOME/registry"
47+
ln -s "$USER_MCPP/registry/bin" "$MCPP_HOME/registry/bin" 2>/dev/null || true
48+
fi
49+
if [[ -f "$USER_MCPP/config.toml" ]]; then
50+
cp -f "$USER_MCPP/config.toml" "$MCPP_HOME/config.toml" 2>/dev/null || true
51+
fi
52+
53+
default_index="$MCPP_HOME/registry/data/mcpplibs"
54+
mkdir -p "$default_index"
55+
cp -a "$ROOT/." "$default_index/"
56+
rm -f "$default_index/.xlings-index-cache.json"
57+
printf 'ok\n' > "$default_index/.mcpp-index-updated"
58+
59+
"$MCPP_BIN" self config --mirror "${MCPP_INDEX_MIRROR:-GLOBAL}" >/dev/null
60+
61+
mkdir -p "$TMP/imgui-module-smoke/src"
62+
cd "$TMP/imgui-module-smoke"
63+
cat > mcpp.toml <<EOF
64+
[package]
65+
name = "imgui-module-smoke"
66+
version = "0.1.0"
67+
68+
[toolchain]
69+
default = "${MCPP_INDEX_IMGUI_MODULE_TOOLCHAIN:-llvm@20.1.7}"
70+
71+
[dependencies]
72+
imgui = "0.0.1"
73+
74+
[targets.imgui-module-smoke]
75+
kind = "bin"
76+
main = "src/main.cpp"
77+
EOF
78+
79+
cat > src/main.cpp <<'EOF'
80+
import std;
81+
import imgui.core;
82+
import imgui.backend.glfw_opengl3;
83+
84+
int main() {
85+
auto init = &ImGui::Backend::GlfwOpenGL3::Init;
86+
auto shutdown = &ImGui::Backend::GlfwOpenGL3::Shutdown;
87+
if (init == nullptr || shutdown == nullptr) {
88+
return 1;
89+
}
90+
91+
ImGuiContext* context = ImGui::CreateContext();
92+
if (context == nullptr) {
93+
return 2;
94+
}
95+
ImGui::SetCurrentContext(context);
96+
97+
ImGuiIO& io = ImGui::GetIO();
98+
io.DisplaySize = ImVec2 { 320.0f, 240.0f };
99+
unsigned char* pixels = nullptr;
100+
int width = 0;
101+
int height = 0;
102+
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
103+
if (pixels == nullptr || width <= 0 || height <= 0) {
104+
ImGui::DestroyContext(context);
105+
return 3;
106+
}
107+
108+
ImGui::NewFrame();
109+
bool open = true;
110+
ImGui::Begin("mcpp-index imgui smoke", &open);
111+
ImGui::TextUnformatted("import imgui.core");
112+
ImGui::End();
113+
ImGui::Render();
114+
115+
std::println("Dear ImGui {} module package ok", ImGui::GetVersion());
116+
ImGui::DestroyContext(context);
117+
return 0;
118+
}
119+
EOF
120+
121+
"$MCPP_BIN" build
122+
"$MCPP_BIN" run

0 commit comments

Comments
 (0)