daniel5151 / gdbstub

An ergonomic, featureful, and easy-to-integrate implementation of the GDB Remote Serial Protocol in Rust (with no-compromises #![no_std] support)
Other
308 stars 49 forks source link

example_no_std doesn't build on Windows #131

Open xobs opened 1 year ago

xobs commented 1 year ago

The example_no_std package doesn't build on Windows because it seems to use Unix-specific libc calls:

[10:48:46 am] E:/Code/Xous/Core/gdbstub/example_no_std> cargo build --release
    Updating crates.io index
    Blocking waiting for file lock on package cache
    Blocking waiting for file lock on package cache
   Compiling autocfg v1.1.0
   Compiling log v0.4.17
   Compiling paste v1.0.12
   Compiling cfg-if v1.0.0
   Compiling libc v0.2.140
   Compiling bitflags v1.3.2
   Compiling managed v0.8.0
   Compiling num-traits v0.2.15
   Compiling gdbstub v0.6.4 (E:\Code\Xous\Core\gdbstub)
   Compiling gdbstub_arch v0.2.4 (E:\Code\Xous\Core\gdbstub\gdbstub_arch)
   Compiling gdbstub-nostd v0.1.0 (E:\Code\Xous\Core\gdbstub\example_no_std)
error[E0422]: cannot find struct, variant or union type `sockaddr_in` in crate `libc`
   --> src\conn.rs:11:34
    |
11  |               let sockaddr = libc::sockaddr_in {
    |                                    ^^^^^^^^^^^ help: a struct with a similar name exists: `sockaddr`
    |
   ::: C:\Users\Sean\.cargo\registry\src\github.com-1ecc6299db9ec823\libc-0.2.140\src\windows\mod.rs:55:1
    |
55  | / s! {
56  | |     // note this is the struct called stat64 in Windows. Not stat, nor stati64.
57  | |     pub struct stat {
58  | |         pub st_dev: dev_t,
...   |
102 | |     }
103 | | }
    | |_- similarly named struct `sockaddr` defined here

error[E0425]: cannot find value `AF_INET` in crate `libc`
  --> src\conn.rs:12:35
   |
12 |                 sin_family: libc::AF_INET as _,
   |                                   ^^^^^^^ not found in `libc`

error[E0422]: cannot find struct, variant or union type `in_addr` in crate `libc`
  --> src\conn.rs:15:33
   |
15 |                 sin_addr: libc::in_addr {
   |                                 ^^^^^^^ not found in `libc`

error[E0412]: cannot find type `sockaddr_in` in crate `libc`
   --> src\conn.rs:20:54
    |
20  |               let socklen = core::mem::size_of::<libc::sockaddr_in>();
    |                                                        ^^^^^^^^^^^ help: a struct with a similar name exists: `sockaddr`
    |
   ::: C:\Users\Sean\.cargo\registry\src\github.com-1ecc6299db9ec823\libc-0.2.140\src\windows\mod.rs:55:1
    |
55  | / s! {
56  | |     // note this is the struct called stat64 in Windows. Not stat, nor stati64.
57  | |     pub struct stat {
58  | |         pub st_dev: dev_t,
...   |
102 | |     }
103 | | }
    | |_- similarly named struct `sockaddr` defined here

error[E0425]: cannot find value `AF_INET` in crate `libc`
  --> src\conn.rs:22:43
   |
22 |             let sock = libc::socket(libc::AF_INET, libc::SOCK_STREAM, 0);
   |                                           ^^^^^^^ not found in `libc`

error[E0425]: cannot find value `SOCK_STREAM` in crate `libc`
  --> src\conn.rs:22:58
   |
22 |             let sock = libc::socket(libc::AF_INET, libc::SOCK_STREAM, 0);
   |                                                          ^^^^^^^^^^^ not found in `libc`

error[E0425]: cannot find function `recv` in crate `libc`
  --> src\conn.rs:58:19
   |
58 |             libc::recv(
   |                   ^^^^ not found in `libc`

error[E0425]: cannot find value `MSG_PEEK` in crate `libc`
  --> src\conn.rs:62:23
   |
62 |                 libc::MSG_PEEK,
   |                       ^^^^^^^^ not found in `libc`

error[E0600]: cannot apply unary operator `-` to type `usize`
  --> src\conn.rs:23:24
   |
23 |             if sock == -1 {
   |                        ^^
   |                        |
   |                        cannot apply unary operator `-`
   |                        help: you may have meant the maximum value of `usize`: `usize::MAX`
   |
   = note: unsigned values cannot be negated

error[E0308]: mismatched types
   --> src\conn.rs:27:61
    |
27  |             if libc::bind(sock, &sockaddr as *const _ as _, socklen as u32) < 0 {
    |                ----------                                   ^^^^^^^^^^^^^^ expected `i32`, found `u32`
    |                |
    |                arguments to this function are incorrect
    |
note: function defined here
   --> C:\Users\Sean\.cargo\registry\src\github.com-1ecc6299db9ec823\libc-0.2.140\src\windows\mod.rs:529:12
    |
529 |     pub fn bind(s: SOCKET, name: *const ::sockaddr, namelen: ::c_int) -> ::c_int;
    |            ^^^^
help: you can convert a `u32` to an `i32` and panic if the converted value doesn't fit
    |
27  |             if libc::bind(sock, &sockaddr as *const _ as _, (socklen as u32).try_into().unwrap()) < 0 {
    |                                                             +              +++++++++++++++++++++

error[E0308]: mismatched types
  --> src\conn.rs:40:32
   |
40 |             Ok(TcpConnection { sock, fd })
   |                                ^^^^ expected `i32`, found `usize`
   |
help: you can convert a `usize` to an `i32` and panic if the converted value doesn't fit
   |
40 |             Ok(TcpConnection { sock: sock.try_into().unwrap(), fd })
   |                                +++++     ++++++++++++++++++++

error[E0308]: mismatched types
  --> src\conn.rs:40:38
   |
40 |             Ok(TcpConnection { sock, fd })
   |                                      ^^ expected `i32`, found `usize`
   |
help: you can convert a `usize` to an `i32` and panic if the converted value doesn't fit
   |
40 |             Ok(TcpConnection { sock, fd: fd.try_into().unwrap() })
   |                                      +++   ++++++++++++++++++++

error[E0308]: mismatched types
   --> src\print_str.rs:3:41
    |
3   |         libc::write(1, s.as_ptr() as _, s.len());
    |         -----------                     ^^^^^^^ expected `u32`, found `usize`
    |         |
    |         arguments to this function are incorrect
    |
note: function defined here
   --> C:\Users\Sean\.cargo\registry\src\github.com-1ecc6299db9ec823\libc-0.2.140\src\windows\mod.rs:502:12
    |
502 |     pub fn write(fd: ::c_int, buf: *const ::c_void, count: ::c_uint) -> ::c_int;
    |            ^^^^^
help: you can convert a `usize` to a `u32` and panic if the converted value doesn't fit
    |
3   |         libc::write(1, s.as_ptr() as _, s.len().try_into().unwrap());
    |                                                ++++++++++++++++++++

Some errors have detailed explanations: E0308, E0412, E0422, E0425, E0600.
For more information about an error, try `rustc --explain E0308`.
error: could not compile `gdbstub-nostd` due to 13 previous errors
[10:51:02 am] E:/Code/Xous/Core/gdbstub/example_no_std>
daniel5151 commented 1 year ago

Ah, hmm, indeed. I'm not particularly surprised. I typically stick to Linux / WSL when working on projects in my free time, so I've never actually tried building example_no_std on windows.

If you (or anyone else reading this issue in the future!) would like to fix up this code to work correctly on windows (and, to be perfectly frank - work correctly at all, since the socket code is a bit bogus as-is), I'd be happy to accept a PR fixing it.

In the meantime, I'll leave this issue open, and slap a "help wanted" on the issue.