Prefer Native Shell on supported Linux installations

This commit is contained in:
Kevin Yue committed 2026-11-20 22:00:51 +08:00
1 parent 4ba50ca945
commit d81b1dc3ec
37 files changed
+869 -250

No files matched your search

+5 -4
View File
@@ -5,7 +5,7 @@ use super::{
is_crash_exit,
},
};
use crate::service::transport::SessionCredential;
use crate::{gui::GuiVariant, service::transport::SessionCredential};
use anyhow::Context;
use std::{
cell::Cell,
@@ -23,10 +23,11 @@ pub(super) async fn launch_desktop_child(
envs: Option<&HashMap<String, String>>,
credential: &SessionCredential,
cancellation: &CancellationToken,
detect_gbm_failure: bool,
interface: Option<GuiVariant>,
) -> anyhow::Result<ExitStatus> {
let retry_eligible = eligible_with_inheritance(&command, envs.is_none());
let detect_gbm_failure = detect_gbm_failure && allows_shared_memory_override(&command, envs.is_none());
let retry_eligible = interface != Some(GuiVariant::Nsh) && eligible_with_inheritance(&command, envs.is_none());
let detect_gbm_failure =
interface == Some(GuiVariant::Tauri) && allows_shared_memory_override(&command, envs.is_none());
let log_file = match envs {
Some(envs) => envs.get("GP_LOG_FILE").map(PathBuf::from),
None => std::env::var_os("GP_LOG_FILE").map(PathBuf::from),
+50 -13
View File
@@ -24,26 +24,48 @@ use crate::service::transport::{MAX_CREDENTIAL_FRAME, SessionCredential};
/// Owns the desktop GUI and its privileged service without leaving the desktop session.
pub struct DesktopLauncher<'a> {
version: &'a str,
#[cfg(target_os = "linux")]
interface: Option<crate::gui::GuiVariant>,
minimized: bool,
log_file: Option<String>,
}
impl<'a> DesktopLauncher<'a> {
/// Bring an already-running GUI to the foreground through its service.
pub async fn activate_existing() -> anyhow::Result<()> {
let endpoint = crate::utils::endpoint::http_endpoint().await?;
crate::utils::request::client_builder()
.build()?
.post(format!("{endpoint}/active-gui"))
.send()
.await?
.error_for_status()?;
Ok(())
/// Plain launches raise the existing window. Explicit selections require a cold launch.
pub async fn activate_or_reject_existing(&self) -> anyhow::Result<bool> {
let Ok(endpoint) = crate::utils::endpoint::http_endpoint().await else {
return Ok(false);
};
let client = crate::utils::request::client_builder().no_proxy().build()?;
#[cfg(target_os = "linux")]
if self.interface.is_some() {
let response = client.get(format!("{endpoint}/health")).send().await;
ensure!(
!response.is_ok_and(|r| r.status().is_success()),
"GP Connect is already running. Quit GP Connect and run this command again."
);
return Ok(false);
}
Ok(
client
.post(format!("{endpoint}/active-gui"))
.send()
.await
.is_ok_and(|r| r.status().is_success()),
)
}
#[cfg(target_os = "linux")]
pub fn interface(mut self, interface: Option<crate::gui::GuiVariant>) -> Self {
self.interface = interface;
self
}
pub fn new(version: &'a str) -> Self {
Self {
version,
#[cfg(target_os = "linux")]
interface: None,
minimized: false,
log_file: None,
}
@@ -87,6 +109,8 @@ impl<'a> DesktopLauncher<'a> {
let result = {
let operation = async {
let mut minimized = self.minimized;
#[cfg(target_os = "linux")]
let mut explicit_interface = self.interface;
let mut expecting_renewal = false;
loop {
let credential = tokio::select! {
@@ -119,15 +143,27 @@ impl<'a> DesktopLauncher<'a> {
if let Some(path) = &self.log_file {
envs.insert("GP_LOG_FILE".into(), path.clone());
}
let launcher = GuiLauncher::new(self.version, Arc::new(credential), crate::gui::preferred()?)
.envs(envs)
.minimized(minimized);
#[cfg(not(target_os = "linux"))]
let mut unexpected = [0];
// Program resolution may launch the WebKit download helper. Keep it under
// the same cancellation, service ownership and recovery budget as gpgui.
let outcome = {
let attempt = async {
#[cfg(target_os = "linux")]
let variant = {
let requested = match explicit_interface {
Some(variant) => Some(variant),
None => crate::gui::saved_preference()?,
};
super::nsh_runtime::select(requested, &mut input, &mut output)
.await
.context(super::nsh_runtime::TAURI_RECOVERY)?
};
#[cfg(not(target_os = "linux"))]
let variant = crate::gui::GuiVariant::Tauri;
let launcher = GuiLauncher::new(self.version, Arc::new(credential), variant)
.envs(envs)
.minimized(minimized);
let program = launcher
.resolve_program(&cancellation, crate::gui::GuiTheme::System)
.await?;
@@ -137,6 +173,7 @@ impl<'a> DesktopLauncher<'a> {
&program,
&cancellation,
&switch_listener.listener,
&mut explicit_interface,
&mut input,
&mut output,
)
@@ -79,7 +79,7 @@ impl<'a> GuiHelperLauncher<'a> {
self.envs,
self.credential,
cancellation,
false,
None,
)
.await?;
Ok(())
+203 -113
View File
@@ -5,6 +5,8 @@ use std::{
sync::Arc,
};
#[cfg(target_os = "linux")]
use anyhow::Context;
use anyhow::bail;
use log::info;
use tokio::process::Command;
@@ -113,12 +115,12 @@ impl<'a> GuiLauncher<'a> {
}
info!("Launching {}", program.display());
super::desktop_child::launch_desktop_child(
"gpgui",
self.variant.binary_name(),
cmd.into_std(),
self.envs.as_ref(),
&self.credential,
cancellation,
self.variant == crate::gui::GuiVariant::Tauri,
Some(self.variant),
)
.await
}
@@ -172,6 +174,7 @@ impl<'a> GuiLauncher<'a> {
program: &Path,
cancellation: &CancellationToken,
listener: &tokio::net::UnixListener,
explicit_interface: &mut Option<crate::gui::GuiVariant>,
service_input: &mut (impl tokio::io::AsyncWrite + Unpin),
service_output: &mut (impl tokio::io::AsyncRead + Unpin),
) -> anyhow::Result<ExitStatus> {
@@ -179,119 +182,111 @@ impl<'a> GuiLauncher<'a> {
use crate::gui::GuiSwitchOutcome;
use crate::service::transport::{DESKTOP_SWITCH_BEGIN, DESKTOP_SWITCH_CANCEL, DESKTOP_SWITCH_COMMIT};
use tokio::io::{AsyncReadExt, AsyncWriteExt};
let mut current = Some(self.start_owned(program.to_owned(), cancellation.child_token()));
let mut cold_nsh = self.variant == crate::gui::GuiVariant::Nsh;
let first = if explicit_interface.is_some() {
let started = self.start_and_save(program, cancellation).await;
let child = if cold_nsh {
started.context(super::nsh_runtime::TAURI_RECOVERY)?
} else {
started?
};
*explicit_interface = None;
child
} else {
self.start_owned(program, cancellation.child_token(), None)
};
let mut current = Some(first);
let mut retired = Vec::new();
let mut unexpected = [0];
let result = async { loop {
tokio::select! {
biased;
outcome = &mut current.as_mut().unwrap().task => {
current.take();
break outcome?;
}
accepted = listener.accept() => {
let (mut socket, _) = accepted?;
let mut pending = false;
let replacement = async {
let command = gui_switch::receive(&mut socket).await?;
let selection = command.selection;
let variant = selection.variant;
let candidate = Self::new(self.version, self.credential.clone(), variant).envs(self.envs.clone());
let program = candidate.find_compatible_program(cancellation).await?;
if program.is_none() && variant == crate::gui::GuiVariant::Nsh {
use crate::service::transport::DESKTOP_GUI_INSTALLER;
service_input.write_all(&[DESKTOP_GUI_INSTALLER]).await?;
let supplies_runtime = match service_output.read_u8().await? {
0 => false,
1 => true,
_ => anyhow::bail!("Invalid GUI installer capability response"),
};
if !supplies_runtime {
super::nsh_runtime::check()?;
let result = async {
loop {
tokio::select! {
biased;
outcome = &mut current.as_mut().unwrap().task => {
current.take();
break if cold_nsh {
outcome?.context(super::nsh_runtime::TAURI_RECOVERY)
} else {
outcome?
};
}
accepted = listener.accept() => {
let (mut socket, _) = accepted?;
let mut pending = false;
let replacement = async {
let command = gui_switch::receive(&mut socket).await?;
let selection = command.selection;
let variant = selection.variant;
super::nsh_runtime::select(Some(variant), service_input, service_output).await?;
let candidate = Self::new(self.version, self.credential.clone(), variant).envs(self.envs.clone());
let program = candidate.find_compatible_program(cancellation).await?;
if program.is_none() && !selection.allow_download {
gui_switch::reply(&mut socket, Ok(GuiSwitchOutcome::DownloadRequired)).await?;
return Ok(None);
}
}
if program.is_none() && !selection.allow_download {
gui_switch::reply(&mut socket, Ok(GuiSwitchOutcome::DownloadRequired)).await?;
return Ok(None);
}
use super::rendering_recovery::{GbmBufferFailure, RecoveryState};
let mut recovery = RecoveryState::default();
let mut program = program;
let (child, start_result) = loop {
service_input.write_all(&[DESKTOP_SWITCH_BEGIN]).await?;
pending = true;
let credential = super::desktop_launcher::read_credential(service_output).await?
.ok_or_else(|| anyhow::anyhow!("Service closed before issuing the switch credential"))?;
anyhow::ensure!(credential.product_version() == self.version, "Service product version mismatch");
let ready = gui_switch::SwitchListener::new()?;
let mut envs = self.envs.clone().unwrap_or_else(|| std::env::vars().collect());
envs.insert(gui_switch::READY_ENV.into(), ready.path().to_string_lossy().into_owned());
let launcher = Self::new(self.version, Arc::new(credential), variant)
.envs(envs)
.minimized(false);
let executable = match &program {
Some(program) => program.clone(),
None => launcher.resolve_program(cancellation, command.theme).await?,
};
let mut child = launcher.start_owned(executable.clone(), cancellation.child_token());
let start_result = tokio::select! {
result = tokio::time::timeout(std::time::Duration::from_secs(30), ready.ready()) => {
result.map_err(|_| anyhow::anyhow!("The selected GUI did not finish starting" )).and_then(|result| result)
},
outcome = &mut child.task => {
match outcome? {
Ok(status) => return Err(anyhow::anyhow!("The selected GUI exited during startup: {status}")),
Err(error) if error.is::<GbmBufferFailure>() && recovery.recover(&error) => {
log::warn!("{error}; restarting the selected GUI with compatibility graphics");
service_input.write_all(&[DESKTOP_SWITCH_CANCEL]).await?;
pending = false;
program = Some(executable);
continue;
}
Err(error) => return Err(recovery.terminal(error)),
use super::rendering_recovery::{GbmBufferFailure, RecoveryState};
let mut recovery = RecoveryState::default();
let mut program = program;
let child = loop {
service_input.write_all(&[DESKTOP_SWITCH_BEGIN]).await?;
pending = true;
let credential = super::desktop_launcher::read_credential(service_output).await?
.ok_or_else(|| anyhow::anyhow!("Service closed before issuing the switch credential"))?;
anyhow::ensure!(credential.product_version() == self.version, "Service product version mismatch");
let launcher = Self::new(self.version, Arc::new(credential), variant).envs(self.envs.clone());
let executable = match &program {
Some(program) => program.clone(),
None => launcher.resolve_program(cancellation, command.theme).await?,
};
match launcher.start_and_save(&executable, cancellation).await {
Ok(child) => break child,
Err(error) if error.is::<GbmBufferFailure>() && recovery.recover(&error) => {
log::warn!("{error}; restarting the selected GUI with compatibility graphics");
service_input.write_all(&[DESKTOP_SWITCH_CANCEL]).await?;
pending = false;
program = Some(executable);
}
Err(error) => return Err(recovery.terminal(error)),
}
};
break (child, start_result);
};
if let Err(error) = start_result.and_then(|()| crate::gui::save_preference(variant)) {
child.cancel.cancel();
let _ = child.task.await;
return Err(error);
}
if let Err(error) = gui_switch::reply(&mut socket, Ok(GuiSwitchOutcome::Switched)).await {
child.cancel.cancel();
let _ = child.task.await;
return Err(error);
}
if let Err(error) = service_input.write_all(&[DESKTOP_SWITCH_COMMIT]).await {
child.cancel.cancel();
let _ = child.task.await;
return Err(error.into());
}
pending = false;
Ok(Some(child))
}.await;
match replacement {
Ok(Some(child)) => retired.push(current.replace(child).unwrap()),
Ok(None) => {},
Err(error) => {
if pending {
service_input.write_all(&[DESKTOP_SWITCH_CANCEL]).await?;
if let Err(error) = gui_switch::reply(&mut socket, Ok(GuiSwitchOutcome::Switched)).await {
child.cancel.cancel();
let _ = child.task.await;
return Err(error);
}
if let Err(error) = service_input.write_all(&[DESKTOP_SWITCH_COMMIT]).await {
child.cancel.cancel();
let _ = child.task.await;
return Err(error.into());
}
pending = false;
Ok(Some(child))
}.await;
match replacement {
Ok(Some(child)) => {
cold_nsh = false;
retired.push(current.replace(child).unwrap());
}
Ok(None) => {},
Err(error) => {
if pending {
service_input.write_all(&[DESKTOP_SWITCH_CANCEL]).await?;
}
let _ = gui_switch::reply(&mut socket, Err(format!("{error:#}"))).await;
}
let _ = gui_switch::reply(&mut socket, Err(format!("{error:#}"))).await;
}
}
}
result = service_output.read(&mut unexpected) => {
break match result {
Ok(0) => Err(anyhow::anyhow!("The privileged service closed its credential channel")),
Ok(_) => Err(anyhow::anyhow!("Unexpected service credential data while the GUI is running")),
Err(error) => Err(error.into()),
};
result = service_output.read(&mut unexpected) => {
break match result {
Ok(0) => Err(anyhow::anyhow!("The privileged service closed its credential channel")),
Ok(_) => Err(anyhow::anyhow!("Unexpected service credential data while the GUI is running")),
Err(error) => Err(error.into()),
};
}
}
}
}}.await;
}
.await;
// Every GUI remains owned by this supervisor until it is reaped. The retiring
// GUI exits after the successful switch reply; cancellation also joins it.
if let Some(child) = current {
@@ -307,11 +302,38 @@ impl<'a> GuiLauncher<'a> {
}
#[cfg(target_os = "linux")]
fn start_owned(&self, program: PathBuf, cancel: CancellationToken) -> RunningGui {
/// Cold CLI selection and a Settings switch commit the preference after native readiness.
async fn start_and_save(&self, program: &Path, cancellation: &CancellationToken) -> anyhow::Result<RunningGui> {
let ready = super::gui_switch::SwitchListener::new()?;
let mut child = self.start_owned(program, cancellation.child_token(), Some(&ready.path()));
let started = tokio::select! {
biased;
_ = cancellation.cancelled() => Err(anyhow::anyhow!("GUI startup cancelled")),
status = &mut child.task => bail!("The selected GUI exited during startup: {}", status??),
result = tokio::time::timeout(std::time::Duration::from_secs(30), ready.ready()) => {
result.context("The selected GUI did not finish starting").and_then(|result| result)
}
};
if let Err(error) = started.and_then(|()| crate::gui::save_preference(self.variant)) {
child.cancel.cancel();
let _ = child.task.await;
return Err(error);
}
Ok(child)
}
#[cfg(target_os = "linux")]
fn start_owned(&self, program: &Path, cancel: CancellationToken, ready: Option<&Path>) -> RunningGui {
let program = program.to_owned();
let version = self.version.to_owned();
let variant = self.variant;
let credential = self.credential.clone();
let envs = self.envs.clone();
let mut envs = self.envs.clone();
if let Some(path) = ready {
envs
.get_or_insert_with(|| std::env::vars().collect())
.insert(super::gui_switch::READY_ENV.into(), path.to_string_lossy().into_owned());
}
let minimized = self.minimized;
let task_cancel = cancel.clone();
let task = tokio::spawn(async move {
@@ -535,6 +557,11 @@ mod tests {
"incompatible",
"runtime-too-old",
"runtime-too-old-confirmed",
"cold-default",
"cold-explicit",
"cold-explicit-failure",
"cold-explicit-clean-exit",
"cold-default-failure",
] {
let directory = TempDir::new().unwrap();
let executable = std::env::current_exe().unwrap();
@@ -542,7 +569,7 @@ mod tests {
let gtk = super::super::nsh_runtime::tests::gtk_fixture(directory.path(), 12);
fs::rename(gtk, directory.path().join("libgtk-4.so.1")).unwrap();
for name in ["gpgui", "gpgui-nsh"] {
if (scenario == "missing" || scenario.starts_with("runtime-too-old")) && name == "gpgui-nsh" {
if (scenario == "missing" || scenario == "runtime-too-old") && name == "gpgui-nsh" {
continue;
}
let version = if scenario == "incompatible" && name == "gpgui-nsh" {
@@ -631,7 +658,7 @@ mod tests {
async fn upgrade_fixture() {
crate::gui::save_preference(crate::gui::GuiVariant::Nsh).unwrap();
let credential = Arc::new(SessionCredential::generate(Uuid::new_v4(), VERSION).unwrap());
let selected = GuiLauncher::new(VERSION, credential, crate::gui::preferred().unwrap());
let selected = GuiLauncher::new(VERSION, credential, crate::gui::saved_preference().unwrap().unwrap());
let program = selected
.resolve_program(&CancellationToken::new(), crate::gui::GuiTheme::System)
.await
@@ -670,8 +697,14 @@ mod tests {
input.read_exact(&mut frame).unwrap();
let directory = PathBuf::from(std::env::var_os("GP_SWITCH_DIRECTORY").unwrap());
let variant = std::env::var("GP_SWITCH_GUI_VARIANT").unwrap();
if variant == "gpgui-nsh" && std::env::var("GP_SWITCH_SCENARIO").unwrap() == "failure" {
panic!("fixture: native host failed to initialize");
if variant == "gpgui-nsh" {
let scenario = std::env::var("GP_SWITCH_SCENARIO").unwrap();
if scenario.ends_with("failure") {
panic!("fixture: native host failed to initialize");
}
if scenario.ends_with("clean-exit") {
return;
}
}
super::super::gui_switch::notify_ready().unwrap();
fs::write(directory.join(format!("{variant}-started")), "").unwrap();
@@ -719,13 +752,64 @@ mod tests {
}
});
let envs = std::env::vars().collect::<HashMap<_, _>>();
let launcher = launcher(VERSION, vec![]).envs(envs);
let mut launcher = launcher(VERSION, vec![]).envs(envs);
let cancel = CancellationToken::new();
if runtime_too_old {
assert_eq!(
super::super::nsh_runtime::select(None, &mut service_input, &mut service_output)
.await
.unwrap(),
crate::gui::GuiVariant::Tauri
);
}
if scenario.starts_with("cold-") {
use crate::gui::{GuiVariant, saved_preference};
let mut explicit = scenario.contains("explicit").then_some(GuiVariant::Nsh);
if explicit.is_some() {
crate::gui::save_preference(GuiVariant::Tauri).unwrap();
}
launcher.variant = super::super::nsh_runtime::select(explicit, &mut service_input, &mut service_output)
.await
.unwrap();
assert_eq!(launcher.variant, GuiVariant::Nsh);
let program = directory.join(launcher.variant.binary_name());
let run = launcher.launch_with_switches(
&program,
&cancel,
&listener.listener,
&mut explicit,
&mut service_input,
&mut service_output,
);
if scenario.ends_with("failure") || scenario.ends_with("clean-exit") {
assert!(run.await.unwrap_err().to_string().contains("--interface tauri"));
let original = explicit.map(|_| GuiVariant::Tauri);
assert_eq!(saved_preference().unwrap(), original);
} else {
let expected = scenario.contains("explicit").then_some(GuiVariant::Nsh);
let stop = async {
while !directory.join("gpgui-nsh-started").exists() || saved_preference().unwrap() != expected {
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
}
fs::write(directory.join("stop-gpgui-nsh"), "").unwrap();
};
let (status, ()) = tokio::time::timeout(std::time::Duration::from_secs(10), async { tokio::join!(run, stop) })
.await
.unwrap();
assert!(status.unwrap().success());
assert!(explicit.is_none());
assert_eq!(saved_preference().unwrap(), expected);
}
service.abort();
return;
}
let program = directory.join("gpgui");
let mut explicit = None;
let run = launcher.launch_with_switches(
&program,
&cancel,
&listener.listener,
&mut explicit,
&mut service_input,
&mut service_output,
);
@@ -756,6 +840,12 @@ mod tests {
);
} else {
anyhow::ensure!(result.is_ok() == success, "Unexpected switch result: {result:?}");
if let Err(error) = &result {
anyhow::ensure!(
!error.to_string().contains("--interface tauri"),
"Unexpected CLI recovery hint"
);
}
if success {
anyhow::ensure!(
result? == crate::gui::GuiSwitchOutcome::Switched,
@@ -779,7 +869,7 @@ mod tests {
);
if success {
anyhow::ensure!(
crate::gui::preferred()? == crate::gui::GuiVariant::Nsh,
crate::gui::saved_preference()? == Some(crate::gui::GuiVariant::Nsh),
"Successful switch did not save preference"
);
fs::write(directory.join("stop-gpgui"), "")?;
@@ -788,7 +878,7 @@ mod tests {
}
} else {
anyhow::ensure!(
crate::gui::preferred()? == crate::gui::GuiVariant::Tauri,
crate::gui::saved_preference()?.is_none(),
"Failed switch changed preference"
);
}
+72 -1
View File
@@ -1,4 +1,4 @@
//! Checks the generic Linux NSH runtime before offering a download.
//! Selects the Linux GUI using its installed or package-managed runtime.
//! Runs in the desktop supervisor, which does not load either GUI's GTK runtime.
use std::{ffi::OsStr, os::raw::c_uint};
@@ -11,14 +11,70 @@ use libloading::{
// Match nsh-platform-linux's gtk4/v4_14 feature when changing the NSH build.
const MIN_GTK_MINOR: u32 = 14;
#[cfg(target_os = "linux")]
pub(super) const TAURI_RECOVERY: &str = "To use Tauri, run: gpclient launch-gui --interface tauri";
#[cfg(target_os = "linux")]
pub(super) async fn select(
requested: Option<crate::gui::GuiVariant>,
service_input: &mut (impl tokio::io::AsyncWrite + Unpin),
service_output: &mut (impl tokio::io::AsyncRead + Unpin),
) -> anyhow::Result<crate::gui::GuiVariant> {
use crate::{gui::GuiVariant, service::transport::DESKTOP_GUI_INSTALLER};
use tokio::io::{AsyncReadExt, AsyncWriteExt};
if requested == Some(GuiVariant::Tauri) {
return Ok(GuiVariant::Tauri);
}
let runtime = if crate::gui::NATIVE_SHELL_SUPPORTED {
service_input.write_all(&[DESKTOP_GUI_INSTALLER]).await?;
match service_output.read_u8().await? {
0 => check(),
// The package installer provides and wraps NSH's dependencies (e.g. NixOS).
1 => Ok(()),
_ => anyhow::bail!("Invalid GUI installer capability response"),
}
} else {
Err(anyhow::anyhow!("Native Shell is unavailable for this platform."))
};
match runtime {
Ok(()) => Ok(GuiVariant::Nsh),
Err(err) if requested.is_some() => Err(err),
Err(err) => {
log::info!("Selecting Tauri: {err:#}");
Ok(GuiVariant::Tauri)
}
}
}
#[cfg(target_os = "linux")]
pub(super) fn check() -> anyhow::Result<()> {
check_gtk(OsStr::new("libgtk-4.so.1"))?;
#[cfg(target_env = "gnu")]
{
// glibc returns a static, NUL-terminated runtime version string.
let version = unsafe { std::ffi::CStr::from_ptr(nix::libc::gnu_get_libc_version()) };
check_glibc_version(version.to_str()?)?;
}
load_library(OsStr::new("libgnutls.so.30"), "GnuTLS 3")?;
load_library(OsStr::new("libdbus-1.so.3"), "D-Bus")?;
Ok(())
}
#[cfg(any(all(target_os = "linux", target_env = "gnu"), test))]
fn check_glibc_version(version: &str) -> anyhow::Result<()> {
let mut parts = version.split('.');
let major = parts.next().and_then(|part| part.parse::<u32>().ok());
let minor = parts.next().and_then(|part| part.parse::<u32>().ok());
ensure!(
major.zip(minor).is_some_and(|version| version >= (2, 39)),
"Native Shell requires glibc 2.39 or later. This system reports glibc {version}."
);
Ok(())
}
fn load_library(path: &OsStr, name: &str) -> anyhow::Result<Library> {
// Resolve symbols now as well as transitive dependencies, without initializing GTK.
let library = unsafe { libloading::os::unix::Library::open(Some(path), RTLD_LOCAL | RTLD_NOW) };
@@ -55,6 +111,21 @@ pub(super) mod tests {
use super::*;
use std::{fs, process::Command};
#[test]
fn requires_glibc_2_39_or_later() {
for version in ["2.9", "2.38", "unknown"] {
assert!(
check_glibc_version(version)
.unwrap_err()
.to_string()
.contains("glibc 2.39")
);
}
for version in ["2.39", "2.39.1", "2.40", "3.0"] {
check_glibc_version(version).unwrap();
}
}
pub(in crate::process) fn gtk_fixture(directory: &std::path::Path, minor: u32) -> std::path::PathBuf {
let source = directory.join(format!("gtk-{minor}.c"));
let library = directory.join(format!("gtk-{minor}.so"));