ghostty icon indicating copy to clipboard operation
ghostty copied to clipboard

gtk4-layer-shell shared lib needs to be installed when not linking external library

Open jcollie opened this issue 1 year ago • 23 comments

Discussed in https://github.com/ghostty-org/ghostty/discussions/6631

Originally posted by vaskark March 8, 2025 Hi. I build ghostty on Ubuntu 24.10 and usually delete .zig-cache (along with .cache/zig) after a successful build. Ghostty usually runs just fine. But the past few days I've been getting this error:

ghostty: error while loading shared libraries: libgtk4-layer-shell.so: cannot open shared object file: No such file or directory

I suppose I just need to keep .zig-cache. But is there any reason why this has changed all the sudden?

Thanks.

jcollie avatar Mar 09 '25 01:03 jcollie

@pluiedev

jcollie avatar Mar 09 '25 01:03 jcollie

Running zig build does not install libgtk4-layer-shell.so to the output directory, seems to be missing an install dependency in Ghostty's build. zig build in pkg/gtk4-layer-shell/ does correctly output a lib.

I think we should prefer the system library by default for gtk4-layer-shell, similar to other dynamic-link only dependencies.

AnthonyZhOon avatar Mar 09 '25 02:03 AnthonyZhOon

D'oh! Makes sense, since this is the only dynamic library that we build. I'll draw up a fix some time today

pluiedev avatar Mar 09 '25 07:03 pluiedev

I'm experiencing the same issue, so I just keep an eye on this issue.

tl87 avatar Mar 11 '25 12:03 tl87

I'm experiencing the same issue, so I just keep an eye on this issue.

Same here.

chrispaig3 avatar Mar 11 '25 14:03 chrispaig3

This also affects rpm builds in COPR, e.g. mine and pgdev (@ps-gill)

✸ sudo dnf install ghostty
Updating and loading repositories:
Repositories loaded.
Problem: cannot install the best candidate for the job
  - nothing provides libgtk4-layer-shell.so()(64bit) needed by ghostty-1.1.2^96.95daca61-2.fc41.x86_64 from copr:copr.fedorainfracloud.org:agriffis:ghostty-nightly
Package                 Arch   Version                  Repository          Size
Installing:
 ghostty                x86_64 1.1.2^82.e07b6fdf-1.fc41 copr:copr.fedo  35.4 MiB
Skipping packages with broken dependencies:
 ghostty                x86_64 1.1.2^96.95daca61-2.fc41 copr:copr.fedo  35.4 MiB

Ideally, for adherence to Fedora's packaging guidelines, we'd link to the system-provided gtk4-layer-shell instead of the included one. I added the dep to mine in https://github.com/agriffis/ghostty/commit/31dd4b706a5002625da7843b1c03e4fe6fec83a0 but it seems to need a change to the Zig build files, which is beyond my ken.

agriffis avatar Mar 13 '25 12:03 agriffis

Yeah - the intention is that we only compile the dep for distros that truly don't have it (e.g. Debian 12, Ubuntu 24.04, openSUSE). For other distros you should absolutely enable system integration and use system libraries.

pluiedev avatar Mar 13 '25 13:03 pluiedev

That's all well and good but dnf complains about broken dependencies (gtk4-layer-shell) even though it is installed. I'm on Fedora 41 x86_64. I'll get the actual error message when I get back to my computer.

Update - @agriffis already captured the error above.

roehnan avatar Mar 13 '25 13:03 roehnan

adding -fsys=gtk4-layer-shell as a zig build arg should use the system sharedlib without compiling another one, but it is understandable that it should work out of the box regardless of mode

AnthonyZhOon avatar Mar 13 '25 14:03 AnthonyZhOon

@AnthonyZhOon Thank you! That's what I needed. My COPR is installable again, now.

agriffis avatar Mar 13 '25 14:03 agriffis

Packagers should use the --system flag anyway which enables all system integrations. Ideally only distros like Debian 12 should manually turn off system integration for gtk4-layer-shell via -fno-sys=gtk4-layer-shell.

pluiedev avatar Mar 13 '25 15:03 pluiedev

@pluiedev Thank you, I'll switch to that.

agriffis avatar Mar 13 '25 16:03 agriffis

Here's what I get with --system

$ zig build --summary all --prefix /builddir/build/BUILD/ghostty-1.1.2_96.95daca61-build/BUILDROOT/usr -Dversion-string=1.1.2+96.95daca61-4.fc41 -Doptimize=ReleaseFast -Dcpu=baseline -Dpie=true -Demit-docs --system
error: expected argument after '--system'

agriffis avatar Mar 13 '25 21:03 agriffis

Here's what I get with --system

$ zig build --summary all --prefix /builddir/build/BUILD/ghostty-1.1.2_96.95daca61-build/BUILDROOT/usr -Dversion-string=1.1.2+96.95daca61-4.fc41 -Doptimize=ReleaseFast -Dcpu=baseline -Dpie=true -Demit-docs --system
error: expected argument after '--system'

See: https://github.com/ghostty-org/ghostty/blob/main/PACKAGING.md

You need to download dependencies.

mitchellh avatar Mar 13 '25 21:03 mitchellh

@mitchellh Thanks for the tip! I hadn't read that page, which seems like an obvious oversight on my part. 🤦

My COPR builds/installs/runs now with this change: https://github.com/agriffis/ghostty/commit/807016bd69f0f45ac89087910aa4c42fd9fcf752

agriffis avatar Mar 13 '25 22:03 agriffis

I believe any snap built from main is currently affected by this, or an issue directly related to it. The snap builds fine (e.g. by running snapcraft at the repo root), but if you install and run the snap you get a runtime error.

/snap/ghostty/x1/bin/ghostty: error while loading shared libraries: libgtk4-layer-shell.so: cannot open shared object file: No such file or directory

I found this TODO to add a dependency on gtk4-layer-shell for Ubuntu 24.10+ snaps, however:

  • Snaps are built using base snaps, which come from Ubuntu LTS releases.
  • The current base snap is core24, based on Ubuntu 24.04 LTS.
  • The next core won't be until core26, for ubuntu 26.04 LTS, in another year.

In the mean time, the snap is broken because we can't declare a dependency on gtk4-layer-shell because the package doesn't exist in 24.04 LTS.

(LMK if you'd prefer to open a separate issue for this snap thing, I wasn't sure if it should be part of the discussion here.)

mkasberg avatar Mar 28 '25 00:03 mkasberg

Just realized Ken already has a PR for the snap build issue, #6920

mkasberg avatar Mar 28 '25 00:03 mkasberg

/snap/ghostty/x1/bin/ghostty: error while loading shared libraries: libgtk4-layer-shell.so: cannot open shared object file: No such file or directory

This might be due to the libgtk4-layer-shell.so artifact being built but not moved into the install directory, I added

                const sharedLib = gtk4_layer_shell.artifact("gtk4-layer-shell");
                const artifact: *std.Build.Step.InstallArtifact = b.addInstallArtifact(sharedLib, .{});

https://github.com/ghostty-org/ghostty/compare/main...AnthonyZhOon:ghostty-dev:missing-artifact#diff-3c27f71e7b0ef00072a7d994ae2af66c62b15fc7301fb43aad52bcd96a64da24R658-R659 to my In my PR I added a step to install the libgtk4-layer-shell.so to the output directory which shouldn't require additional linker-config if the install is a default library path, could try if that works for you.

AnthonyZhOon avatar Mar 28 '25 04:03 AnthonyZhOon

This became an issue "recently" (not sure as of which Ghostty rev) on my Slackware builds, where it references this library in the build dir, and therefore the package works only on the build machine and only as long as that zig cache dir exists:

ldd /usr/bin/ghostty | grep gtk4-layer-shell

        libgtk4-layer-shell.so => /usr/local/src/ghostty/src/ghostty-git/.zig-cache/o/098b92a2d7ef0364ecc9ca03f28e0522/libgtk4-layer-shell.so (0x00007f6089252000)

I'll go through the various suggestions above and figure out what the right thing to do is. My systems don't use Wayland currently. And the systems do not have a gtk4-layer-shell installed by default.


It's working fine now:

  • Built & installed from source gtk4-layer-shell-1.1.1
  • Built latest ghostty 1.1.4-main+60da3cf6 with: $ zig build -p /usr/local/src/ghostty/pkg -Doptimize=ReleaseFast
  • Reorganized contents of /usr/local/src/ghostty/pkg, made a pkg out of it and installed it

Confirmed:

$ ldd /usr/bin/ghostty | grep gtk4

	libgtk4-layer-shell.so => /usr/lib64/libgtk4-layer-shell.so (0x00007eff86303000)

edrozenberg avatar Apr 04 '25 20:04 edrozenberg

ldd /usr/bin/ghostty | grep gtk4-layer-shell

        libgtk4-layer-shell.so => /usr/local/src/ghostty/src/ghostty-git/.zig-cache/o/098b92a2d7ef0364ecc9ca03f28e0522/libgtk4-layer-shell.so (0x00007f6089252000)

There's a missing install step, so we build the gtk4-layer-shell.so lib but don't copy it to the install directory currently.

$ ldd /usr/bin/ghostty | grep gtk4

	libgtk4-layer-shell.so => /usr/lib64/libgtk4-layer-shell.so (0x00007eff86303000)

In my open PR, I make a change to rely on a system-installed gtk4-layer-shell by default. You can change to linking it over compiling with ghostty by zig build -fsys=gtk4-layer-shell and rely on a pkgconfig file with the flags to find header files and the shared library in the future.

Built & installed from source gtk4-layer-shell-1.1.1

You can also build the shared library by entering the pkg/gtk4-layer-shell directory and running zig build -Doptimize=ReleaseFast all of the pkg directories should work as independent builds.

AnthonyZhOon avatar Apr 05 '25 01:04 AnthonyZhOon

In the mean time, the snap is broken because we can't declare a dependency on gtk4-layer-shell because the package doesn't exist in 24.04 LTS.

I got it running adding libgtk-layer-shell0 to the libs -> stage-packages.

  libs:
    plugin: nil
    build-attributes: [enable-patchelf]
    stage-packages:
      - libadwaita-1-0
      - libglib2.0-0t64
      - libgtk-4-1
      - libgtk-4-media-gstreamer
      - ibus-gtk4
      - libpciaccess0
      - libtinfo6
      - libedit2
      - libelf1t64
      - libsensors5
      - libllvm17
      - libunistring5
      - librsvg2-2
      - librsvg2-common
      - libgdk-pixbuf-2.0-0
      - libgtk-layer-shell0 # NEW DEPENDENCY
      - on amd64:
          [
            i965-va-driver,
            libdrm-intel1,
            libdrm-nouveau2,
            libdrm-amdgpu1,
            libdrm-radeon1,
          ]
    stage:
      # The libraries in dri need no-patchelf, so they come from the mesa-unpatched part
      - -usr/lib/*/dri

Beisdes that I also had some other problems creating the snaps with file permissions

meldron avatar Apr 14 '25 11:04 meldron

As quoted, that package doesn't exist on Ubuntu 24.04, which the snap builds from https://pkgs.org/search/?q=gtk4-layer-shell Not sure what our policy is for updating the ubuntu version but I think the snap is fixed with my PR #6706

AnthonyZhOon avatar Apr 14 '25 12:04 AnthonyZhOon

Sorry, you are totally right, i mixed app the final snaps and it still fails with libgtk4-layer-shell.so missing

meldron avatar Apr 14 '25 13:04 meldron

This seems to be broken after zig 0.15 for -fno-sys=gtk4-layer-shell? Prior to zig 0.15, building with -fno-sys=gtk4-layer-shell gives a binary that has:

libgtk4-layer-shell.so => /home/shuhao/apps/ghostty/.zig-cache/o/22ae033a3326d2846087d1173b5052e4/libgtk4-layer-shell.so (0x00007fa0775ab000)

But after, it seems to be pointing to a relative path:

libgtk4-layer-shell.so => .zig-cache/o/d984b353071b0fbbf6cf6b695586f76a/libgtk4-layer-shell.so (0x000071df2d157000)

This is causing ghostty to not launch.

shuhaowu avatar Nov 07 '25 14:11 shuhaowu

@shuhaowu Let's move discussion to a new issue so that we don't revive this old one https://github.com/ghostty-org/ghostty/issues/9631

gpanders avatar Nov 18 '25 14:11 gpanders