feat: enhance build process for xkbcommon-x11 library linking

This commit is contained in:
Niklas Haiden
2026-09-09 22:26:04 +02:00
parent 32fdf8d2e3
commit e66e15fe21
3 changed files with 50 additions and 15 deletions
+1 -1
View File
@@ -34,7 +34,7 @@ Required on the Linux host:
- `ffmpeg` with the `libx264` encoder, and PipeWire's `pw-cat` utility. Hardware encoding additionally needs `h264_vaapi`, a VA-API driver with H.264 encoding support, and access to `/dev/dri/renderD*`. - `ffmpeg` with the `libx264` encoder, and PipeWire's `pw-cat` utility. Hardware encoding additionally needs `h264_vaapi`, a VA-API driver with H.264 encoding support, and access to `/dev/dri/renderD*`.
- Apple TV on the same reachable network with AirPlay enabled. - Apple TV on the same reachable network with AirPlay enabled.
The runner handles the missing libxkbcommon-x11 development symlink on this host using a local build directory. A normal `cargo build --locked` also works when all development libraries are installed. Plain `cargo run` and `cargo build --locked` work on this host. For native Linux GUI builds, `build.rs` supplies a build-local xkbcommon-x11 linker symlink when the compiler can find the runtime library but its development symlink is missing. No system files are changed. If neither library is installed, install the distribution’s xkbcommon-x11 development package. Cross-compilation requires the target development libraries.
The development profile optimizes Spielab's packet handling and ChaCha20-Poly1305 dependencies because the development runner is used for live sharing. On this host the isolated 64 KiB video-packet encryption diagnostic fell from approximately 7.8 ms to 0.057 ms per packet. This microbenchmark does not measure display latency. The development profile optimizes Spielab's packet handling and ChaCha20-Poly1305 dependencies because the development runner is used for live sharing. On this host the isolated 64 KiB video-packet encryption diagnostic fell from approximately 7.8 ms to 0.057 ms per packet. This microbenchmark does not measure display latency.
+49
View File
@@ -0,0 +1,49 @@
//! GPUI 0.2.2 links xkbcommon-x11 even with only its Wayland backend enabled.
//! Some hosts have the runtime SONAME but no development linker symlink.
use std::{env, path::PathBuf, process::Command};
fn compiler_library(name: &str) -> Option<PathBuf> {
let output = Command::new(env::var_os("CC").unwrap_or_else(|| "cc".into()))
.arg(format!("-print-file-name={name}"))
.output()
.ok()?;
if !output.status.success() {
return None;
}
let path = PathBuf::from(String::from_utf8(output.stdout).ok()?.trim());
path.is_absolute().then_some(path).filter(|p| p.is_file())
}
fn main() {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-env-changed=CC");
println!("cargo:rerun-if-env-changed=LIBRARY_PATH");
if env::var_os("CARGO_FEATURE_GUI").is_none()
|| env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("linux")
|| env::var_os("HOST") != env::var_os("TARGET")
{
return;
}
if compiler_library("libxkbcommon-x11.so").is_some() {
return;
}
let Some(runtime) = compiler_library("libxkbcommon-x11.so.0") else {
println!(
"cargo:warning=Install the xkbcommon-x11 development library (libxkbcommon-x11-devel on Fedora, libxkbcommon-x11-dev on Debian/Ubuntu)"
);
return;
};
println!("cargo:rerun-if-changed={}", runtime.display());
#[cfg(unix)]
{
let directory =
PathBuf::from(env::var_os("OUT_DIR").expect("Cargo OUT_DIR")).join("native");
std::fs::create_dir_all(&directory).expect("Create native linker directory");
let link = directory.join("libxkbcommon-x11.so");
if link.symlink_metadata().is_ok() {
std::fs::remove_file(&link).expect("Refresh native linker symlink");
}
std::os::unix::fs::symlink(runtime, link).expect("Create xkbcommon-x11 linker symlink");
println!("cargo:rustc-link-search=native={}", directory.display());
}
}
-14
View File
@@ -4,20 +4,6 @@ project_root="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$project_root" cd "$project_root"
export CARGO_HOME="${CARGO_HOME:-$project_root/.cargo-home}" export CARGO_HOME="${CARGO_HOME:-$project_root/.cargo-home}"
# Some distributions install the xkbcommon-x11 runtime without its linker name.
# GPUI 0.2.2 still links this library when built with only its Wayland feature.
# Provide a build-local linker name; no system library files are modified.
if ! pkg-config --exists xkbcommon-x11; then
for library in /usr/lib64/libxkbcommon-x11.so.0 /usr/lib/x86_64-linux-gnu/libxkbcommon-x11.so.0; do
if [[ -f "$library" ]]; then
mkdir -p "$project_root/target/native"
ln -sf "$library" "$project_root/target/native/libxkbcommon-x11.so"
export LIBRARY_PATH="$project_root/target/native${LIBRARY_PATH:+:$LIBRARY_PATH}"
break
fi
done
fi
# Reuse development pairing identities, when present, across local launches. # Reuse development pairing identities, when present, across local launches.
if [[ -d "$project_root/.state" && -z "${SPIELAB_STATE_DIR:-}" ]]; then if [[ -d "$project_root/.state" && -z "${SPIELAB_STATE_DIR:-}" ]]; then
export SPIELAB_STATE_DIR="$project_root/.state" export SPIELAB_STATE_DIR="$project_root/.state"