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

fails to compile (cargo install) on Alpine Linux (utmpx.h declarations) #100

Closed
jtmoon79 opened this issue Apr 16, 2023 · 3 comments
Closed
Labels
bug Something isn't working P1 important

Comments

@jtmoon79
Copy link
Owner

jtmoon79 commented Apr 16, 2023

Summary

cargo install super_speedy_syslog_searcher fails on Alpine Linux 3.17.

Current behavior

root@alpine:~
$ cargo install super_speedy_syslog_searcher
    Updating crates.io index
  Installing super_speedy_syslog_searcher v0.5.59
   Compiling libc v0.2.141
...
   Compiling super_speedy_syslog_searcher v0.5.59
error[E0432]: unresolved import `uapi::c::__timeval`
   --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/super_speedy_syslog_searcher-0.5.59/src/data/utmpx.rs:113:13
    |
113 |             __timeval,
    |             ^^^^^^^^^
    |             |
    |             no `__timeval` in `c`
    |             help: a similar name exists in the module: `timeval`

error[E0277]: the trait bound `i32: From<i64>` is not satisfied
   --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/super_speedy_syslog_searcher-0.5.59/src/data/utmpx.rs:426:54
    |
426 |         let tv_sec: tv_sec_type = entry.ut_tv.tv_sec.into();
    |                                                      ^^^^ the trait `From<i64>` is not implemented for `i32`
    |
    = help: the following other types implement trait `From<T>`:
              <i32 as From<NonZeroI32>>
              <i32 as From<bool>>
              <i32 as From<i16>>
              <i32 as From<i8>>
              <i32 as From<u16>>
              <i32 as From<u8>>
    = note: required for `i64` to implement `Into<i32>`

error[E0277]: the trait bound `i32: From<i64>` is not satisfied
   --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/super_speedy_syslog_searcher-0.5.59/src/data/utmpx.rs:427:57
    |
427 |         let tv_usec: tv_usec_type = entry.ut_tv.tv_usec.into();
    |                                                         ^^^^ the trait `From<i64>` is not implemented for `i32`
    |
    = help: the following other types implement trait `From<T>`:
              <i32 as From<NonZeroI32>>
              <i32 as From<bool>>
              <i32 as From<i16>>
              <i32 as From<i8>>
              <i32 as From<u16>>
              <i32 as From<u8>>
    = note: required for `i64` to implement `Into<i32>`

Some errors have detailed explanations: E0277, E0432.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `super_speedy_syslog_searcher` due to 3 previous errors
error: failed to compile `super_speedy_syslog_searcher v0.5.59`, intermediate artifacts can be found at `/tmp/cargo-installWPo68r`

Reviewing the resident utmpx.h,

$ cat /usr/include/utmpx.h
#ifndef _UTMPX_H
#define _UTMPX_H

#ifdef __cplusplus
extern "C" {
#endif

#include <features.h>

#define __NEED_pid_t
#define __NEED_time_t
#define __NEED_suseconds_t
#define __NEED_struct_timeval

#include <bits/alltypes.h>

struct utmpx {
        short ut_type;
        short __ut_pad1;
        pid_t ut_pid;
        char ut_line[32];
        char ut_id[4];
        char ut_user[32];
        char ut_host[256];
        struct {
                short __e_termination;
                short __e_exit;
        } ut_exit;
#if __BYTE_ORDER == 1234
        int ut_session, __ut_pad2;
#else
        int __ut_pad2, ut_session;
#endif
        struct timeval ut_tv;
        unsigned ut_addr_v6[4];
        char __unused[20];
};

//...

Indeed, there is a utmpx.ut_tv but no utmpx.__timeval.

Suggested behavior

It should build and install.

Environment:

  • OS: Alpine 3.17
  • Platform: amd64
  • s4 version: 0.5.59
  • cargo version: 1.68.0
@jtmoon79
Copy link
Owner Author

jtmoon79 commented Apr 23, 2023

tl;dr A good way to allow Alpine builds is using #[cfg(accessible(..))], e.g.

// if not defined __timeval then define it
#[cfg(not(accessible(::uapi::c::__timeval)))]
#[doc(hidden)]
#[derive(Clone, Copy)]
#[repr(C)]
pub struct __timeval {
    pub tv_sec: i32,
    pub tv_usec: i32,
}

These uapi imports have been handled by conditional compilation based on target_os. See https://github.com/jtmoon79/super-speedy-syslog-searcher/blob/0.5.59/src/data/utmpx.rs#L33-L117

But there is currently no way to further distinguish at build-time that this is Alpine Linux, e.g. there is no #[cfg(target_os_flavor = "Alpine")].

The ideal mechanism is cfg(accessible). This could be used to entirely replace conditional compilation based on target_os and would be more reliable.

Currently, #[cfg(accessible(..))] is still unimplemented rust-lang/rust#64797

jtmoon79 added a commit that referenced this issue Apr 23, 2023
@jtmoon79
Copy link
Owner Author

Version 0.6.62 fails less

   Compiling super_speedy_syslog_searcher v0.6.62
error[E0432]: unresolved import `uapi::c::__timeval`
   --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/super_speedy_syslog_searcher-0.6.62/src/data/utmpx.rs:118:13
    |
118 |             __timeval,
    |             ^^^^^^^^^
    |             |
    |             no `__timeval` in `c`
    |             help: a similar name exists in the module: `timeval`

@jtmoon79 jtmoon79 added bug Something isn't working P1 important labels May 10, 2023
@jtmoon79 jtmoon79 changed the title fails to build on Apline Linux fails to build on Alpine Linux Aug 13, 2023
@jtmoon79 jtmoon79 changed the title fails to build on Alpine Linux fails to build on Alpine Linux (utmpx.h declarations) Nov 3, 2023
@jtmoon79 jtmoon79 changed the title fails to build on Alpine Linux (utmpx.h declarations) fails to compile (cargo install) on Alpine Linux (utmpx.h declarations) Nov 3, 2023
jtmoon79 added a commit that referenced this issue Nov 27, 2023
Remove crate `uapi`, it causes numerous problems as outlined
in the linked issues. Use hardcoded utmpx structures.

Currently only handles one hardcoded structure, Linux Gnu utmpx struct.
This is copied from uapi crate code. So this commit is effectively NFC.

Issue #171
Issue #100
Issue #121
Issue #109
Issue #217
Issue #108
jtmoon79 added a commit that referenced this issue Mar 15, 2024
Refactor `utmpx` for Linux into cross-platform "FixedStruct"
for fixed-size record structs. This includes acct, acct_v3,
lastlog, lastlogx, utmp, and utmpx. This removes crate `uapi`.

Refactor FileType to allow sub-variants.

Add scraped logs from varying platforms.

Update compare-current-and-expected with newly scraped logs.

Add utility utmp-offsets for generating real offsets of fixed-size
structs on any system.

Issue #171
Issue #100
Issue #121
Issue #109
Issue #217
jtmoon79 added a commit that referenced this issue Mar 16, 2024
Refactor `utmpx` for Linux into cross-platform "FixedStruct"
for fixed-size record structs. This includes acct, acct_v3,
lastlog, lastlogx, utmp, and utmpx. This removes crate `uapi`.

Refactor FileType to allow sub-variants.

Add scraped logs from varying platforms.

Update compare-current-and-expected with newly scraped logs.

Add utility utmp-offsets for generating real offsets of fixed-size
structs on any system.

Issue #171
Issue #100
Issue #121
Issue #109
Issue #217
jtmoon79 added a commit that referenced this issue Mar 16, 2024
Refactor `utmpx` for Linux into cross-platform "FixedStruct"
for fixed-size record structs. This includes acct, acct_v3,
lastlog, lastlogx, utmp, and utmpx. This removes crate `uapi`.

Refactor FileType to allow sub-variants.

Add scraped logs from varying platforms.

Update compare-current-and-expected with newly scraped logs.

Add utility utmp-offsets for generating real offsets of fixed-size
structs on any system.

Issue #171
Issue #100
Issue #121
Issue #109
Issue #217
jtmoon79 added a commit that referenced this issue Mar 17, 2024
Refactor `utmpx` for Linux into cross-platform "FixedStruct"
for fixed-size record structs. This includes acct, acct_v3,
lastlog, lastlogx, utmp, and utmpx. This removes crate `uapi`.

Refactor FileType to allow sub-variants.

Add scraped logs from varying platforms.

Update compare-current-and-expected with newly scraped logs.

Add utility utmp-offsets for generating real offsets of fixed-size
structs on any system.

Issue #171
Issue #100
Issue #121
Issue #109
Issue #217
jtmoon79 added a commit that referenced this issue Mar 17, 2024
Remove crate `uapi`, it causes numerous problems as outlined
in the linked issues. Use hardcoded utmpx structures.

Currently only handles one hardcoded structure, Linux Gnu utmpx struct.
This is copied from uapi crate code. So this commit is effectively NFC.

Issue #171
Issue #100
Issue #121
Issue #109
Issue #217
Issue #108
jtmoon79 added a commit that referenced this issue Mar 17, 2024
Refactor `utmpx` for Linux into cross-platform "FixedStruct"
for fixed-size record structs. This includes acct, acct_v3,
lastlog, lastlogx, utmp, and utmpx. This removes crate `uapi`.

Refactor FileType to allow sub-variants.

Add scraped logs from varying platforms.

Update compare-current-and-expected with newly scraped logs.

Add utility utmp-offsets for generating real offsets of fixed-size
structs on any system.

Issue #171
Issue #100
Issue #121
Issue #109
Issue #217
@jtmoon79
Copy link
Owner Author

Verified this built on Alpine 3.17 x64.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P1 important
Projects
None yet
Development

No branches or pull requests

1 participant