Skip to content

Fix compile errors when targeting musl#590

Merged
glommer merged 5 commits intoDataDog:masterfrom
mrakh:musl-fix
Feb 28, 2023
Merged

Fix compile errors when targeting musl#590
glommer merged 5 commits intoDataDog:masterfrom
mrakh:musl-fix

Conversation

@mrakh
Copy link
Copy Markdown
Contributor

@mrakh mrakh commented Feb 27, 2023

See #589. This PR contains a few fixes that address some issues that pop up when targeting a musl-based system:

  • The libc::msghdr struct's reserved/padding fields are marked as private, so the compiler throws an error when trying to initialize an instance of libc::msghdr with struct literal syntax. This PR resolves the issue by using std::mem::zeroed() instead.
  • The libc crate does not contain a struct definition for statx. This PR resolves the issue by defining the statx struct directly in glommio.
  • TMPFS_MAGIC is not defined in the nix crate. This PR resolves the issue by qualifying the constant with libc, which does define it.
  • libc::pthread_t is a wrapper around *mut c_void, which is not Send and therefore cannot be moved into a thread. This PR resolves the issue by defining and using a wrapper that explicitly implements Send.

@glommer
Copy link
Copy Markdown
Collaborator

glommer commented Feb 27, 2023

Thanks!

First of all, on the direction, I have no problems with that, and supporting musl-based systems is a good thing.
Keep in mind CI failed. Some of that is due to a toolset upgrade that made clippy unhappy (I can fix those and let you know), but some seem to be fmt related on the added code.

(Keep in mind we format with cargo +nightly fmt all)

Reading the PR in details soon!

@glommer
Copy link
Copy Markdown
Collaborator

glommer commented Feb 27, 2023

@mrakh I have no further comments other than the CI failures.
I pushed an update that should fix the clippy issues, and once CI is green on this PR I'm ready to approve.

Thanks!

When targeting musl, libc::pthread_t aliases to *mut c_void, which is
not Send, and therefore causes compilation failures. pthread_t is meant
to be an opaque handle, so we can safely just wrap it in a newtype that
explicitly implements Send.
@mrakh
Copy link
Copy Markdown
Contributor Author

mrakh commented Feb 28, 2023

Thanks for the feedback! I've reformatted with the nightly version of rustfmt, looks like the CI is happy now.

@apt-install-coffee
Copy link
Copy Markdown

I seem to be currently experiencing the same (or similar) issue addressed by this MR in aecd15e
while compiling version 0.9.0,

error[E0277]: `*mut c_void` cannot be sent between threads safely
   --> /home/jordan/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/glommio-0.9.0/src/executor/stall.rs:168:28
    |
168 |           std::thread::spawn(enclose::enclose! { (terminated, timer) move || {
    |  _________------------------_^
    | |         |
    | |         required by a bound introduced by this call
169 | |             while timer.wait().is_ok() {
170 | |                 if terminated.load(Ordering::Relaxed) {
171 | |                     return
...   |
175 | |         }})
    | |__________^ `*mut c_void` cannot be sent between threads safely
    |
   ::: /home/jordan/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/enclose-1.2.0/src/lib.rs:357:3
    |
357 |           move || $($b)*
    |           ----
    |           |
    |           within this `{closure@/home/jordan/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/enclose-1.2.0/src/lib.rs:357:3: 357:7}`
    |           this tail expression is of type `{closure@lib.rs:357:3}`
    |
    = help: within `{closure@/home/jordan/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/enclose-1.2.0/src/lib.rs:357:3: 357:7}`, the trait `Send` is not implemented for `*mut c_void`
note: required because it's used within this closure
   --> /home/jordan/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/enclose-1.2.0/src/lib.rs:357:3
    |
349 |   macro_rules! enclose {
    |   -------------------- in this expansion of `enclose::enclose!`
...
357 |           move || $($b)*
    |           ^^^^
    |
   ::: /home/jordan/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/glommio-0.9.0/src/executor/stall.rs:168:28
    |
168 |           std::thread::spawn(enclose::enclose! { (terminated, timer) move || {
    |  ____________________________-
169 | |             while timer.wait().is_ok() {
170 | |                 if terminated.load(Ordering::Relaxed) {
171 | |                     return
...   |
175 | |         }})
    | |__________- in this macro invocation
note: required by a bound in `spawn`
   --> /nix/store/p7cnrlmzp7ihm5vmxgacg3nyzb8niyy6-rust-default-1.87.0-nightly-2025-03-28/lib/rustlib/src/rust/library/std/src/thread/mod.rs:726:8
    |
723 | pub fn spawn<F, T>(f: F) -> JoinHandle<T>
    |        ----- required by a bound in this function
...
726 |     F: Send + 'static,
    |        ^^^^ required by this bound in `spawn`

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants