diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..4c044d6 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,36 @@ +name: CI + +on: + push: + +jobs: + build: + strategy: + fail-fast: false + matrix: + os: ['pc-windows-msvc', 'apple-darwin', 'unknown-linux-gnu'] + arch: [x86_64, aarch64] + include: + - runner: ubuntu-latest + os: unknown-linux-gnu + - runner: windows-latest + os: pc-windows-msvc + - runner: macos-latest + os: apple-darwin + runs-on: ${{ matrix.runner }} + + steps: + - uses: actions/checkout@v4 + + - name: Configure runner + run: rustup target add ${{matrix.arch}}-${{matrix.os}} + + - name: Configure runner + if: matrix.os == 'unknown-linux-gnu' + run: | + sudo apt-get update + sudo apt-get -o Acquire:retries=3 install libsystemd-dev + + - name: Build + shell: pwsh + run: cargo build --target ${{matrix.arch}}-${{matrix.os}} \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 6b2b0c6..5d43498 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ winapi = { version = "0.3", features = ["winbase", "winerror", "winuser", "winsv widestring = "0.4.3" [target.'cfg(target_os = "linux")'.dependencies] -systemd-rs = "^0.1.2" +systemd-rs = { version="^0.1.2", optional = true } [target.'cfg(target_os = "macos")'.dependencies] core-foundation = "0.9" diff --git a/src/controller/linux.rs b/src/controller/linux.rs index 0bfdbda..ad82a19 100644 --- a/src/controller/linux.rs +++ b/src/controller/linux.rs @@ -7,14 +7,15 @@ use std::sync::mpsc; use ctrlc; use log::{debug, info}; -use systemd_rs::login::monitor::{Category, Monitor}; -use systemd_rs::login::session as login_session; use crate::controller::{ControllerInterface, ServiceMainFn}; use crate::session; use crate::Error; use crate::ServiceEvent; +#[cfg(feature = "systemd-rs")] +use {systemd_rs::login::monitor::{Category, Monitor}, systemd_rs::login::session as login_session}; + type LinuxServiceMainWrapperFn = extern "system" fn(args: Vec); pub type Session = session::Session_; @@ -179,9 +180,11 @@ impl ControllerInterface for LinuxController { } } +#[cfg(feature = "systemd-rs")] fn run_monitor( tx: mpsc::Sender>, ) -> Result { + let monitor = Monitor::new()?; let mut current_session = match login_session::get_active_session() { @@ -239,8 +242,12 @@ macro_rules! Service { #[doc(hidden)] pub fn dispatch(service_main: ServiceMainFn, args: Vec) { let (tx, rx) = mpsc::channel(); + + #[cfg(feature = "systemd-rs")] + { + let _monitor = run_monitor(tx.clone()).expect("Failed to run session monitor"); + } - let _monitor = run_monitor(tx.clone()).expect("Failed to run session monitor"); let _tx = tx.clone(); ctrlc::set_handler(move || {