Open tichun opened 4 years ago
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.
Is there a good primer on DBUS and can someone roughly estimate how large that change might need to be?
@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.
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:
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.
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.
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)
Only a small issue -
RawSocket
(SOCKET
) is 64-bit, and libdbus casts that toint
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)
Only a small issue -
RawSocket
(SOCKET
) is 64-bit, and libdbus casts that toint
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.
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
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).
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