Skip to content

Make X11 and Wayland libraries optional - #56

Merged
levovix0 merged 15 commits into
levovix0:masterfrom
elcritch:fix/optional-platform-libraries
Oct 6, 2026
Merged

levovix0 merged 15 commits into
levovix0:masterfrom
elcritch:fix/optional-platform-libraries

Conversation

@elcritch

@elcritch elcritch commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A Linux/BSD binary built with both backends should start without requiring libraries for the unused backend. Load the X11, GLX, XRender, Xcursor, Xext, Wayland, xkbcommon, EGL, wayland-egl, and Vulkan entry points through optional runtime handles. Advertise available backends and raise an error when an unavailable renderer is requested.

  • Reuse siwin_loadDynlibIfExists, adding support for explicit importc symbol names.
  • Reuse the original X11 package types and preserve existing EGL/Wayland parameter and return types, GLX call patterns, and Vulkan surface types.
  • Keep X11 visual queries available and load the X11-XCB bridge independently of core X11.
  • Check required symbols before initialization and guard cleanup of partially created windows and rendering contexts. Preserve upstream's libdecor_new != nil availability check.

The C ABI corrections, their caller changes, and the 32-bit binding comments are isolated in the stacked follow-up PR. This PR keeps the existing binding signatures so the optional-loading change can be reviewed separately.

Validation

Rechecked the dynamic-loading-only branch with Nim 2.2.10 on FreeBSD:

  • tests/t_dynlib_loading.nim passed with the default memory manager and --mm:refc: missing libraries/symbols, original and aliased symbol lookup, varargs, and existing public API call patterns.
  • A dlopen shim hiding the optional platform libraries passed startup, nil-pointer, availability, error, and cleanup checks.
  • EGL context creation, make-current, swapping, and cleanup passed under Xvfb.
  • Wayland connection by name and file descriptor, roundtrip, read/cancel, dispatch, proxy lifecycle, and disconnection passed against a temporary libwayland server.
  • tests/t_opengl.nim and tests/t_event_loop.nim passed on isolated Xvfb servers.
  • nim check --os:linux --path:src src/siwin.nim passed for amd64 and i386; git diff --check upstream/master passed.

The i386 checks are compile-time checks only. Live Wayland rendering was not exercised because no compositor was available. ABI limitations of the original declarations remain for the follow-up to address.

Use siwin_loadDynlibIfExists with importc aliases across optional bindings.
Reuse the original X11 package types instead of a private copy, preserve
nullable callable variables and the existing EGL and GLX call patterns,
and restore unrelated formatting changes.

Add loader and source compatibility regression coverage.
@elcritch
elcritch force-pushed the fix/optional-platform-libraries branch from d1f4213 to 43f6471 Compare October 5, 2026 19:11
@elcritch
elcritch marked this pull request as ready for review October 5, 2026 20:24
@levovix0
levovix0 merged commit 0b249c4 into levovix0:master Oct 6, 2026
2 of 3 checks passed
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.

2 participants