zeenix / gps-share

Utility to share your GPS device on local network
GNU General Public License v2.0
69 stars 9 forks source link

can't reproduce release build of 0.2.0 (EDIT: on 32-bit arm) #13

Closed Josua-SR closed 4 years ago

Josua-SR commented 4 years ago

Building gps-share fails with:

All builds were performed using debian based rust toolchain available on dockerhub, namely

Sample Dockerfile:

ARG GPSSHARE_RELEASE=0.2.0

FROM alpine:latest AS fetch
ARG GPSSHARE_RELEASE
WORKDIR /work
RUN apk add curl
RUN curl -L https://github.com/zeenix/gps-share/archive/${GPSSHARE_RELEASE}.tar.gz | tar -xz

FROM rust:1.42.0-buster AS build
ARG GPSSHARE_RELEASE
WORKDIR /work
COPY --from=fetch /work/gps-share-${GPSSHARE_RELEASE} /work/source
RUN apt-get update && apt-get install -y libdbus-1-dev libudev-dev
WORKDIR /work/source
RUN cargo build --release

So in chronological order:

1.28.0

Step 13/14 : RUN cargo build --release
 ---> Running in a7ab44d7fcd9
    Updating registry `https://github.com/rust-lang/crates.io-index`
 Downloading dbus v0.5.4                                                                                                             
 Downloading dbus-macros v0.2.3                                                                                                      
 Downloading chan v0.1.23                                                                                                            
 Downloading serial v0.3.4                                                                                                           
 Downloading libc v0.2.68                                                                                                            
 Downloading chan-signal v0.2.0                                                                                                      
 Downloading clap v2.33.0                                                                                                            
 Downloading libudev v0.2.0                                                                                                          
 Downloading libdbus-sys v0.1.5                                                                                                      
 Downloading pkg-config v0.3.17                                                                                                      
 Downloading rand v0.3.23                                                                                                            
 Downloading rand v0.4.6                                                                                                             
 Downloading ioctl-rs v0.1.6                                                                                                         
 Downloading termios v0.2.2                                                                                                          
 Downloading lazy_static v0.2.11                                                                                                     
 Downloading bit-set v0.4.0                                                                                                          
 Downloading bit-vec v0.4.4                                                                                                          
 Downloading textwrap v0.11.0                                                                                                        
 Downloading ansi_term v0.11.0                                                                                                       
 Downloading unicode-width v0.1.7                                                                                                    
error: unable to get packages from source                                                                                            

Caused by:                                                                                                                           
  failed to parse manifest at `/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/unicode-width-0.1.7/Cargo.toml`             

Caused by:                                                                                                                           
  feature `rename-dependency` is required                                                                                            

this Cargo does not support nightly features, but if you                                                                             
switch to nightly channel you can add                                                                                                
`cargo-features = ["rename-dependency"]` to enable this feature

^^ Well, apparently this cargo (1.28.0) is too old

1.31.1

Step 13/14 : RUN cargo build --release
 ---> Running in a7ca4551e3db
    Updating crates.io index
 Downloading crates ...                                                                                                              
  Downloaded libudev v0.2.0                                                                                                          
  Downloaded libc v0.2.68                                                                                                            
  Downloaded clap v2.33.0                                                                                                            
  Downloaded chan-signal v0.2.0                                                                                                      
  Downloaded dbus v0.5.4                                                                                                             
  Downloaded serial v0.3.4                                                                                                           
  Downloaded chan v0.1.23                                                                                                            
  Downloaded lazy_static v0.2.11                                                                                                     
  Downloaded ansi_term v0.11.0                                                                                                       
  Downloaded strsim v0.8.0                                                                                                           
  Downloaded bit-set v0.4.0                                                                                                          
  Downloaded textwrap v0.11.0                                                                                                        
  Downloaded vec_map v0.8.1                                                                                                          
  Downloaded unicode-width v0.1.7                                                                                                    
  Downloaded atty v0.2.14                                                                                                            
  Downloaded bitflags v1.2.1                                                                                                         
  Downloaded dbus-macros v0.2.3
  Downloaded libdbus-sys v0.1.5
  Downloaded ioctl-rs v0.1.6
  Downloaded libudev-sys v0.1.4
  Downloaded rand v0.3.23
  Downloaded bit-vec v0.4.4
  Downloaded pkg-config v0.3.17
  Downloaded rand v0.4.6
  Downloaded termios v0.2.2
   Compiling libc v0.2.68
   Compiling pkg-config v0.3.17
   Compiling bitflags v1.2.1
   Compiling unicode-width v0.1.7
   Compiling bit-vec v0.4.4
   Compiling vec_map v0.8.1
   Compiling strsim v0.8.0
   Compiling lazy_static v0.2.11
   Compiling ansi_term v0.11.0
   Compiling textwrap v0.11.0
   Compiling bit-set v0.4.0
   Compiling libdbus-sys v0.1.5
   Compiling libudev-sys v0.1.4
   Compiling rand v0.4.6
   Compiling ioctl-rs v0.1.6
   Compiling termios v0.2.2
   Compiling atty v0.2.14
   Compiling clap v2.33.0
   Compiling serial v0.3.4
   Compiling dbus v0.5.4
   Compiling libudev v0.2.0
   Compiling rand v0.3.23
   Compiling chan v0.1.23
   Compiling chan-signal v0.2.0
   Compiling dbus-macros v0.2.3
   Compiling gps-share v0.2.0 (/work/source)
error[E0308]: mismatched types
   --> src/config.rs:101:17
    |
101 |                 host_ptr,
    |                 ^^^^^^^^ expected u8, found i8
    |
    = note: expected type `*mut u8`
               found type `*mut i8`

error[E0308]: mismatched types
   --> src/config.rs:107:38
    |
107 |             host = CString::from_raw(host_ptr);
    |                                      ^^^^^^^^ expected u8, found i8
    |
    = note: expected type `*mut u8`
               found type `*mut i8`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0308`.
error: Could not compile `gps-share`.

To learn more, run the command again with --verbose

^^ Hmph.

1.42.0

Step 13/14 : RUN cargo build --release
 ---> Running in 37e5d33bc8ff
    Updating crates.io index
 Downloading crates ...                                                                                                              
  Downloaded chan v0.1.23                                                                                                            
  Downloaded dbus v0.5.4                                                                                                             
  Downloaded dbus-macros v0.2.3                                                                                                      
  Downloaded chan-signal v0.2.0                                                                                                      
  Downloaded clap v2.33.0                                                                                                            
  Downloaded serial v0.3.4                                                                                                           
  Downloaded libudev v0.2.0                                                                                                          
  Downloaded libc v0.2.68                                                                                                            
  Downloaded ioctl-rs v0.1.6                                                                                                         
  Downloaded rand v0.3.23                                                                                                            
  Downloaded atty v0.2.14                                                                                                            
  Downloaded libudev-sys v0.1.4                                                                                                      
  Downloaded libdbus-sys v0.1.5                                                                                                      
  Downloaded lazy_static v0.2.11                                                                                                     
  Downloaded bit-set v0.4.0                                                                                                          
  Downloaded bitflags v1.2.1                                                                                                         
  Downloaded unicode-width v0.1.7                                                                                                    
  Downloaded vec_map v0.8.1                                                                                                          
  Downloaded textwrap v0.11.0                                                                                                        
  Downloaded termios v0.2.2                                                                                                          
  Downloaded strsim v0.8.0                                                                                                           
  Downloaded ansi_term v0.11.0                                                                                                       
  Downloaded rand v0.4.6                                                                                                             
  Downloaded bit-vec v0.4.4                                                                                                          
  Downloaded pkg-config v0.3.17                                                                                                      
   Compiling libc v0.2.68                                                                                                            
   Compiling pkg-config v0.3.17                                                                                                      
   Compiling bitflags v1.2.1                                                                                                         
   Compiling bit-vec v0.4.4                                                                                                          
   Compiling unicode-width v0.1.7                                                                                                    
   Compiling strsim v0.8.0                                                                                                           
   Compiling ansi_term v0.11.0                                                                                                       
   Compiling vec_map v0.8.1                                                                                                          
   Compiling lazy_static v0.2.11                                                                                                     
   Compiling textwrap v0.11.0                                                                                                        
   Compiling bit-set v0.4.0                                                                                                          
   Compiling libdbus-sys v0.1.5                                                                                                      
   Compiling libudev-sys v0.1.4                                                                                                      
   Compiling rand v0.4.6                                                                                                             
   Compiling ioctl-rs v0.1.6                                                                                                         
   Compiling termios v0.2.2                                                                                                          
   Compiling atty v0.2.14                                                                                                            
   Compiling clap v2.33.0                                                                                                            
   Compiling serial v0.3.4                                                                                                           
   Compiling dbus v0.5.4                                                                                                             
   Compiling libudev v0.2.0                                                                                                          
   Compiling rand v0.3.23                                                                                                            
   Compiling chan v0.1.23                                                                                                            
   Compiling chan-signal v0.2.0                                                                                                      
   Compiling dbus-macros v0.2.3                                                                                                      
   Compiling gps-share v0.2.0 (/work/source)                                                                                         
warning: use of deprecated item 'try': use the `?` operator instead                                                                  
  --> src/avahi.rs:27:1                                                                                                              
   |                                                                                                                                 
27 | / dbus_interface!("org.freedesktop.Avahi.Server", interface Server {                                                            
28 | |     fn entry_group_new() -> dbus::Path;                                                                                       
29 | |     fn get_network_interface_index_by_name(name: &str) -> i32;                                                                
30 | | });                                                                                                                           
   | |___^                                                                                                                           
   |                                                                                                                                 
   = note: `#[warn(deprecated)]` on by default                                                                                       
   = note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)                                                                                                                        

warning: use of deprecated item 'try': use the `?` operator instead                                                                  
  --> src/avahi.rs:27:1                                                                                                              
   |                                                                                                                                 
27 | / dbus_interface!("org.freedesktop.Avahi.Server", interface Server {                                                            
28 | |     fn entry_group_new() -> dbus::Path;                                                                                       
29 | |     fn get_network_interface_index_by_name(name: &str) -> i32;                                                                
30 | | });                                                                                                                           
   | |___^                                                                                                                           
   |                                                                                                                                 
   = note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)                                                                                                                        

warning: trait objects without an explicit `dyn` are deprecated                                                                      
  --> src/rs232.rs:49:44                                                                                                             
   |                                                                                                                                 
49 |         RS232::configure(&mut port as &mut serial::SerialPort, config)?;                                                        
   |                                            ^^^^^^^^^^^^^^^^^^ help: use `dyn`: `dyn serial::SerialPort`                         
   |                                                                                                                                 
   = note: `#[warn(bare_trait_objects)]` on by default                                                                               

warning: trait objects without an explicit `dyn` are deprecated                                                                      
  --> src/rs232.rs:54:29                                                                                                             
   |                                                                                                                                 
54 |     fn configure(port: &mut serial::SerialPort, config: &Config) -> serial::Result<()> {                                        
   |                             ^^^^^^^^^^^^^^^^^^ help: use `dyn`: `dyn serial::SerialPort`                                        

warning: trait objects without an explicit `dyn` are deprecated
  --> src/server.rs:35:20
   |
35 |     gps: Arc<Mutex<gps::GPS>>,
   |                    ^^^^^^^^ help: use `dyn`: `dyn gps::GPS`

warning: trait objects without an explicit `dyn` are deprecated
  --> src/client_handler.rs:30:20
   |
30 |     gps: Arc<Mutex<gps::GPS>>,
   |                    ^^^^^^^^ help: use `dyn`: `dyn gps::GPS`

warning: trait objects without an explicit `dyn` are deprecated
  --> src/client_handler.rs:35:31
   |
35 |     pub fn new(gps: Arc<Mutex<gps::GPS>>, streams: Arc<Mutex<Vec<TcpStream>>>) -> Self {
   |                               ^^^^^^^^ help: use `dyn`: `dyn gps::GPS`

warning: trait objects without an explicit `dyn` are deprecated
  --> src/main.rs:90:39
   |
90 | fn get_gps(config: Rc<Config>) -> Box<GPS> {
   |                                       ^^^ help: use `dyn`: `dyn GPS`

warning: trait objects without an explicit `dyn` are deprecated
   --> src/main.rs:112:35
    |
112 | fn run_server_handle_err(gps: Box<GPS>, config: Rc<Config>) {
    |                                   ^^^ help: use `dyn`: `dyn GPS`

warning: trait objects without an explicit `dyn` are deprecated
   --> src/main.rs:120:24
    |
120 | fn run_server(gps: Box<GPS>, config: Rc<Config>) -> ::std::io::Result<()> {
    |                        ^^^ help: use `dyn`: `dyn GPS`

error[E0308]: mismatched types
   --> src/config.rs:101:17
    |
101 |                 host_ptr,
    |                 ^^^^^^^^ expected `u8`, found `i8`
    |
    = note: expected raw pointer `*mut u8`
               found raw pointer `*mut i8`

error[E0308]: mismatched types
   --> src/config.rs:107:38
    |
107 |             host = CString::from_raw(host_ptr);
    |                                      ^^^^^^^^ expected `u8`, found `i8`
    |
    = note: expected raw pointer `*mut u8`
               found raw pointer `*mut i8`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0308`.
error: could not compile `gps-share`.

To learn more, run the command again with --verbose.

Now that's a lot of noise, but the error is same as with 1.31.1 .... any ideas?

zeenix commented 4 years ago

Thanks for reporting with all the detail! From the first look it seems I used some unstable API (i wrote this code years ago) and now it changed. Should be trivial to fix, as you can see from the error. Care to send a PR? If not, I'll look into it soon.

Josua-SR commented 4 years ago

I have attempted a fix that purely follows the error message:

diff --git a/src/config.rs b/src/config.rs
index f04af20..993508e 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -94,7 +94,7 @@ impl Config {
                 libc::AF_INET6 => size = mem::size_of::<libc::sockaddr_in6>() as u32,
                 _ => continue,
             };
-            let host_ptr = host.into_raw() as *mut i8;
+            let host_ptr = host.into_raw() as *mut u8;
             let ret = libc::getnameinfo(
                 addr.ifa_addr,
                 size,

This is enough for the build to succeed with 0.42.0. No runtime testing done so far though, and I don't know rust, so .... ..... ....... you shpould be the judge if this is the right fix

zeenix commented 4 years ago

This is enough for the build to succeed with 0.42.0. No runtime testing done so far though, and I don't know rust, so .... ..... ....... you shpould be the judge if this is the right fix

Awesome. For testing, just see if cargo test succeeds.

Josua-SR commented 4 years ago

This is enough for the build to succeed with 0.42.0. No runtime testing done so far though, and I don't know rust, so .... ..... ....... you shpould be the judge if this is the right fix

Awesome. For testing, just see if cargo test succeeds.

Thanks for the quick replies! cargo test does indeed succeed. The only thing that surprised me is that it triggered a rebuild after I had already done cargo build --release in a previous step.

     Running target/debug/deps/stdin_gps-9c1b383e1c89bdd0

running 3 tests
test test_stdin_gps_with_port ... ok
test test_stdin_gps_with_port_iface ... ok
test test_stdin_gps_defaults ... ok

test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Josua-SR commented 4 years ago

BUT BEWARE ... I was building on armv7-a!

Turns out that the signage is different for x86_64 ....

error[E0308]: mismatched types
   --> src/config.rs:101:17
    |
101 |                 host_ptr,
    |                 ^^^^^^^^ expected `i8`, found `u8`
    |
    = note: expected raw pointer `*mut i8`
               found raw pointer `*mut u8`
zeenix commented 4 years ago

BUT BEWARE ... I was building on armv7-a!

Ah, that explains it then. :) You can check for architecture and use the correct signage. If you make it a PR, the CI will run the tests on x86-64 so you won't need to worry about the diff.

zeenix commented 4 years ago

also since I don't have a armv7 build machine around, it'd be awesome if you could submit a PR.

Josua-SR commented 4 years ago

Well, I am not happy. Here is some reasearch I did:

The first error refers to argument 3 of the C getnameinfo function.

Here is the C declaration of that function on x86_64, Debian 10, GNU libc 2.28 (matching dockerhub rust:1.42.0-buster):

/* Translate a socket address to a location and service name.

   This function is a possible cancellation point and therefore not
   marked with __THROW.  */
extern int getnameinfo (const struct sockaddr *__restrict __sa,
            socklen_t __salen, char *__restrict __host,
            socklen_t __hostlen, char *__restrict __serv,
            socklen_t __servlen, int __flags);

Here is the C declaration of that function on armv7-a, Debian 10, GNU libc 2.28 (matching dockerhub arm32v7/rust:1.42.0-buster):

/* Translate a socket address to a location and service name.

   This function is a possible cancellation point and therefore not
   marked with __THROW.  */
extern int getnameinfo (const struct sockaddr *__restrict __sa,
            socklen_t __salen, char *__restrict __host,
            socklen_t __hostlen, char *__restrict __serv,
            socklen_t __servlen, int __flags);

On both architectures the GNU libc defines the third argument as a pointer to signed char. So imo the correct version is signed, always ... :/

Josua-SR commented 4 years ago

@zeenix Can you use the c_char type from the rust libc bindings?

See https://github.com/rust-lang/libc/blob/master/src/unix/linux_like/linux/mod.rs#L2862 - it is used for declaration of the function to rust. I believe that would be the best solution. Why the rust libc bindings have a different signage where gnu does not is beyond me though :(