qt: GHASTTY_VARIANT=vulkan installs side-by-side with the OpenGL build

The renderer is comptime-chosen in libghostty (`Renderer = switch
(build_config.renderer)` in `src/renderer.zig`), so one
`libghostty.so` only handles one renderer. The previous Qt build
overwrote `~/.local/lib/libghostty.so` on each install, which
silently broke whichever variant wasn't the last installed.

Adds a CMake option, `GHASTTY_VARIANT={opengl,vulkan}`, that:

  - Renames the installed executable when set to vulkan:
      ~/.local/bin/ghastty         (opengl, default)
      ~/.local/bin/ghastty-vulkan  (vulkan)

  - Tucks the Vulkan variant's libghostty.so into a sibling
    directory so the .so files coexist:
      ~/.local/lib/libghostty.so              (OpenGL)
      ~/.local/lib/ghastty-vulkan/libghostty.so (Vulkan)

  - Sets each binary's `INSTALL_RPATH` to point at the matching
    .so location (`$ORIGIN/../lib` vs
    `$ORIGIN/../lib/ghastty-vulkan`) so the dynamic linker resolves
    `libghostty.so` (same SONAME in both .so files) to the right
    one for each binary. No `LD_LIBRARY_PATH` games needed.

  - Skips installing the .desktop / icon for the Vulkan variant —
    it's a developer-facing side-by-side build, not a user-facing
    app, and avoids duplicating the launcher entry.

Workflow:

  # OpenGL (default)
  zig build -Dapp-runtime=none -Doptimize=ReleaseFast
  cmake -S qt -B qt/build-opengl
  cmake --build qt/build-opengl -j
  cmake --install qt/build-opengl --prefix ~/.local

  # Vulkan, side-by-side
  zig build -Dapp-runtime=none -Drenderer=vulkan -Doptimize=Debug
  cmake -S qt -B qt/build-vulkan -DGHASTTY_VARIANT=vulkan
  cmake --build qt/build-vulkan -j
  cmake --install qt/build-vulkan --prefix ~/.local

  # Verify (both binaries exist, each finds its own libghostty.so)
  readelf -d ~/.local/bin/ghastty | grep RUNPATH
  #   → $ORIGIN/../lib
  readelf -d ~/.local/bin/ghastty-vulkan | grep RUNPATH
  #   → $ORIGIN/../lib/ghastty-vulkan

  # Run
  ghastty                                # OpenGL, working terminal
  GHASTTY_RENDERER=vulkan ghastty-vulkan # Vulkan path, blank window for now

This unblocks parallel work: `ghastty` keeps working as a normal
terminal while `ghastty-vulkan` is the testbed for the renderer
integration. Long-term destination is still upstream libghostty
growing runtime renderer selection (collapses this back to one
binary), but that's out of scope here.

Co-Authored-By: claude-flow <ruv@ruv.net>
pull/12846/head
Nathan 2026-05-24 11:49:39 -05:00
parent 4cf3b29c85
commit 545898bb43
1 changed files with 55 additions and 7 deletions

View File

@ -76,6 +76,33 @@ get_filename_component(GHOSTTY_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/.." ABSOLUTE)
set(GHOSTTY_LIB_DIR "${GHOSTTY_ROOT}/zig-out/lib")
set(GHOSTTY_SO "${GHOSTTY_LIB_DIR}/ghostty-internal.so")
# Variant: which renderer libghostty was built with. Drives the
# installed executable name and (for the Vulkan variant) the
# libghostty install location, so the two builds can coexist
# side-by-side under the same `~/.local` prefix:
#
# GHASTTY_VARIANT=opengl (default)
# ~/.local/bin/ghastty
# ~/.local/lib/libghostty.so
# GHASTTY_VARIANT=vulkan
# ~/.local/bin/ghastty-vulkan
# ~/.local/lib/ghastty-vulkan/libghostty.so
# (and the binary's INSTALL_RPATH points into the subdir
# so the two .so files never conflict.)
#
# Set via `cmake -DGHASTTY_VARIANT=vulkan -S qt -B qt/build-vulkan`.
set(GHASTTY_VARIANT "opengl" CACHE STRING
"Renderer variant: opengl (default) or vulkan")
set_property(CACHE GHASTTY_VARIANT PROPERTY STRINGS opengl vulkan)
if(GHASTTY_VARIANT STREQUAL "vulkan")
set(GHASTTY_EXE_NAME "ghastty-vulkan")
set(GHASTTY_LIB_SUBDIR "ghastty-vulkan")
message(STATUS "Building Vulkan variant — exe=${GHASTTY_EXE_NAME}, lib=lib/${GHASTTY_LIB_SUBDIR}/")
else()
set(GHASTTY_EXE_NAME "ghastty")
set(GHASTTY_LIB_SUBDIR "")
endif()
if(NOT EXISTS "${GHOSTTY_SO}")
message(FATAL_ERROR
"libghostty not found at ${GHOSTTY_SO}\n"
@ -189,9 +216,24 @@ endif()
# actual zig-out artifact), and the .so's NEEDED entries also point
# into zig-out/lib for transitive deps.
# - Installed: libghostty.so lives next to the binary ($ORIGIN/../lib).
# Vulkan variant lives at lib/ghastty-vulkan/libghostty.so so it can
# coexist with the OpenGL build's lib/libghostty.so under the same
# install prefix. The INSTALL_RPATH steers each variant's binary at
# its own .so without polluting the other's lookup.
if(GHASTTY_VARIANT STREQUAL "vulkan")
set(GHASTTY_INSTALL_RPATH
"$ORIGIN/../${CMAKE_INSTALL_LIBDIR}/${GHASTTY_LIB_SUBDIR}")
set(GHASTTY_LIB_INSTALL_DIR
"${CMAKE_INSTALL_LIBDIR}/${GHASTTY_LIB_SUBDIR}")
else()
set(GHASTTY_INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}")
set(GHASTTY_LIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}")
endif()
set_target_properties(ghastty PROPERTIES
OUTPUT_NAME "${GHASTTY_EXE_NAME}"
BUILD_RPATH "${GHOSTTY_LINK_DIR};${GHOSTTY_LIB_DIR}"
INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}"
INSTALL_RPATH "${GHASTTY_INSTALL_RPATH}"
)
# --- install ---------------------------------------------------------
@ -199,12 +241,18 @@ install(TARGETS ghastty RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
# libghostty.so the binary links against (SONAME is libghostty.so).
install(FILES "${GHOSTTY_SO}"
DESTINATION "${CMAKE_INSTALL_LIBDIR}"
DESTINATION "${GHASTTY_LIB_INSTALL_DIR}"
RENAME libghostty.so)
install(FILES dist/ghastty.desktop
DESTINATION "${CMAKE_INSTALL_DATADIR}/applications")
# Desktop entry + icon: only install for the OpenGL variant the
# Vulkan binary is a developer-facing side-by-side build, not a
# user-facing app. Avoids duplicating the .desktop file with a
# different Exec= line.
if(GHASTTY_VARIANT STREQUAL "opengl")
install(FILES dist/ghastty.desktop
DESTINATION "${CMAKE_INSTALL_DATADIR}/applications")
# The custom scalable app icon.
install(FILES dist/ghastty.svg
DESTINATION "${CMAKE_INSTALL_DATADIR}/icons/hicolor/scalable/apps")
# The custom scalable app icon.
install(FILES dist/ghastty.svg
DESTINATION "${CMAKE_INSTALL_DATADIR}/icons/hicolor/scalable/apps")
endif()