Skip to content

libghostty-vt-sys: use pkg-config when available#27

Closed
domenkozar wants to merge 6 commits into
Uzaaft:masterfrom
domenkozar:pkg-config-support
Closed

libghostty-vt-sys: use pkg-config when available#27
domenkozar wants to merge 6 commits into
Uzaaft:masterfrom
domenkozar:pkg-config-support

Conversation

@domenkozar

Copy link
Copy Markdown
Contributor

Summary

  • Try pkg-config first to find libghostty-vt; if available (e.g. NixOS where the wrapper adds rpath automatically), skip the zig build entirely
  • Fall back to vendored zig build when pkg-config cannot find the library
  • After a vendored build, generate ghostty-vt.pc so downstream consumers can discover the library via pkg-config

Test plan

  • Verify vendored build still works (cargo build)
  • Verify pkg-config mode works when PKG_CONFIG_PATH points at the generated .pc file
  • Verify NixOS rpath is handled automatically via pkg-config wrapper

🤖 Generated with Claude Code

@domenkozar

Copy link
Copy Markdown
Contributor Author

Now I see that this landed upstream: https://github.com/ghostty-org/ghostty/pull/12210/changes

@Uzaaft

Uzaaft commented Apr 12, 2026

Copy link
Copy Markdown
Owner

lets make this an opt-in feature. @domenkozar

@domenkozar

Copy link
Copy Markdown
Contributor Author

lets make this an opt-in feature. @domenkozar

I've made it optional if pkg-config is around, do you want to make it a feature to have one dependency less?

@Uzaaft

Uzaaft commented Apr 13, 2026

Copy link
Copy Markdown
Owner

lets make this an opt-in feature. @domenkozar

I've made it optional if pkg-config is around, do you want to make it a feature to have one dependency less?

Yes.

@domenkozar

Copy link
Copy Markdown
Contributor Author

Done - CI fails because of github errors.

Add a `pkg-config` cargo feature (off by default) that tries pkg-config
first to locate libghostty-vt. If found (e.g. on NixOS where the
pkg-config wrapper adds rpath automatically), skip the zig build
entirely. Otherwise fall back to building from source.

Bump pinned ghostty commit to include ghostty-org/ghostty#12210 which
generates libghostty-vt.pc and libghostty-vt-static.pc during the zig
build.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@domenkozar domenkozar changed the title libghostty-vt-sys: use pkg-config when available, generate .pc file libghostty-vt-sys: use pkg-config when available Apr 21, 2026
@Uzaaft

Uzaaft commented Apr 21, 2026

Copy link
Copy Markdown
Owner

Sorry for the delay in the last round of review. Doing it now :)

Uzaaft added 5 commits April 21, 2026 18:14
Update the checked-in export manifest to match the regenerated bindings
from the new Ghostty pin.
Turn off doctests for the generated sys crate so rustdoc stops treating
imported C prose from bindgen as runnable Rust examples.

The handwritten crate-level docs stay covered elsewhere, while the
generated bindings no longer fail cargo test for reasons unrelated to
the FFI code itself.
Use Debug formatting for ImageFormat in the Kitty graphics example. The
type does not implement Display
Keep an explicit GHOSTTY_SOURCE_DIR override authoritative even when
the pkg-config feature is enabled.

The build script now checks for GHOSTTY_SOURCE_DIR before probing
pkg-config, and the README files now describe the resulting behavior.
The pkg-config path remains opt-in, but it is only used when no source
override is set.
@Uzaaft

Uzaaft commented Apr 21, 2026

Copy link
Copy Markdown
Owner

Gonna do one last round of review tomorrow before merging. I expect it to need more edits.

FWIW @domenkozar instead of just slopping out a half-assed PR I’d appreciate it if either you use your AI in a more skilful manner, or just open an issue instead.

@Uzaaft

Uzaaft commented Apr 22, 2026

Copy link
Copy Markdown
Owner

@domenkozar I'm struggling to see how the rpath stuff applied to libghostty-vt.
From the docs:
image

Isn't rpath for like runtime path detection, i.e dlopen etc.
We don't do that in libghostty-vt.

Another thing is that we need stronger compat. guard on the pkg-config path.

build.rs accepts any installed libghostty-vt >= 0.1.0, but this crate’s bindings are checked in from a specific Ghostty snapshot. Since the C API is still unstable, >= 0.1.0 is not enough to guarantee that the discovered native library actually matches the Rust bindings.

This risks turning into link failures for newer symbols or, worse, ABI mismatches.

@domenkozar

Copy link
Copy Markdown
Contributor Author

Isn't rpath for like runtime path detection, i.e dlopen etc.

rpath isn't just for dlopen — it's the runtime library search path the dynamic loader uses for any DT_NEEDED entry (including normal -lghostty-vt
links). The vendored build puts libghostty-vt.so.0.1.0 in OUT_DIR, which isn't on the system loader's default path, so without rpath the final binary fails
at startup with "cannot open shared object file." That's the only reason it's there.

Another thing is that we need stronger compat. guard on the pkg-config path.

Given that C API is unstable, I'm not sure if restricting versioning makes sense, but I'm open to change it however you'd like.

@Uzaaft

Uzaaft commented Apr 27, 2026

Copy link
Copy Markdown
Owner

Honestly with the C API being unstable, I'm unsure if pkg-config makes sense at all. me and @pluiedev gotta discuss when pre-1.0.0 means a bit more, and the 'guarantees'.

i'll come back to this PR

@domenkozar

Copy link
Copy Markdown
Contributor Author

Note that libghostty ships pkg-config, and here we're just consuming it.

It's the only way on linux to make packaging sane, but we can maintain our fork if you decide not to use.

@Uzaaft Uzaaft mentioned this pull request Apr 28, 2026
@Uzaaft Uzaaft closed this Apr 28, 2026
@Uzaaft

Uzaaft commented Apr 28, 2026

Copy link
Copy Markdown
Owner

Replaced with #29

Repository owner locked and limited conversation to collaborators Apr 28, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants