Skip to content

Commit

Permalink
Merge pull request #202 from zeenix/drop-windows-support
Browse files Browse the repository at this point in the history
🔥 Drop support for Windows
  • Loading branch information
zeenix authored Feb 6, 2025
2 parents 7b259ba + 7ce213a commit 229d42b
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 98 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
Expand All @@ -33,7 +33,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
Expand Down
9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ name = "busd"
path = "src/bin/busd.rs"

[dependencies]
zbus = { git = "https://github.com/dbus2/zbus/", features = [
#zbus = { version = "5.0", features = [
zbus = { git = "https://github.com/dbus2/zbus/", features = [
"tokio",
"bus-impl",
], default-features = false }
Expand All @@ -32,7 +32,11 @@ tokio = { version = "1.37.0", features = [
"signal",
"tracing",
] }
clap = { version = "4.5.4", features = ["derive", "std", "help"], default-features = false }
clap = { version = "4.5.4", features = [
"derive",
"std",
"help",
], default-features = false }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = [
"env-filter",
Expand All @@ -50,7 +54,6 @@ event-listener = "5.3.0"
fastrand = "2.2.0"
quick-xml = { version = "0.37.0", features = ["serialize"] }

[target.'cfg(unix)'.dependencies]
nix = { version = "0.29.0", features = ["user"] }

[features]
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

# busd

A D-Bus bus (broker) implementation in Rust. Since it's pure Rust, it's much easier to build for
multiple platforms (Linux, Mac and Windows being the primary targets) than other D-Bus brokers.
A D-Bus bus (broker) implementation in Rust. Since it's pure Rust, it's much easier to cross-build
than other D-Bus brokers.

## Status

Expand Down
35 changes: 11 additions & 24 deletions src/bin/busd.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
extern crate busd;

use std::path::PathBuf;
#[cfg(unix)]
use std::{fs::File, io::Write, os::fd::FromRawFd};
use std::{fs::File, io::Write, os::fd::FromRawFd, path::PathBuf};

use busd::{bus, config::Config};

use anyhow::Result;
use clap::Parser;
#[cfg(unix)]
use tokio::{select, signal::unix::SignalKind};
#[cfg(unix)]
use tracing::warn;
use tracing::{error, info};
use tracing::{error, info, warn};

/// A simple D-Bus broker.
#[derive(Parser, Debug)]
Expand All @@ -39,7 +34,6 @@ struct Args {
/// This readiness notification mechanism which works on both systemd and s6.
///
/// This feature is only available on unix-like platforms.
#[cfg(unix)]
#[clap(long)]
ready_fd: Option<i32>,

Expand Down Expand Up @@ -77,7 +71,6 @@ async fn main() -> Result<()> {

let mut bus = bus::Bus::for_address(address.as_deref()).await?;

#[cfg(unix)]
if let Some(fd) = args.ready_fd {
// SAFETY: We don't have any way to know if the fd is valid or not. The parent process is
// responsible for passing a valid fd.
Expand All @@ -89,23 +82,17 @@ async fn main() -> Result<()> {
println!("{}", bus.address());
}

// FIXME: How to handle this gracefully on Windows?
#[cfg(unix)]
{
let mut sig_int = tokio::signal::unix::signal(SignalKind::interrupt())?;

select! {
_ = sig_int.recv() => {
info!("Received SIGINT, shutting down..");
}
res = bus.run() => match res {
Ok(()) => warn!("Bus stopped, shutting down.."),
Err(e) => error!("Bus stopped with an error: {}", e),
}
let mut sig_int = tokio::signal::unix::signal(SignalKind::interrupt())?;

select! {
_ = sig_int.recv() => {
info!("Received SIGINT, shutting down..");
}
res = bus.run() => match res {
Ok(()) => warn!("Bus stopped, shutting down.."),
Err(e) => error!("Bus stopped with an error: {}", e),
}
}
#[cfg(not(unix))]
bus.run().await?;

if let Err(e) = bus.cleanup().await {
error!("Failed to clean up: {}", e);
Expand Down
33 changes: 7 additions & 26 deletions src/bus/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
use anyhow::{bail, Ok, Result};
#[cfg(unix)]
use std::{env, path::Path};
use std::{str::FromStr, sync::Arc};
#[cfg(unix)]
use tokio::fs::remove_file;
use tokio::spawn;
use std::{env, path::Path, str::FromStr, sync::Arc};
use tokio::{fs::remove_file, spawn};
use tracing::{debug, info, trace, warn};
#[cfg(unix)]
use zbus::address::transport::{Unix, UnixSocket};
use zbus::{
address::{transport::Tcp, Transport},
address::{
transport::{Tcp, Unix, UnixSocket},
Transport,
},
connection::{self, socket::BoxedSplit},
Address, AuthMechanism, Connection, Guid, OwnedGuid,
};
Expand Down Expand Up @@ -39,7 +36,6 @@ pub struct Inner {

#[derive(Debug)]
enum Listener {
#[cfg(unix)]
Unix(tokio::net::UnixListener),
Tcp(tokio::net::TcpListener),
}
Expand All @@ -60,7 +56,6 @@ impl Bus {
}
};
let (listener, auth_mechanism) = match address.transport() {
#[cfg(unix)]
Transport::Unix(unix) => {
// Resolve address specification into address that clients can use.
let addr = Self::unix_addr(unix)?;
Expand All @@ -76,16 +71,7 @@ impl Bus {
AuthMechanism::External,
)
}
Transport::Tcp(tcp) => {
#[cfg(not(windows))]
let auth_mechanism = AuthMechanism::Anonymous;
#[cfg(windows)]
let auth_mechanism = AuthMechanism::External;

(Self::tcp_stream(tcp).await?, auth_mechanism)
}
#[cfg(windows)]
Transport::Autolaunch(_) => bail!("`autolaunch` transport is not supported (yet)."),
Transport::Tcp(tcp) => (Self::tcp_stream(tcp).await?, AuthMechanism::Anonymous),
_ => bail!("Unsupported address `{}`.", address),
};

Expand Down Expand Up @@ -139,7 +125,6 @@ impl Bus {
// AsyncDrop would have been nice!
pub async fn cleanup(self) -> Result<()> {
match self.inner.address.transport() {
#[cfg(unix)]
Transport::Unix(unix) => match unix.path() {
UnixSocket::File(path) => remove_file(path).await.map_err(Into::into),
_ => Ok(()),
Expand All @@ -148,7 +133,6 @@ impl Bus {
}
}

#[cfg(unix)]
fn unix_addr(unix: &Unix) -> Result<std::os::unix::net::SocketAddr> {
use std::os::unix::net::SocketAddr;

Expand Down Expand Up @@ -188,7 +172,6 @@ impl Bus {
})
}

#[cfg(unix)]
async fn unix_stream(addr: std::os::unix::net::SocketAddr) -> Result<Listener> {
// TODO: Use tokio::net::UnixListener directly once it supports abstract sockets:
//
Expand Down Expand Up @@ -237,7 +220,6 @@ impl Bus {

async fn accept(&mut self) -> Result<BoxedSplit> {
let stream = match &mut self.listener {
#[cfg(unix)]
Listener::Unix(listener) => listener.accept().await.map(|(stream, _)| stream.into())?,
Listener::Tcp(listener) => listener.accept().await.map(|(stream, _)| stream.into())?,
};
Expand Down Expand Up @@ -265,7 +247,6 @@ impl Bus {
}
}

#[cfg(unix)]
fn default_address() -> String {
let runtime_dir = env::var("XDG_RUNTIME_DIR")
.as_ref()
Expand Down
1 change: 0 additions & 1 deletion src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ impl TryFrom<Document> for Config {
config
.servicedirs
.push(PathBuf::from("/usr/share/dbus-1/services"));
// TODO: add Windows-specific session directories
}
Element::StandardSystemServicedirs => {
// TODO: warn and then ignore if we aren't reading:
Expand Down
11 changes: 2 additions & 9 deletions src/peer/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,15 @@ impl Stream {
let signature = header.signature();
let body = msg.body();
let body_bytes = body.data();
#[cfg(unix)]
let fds = body_bytes
.fds()
.iter()
.map(|fd| fd.try_clone().map(Into::into))
.collect::<zbus::zvariant::Result<Vec<_>>>()?;
let builder =
message::Builder::from(header.clone()).sender(&unique_name)?;
let new_msg = unsafe {
builder.build_raw_body(
body_bytes,
signature,
#[cfg(unix)]
fds,
)?
};
let new_msg =
unsafe { builder.build_raw_body(body_bytes, signature, fds)? };
trace!("Added sender field to message: {:?}", new_msg);

Ok(new_msg)
Expand Down
2 changes: 0 additions & 2 deletions tests/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,6 @@ fn config_read_file_system_conf_ok() {
assert_eq!(got, want,);
}

#[cfg(unix)]
#[test]
fn config_read_file_real_usr_share_dbus1_session_conf_ok() {
let config_path = PathBuf::from("/usr/share/dbus-1/session.conf");
Expand All @@ -465,7 +464,6 @@ fn config_read_file_real_usr_share_dbus1_session_conf_ok() {
Config::read_file(config_path).expect("should read and parse XML input");
}

#[cfg(unix)]
#[test]
fn config_read_file_real_usr_share_dbus1_system_conf_ok() {
let config_path = PathBuf::from("/usr/share/dbus-1/system.conf");
Expand Down
13 changes: 4 additions & 9 deletions tests/fdo.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#[cfg(unix)]
use std::env::temp_dir;

use anyhow::ensure;
use busd::bus::Bus;
use futures_util::stream::StreamExt;
use ntest::timeout;
#[cfg(unix)]
use rand::{
distr::{Alphanumeric, SampleString},
rng,
Expand All @@ -26,13 +24,10 @@ async fn name_ownership_changes() {
busd::tracing_subscriber::init();

// Unix socket
#[cfg(unix)]
{
let s = Alphanumeric.sample_string(&mut rng(), 10);
let path = temp_dir().join(s);
let address = format!("unix:path={}", path.display());
name_ownership_changes_(&address).await;
}
let s = Alphanumeric.sample_string(&mut rng(), 10);
let path = temp_dir().join(s);
let address = format!("unix:path={}", path.display());
name_ownership_changes_(&address).await;

// TCP socket
let address = "tcp:host=127.0.0.1,port=4242".to_string();
Expand Down
16 changes: 5 additions & 11 deletions tests/greet.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#[cfg(unix)]
use std::env::temp_dir;
use std::time::Duration;
use std::{env::temp_dir, time::Duration};

use anyhow::anyhow;
use busd::bus::Bus;
use futures_util::{pin_mut, stream::StreamExt};
use ntest::timeout;
#[cfg(unix)]
use rand::{
distr::{Alphanumeric, SampleString},
rng,
Expand All @@ -31,13 +28,10 @@ async fn greet() {
busd::tracing_subscriber::init();

// Unix socket
#[cfg(unix)]
{
let s = Alphanumeric.sample_string(&mut rng(), 10);
let path = temp_dir().join(s);
let address = format!("unix:path={}", path.display());
greet_(&address).await;
}
let s = Alphanumeric.sample_string(&mut rng(), 10);
let path = temp_dir().join(s);
let address = format!("unix:path={}", path.display());
greet_(&address).await;

// TCP socket
let address = "tcp:host=127.0.0.1,port=4248".to_string();
Expand Down
14 changes: 5 additions & 9 deletions tests/multiple_conns.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#[cfg(unix)]
use std::env::temp_dir;

use busd::bus::Bus;
use futures_util::future::join_all;
use ntest::timeout;
#[cfg(unix)]
use rand::{
distr::{Alphanumeric, SampleString},
rng,
Expand All @@ -19,13 +17,11 @@ use zbus::connection;
async fn multi_conenct() {
busd::tracing_subscriber::init();

#[cfg(unix)]
{
let s = Alphanumeric.sample_string(&mut rng(), 10);
let path = temp_dir().join(s);
let address = format!("unix:path={}", path.display());
multi_conenct_(&address).await;
}
// Unix socket
let s = Alphanumeric.sample_string(&mut rng(), 10);
let path = temp_dir().join(s);
let address = format!("unix:path={}", path.display());
multi_conenct_(&address).await;

// TCP socket
let address = "tcp:host=127.0.0.1,port=4246".to_string();
Expand Down

0 comments on commit 229d42b

Please sign in to comment.