From 00a54b450ccb01e46f2486b347957483983c56cb Mon Sep 17 00:00:00 2001 From: sunrisepeak Date: Wed, 3 Jun 2026 08:12:48 +0800 Subject: [PATCH] Add GLX runtime closure for GLFW --- .github/workflows/validate.yml | 21 ++--- README.md | 16 +++- pkgs/c/compat.glfw.lua | 21 +---- pkgs/c/compat.glx-runtime.lua | 135 +++++++++++++++++++++++++++++ pkgs/c/compat.x11.lua | 2 +- pkgs/c/compat.xau.lua | 2 +- pkgs/c/compat.xcb.lua | 2 +- pkgs/c/compat.xcursor.lua | 2 +- pkgs/c/compat.xdmcp.lua | 2 +- pkgs/c/compat.xext.lua | 2 +- pkgs/c/compat.xfixes.lua | 2 +- pkgs/c/compat.xi.lua | 2 +- pkgs/c/compat.xinerama.lua | 2 +- pkgs/c/compat.xrandr.lua | 2 +- pkgs/c/compat.xrender.lua | 2 +- tests/smoke_compat_imgui.sh | 63 +++++++++----- tests/smoke_compat_imgui_window.sh | 97 +++------------------ 17 files changed, 226 insertions(+), 149 deletions(-) create mode 100644 pkgs/c/compat.glx-runtime.lua diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index d066027..20598c1 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -53,12 +53,12 @@ jobs: uses: actions/cache@v4 with: path: ~/.mcpp/registry - key: mcpp-registry-${{ runner.os }}-0.0.45-${{ hashFiles('pkgs/**/*.lua', 'tests/*.sh', '.github/workflows/validate.yml') }} + key: mcpp-registry-${{ runner.os }}-0.0.46-${{ hashFiles('pkgs/**/*.lua', 'tests/*.sh', '.github/workflows/validate.yml') }} restore-keys: | - mcpp-registry-${{ runner.os }}-0.0.45- + mcpp-registry-${{ runner.os }}-0.0.46- - name: Download mcpp env: - MCPP_VERSION: "0.0.45" + MCPP_VERSION: "0.0.46" run: | curl -L -fsS -o mcpp.tar.gz \ "https://github.com/mcpp-community/mcpp/releases/download/v${MCPP_VERSION}/mcpp-${MCPP_VERSION}-linux-x86_64.tar.gz" @@ -72,6 +72,7 @@ jobs: - name: Run compat smoke tests env: MCPP_INDEX_SMOKE_MCPP_HOME: ${{ runner.temp }}/mcpp-smoke-home + MCPP_INDEX_SMOKE_CACHE_DIR: ${{ runner.temp }}/mcpp-smoke-cache run: | mkdir -p "$MCPP_INDEX_SMOKE_MCPP_HOME" "$MCPP" --version @@ -91,14 +92,14 @@ jobs: include: - platform: macos os: macos-15 - archive: mcpp-0.0.45-macosx-arm64.tar.gz - root: mcpp-0.0.45-macosx-arm64 + archive: mcpp-0.0.46-macosx-arm64.tar.gz + root: mcpp-0.0.46-macosx-arm64 mcpp: bin/mcpp xlings: registry/bin/xlings - platform: windows os: windows-latest - archive: mcpp-0.0.45-windows-x86_64.zip - root: mcpp-0.0.45-windows-x86_64 + archive: mcpp-0.0.46-windows-x86_64.zip + root: mcpp-0.0.46-windows-x86_64 mcpp: bin/mcpp.exe xlings: registry/bin/xlings.exe steps: @@ -107,13 +108,13 @@ jobs: uses: actions/cache@v4 with: path: ~/.mcpp/registry - key: mcpp-registry-${{ runner.os }}-0.0.45-${{ hashFiles('pkgs/**/*.lua', 'tests/*.sh', '.github/workflows/validate.yml') }} + key: mcpp-registry-${{ runner.os }}-0.0.46-${{ hashFiles('pkgs/**/*.lua', 'tests/*.sh', '.github/workflows/validate.yml') }} restore-keys: | - mcpp-registry-${{ runner.os }}-0.0.45- + mcpp-registry-${{ runner.os }}-0.0.46- - name: Download mcpp shell: bash env: - MCPP_VERSION: "0.0.45" + MCPP_VERSION: "0.0.46" MCPP_ARCHIVE: ${{ matrix.archive }} MCPP_ROOT: ${{ matrix.root }} run: | diff --git a/README.md b/README.md index dfb8893..d2022ee 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ mcpp build # 自动拉取源码 + 构建 | `gtest` | 1.15.2 | Google Test 测试框架 | | `imgui` | 1.92.8 | Dear ImGui immediate-mode GUI 核心源码 | | `opengl` | 2026.05.31 | Khronos OpenGL API 头文件 | +| `glx-runtime` | 2026.06.03 | Linux host GLVND/GLX/OpenGL runtime adapter | | `khrplatform` | 2026.05.31 | Khronos KHR platform 头文件 | | `xorgproto` | 2025.1 | X.Org protocol 头文件 | | `xtrans` | 1.6.0 | X.Org transport support headers/source snippets | @@ -77,7 +78,10 @@ mcpplibs.xpkg imgui ├── compat.imgui ├── compat.glfw - │ └── compat.opengl + │ ├── compat.opengl + │ └── compat.glx-runtime + │ └── compat.xext → compat.x11 + │ ← Linux GLX/OpenGL driver runtime provider └── compat.opengl ← 消费者只需要 import imgui.* 模块 libarchive @@ -90,6 +94,8 @@ libarchive glfw ├── opengl │ └── khrplatform ← GLFW/glfw3.h 所需 OpenGL/KHR 头文件 + ├── glx-runtime + │ └── xext → x11 ← GLFW GLX dlopen 所需 host GLVND/driver runtime └── x11 / xcursor / xext / xfixes / xi / xinerama / xorgproto / xrandr / xrender ← GLFW Linux X11 后端所需 runtime/header 闭包 @@ -111,9 +117,11 @@ x11 mcpp 0.0.3+ 的 transitive walker 自动沿链路传播头文件和依赖,消费者只需声明直接依赖。 > 当前 X11/XCB/Xau/Xdmcp 以及 GLFW 需要的 Xcursor/Xext/Xfixes/Xi/Xinerama/ -> Xrandr/Xrender 都已按上游源码提供 runtime `.so`。`compat.glfw` 仍沿用 -> GLFW 上游的 GLX/OpenGL 动态加载行为,包描述会声明需要 `dlopen` 的 -> `libGLX.so.0`/`libGL.so.1`/`libGL.so` 以及 `opengl.glx.driver` 能力。 +> Xrandr/Xrender 都已按上游源码提供 runtime `.so`,并声明标准 ELF SONAME +> (如 `libX11.so.6`、`libxcb.so.1`)。`compat.glx-runtime` 是 Linux host +> GLVND/GLX/OpenGL driver runtime adapter,提供 GLFW 上游 `dlopen` 需要的 +> `libGLX.so.0`/`libGL.so.1`/`libGL.so` runtime 目录,并通过 `compat.xext` +> 带入 host GLX 库常见的 X11/Xext ABI 依赖闭包。 > 窗口运行时仍需要宿主环境提供可用的 X server/GLX/OpenGL 驱动。 ### 本地 smoke 验证 diff --git a/pkgs/c/compat.glfw.lua b/pkgs/c/compat.glfw.lua index 9693814..381fa47 100644 --- a/pkgs/c/compat.glfw.lua +++ b/pkgs/c/compat.glfw.lua @@ -71,6 +71,7 @@ package = { "src/posix_module.c", }, deps = { + ["compat.glx-runtime"] = "2026.06.03", ["compat.x11"] = "1.8.13", ["compat.xcursor"] = "1.2.3", ["compat.xext"] = "1.3.7", @@ -119,25 +120,6 @@ package = { import("xim.libxpkg.pkginfo") -local function patch_x11_loader_names(root) - local file = path.join(root, "src", "x11_init.c") - local data = io.readfile(file) - local replacements = { - ['"libX11.so.6"'] = '"libX11.so"', - ['"libXi.so.6"'] = '"libXi.so"', - ['"libXrandr.so.2"'] = '"libXrandr.so"', - ['"libXcursor.so.1"'] = '"libXcursor.so"', - ['"libXinerama.so.1"'] = '"libXinerama.so"', - ['"libX11-xcb.so.1"'] = '"libX11-xcb.so"', - ['"libXrender.so.1"'] = '"libXrender.so"', - ['"libXext.so.6"'] = '"libXext.so"', - } - for from, to in pairs(replacements) do - data = data:gsub(from, to) - end - io.writefile(file, data) -end - function install() local srcdir = pkginfo.install_file():replace(".tar.gz", "") if not os.isdir(srcdir) then @@ -146,6 +128,5 @@ function install() os.tryrm(pkginfo.install_dir()) os.mv(srcdir, pkginfo.install_dir()) - patch_x11_loader_names(pkginfo.install_dir()) return true end diff --git a/pkgs/c/compat.glx-runtime.lua b/pkgs/c/compat.glx-runtime.lua new file mode 100644 index 0000000..d89b304 --- /dev/null +++ b/pkgs/c/compat.glx-runtime.lua @@ -0,0 +1,135 @@ +package = { + spec = "1", + namespace = "compat", + name = "compat.glx-runtime", + description = "Host GLVND/GLX/OpenGL runtime adapter for mcpp Linux window applications", + licenses = {"MIT"}, + repo = "https://github.com/KhronosGroup/OpenGL-Registry", + type = "package", + + xpm = { + linux = { + ["2026.06.03"] = { + url = "https://raw.githubusercontent.com/KhronosGroup/OpenGL-Registry/a30033d3e812c9bf10094f1010374a6b15e192eb/README.adoc", + sha256 = "ea68efce197e68413ebb62c51ab4bccfb2309a2fca776d31b49d972f59f3640e", + }, + }, + }, + + mcpp = { + language = "c++23", + import_std = false, + c_standard = "c11", + generated_files = { + ["mcpp_generated/glx_runtime_empty.c"] = "int mcpp_compat_glx_runtime_anchor(void) { return 0; }\n", + }, + sources = {"mcpp_generated/glx_runtime_empty.c"}, + targets = { ["glx_runtime"] = { kind = "lib" } }, + runtime = { + library_dirs = { "mcpp_generated/glx_runtime/lib" }, + dlopen_libs = { "libGLX.so.0", "libGL.so.1", "libGL.so" }, + capabilities = { "x11.display", "opengl.glx.driver" }, + }, + deps = { + ["compat.xext"] = "1.3.7", + }, + }, +} + +import("xim.libxpkg.pkginfo") +import("xim.libxpkg.log") + +local function sh_quote(value) + return "'" .. tostring(value):gsub("'", "'\\''") .. "'" +end + +local function split_paths(value) + local out = {} + if not value or value == "" then + return out + end + for item in tostring(value):gmatch("[^:]+") do + if item ~= "" then + table.insert(out, item) + end + end + return out +end + +local function candidate_dirs() + local out = {} + local seen = {} + local function add(dir) + if dir and dir ~= "" and not seen[dir] and os.isdir(dir) then + seen[dir] = true + table.insert(out, dir) + end + end + + for _, dir in ipairs(split_paths(os.getenv("MCPP_HOST_GL_LIBRARY_PATH"))) do + add(dir) + end + add("/lib/x86_64-linux-gnu") + add("/usr/lib/x86_64-linux-gnu") + add("/lib64") + add("/usr/lib64") + add("/usr/lib") + return out +end + +local host_gl_patterns = { + "libGL.so*", + "libGLX.so*", + "libGLX_*.so*", + "libGLdispatch.so*", + "libOpenGL.so*", + "libEGL.so*", + "libEGL_*.so*", + "libGLES*.so*", + "libnvidia*.so*", + "libglapi.so*", + "libdrm*.so*", + "libexpat.so*", + "libxshmfence.so*", + "libbsd.so*", + "libmd.so*", +} + +local required = { + ["libGLX.so.0"] = false, + ["libGL.so.1"] = false, +} + +local function link_runtime_libs(outdir) + os.mkdir(outdir) + for _, dir in ipairs(candidate_dirs()) do + for _, pattern in ipairs(host_gl_patterns) do + os.exec( + "for lib in " .. sh_quote(dir) .. "/" .. pattern .. + "; do [ -e \"$lib\" ] || continue; " .. + "ln -sf \"$lib\" " .. sh_quote(outdir) .. "/\"$(basename \"$lib\")\"; " .. + "done" + ) + end + end + + for name, _ in pairs(required) do + if not os.isfile(path.join(outdir, name)) then + log.error("required host GL runtime library not found: %s", name) + return false + end + end + return true +end + +function install() + os.tryrm(pkginfo.install_dir()) + os.mkdir(pkginfo.install_dir()) + + local generated = path.join(pkginfo.install_dir(), "mcpp_generated") + os.mkdir(generated) + io.writefile(path.join(generated, "glx_runtime_empty.c"), + "int mcpp_compat_glx_runtime_anchor(void) { return 0; }\n") + + return link_runtime_libs(path.join(generated, "glx_runtime", "lib")) +end diff --git a/pkgs/c/compat.x11.lua b/pkgs/c/compat.x11.lua index e7f0bd4..1469acf 100644 --- a/pkgs/c/compat.x11.lua +++ b/pkgs/c/compat.x11.lua @@ -55,7 +55,7 @@ package = { "modules/lc/Utf8/*.c", "modules/om/generic/*.c", }, - targets = { ["X11"] = { kind = "shared" } }, + targets = { ["X11"] = { kind = "shared", soname = "libX11.so.6" } }, deps = { ["compat.xcb"] = "1.17.0", ["compat.xorgproto"] = "2025.1", diff --git a/pkgs/c/compat.xau.lua b/pkgs/c/compat.xau.lua index 01723bc..2ccde32 100644 --- a/pkgs/c/compat.xau.lua +++ b/pkgs/c/compat.xau.lua @@ -32,7 +32,7 @@ package = { "*/AuUnlock.c", "*/AuWrite.c", }, - targets = { ["Xau"] = { kind = "shared" } }, + targets = { ["Xau"] = { kind = "shared", soname = "libXau.so.6" } }, deps = { ["compat.xorgproto"] = "2025.1", }, diff --git a/pkgs/c/compat.xcb.lua b/pkgs/c/compat.xcb.lua index 4342e5e..e74302d 100644 --- a/pkgs/c/compat.xcb.lua +++ b/pkgs/c/compat.xcb.lua @@ -42,7 +42,7 @@ package = { "src/bigreq.c", "src/xc_misc.c", }, - targets = { ["xcb"] = { kind = "shared" } }, + targets = { ["xcb"] = { kind = "shared", soname = "libxcb.so.1" } }, deps = { ["compat.xau"] = "1.0.12", ["compat.xcb-proto"] = "1.17.0", diff --git a/pkgs/c/compat.xcursor.lua b/pkgs/c/compat.xcursor.lua index 5f5c70e..aa6b495 100644 --- a/pkgs/c/compat.xcursor.lua +++ b/pkgs/c/compat.xcursor.lua @@ -23,7 +23,7 @@ package = { cflags = {"-D_GNU_SOURCE", "-D_DEFAULT_SOURCE", "-DHAVE_XFIXES=1"}, include_dirs = {"*/include", "*/include/X11/Xcursor", "*/include/X11/extensions", "*/src"}, sources = {"*/src/*.c"}, - targets = { ["Xcursor"] = { kind = "shared" } }, + targets = { ["Xcursor"] = { kind = "shared", soname = "libXcursor.so.1" } }, deps = { ["compat.x11"] = "1.8.13", ["compat.xfixes"] = "6.0.2", diff --git a/pkgs/c/compat.xdmcp.lua b/pkgs/c/compat.xdmcp.lua index 14ebfd3..be6c488 100644 --- a/pkgs/c/compat.xdmcp.lua +++ b/pkgs/c/compat.xdmcp.lua @@ -32,7 +32,7 @@ package = { "*/Wrap.c", "*/Write.c", }, - targets = { ["Xdmcp"] = { kind = "shared" } }, + targets = { ["Xdmcp"] = { kind = "shared", soname = "libXdmcp.so.6" } }, deps = { ["compat.xorgproto"] = "2025.1", }, diff --git a/pkgs/c/compat.xext.lua b/pkgs/c/compat.xext.lua index c203ad0..784a79e 100644 --- a/pkgs/c/compat.xext.lua +++ b/pkgs/c/compat.xext.lua @@ -23,7 +23,7 @@ package = { cflags = {"-D_GNU_SOURCE", "-D_DEFAULT_SOURCE"}, include_dirs = {"*/include", "*/include/X11/extensions", "*/src"}, sources = {"*/src/*.c"}, - targets = { ["Xext"] = { kind = "shared" } }, + targets = { ["Xext"] = { kind = "shared", soname = "libXext.so.6" } }, deps = { ["compat.x11"] = "1.8.13", ["compat.xorgproto"] = "2025.1", diff --git a/pkgs/c/compat.xfixes.lua b/pkgs/c/compat.xfixes.lua index 28765e5..d8b66eb 100644 --- a/pkgs/c/compat.xfixes.lua +++ b/pkgs/c/compat.xfixes.lua @@ -23,7 +23,7 @@ package = { cflags = {"-D_GNU_SOURCE", "-D_DEFAULT_SOURCE"}, include_dirs = {"*/include", "*/include/X11/extensions", "*/src"}, sources = {"*/src/*.c"}, - targets = { ["Xfixes"] = { kind = "shared" } }, + targets = { ["Xfixes"] = { kind = "shared", soname = "libXfixes.so.3" } }, deps = { ["compat.x11"] = "1.8.13", ["compat.xext"] = "1.3.7", diff --git a/pkgs/c/compat.xi.lua b/pkgs/c/compat.xi.lua index 903adbf..7c6078d 100644 --- a/pkgs/c/compat.xi.lua +++ b/pkgs/c/compat.xi.lua @@ -26,7 +26,7 @@ package = { "*/src/*.c", "!*/src/XFreeLst.c", }, - targets = { ["Xi"] = { kind = "shared" } }, + targets = { ["Xi"] = { kind = "shared", soname = "libXi.so.6" } }, deps = { ["compat.x11"] = "1.8.13", ["compat.xext"] = "1.3.7", diff --git a/pkgs/c/compat.xinerama.lua b/pkgs/c/compat.xinerama.lua index f76a0cf..d563771 100644 --- a/pkgs/c/compat.xinerama.lua +++ b/pkgs/c/compat.xinerama.lua @@ -23,7 +23,7 @@ package = { cflags = {"-D_GNU_SOURCE", "-D_DEFAULT_SOURCE"}, include_dirs = {"*/include", "*/include/X11/extensions", "*/src"}, sources = {"*/src/*.c"}, - targets = { ["Xinerama"] = { kind = "shared" } }, + targets = { ["Xinerama"] = { kind = "shared", soname = "libXinerama.so.1" } }, deps = { ["compat.x11"] = "1.8.13", ["compat.xext"] = "1.3.7", diff --git a/pkgs/c/compat.xrandr.lua b/pkgs/c/compat.xrandr.lua index 3939072..124b45a 100644 --- a/pkgs/c/compat.xrandr.lua +++ b/pkgs/c/compat.xrandr.lua @@ -23,7 +23,7 @@ package = { cflags = {"-D_GNU_SOURCE", "-D_DEFAULT_SOURCE"}, include_dirs = {"*/include", "*/include/X11/extensions", "*/src"}, sources = {"*/src/*.c"}, - targets = { ["Xrandr"] = { kind = "shared" } }, + targets = { ["Xrandr"] = { kind = "shared", soname = "libXrandr.so.2" } }, deps = { ["compat.x11"] = "1.8.13", ["compat.xext"] = "1.3.7", diff --git a/pkgs/c/compat.xrender.lua b/pkgs/c/compat.xrender.lua index ef3e0f1..04b512b 100644 --- a/pkgs/c/compat.xrender.lua +++ b/pkgs/c/compat.xrender.lua @@ -23,7 +23,7 @@ package = { cflags = {"-D_GNU_SOURCE", "-D_DEFAULT_SOURCE"}, include_dirs = {"*/include", "*/include/X11/extensions", "*/src"}, sources = {"*/src/*.c"}, - targets = { ["Xrender"] = { kind = "shared" } }, + targets = { ["Xrender"] = { kind = "shared", soname = "libXrender.so.1" } }, deps = { ["compat.x11"] = "1.8.13", ["compat.xorgproto"] = "2025.1", diff --git a/tests/smoke_compat_imgui.sh b/tests/smoke_compat_imgui.sh index 7875a0c..f892553 100755 --- a/tests/smoke_compat_imgui.sh +++ b/tests/smoke_compat_imgui.sh @@ -19,8 +19,9 @@ if [[ "${MCPP_INDEX_KEEP_SMOKE_TMP:-0}" == "1" ]]; then else trap 'rm -rf "$TMP"' EXIT fi -SMOKE_CACHE_DIR="${MCPP_INDEX_SMOKE_CACHE_DIR:-}" +SMOKE_CACHE_DIR="${MCPP_INDEX_SMOKE_CACHE_DIR:-$TMP/smoke-cache}" SMOKE_XPKGS_DIR="${MCPP_INDEX_SMOKE_XPKGS_DIR:-}" +mkdir -p "$SMOKE_CACHE_DIR" if [[ -n "${MCPP_INDEX_SMOKE_MCPP_HOME:-}" ]]; then export MCPP_HOME="$MCPP_INDEX_SMOKE_MCPP_HOME" @@ -54,6 +55,26 @@ if [[ -f "$USER_MCPP/config.toml" ]]; then cp -f "$USER_MCPP/config.toml" "$MCPP_HOME/config.toml" 2>/dev/null || true fi +restore_smoke_cache() { + [[ -n "$SMOKE_CACHE_DIR" && -d "$SMOKE_CACHE_DIR" ]] || return 0 + mkdir -p .mcpp/.xlings/data/runtimedir + find "$SMOKE_CACHE_DIR" -maxdepth 1 -type f \ + \( -name '*.tar.gz' -o -name '*.tar.xz' -o -name '*.zip' \) \ + -exec cp -f {} .mcpp/.xlings/data/runtimedir/ \; +} + +save_smoke_cache() { + [[ -n "$SMOKE_CACHE_DIR" && -d .mcpp/.xlings/data ]] || return 0 + find .mcpp/.xlings/data -type f \ + \( -name '*.tar.gz' -o -name '*.tar.xz' -o -name '*.zip' \) \ + -exec cp -n {} "$SMOKE_CACHE_DIR"/ \; 2>/dev/null || true +} + +mcpp_build() { + "$MCPP_BIN" build + save_smoke_cache +} + make_project() { local name="$1" mkdir -p "$TMP/$name/src" @@ -74,12 +95,7 @@ kind = "bin" main = "src/main.cpp" EOF - if [[ -n "$SMOKE_CACHE_DIR" && -d "$SMOKE_CACHE_DIR" ]]; then - mkdir -p .mcpp/.xlings/data/runtimedir - find "$SMOKE_CACHE_DIR" -maxdepth 1 -type f \ - \( -name '*.tar.gz' -o -name '*.tar.xz' -o -name '*.zip' \) \ - -exec cp -f {} .mcpp/.xlings/data/runtimedir/ \; - fi + restore_smoke_cache } make_project "compat-imgui-core-smoke" @@ -114,7 +130,7 @@ int main() { return ok ? 0 : 1; } EOF -"$MCPP_BIN" build +mcpp_build "$MCPP_BIN" run make_project "compat-xlibs-runtime-smoke" @@ -151,11 +167,12 @@ int main() { XIQueryVersion != nullptr ? 0 : 1; } EOF -"$MCPP_BIN" build +mcpp_build "$MCPP_BIN" run if command -v readelf >/dev/null 2>&1; then bin="$(find target -path '*/bin/compat-xlibs-runtime-smoke' -type f | head -1)" - for lib in libXext.so libXrender.so libXfixes.so libXcursor.so libXinerama.so libXrandr.so libXi.so; do + for lib in libXext.so.6 libXrender.so.1 libXfixes.so.3 libXcursor.so.1 libXinerama.so.1 libXrandr.so.2 libXi.so.6; do + test -e "$(dirname "$bin")/$lib" readelf -d "$bin" | grep -q "Shared library: \\[$lib\\]" done fi @@ -178,11 +195,11 @@ int main() { return GLFW_VERSION_MAJOR == 3 ? 0 : 1; } EOF -"$MCPP_BIN" build +mcpp_build "$MCPP_BIN" run if command -v readelf >/dev/null 2>&1; then bin="$(find target -path '*/bin/compat-glfw-runtime-smoke' -type f | head -1)" - for lib in libX11.so libXcursor.so libXext.so libXfixes.so libXi.so libXinerama.so libXrandr.so libXrender.so; do + for lib in libX11.so.6 libXcursor.so.1 libXext.so.6 libXfixes.so.3 libXi.so.6 libXinerama.so.1 libXrandr.so.2 libXrender.so.1; do readelf -d "$bin" | grep -q "Shared library: \\[$lib\\]" done fi @@ -209,12 +226,14 @@ int main() { return allocated && auth_file != nullptr ? 0 : 1; } EOF -"$MCPP_BIN" build +mcpp_build "$MCPP_BIN" run if command -v readelf >/dev/null 2>&1; then bin="$(find target -path '*/bin/compat-xorg-runtime-smoke' -type f | head -1)" - readelf -d "$bin" | grep -q 'Shared library: \[libXau.so\]' - readelf -d "$bin" | grep -q 'Shared library: \[libXdmcp.so\]' + test -e "$(dirname "$bin")/libXau.so.6" + test -e "$(dirname "$bin")/libXdmcp.so.6" + readelf -d "$bin" | grep -q 'Shared library: \[libXau.so.6\]' + readelf -d "$bin" | grep -q 'Shared library: \[libXdmcp.so.6\]' fi make_project "compat-xcb-runtime-smoke" @@ -236,11 +255,12 @@ int main() { return ok && display == 0 && screen == 1 ? 0 : 1; } EOF -"$MCPP_BIN" build +mcpp_build "$MCPP_BIN" run if command -v readelf >/dev/null 2>&1; then bin="$(find target -path '*/bin/compat-xcb-runtime-smoke' -type f | head -1)" - readelf -d "$bin" | grep -q 'Shared library: \[libxcb.so\]' + test -e "$(dirname "$bin")/libxcb.so.1" + readelf -d "$bin" | grep -q 'Shared library: \[libxcb.so.1\]' fi make_project "compat-x11-runtime-smoke" @@ -258,13 +278,16 @@ int main() { return X_PROTOCOL == 11 && escape == XK_Escape ? 0 : 1; } EOF -"$MCPP_BIN" build +mcpp_build "$MCPP_BIN" run if command -v readelf >/dev/null 2>&1; then bin="$(find target -path '*/bin/compat-x11-runtime-smoke' -type f | head -1)" lib="$(find target -path '*/bin/libX11.so' -type f | head -1)" - readelf -d "$bin" | grep -q 'Shared library: \[libX11.so\]' - readelf -d "$lib" | grep -q 'Shared library: \[libxcb.so\]' + test -e "$(dirname "$bin")/libX11.so.6" + test -e "$(dirname "$bin")/libxcb.so.1" + readelf -d "$bin" | grep -q 'Shared library: \[libX11.so.6\]' + readelf -d "$lib" | grep -q 'Library soname: \[libX11.so.6\]' + readelf -d "$lib" | grep -q 'Shared library: \[libxcb.so.1\]' fi echo "OK" diff --git a/tests/smoke_compat_imgui_window.sh b/tests/smoke_compat_imgui_window.sh index e1df169..05f9c93 100755 --- a/tests/smoke_compat_imgui_window.sh +++ b/tests/smoke_compat_imgui_window.sh @@ -1,7 +1,8 @@ #!/usr/bin/env bash # Build a minimal Dear ImGui + GLFW + OpenGL window program through this -# checkout as a local mcpp path index. Runtime execution is optional because -# GLX/OpenGL driver libraries are host-specific. +# checkout as a local mcpp path index. Runtime execution is opt-in because it +# requires a live X11/GLX display, but when enabled it must run through mcpp +# without test-local library shims. set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" @@ -176,7 +177,15 @@ if [[ -z "$bin" ]]; then fi if command -v readelf >/dev/null 2>&1; then - for lib in libX11.so libXcursor.so libXext.so libXfixes.so libXi.so libXinerama.so libXrandr.so libXrender.so; do + for lib in \ + libX11.so.6 \ + libXcursor.so.1 \ + libXext.so.6 \ + libXfixes.so.3 \ + libXi.so.6 \ + libXinerama.so.1 \ + libXrandr.so.2 \ + libXrender.so.1; do readelf -d "$bin" | grep -q "Shared library: \\[$lib\\]" done fi @@ -191,85 +200,5 @@ if [[ -z "${DISPLAY:-}" ]]; then exit 1 fi -bindir="$(dirname "$bin")" -shim="$TMP/gl-runtime-shim" -mkdir -p "$shim" - -HOST_GL_LIBDIR="${MCPP_INDEX_HOST_GL_LIBDIR:-/lib/x86_64-linux-gnu}" -if [[ ! -d "$HOST_GL_LIBDIR" ]]; then - echo "FATAL: host GL library directory not found: $HOST_GL_LIBDIR" >&2 - exit 1 -fi - -link_host_glob() { - local pattern="$1" - local matched=0 - for lib in "$HOST_GL_LIBDIR"/$pattern; do - [[ -e "$lib" ]] || continue - ln -sf "$lib" "$shim/$(basename "$lib")" - matched=1 - done - return $matched -} - -link_host_glob 'libGL*.so*' || true -link_host_glob 'libEGL*.so*' || true -link_host_glob 'libnvidia*.so*' || true -link_host_glob 'libglapi.so*' || true -link_host_glob 'libdrm.so*' || true -link_host_glob 'libxcb*.so*' || true -link_host_glob 'libX11-xcb.so*' || true -link_host_glob 'libX11.so*' || true -link_host_glob 'libXau.so*' || true -link_host_glob 'libXdmcp.so*' || true -link_host_glob 'libXext.so*' || true -link_host_glob 'libXfixes.so*' || true -link_host_glob 'libXrender.so*' || true -link_host_glob 'libXcursor.so*' || true -link_host_glob 'libXinerama.so*' || true -link_host_glob 'libXrandr.so*' || true -link_host_glob 'libXi.so*' || true -link_host_glob 'libXxf86vm.so*' || true -link_host_glob 'libexpat.so*' || true -link_host_glob 'libxshmfence.so*' || true -link_host_glob 'libbsd.so*' || true -link_host_glob 'libmd.so*' || true - -runpath="$(readelf -d "$bin" | sed -n 's/.*RUNPATH.*\[\(.*\)\].*/\1/p' | head -1)" -IFS=':' read -r -a runpath_dirs <<< "$runpath" -for dir in "${runpath_dirs[@]}"; do - for lib in libdl.so.2 libpthread.so.0 librt.so.1; do - [[ -e "$dir/$lib" ]] && ln -sf "$dir/$lib" "$shim/$lib" - done -done - -find_target_lib() { - local name="$1" - find target -path "*/bin/$name" -type f | head -1 -} - -link_compat_lib() { - local file="$1" - shift - local src - src="$(find_target_lib "$file")" - [[ -n "$src" ]] || return 0 - for soname in "$@"; do - ln -sf "$(cd "$(dirname "$src")" && pwd)/$(basename "$src")" "$shim/$soname" - done -} - -link_compat_lib libX11.so libX11.so libX11.so.6 -link_compat_lib libxcb.so libxcb.so libxcb.so.1 -link_compat_lib libXau.so libXau.so libXau.so.6 -link_compat_lib libXdmcp.so libXdmcp.so libXdmcp.so.6 -link_compat_lib libXext.so libXext.so libXext.so.6 -link_compat_lib libXfixes.so libXfixes.so libXfixes.so.3 -link_compat_lib libXrender.so libXrender.so libXrender.so.1 -link_compat_lib libXcursor.so libXcursor.so libXcursor.so.1 -link_compat_lib libXinerama.so libXinerama.so libXinerama.so.1 -link_compat_lib libXrandr.so libXrandr.so libXrandr.so.2 -link_compat_lib libXi.so libXi.so libXi.so.6 - -LD_LIBRARY_PATH="$shim${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" "$bin" +"$MCPP_BIN" run echo "OK"