Skip to content

Commit 28b23fd

Browse files
committed
fix: Allow to build with autostart and without systemd feature
Before this change, import of `systemd::is_systemd_used` was hidden behind `cfg(feature = "systemd")` predicate. But that function is expected to be present in the autostart block even if `systemd` feature is disabled. Fix that by importing `is_systemd_used` unconditionally. Provide an implementation of `is_systemd_used` for `cfg(not(feature = "systemd"))` which just returns `false`. Fixes: #136
1 parent 379ce30 commit 28b23fd

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ use std::{
3030
os::fd::{AsRawFd, OwnedFd},
3131
sync::Arc,
3232
};
33+
use systemd::is_systemd_used;
3334
#[cfg(feature = "systemd")]
34-
use systemd::{get_systemd_env, is_systemd_used, spawn_scope};
35+
use systemd::{get_systemd_env, spawn_scope};
3536
use tokio::{
3637
net::UnixStream,
3738
sync::{

src/systemd.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,15 @@ pub fn stop_systemd_target() {
5252

5353
/// Determine if systemd is used as the init system. This should work on all
5454
/// linux distributions.
55+
#[cfg(feature = "systemd")]
5556
pub fn is_systemd_used() -> &'static bool {
5657
static IS_SYSTEMD_USED: OnceLock<bool> = OnceLock::new();
5758
IS_SYSTEMD_USED.get_or_init(|| Path::new("/run/systemd/system").exists())
5859
}
60+
#[cfg(not(feature = "systemd"))]
61+
pub fn is_systemd_used() -> &'static bool {
62+
&false
63+
}
5964

6065
#[cfg(feature = "systemd")]
6166
pub async fn get_systemd_env() -> Result<Vec<EnvVar>, zbus::Error> {

0 commit comments

Comments
 (0)