Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken RPath when installing and dynamic linking gtk4-layer-shell #6706

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

AnthonyZhOon
Copy link
Contributor

@AnthonyZhOon AnthonyZhOon commented Mar 14, 2025

Closes #6632
When compiling the dynamic lib and linking, the rpath resolves to the compile cache location instead of the install location for the lib. This resulted in loading the dylib failing when the compile cache was removed or the install location is changed.

Based on ziglang/zig#5827 , we specify the rpath to search relative to the executable.
Previous state:

  • dynamic lib was not installed to the output directory -> now appears in $OUT/lib/libgtk4-layer-shell.so
  • rpath only included the compile cache location, not the install location.
    Before:
$ patchelf --print-rpath zig-out/bin/ghostty
/home/anthony/dev/ghostty-pure/.zig-cache/o/0254fb4753185c5429180337a720248d
$ ldd zig-out/bin/ghostty
        ...
        libgtk4-layer-shell.so => /home/anthony/dev/ghostty-pure/.zig-cache/o/0254fb4753185c5429180337a720248d/libgtk4-layer-shell.so (0x00007f7975468000)
        ...
$  ldd zig-out/bin/ghostty
        ...
        libgtk4-layer-shell.so => not found
        ...

After:

$ zig build
$ patchelf --print-rpath zig-out/bin/ghostty
/home/anthony/dev/ghostty/.zig-cache/o/f45360ddde653cb3bc70966c326dd96d:$ORIGIN/../lib/
$ ldd zig-out/bin/ghostty
        ...
        libgtk4-layer-shell.so => /home/anthony/dev/ghostty/.zig-cache/o/f45360ddde653cb3bc70966c326dd96d/libgtk4-layer-shell.so (0x00007fbf81ad8000)
        ...
 $ rm -r .zig-cache/
 $ ldd zig-out/bin/ghostty
        ...
        libgtk4-layer-shell.so => /home/anthony/dev/ghostty/zig-out/bin/../lib/libgtk4-layer-shell.so (0x00007f60dc087000)
        ...

@AnthonyZhOon
Copy link
Contributor Author

Dissatified by:

  • Potentially conflicts with our patchelf --set-rpath step in
    run.addArgs(&.{ "patchelf", "--set-rpath", rpath });
    . I should setup Nix and test if this can be converted to an addRPathSpecial() as well.
  • This mixes adding install steps into the deps.add() function
  • We don't default to preferring a system-installed gtk4-layer-shell dylib.

@AnthonyZhOon
Copy link
Contributor Author

Open issues in Zig related to RPath handling in the build system ziglang/zig#17373

@jwbowen
Copy link

jwbowen commented Mar 14, 2025

FWIW, I applied this on top of 73c7943 on origin/main and can confirm that after removing .zig-cache it points to the system library:

[jbowen@bender ~]$ ldd /usr/local/bin/ghostty | grep libgtk4-layer
        libgtk4-layer-shell.so => /usr/local/bin/../lib/libgtk4-layer-shell.so (0x0000731136135000)
[jbowen@bender ~]$

I don't feel qualified to comment on any other aspects of it, but for now I'm going to carry the patch around to survive reboots.

Copy link
Member

@pluiedev pluiedev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense pending the linker path comment

@jwbowen
Copy link

jwbowen commented Mar 16, 2025

Just a heads up/FYI, but the patch as-is at time of writing no longer cleanly applies after cfea2ea; cf. this bit (the diff of src/build/SharedDeps.zig is large, so GH doesn't expand it by default >:(, so the link doesn't work neatly, but if you do expand it the relevant portions are highlighted.)

I have the library in $PREFIX/lib/ after doing an install with this patch a few days ago, so I'm able to "survive" the loss of $BUILDDIR/.zig-cache/, but I won't be getting new copies of the library installed after building.

@00-kat
Copy link
Contributor

00-kat commented Mar 16, 2025

I have the library in $PREFIX/lib/ after doing an install with this patch a few days ago, so I'm able to "survive" the loss of $BUILDDIR/.zig-cache/, but I won't be getting new copies of the library installed after building.

@jwbowen Couldn't you stick to an older commit (i.e.: not upgrade for a bit) until this PR is merged?

@jwbowen
Copy link

jwbowen commented Mar 16, 2025

@jwbowen Couldn't you stick to an older commit (i.e.: not upgrade for a bit) until this PR is merged?

I certainly could, but I really like riding the bleeding edge where I can and am willing to go out of my way to make it work. I'm not concerned with practicality in this case :)

I should have been clearer in my last message that I wasn't complaining about the patch, I just wanted to give a heads up/FYI.

Edit: I updated my previous comment to hopefully make that clearer. I'm very excited about the project :)

@AnthonyZhOon AnthonyZhOon force-pushed the missing-artifact branch 2 times, most recently from 382abeb to 8626fda Compare March 19, 2025 09:01
@AnthonyZhOon AnthonyZhOon marked this pull request as ready for review March 19, 2025 09:02
@AnthonyZhOon
Copy link
Contributor Author

Should I leave the install step config at https://github.com/ghostty-org/ghostty/pull/6706/files#diff-3c27f71e7b0ef00072a7d994ae2af66c62b15fc7301fb43aad52bcd96a64da24R653-R654 or is there a better place to organise it?

At this point, an absolute rpath link is made in Debug mode but we default to system integration for gtk4-layer-shell so a source compile will give a system package not found error.

> ~/zig/0.14.0/files/zig build
install
└─ install ghostty
   └─ zig build-exe ghostty Debug native failure
error: error: unable to find dynamic system library 'gtk4-layer-shell-0' using strategy 'mode_first'. searched paths:
  /usr/local/lib64/libgtk4-layer-shell-0.so
  /usr/local/lib/libgtk4-layer-shell-0.so
  /lib64/libgtk4-layer-shell-0.so
  /lib/libgtk4-layer-shell-0.so
  /usr/lib64/libgtk4-layer-shell-0.so
  /usr/lib/libgtk4-layer-shell-0.so
  /usr/local/lib64/libgtk4-layer-shell-0.a
  /usr/local/lib/libgtk4-layer-shell-0.a
  /lib64/libgtk4-layer-shell-0.a
  /lib/libgtk4-layer-shell-0.a
  /usr/lib64/libgtk4-layer-shell-0.a
  /usr/lib/libgtk4-layer-shell-0.a

Otherwise I think this is in a working state where docs for building on Debian 12 (missing gtk4-layer-shell) need -fno-sys=gtk4-layer-shell and should configure custom prefix lib/ paths via ldconfig.

Copy link
Contributor

@mitchellh mitchellh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for plugging away at this. A couple points of feedback.

I think this is looking fine. I still want to consider the release packaging implications. I think this will fix debug builds just fine but release builds seem like there's going to be issues and I wonder if we need to reintroduce a way to wholesale disable gtk4-layer-shell from some builds... (don't bother in this PR)

When compiling the dynamic lib and linking, the rpath resolves to the
compile cache location instead of the install location for the lib.
This resulted in loading the dylib failing when the compile cache
was removed or the install location is changed.
- Add an absolute rpath entry in Debug mode only to test gtk4-layer-shell when not
  using the system package
  * Prefer using ldconfig to discover installed libs in custom prefixes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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