Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Windows #236

Open
tichun opened this issue Feb 23, 2020 · 9 comments
Open

Support Windows #236

tichun opened this issue Feb 23, 2020 · 9 comments

Comments

@tichun
Copy link

tichun commented Feb 23, 2020

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
@diwic
Copy link
Owner

diwic commented Feb 23, 2020

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 diwic changed the title [Windows] Build errors Support Windows Feb 23, 2020
@ccoenen
Copy link

ccoenen commented Aug 26, 2020

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

@diwic
Copy link
Owner

diwic commented Aug 27, 2020

@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.

@amezin
Copy link
Contributor

amezin commented Mar 18, 2021

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
Copy link
Contributor

amezin commented Mar 19, 2021

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
Copy link
Contributor

amezin commented Mar 20, 2021

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)

@diwic
Copy link
Owner

diwic commented Mar 20, 2021

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.

@amezin
Copy link
Contributor

amezin commented Mar 23, 2021

Even though #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

@diwic
Copy link
Owner

diwic commented Mar 23, 2021

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants