dbus-rs icon indicating copy to clipboard operation
dbus-rs copied to clipboard

Support Windows

Open tichun opened this issue 4 years ago • 9 comments

https://www.freedesktop.org/wiki/Software/dbus/ here we can read that dbus has been ported to windows, but when building the crate there are only errors


error[E0433]: failed to resolve: could not find `unix` in `os`
 --> C:/Users/.../build/target/cargo-home\registry\src\github.com-1ecc6299db9ec823\dbus-0.6.5\src\message.rs:5:14
  |
5 | use std::os::unix::io::{RawFd, AsRawFd};
  |              ^^^^ could not find `unix` in `os`

error[E0433]: failed to resolve: could not find `unix` in `os`
 --> C:/Users/.../build/target/cargo-home\registry\src\github.com-1ecc6299db9ec823\dbus-0.6.5\src\watch.rs:7:14
  |
7 | use std::os::unix::io::{RawFd, AsRawFd};
  |              ^^^^ could not find `unix` in `os`

error[E0433]: failed to resolve: could not find `unix` in `os`
 --> C:/Users/.../build/target/cargo-home\registry\src\github.com-1ecc6299db9ec823\dbus-0.6.5\src\connection.rs:7:14
  |
7 | use std::os::unix::io::RawFd;
  |              ^^^^ could not find `unix` in `os`

error[E0433]: failed to resolve: could not find `unix` in `os`
   --> C:/Users/.../build/target/cargo-home\registry\src\github.com-1ecc6299db9ec823\dbus-0.6.5\src\arg\basic_impl.rs:243:22
    |
243 |         use std::os::unix::io::AsRawFd;
    |                      ^^^^ could not find `unix` in `os`

error[E0433]: failed to resolve: could not find `unix` in `os`
   --> C:/Users/.../build/target/cargo-home\registry\src\github.com-1ecc6299db9ec823\dbus-0.6.5\src\arg\basic_impl.rs:254:42
    |
254 | refarg_impl!(OwnedFd, _i, { use std::os::unix::io::AsRawFd; Some(_i.as_raw_fd() as i64) }, None, None, None);
    |                                          ^^^^ could not find `unix` in `os`

error[E0658]: use of unstable library feature 'ptr_cast'
   --> C:/Users/.../build/target/cargo-home\registry\src\github.com-1ecc6299db9ec823\backtrace-0.3.42\src\backtrace\dbghelp.rs:110:74
    |
110 |                 RtlLookupFunctionEntry(addr, &mut base, ptr::null_mut()).cast()
    |                                                                          ^^^^
    |
    = note: for more information, see https://github.com/rust-lang/rust/issues/60602

error[E0412]: cannot find type `RawFd` in this scope
  --> C:/Users/.../build/target/cargo-home\registry\src\github.com-1ecc6299db9ec823\dbus-0.6.5\src\message.rs:29:9
   |
29 |     fd: RawFd
   |         ^^^^^ not found in this scope

error[E0412]: cannot find type `RawFd` in this scope
  --> C:/Users/.../build/target/cargo-home\registry\src\github.com-1ecc6299db9ec823\dbus-0.6.5\src\message.rs:34:20
   |
34 |     pub fn new(fd: RawFd) -> OwnedFd {
   |                    ^^^^^ not found in this scope

error[E0412]: cannot find type `RawFd` in this scope
  --> C:/Users/.../build/target/cargo-home\registry\src\github.com-1ecc6299db9ec823\dbus-0.6.5\src\message.rs:39:29
   |
39 |     pub fn into_fd(self) -> RawFd {
   |                             ^^^^^ not found in this scope

error[E0405]: cannot find trait `AsRawFd` in this scope
  --> C:/Users/.../target/cargo-home\registry\src\github.com-1ecc6299db9ec823\dbus-0.6.5\src\message.rs:58:6
   |
58 | impl AsRawFd for OwnedFd {
   |      ^^^^^^^ not found in this scope

error[E0412]: cannot find type `RawFd` in this scope
  --> C:/Users/.../build/target/cargo-home\registry\src\github.com-1ecc6299db9ec823\dbus-0.6.5\src\message.rs:59:28
   |
59 |     fn as_raw_fd(&self) -> RawFd {
   |                            ^^^^^ not found in this scope

error[E0425]: cannot find value `POLLIN` in module `libc`
  --> C:/Users/.../build/target/cargo-home\registry\src\github.com-1ecc6299db9ec823\dbus-0.6.5\src\watch.rs:57:29
   |
57 |         if (revents & libc::POLLIN) != 0 { WatchEvent::Readable as c_uint } else { 0 } +
   |                             ^^^^^^ not found in `libc`

error[E0425]: cannot find value `POLLOUT` in module `libc`
  --> C:/Users/.../build/target/cargo-home\registry\src\github.com-1ecc6299db9ec823\dbus-0.6.5\src\watch.rs:58:29
   |
58 |         if (revents & libc::POLLOUT) != 0 { WatchEvent::Writable as c_uint } else { 0 } +
   |                             ^^^^^^^ not found in `libc`

error[E0425]: cannot find value `POLLERR` in module `libc`
  --> C:/Users/.../build/target/cargo-home\registry\src\github.com-1ecc6299db9ec823\dbus-0.6.5\src\watch.rs:59:29
   |
59 |         if (revents & libc::POLLERR) != 0 { WatchEvent::Error as c_uint } else { 0 } +
   |                             ^^^^^^^ not found in `libc`

error[E0425]: cannot find value `POLLHUP` in module `libc`
  --> C:/Users/.../build/target/cargo-home\registry\src\github.com-1ecc6299db9ec823\dbus-0.6.5\src\watch.rs:60:29
   |
60 |         if (revents & libc::POLLHUP) != 0 { WatchEvent::Hangup as c_uint } else { 0 }
   |                             ^^^^^^^ not found in `libc`

error[E0412]: cannot find type `RawFd` in this scope
  --> C:/Users/.../build/target/cargo-home\registry\src\github.com-1ecc6299db9ec823\dbus-0.6.5\src\watch.rs:67:9
   |
67 |     fd: RawFd,
   |         ^^^^^ not found in this scope

error[E0412]: cannot find type `RawFd` in this scope
  --> C:/Users/.../build/target/cargo-home\registry\src\github.com-1ecc6299db9ec823\dbus-0.6.5\src\watch.rs:74:25
   |
74 |     pub fn fd(&self) -> RawFd { self.fd }
   |                         ^^^^^ not found in this scope

error[E0412]: cannot find type `pollfd` in module `libc`
  --> C:/Users/.../build/target/cargo-home\registry\src\github.com-1ecc6299db9ec823\dbus-0.6.5\src\watch.rs:80:38
   |
80 |     pub fn to_pollfd(&self) -> libc::pollfd {
   |                                      ^^^^^^ not found in `libc`

error[E0422]: cannot find struct, variant or union type `pollfd` in module `libc`
  --> C:/Users/.../build/target/cargo-home\registry\src\github.com-1ecc6299db9ec823\dbus-0.6.5\src\watch.rs:81:15
   |
81 |         libc::pollfd { fd: self.fd, revents: 0, events: libc::POLLERR + libc::POLLHUP + 
   |               ^^^^^^ not found in `libc`

error[E0425]: cannot find value `POLLERR` in module `libc`
  --> C:/Users/.../build/target/cargo-home\registry\src\github.com-1ecc6299db9ec823\dbus-0.6.5\src\watch.rs:81:63
   |
81 |         libc::pollfd { fd: self.fd, revents: 0, events: libc::POLLERR + libc::POLLHUP +
   |                                                               ^^^^^^^ not found in `libc`

error[E0425]: cannot find value `POLLHUP` in module `libc`
  --> C:/Users/.../build/target/cargo-home\registry\src\github.com-1ecc6299db9ec823\dbus-0.6.5\src\watch.rs:81:79
   |
81 |         libc::pollfd { fd: self.fd, revents: 0, events: libc::POLLERR + libc::POLLHUP +
   |                                                                               ^^^^^^^ not found in `libc`

error[E0425]: cannot find value `POLLIN` in module `libc`
  --> C:/Users/.../build/target/cargo-home\registry\src\github.com-1ecc6299db9ec823\dbus-0.6.5\src\watch.rs:82:40
   |
82 |             if self.readable() { libc::POLLIN } else { 0 } +
   |                                        ^^^^^^ not found in `libc`

error[E0425]: cannot find value `POLLOUT` in module `libc`
  --> C:/Users/.../build/target/cargo-home\registry\src\github.com-1ecc6299db9ec823\dbus-0.6.5\src\watch.rs:83:40
   |
83 |             if self.writable() { libc::POLLOUT } else { 0 },
   |                                        ^^^^^^^ not found in `libc`

error[E0405]: cannot find trait `AsRawFd` in this scope
   --> C:/Users/.../build/target/cargo-home\registry\src\github.com-1ecc6299db9ec823\dbus-0.6.5\src\watch.rs:100:6
    |
100 | impl AsRawFd for Watch {
    |      ^^^^^^^ not found in this scope

error: aborting due to previous error

For more information about this error, try `rustc --explain E0658`.
error[E0412]: cannot find type `RawFd` in this scope
   --> C:/Users/.../build/target/cargo-home\registry\src\github.com-1ecc6299db9ec823\dbus-0.6.5\src\watch.rs:101:28
    |
101 |     fn as_raw_fd(&self) -> RawFd { self.fd }
    |                            ^^^^^ not found in this scope

error[E0412]: cannot find type `RawFd` in this scope
   --> C:/Users/.../build/target/cargo-home\registry\src\github.com-1ecc6299db9ec823\dbus-0.6.5\src\watch.rs:123:36
    |
123 |     pub fn watch_handle(&self, fd: RawFd, flags: c_uint) {
    |                                    ^^^^^ not found in this scope

error[E0412]: cannot find type `RawFd` in this scope
   --> C:/Users/.../build/target/cargo-home\registry\src\github.com-1ecc6299db9ec823\dbus-0.6.5\src\connection.rs:498:36
    |
498 |     pub fn watch_handle(&self, fd: RawFd, flags: c_uint) -> ConnectionItems {
    |                                    ^^^^^ not found in this scope

error: Could not compile `backtrace`.
warning: build failed, waiting for other jobs to finish...
error: aborting due to 26 previous errors

Some errors have detailed explanations: E0405, E0412, E0422, E0425, E0433.
For more information about an error, try `rustc --explain E0405`.
error: Could not compile `dbus`.
warning: build failed, waiting for other jobs to finish...
error: build failed

tichun avatar Feb 23 '20 14:02 tichun

Hi!

There is no windows support at the moment, and as I don't run dbus on windows myself (and know nobody else that does) it's unlikely that I'm going to port it myself.

I'll be happy to review and merge PRs that add Windows support.

diwic avatar Feb 23 '20 15:02 diwic

Is there a good primer on DBUS and can someone roughly estimate how large that change might need to be?

ccoenen avatar Aug 26 '20 16:08 ccoenen

@ccoenen Not sure if D-Bus itself is what you need the most knowledge in. It's more about knowledge about how to port things to Windows in general. I don't think the changes to the Rust code will be large, the work would be more about figuring out how to set up an environment to build it.

diwic avatar Aug 27 '20 07:08 diwic

libdbus itself is ported to windows. It is provided prebuilt in MSYS2 mingw, it also can be built using CMake+MSVC. As far as I understand, the only issue in Rust code is that dbus-rs uses std::os::unix, libc::{sockaddr_un, AF_UNIX} unconditionally.

Looks like there are 2 changes needed:

  1. All code that uses Unix sockets should be optional. Recent Windows 10 versions gained UDS support, but I'm not sure if libdbus is aware of that. And even if it is, fd passing is still not possible.

  2. dbus-rs should try to also use CMake to find dbus library. If pkg-config is not available, or maybe even prefer CMake on Windows.

(2) is only necessary for MSVC build of dbus, (1) prevents it from being used even in mingw environment.

amezin avatar Mar 18 '21 20:03 amezin

So, on Windows std::os::unix::io::RawFd should be replaced by std::os::windows::io::RawSocket: https://gitlab.freedesktop.org/dbus/dbus/-/blob/master/dbus/dbus-sysdeps.h#L160 (it is always a socket - https://gitlab.freedesktop.org/dbus/dbus/-/blob/master/dbus/dbus-watch.c#L576)

Only a small issue - RawSocket (SOCKET) is 64-bit, and libdbus casts that to int (https://gitlab.freedesktop.org/dbus/dbus/-/blob/master/dbus/dbus-sysdeps.h#L177)

amezin avatar Mar 19 '21 01:03 amezin

Only a small issue - RawSocket (SOCKET) is 64-bit, and libdbus casts that to int

or may be not so small: https://stackoverflow.com/questions/1953639/is-it-safe-to-cast-socket-to-int-under-win64

https://docs.microsoft.com/en-us/windows/win32/winsock/socket-data-type-2 :

Windows Sockets handles have no restrictions, other than that the value INVALID_SOCKET is not a valid socket. Socket handles may take any value in the range 0 to INVALID_SOCKET–1.

Now I'm not sure if I want to use libdbus on windows (and thus this library too)

amezin avatar Mar 20 '21 01:03 amezin

Only a small issue - RawSocket (SOCKET) is 64-bit, and libdbus casts that to int

or may be not so small: https://stackoverflow.com/questions/1953639/is-it-safe-to-cast-socket-to-int-under-win64

https://docs.microsoft.com/en-us/windows/win32/winsock/socket-data-type-2 :

Windows Sockets handles have no restrictions, other than that the value INVALID_SOCKET is not a valid socket. Socket handles may take any value in the range 0 to INVALID_SOCKET–1.

Now I'm not sure if I want to use libdbus on windows (and thus this library too)

Looking at the answers on the stackoverflow thread, it seems to be safe in practice but not in theory. If this is something that worries you, maybe a patch to libdbus is the right way forward? It would need a new public API function, I suppose, as dbus_watch_get_socket returns an int.

diwic avatar Mar 20 '21 12:03 diwic

Even though https://github.com/diwic/dbus-rs/pull/320 has been merged, dbus-rs is currently only usable in mingw environment, because it depends on pkg-config to find libdbus.

libdbus has CMake config on Debian and Fedora. As far as I can tell, D-bus' Autotools build system always generates and installs CMake config. On Windows without mingw (i. e. MSVC builds of libdbus), pkg-config may be unavailable. So maybe switch to CMake for searching for the library? And keep pkg-config as a fallback when it's available

amezin avatar Mar 23 '21 10:03 amezin

So maybe switch to CMake for searching for the library? And keep pkg-config as a fallback when it's available

I don't use D-Bus on Windows myself so I have no idea how people build Windows there. If you were to add some build instructions or so I'll be happy to review and merge that. Same goes for other Windows support patches, as long as they don't add additional dependencies or other trouble for Linux/Unix platforms (which has several orders of magnitude more users).

diwic avatar Mar 23 '21 17:03 diwic