lucab / libsystemd-rs

A pure-Rust client library to work with systemd
https://crates.io/crates/libsystemd
Other
106 stars 19 forks source link

Can't install on OSX #145

Open therealjasonkenney opened 1 year ago

therealjasonkenney commented 1 year ago

I use OSX as a dev machine, and it would be nice if this could install just so I don't have wrap everything in platform checks. My project uses journald on linux and defaults to stderr when it's not available.

Anyhow here are the errors, and some seemed simple to fix

   Compiling libsystemd v0.6.0
error[E0432]: unresolved import `nix::sys::memfd`
 --> /Volumes/Navi/Users/lain/.cargo/registry/src/github.com-1ecc6299db9ec823/libsystemd-0.6.0/src/logging.rs:3:15
  |
3 | use nix::sys::memfd::memfd_create;
  |               ^^^^^ could not find `memfd` in `sys`

error[E0433]: failed to resolve: could not find `linux` in `os`
  --> /Volumes/Navi/Users/lain/.cargo/registry/src/github.com-1ecc6299db9ec823/libsystemd-0.6.0/src/logging.rs:11:14
   |
11 | use std::os::linux::fs::MetadataExt;
   |              ^^^^^ could not find `linux` in `os`

error[E0432]: unresolved import `nix::sys::memfd`
 --> /Volumes/Navi/Users/lain/.cargo/registry/src/github.com-1ecc6299db9ec823/libsystemd-0.6.0/src/logging.rs:4:15
  |
4 | use nix::sys::memfd::MemFdCreateFlag;
  |               ^^^^^ could not find `memfd` in `sys`

error[E0412]: cannot find type `mq_attr` in crate `libc`
   --> /Volumes/Navi/Users/lain/.cargo/registry/src/github.com-1ecc6299db9ec823/libsystemd-0.6.0/src/activation.rs:202:54
    |
202 |         let mut attr = std::mem::MaybeUninit::<libc::mq_attr>::uninit();
    |                                                      ^^^^^^^ not found in `libc`

error[E0425]: cannot find function `mq_getattr` in crate `libc`
    --> /Volumes/Navi/Users/lain/.cargo/registry/src/github.com-1ecc6299db9ec823/libsystemd-0.6.0/src/activation.rs:203:34
     |
203  |         let res = unsafe { libc::mq_getattr(*self, attr.as_mut_ptr()) };
     |                                  ^^^^^^^^^^ help: a function with a similar name exists: `tcgetattr`
     |
    ::: /Volumes/Navi/Users/lain/.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.144/src/unix/mod.rs:1383:5
     |
1383 |     pub fn tcgetattr(fd: ::c_int, termios: *mut ::termios) -> ::c_int;
     |     ----------------------------------------------------------------- similarly named function `tcgetattr` defined here

error[E0599]: no function or associated item named `new_abstract` found for struct `UnixAddr` in the current scope
  --> /Volumes/Navi/Users/lain/.cargo/registry/src/github.com-1ecc6299db9ec823/libsystemd-0.6.0/src/daemon.rs:95:50
   |
95 |         Some(stripped_addr) => socket::UnixAddr::new_abstract(stripped_addr.as_bytes())
   |                                                  ^^^^^^^^^^^^ function or associated item not found in `UnixAddr`

error[E0599]: no variant or associated item named `F_ADD_SEALS` found for enum `nix::fcntl::FcntlArg` in the current scope
   --> /Volumes/Navi/Users/lain/.cargo/registry/src/github.com-1ecc6299db9ec823/libsystemd-0.6.0/src/logging.rs:227:40
    |
227 |     fcntl(memfd.as_raw_fd(), FcntlArg::F_ADD_SEALS(SealFlag::all()))
    |                                        ^^^^^^^^^^^ variant or associated item not found in `FcntlArg<'_>`

error[E0433]: failed to resolve: use of undeclared type `SealFlag`
   --> /Volumes/Navi/Users/lain/.cargo/registry/src/github.com-1ecc6299db9ec823/libsystemd-0.6.0/src/logging.rs:227:52
    |
227 |     fcntl(memfd.as_raw_fd(), FcntlArg::F_ADD_SEALS(SealFlag::all()))
    |                                                    ^^^^^^^^ use of undeclared type `SealFlag`

error[E0599]: no method named `st_dev` found for reference `&std::fs::Metadata` in the current scope
   --> /Volumes/Navi/Users/lain/.cargo/registry/src/github.com-1ecc6299db9ec823/libsystemd-0.6.0/src/logging.rs:315:30
    |
315 |             device: metadata.st_dev(),
    |                              ^^^^^^ method not found in `&Metadata`
    |
    = help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
1   | use std::os::macos::fs::MetadataExt;
    |

error[E0599]: no method named `st_ino` found for reference `&std::fs::Metadata` in the current scope
   --> /Volumes/Navi/Users/lain/.cargo/registry/src/github.com-1ecc6299db9ec823/libsystemd-0.6.0/src/logging.rs:316:29
    |
316 |             inode: metadata.st_ino(),
    |                             ^^^^^^ method not found in `&Metadata`
    |
    = help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
1   | use std::os::macos::fs::MetadataExt;
    |
swsnr commented 1 year ago

Honestly, I don't see why we should wrap everything in platform checks, or provide stub implementations for effectively the entire API 🙂

This looks like a lot of work and extra build combinations on our side, whereas it's probably just a few lines on your side if it's just about logging.

I'm inclined to close this.

therealjasonkenney commented 1 year ago

Fair, can you add something like this: https://stackoverflow.com/questions/72990789/how-to-specify-the-target-os-in-cargo-toml in lib.rs ?

It would make debugging for people who are using crates that chose to add your crate as a dependency much easier :)

swsnr commented 1 year ago

I thought it'd be obvious that this crate only works on Linux, given that systemd itself only supports Linux 🙂

avi-cenna commented 6 months ago

@swsnr I'm running into the same issue as well trying to use a different package that indirectly imports libsystemd. I didn't know much about systemd, so it wasn't obvious to me.