diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..b7bc5df --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,29 @@ +name: test + +on: + push: + branches: + - master + + pull_request: + branches: + - master + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - uses: taiki-e/install-action@cargo-hack + + - name: Check + run: cargo hack check --feature-powerset + + - name: Build + run: cargo hack build --feature-powerset + + - name: Test + env: + RUST_BACKTRACE: full + run: cargo hack test --feature-powerset diff --git a/src/main.rs b/src/main.rs index a6716af..c26a01f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,8 +30,9 @@ use std::{ os::fd::{AsRawFd, OwnedFd}, sync::Arc, }; +use systemd::is_systemd_used; #[cfg(feature = "systemd")] -use systemd::{get_systemd_env, is_systemd_used, spawn_scope}; +use systemd::{get_systemd_env, spawn_scope}; use tokio::{ net::UnixStream, sync::{ diff --git a/src/systemd.rs b/src/systemd.rs index 6cbfa02..e0b656c 100644 --- a/src/systemd.rs +++ b/src/systemd.rs @@ -52,10 +52,15 @@ pub fn stop_systemd_target() { /// Determine if systemd is used as the init system. This should work on all /// linux distributions. +#[cfg(feature = "systemd")] pub fn is_systemd_used() -> &'static bool { static IS_SYSTEMD_USED: OnceLock = OnceLock::new(); IS_SYSTEMD_USED.get_or_init(|| Path::new("/run/systemd/system").exists()) } +#[cfg(not(feature = "systemd"))] +pub fn is_systemd_used() -> &'static bool { + &false +} #[cfg(feature = "systemd")] pub async fn get_systemd_env() -> Result, zbus::Error> {