ashpd on async-io in voelin-media (pipewire) and voelin-platform (portal)

GPUI's Linux backend enables ashpd's `async-io` feature, and ashpd 0.13.13
refuses `async-io` and `tokio` at once (compile_error! in its lib.rs), so
a binary could not hold the portals and gpui-kit. voelin-media's `pipewire`
feature (the screen-cast and camera portals) and voelin-platform's `portal`
feature (global shortcuts, file chooser, proxy resolver) now ask ashpd for
`async-io`; Cargo.lock loses ashpd's edge to tokio and nothing else (the
package set is the same: THIRD_PARTY_NOTICES.md is unchanged and
`scripts/notices.sh --check` clean).

What zbus 5.19 does with the features (read in its abstractions/mod.rs):
with both `async-io` and `tokio` compiled in it picks per connection, tokio
when a tokio runtime is current on the calling thread, else async-io with an
I/O thread of its own. The workspace has both on already (notify-rust asks
for zbus/tokio, secret-service and others for its defaults), so the engine's
portal calls, which run inside its tokio runtime, still use tokio; a caller
with no runtime (GPUI's foreground executor) gets the I/O thread. Built on
its own, voelin-media has `async-io` only.

The source needed no change beyond a doc comment (capture/portal.rs said
the connection needs a tokio runtime). tests/proxy.rs gains a second test on
the same stand-in portal: ashpd's ProxyResolver called from a thread with no
tokio runtime, polled by hand, gets the answer. Both tests run again under
`dbus-run-session` on a bus of their own (the harness takes the test's name).

Checked on Rust 1.95.0: fmt and clippy (-D warnings, --no-deps) of the own
crates; `cargo test -p voelin-platform -p voelin-media`: all pass, including
tests/proxy.rs (2 tests), the portal-less-bus tests of both crates run with
no session bus (`unavailable_without_session_bus`, the `proxy::tests` that
need none), and tests/pipewire_apps.rs against a private PipeWire and
WirePlumber (found on PATH, ran: 2 passed in 2.7 s). The live portal
(a desktop's screen-cast dialog, the shortcut binding) was not exercised:
no desktop session is used by these runs.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Sonnet 5.5 committed 2026-10-27 06:18:00 +03:00
1 parent 5ce5c0db82
commit e325b65d42
6 files changed
+82 -10

No files matched your search

+5
View File
@@ -69,6 +69,11 @@ User-visible changes of the apps and the `tsgw` gateway. The format follows
### Changed ### Changed
- The desktop portals (screen capture and camera through PipeWire, the push to
talk shortcut, the file chooser and the proxy settings) talk to D-Bus through
ashpd on `async-io` instead of `tokio`. Nothing changes on screen; the GPUI
front end, which is being built, enables ashpd's `async-io` and ashpd cannot
have both. Inside the engine's tokio runtime zbus still runs on it.
- The build needs Rust 1.95 (`rust-toolchain.toml` and the workspace's - The build needs Rust 1.95 (`rust-toolchain.toml` and the workspace's
`rust-version`; 1.95.0 was used to check it), up from 1.94: the GPUI `rust-version`; 1.95.0 was used to check it), up from 1.94: the GPUI
front end, which is being built, depends on a library that calls a function front end, which is being built, depends on a library that calls a function
Generated
-1
View File
@@ -481,7 +481,6 @@ dependencies = [
"getrandom 0.4.3", "getrandom 0.4.3",
"serde", "serde",
"serde_repr", "serde_repr",
"tokio",
"zbus", "zbus",
] ]
+5 -1
View File
@@ -69,7 +69,11 @@ tracing = "0.1.44"
yuv = "0.8.19" yuv = "0.8.19"
[target.'cfg(target_os = "linux")'.dependencies] [target.'cfg(target_os = "linux")'.dependencies]
ashpd = { version = "0.13.13", default-features = false, features = ["camera", "screencast", "tokio"], optional = true } # `async-io`, not `tokio`: GPUI's Linux backend enables ashpd's `async-io`, ashpd
# refuses both at once, and a front end holds the portals and GPUI in one binary.
# zbus then runs a connection on its own I/O thread, or on tokio when it is made
# inside a tokio runtime and another crate turns zbus's `tokio` feature on.
ashpd = { version = "0.13.13", default-features = false, features = ["camera", "screencast", "async-io"], optional = true }
memmap2 = { version = "0.9.11", optional = true } memmap2 = { version = "0.9.11", optional = true }
pipewire = { version = "0.10.1", optional = true } pipewire = { version = "0.10.1", optional = true }
rustix = { version = "1.1.5", features = ["event", "fs", "stdio"], optional = true } rustix = { version = "1.1.5", features = ["event", "fs", "stdio"], optional = true }
+3 -1
View File
@@ -181,7 +181,9 @@ impl ScreenCapture for PortalCapture {
} }
/// Asks the user through the portal dialog (unless a restore token /// Asks the user through the portal dialog (unless a restore token
/// applies). Needs a tokio runtime (the D-Bus connection runs on it). /// applies). Any executor will do: ashpd runs on zbus's `async-io`, whose
/// connection has an I/O thread of its own (inside a tokio runtime, with
/// zbus's `tokio` feature on as well, it runs on tokio instead).
fn start( fn start(
&mut self, &mut self,
source: &SourceId, source: &SourceId,
+3 -1
View File
@@ -24,7 +24,9 @@ tokio = { version = "1", features = ["rt", "sync", "time"] }
tracing = "0.1" tracing = "0.1"
[target.'cfg(all(unix, not(target_os = "macos")))'.dependencies] [target.'cfg(all(unix, not(target_os = "macos")))'.dependencies]
ashpd = { version = "0.13", default-features = false, features = ["tokio", "global_shortcuts", "file_chooser", "proxy_resolver"], optional = true } # `async-io`, not `tokio`, as in voelin-media: GPUI enables ashpd's `async-io` and
# ashpd refuses both features at once.
ashpd = { version = "0.13", default-features = false, features = ["async-io", "global_shortcuts", "file_chooser", "proxy_resolver"], optional = true }
futures-util = { version = "0.3", optional = true } futures-util = { version = "0.3", optional = true }
notify-rust = { version = "4.18", default-features = false, features = ["z-with-tokio"] } notify-rust = { version = "4.18", default-features = false, features = ["z-with-tokio"] }
x11rb = { version = "0.13", features = ["xinput"], optional = true } x11rb = { version = "0.13", features = ["xinput"], optional = true }
+66 -6
View File
@@ -5,6 +5,10 @@
//! the real one is started and answers instead. Without `dbus-run-session`, //! the real one is started and answers instead. Without `dbus-run-session`,
//! or a bus daemon for it, the test says so and checks nothing. Its own test //! or a bus daemon for it, the test says so and checks nothing. Its own test
//! binary: answers are kept process-wide. //! binary: answers are kept process-wide.
//!
//! The second test calls ashpd from a thread with no tokio runtime, as GPUI's
//! executor would: ashpd runs on zbus's `async-io` there (docs/design/gpui-spikes.md,
//! "Dependencies").
#![cfg(all(unix, not(target_os = "macos"), feature = "portal"))] #![cfg(all(unix, not(target_os = "macos"), feature = "portal"))]
@@ -61,17 +65,17 @@ fn bus_config(dir: &std::path::Path) -> String {
) )
} }
/// Run this test again under `dbus-run-session` on a bus of its own, and say /// Run the test `name` again under `dbus-run-session` on a bus of its own, and
/// nothing was checked when that bus cannot be had. /// say nothing was checked when that bus cannot be had.
fn on_a_bus_of_its_own() { fn on_a_bus_of_its_own(name: &str) {
let dir = std::env::temp_dir(); let dir = std::env::temp_dir();
let config = dir.join(format!("voelin-proxy-test-bus-{}.conf", std::process::id())); let config = dir.join(format!("voelin-proxy-test-bus-{}-{name}.conf", std::process::id()));
std::fs::write(&config, bus_config(&dir)).unwrap(); std::fs::write(&config, bus_config(&dir)).unwrap();
let run = std::process::Command::new("dbus-run-session") let run = std::process::Command::new("dbus-run-session")
.arg(format!("--config-file={}", config.display())) .arg(format!("--config-file={}", config.display()))
.arg("--") .arg("--")
.arg(std::env::current_exe().unwrap()) .arg(std::env::current_exe().unwrap())
.args(["--exact", "the_portal_names_the_proxy", "--nocapture", "--test-threads=1"]) .args(["--exact", name, "--nocapture", "--test-threads=1"])
.env(ON_ITS_OWN_BUS, "1") .env(ON_ITS_OWN_BUS, "1")
.output(); .output();
let _ = std::fs::remove_file(&config); let _ = std::fs::remove_file(&config);
@@ -104,7 +108,7 @@ fn on_a_bus_of_its_own() {
#[tokio::test] #[tokio::test]
async fn the_portal_names_the_proxy() { async fn the_portal_names_the_proxy() {
if std::env::var_os(ON_ITS_OWN_BUS).is_none() { if std::env::var_os(ON_ITS_OWN_BUS).is_none() {
on_a_bus_of_its_own(); on_a_bus_of_its_own("the_portal_names_the_proxy");
return; return;
} }
let lookups = Arc::new(AtomicU32::new(0)); let lookups = Arc::new(AtomicU32::new(0));
@@ -133,3 +137,59 @@ async fn the_portal_names_the_proxy() {
assert_eq!(proxy_for("https://capped.example:8443/").await, None); assert_eq!(proxy_for("https://capped.example:8443/").await, None);
assert_eq!(lookups.load(Ordering::SeqCst), 2); assert_eq!(lookups.load(Ordering::SeqCst), 2);
} }
/// Run `future` on the calling thread, which parks while it waits: an executor
/// of no runtime at all, as a GPUI foreground task is to ashpd.
fn block_on<F: std::future::Future>(future: F) -> F::Output {
struct Unpark(std::thread::Thread);
impl std::task::Wake for Unpark {
fn wake(self: Arc<Self>) {
self.0.unpark();
}
}
let waker = std::task::Waker::from(Arc::new(Unpark(std::thread::current())));
let mut cx = std::task::Context::from_waker(&waker);
let mut future = std::pin::pin!(future);
loop {
if let std::task::Poll::Ready(output) = future.as_mut().poll(&mut cx) {
return output;
}
std::thread::park();
}
}
/// ashpd with `async-io`: a caller outside any tokio runtime gets its answer,
/// the connection's I/O running on zbus's own thread.
#[tokio::test(flavor = "multi_thread")]
async fn the_portal_answers_a_caller_without_a_runtime() {
const TEST: &str = "the_portal_answers_a_caller_without_a_runtime";
if std::env::var_os(ON_ITS_OWN_BUS).is_none() {
on_a_bus_of_its_own(TEST);
return;
}
let lookups = Arc::new(AtomicU32::new(0));
let _portal = zbus::connection::Builder::session()
.unwrap()
.name("org.freedesktop.portal.Desktop")
.unwrap()
.serve_at("/org/freedesktop/portal/desktop", Resolver { lookups: lookups.clone() })
.unwrap()
.build()
.await
.unwrap();
// A thread of its own: the pool's threads (`spawn_blocking`) have the
// runtime in reach.
let caller = std::thread::spawn(|| {
assert!(tokio::runtime::Handle::try_current().is_err(), "this thread has no runtime");
block_on(async {
let resolver = ashpd::desktop::proxy_resolver::ProxyResolver::new().await.unwrap();
let uri = ashpd::Uri::parse("https://capped.example/").unwrap();
resolver.lookup(&uri).await.unwrap()
})
});
// The stand-in portal runs on this runtime: keep it free while waiting.
let answer = tokio::task::spawn_blocking(move || caller.join().unwrap()).await.unwrap();
let answer: Vec<&str> = answer.iter().map(|uri| uri.as_str()).collect();
assert_eq!(answer, ["socks://127.0.0.1:2080"]);
assert_eq!(lookups.load(Ordering::SeqCst), 1);
}