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

Fix wrong _IOC_TYPE on musl #51

Closed
wants to merge 1 commit into from

Conversation

jirutka
Copy link

@jirutka jirutka commented Feb 17, 2022

When compiling on Alpine Linux x86_64 with Alpine's rust and target x86_64-alpine-linux-musl:

error[E0308]: mismatched types
  --> libv4l-rs-917e1f4ffd90b94a/d7ac716/src/v4l2/api.rs:23:24
   |
23 |         v4l2_ioctl(fd, request, argp)
   |                        ^^^^^^^ expected `u64`, found `i64`

Ref maximbaz/wluma#43

When compiling on Alpine Linux x86_64 with Alpine's rust and target
x86_64-alpine-linux-musl:

    error[E0308]: mismatched types
      --> libv4l-rs-917e1f4ffd90b94a/d7ac716/src/v4l2/api.rs:23:24
       |
    23 |         v4l2_ioctl(fd, request, argp)
       |                        ^^^^^^^ expected `u64`, found `i64`
@raymanfx
Copy link
Owner

Hmm, I'm not sure this is the correct thing to do, since the conditionals were introduced as part of armv7 musl support here: 874cf29. So it looks like we need to distinguish between ... x86{_64} and ARM as well? Or maybe only 32 bit musl wants signed integers?

@jirutka
Copy link
Author

jirutka commented Feb 17, 2022

That’s interesting because it currently fails to build even on armv7 musl…

error[E0308]: mismatched types
  --> target/patch/d7ac716/src/v4l2/api.rs:33:26
   |
33 |         v4l2_mmap(start, length as u64, prot, flags, fd, offset)
   |                          ^^^^^^^^^^^^^ expected `u32`, found `u64`
   |
help: you can convert a `u64` to a `u32` and panic if the converted value doesn't fit
   |
33 |         v4l2_mmap(start, (length as u64).try_into().unwrap(), prot, flags, fd, offset)
   |                          +             +++++++++++++++++++++
error[E0308]: mismatched types
  --> target/patch/d7ac716/src/v4l2/api.rs:36:28
   |
36 |         v4l2_munmap(start, length as u64)
   |                            ^^^^^^^^^^^^^ expected `u32`, found `u64`
   |
help: you can convert a `u64` to a `u32` and panic if the converted value doesn't fit
   |
36 |         v4l2_munmap(start, (length as u64).try_into().unwrap())
   |                            +             +++++++++++++++++++++
   Compiling mccs-db v0.1.2

I don’t have experience with writing cross-platform bindings in Rust, so I don’t know what’s the correct approach here, except setting up CI to continuously test against all supported targets.

@raymanfx
Copy link
Owner

I'll do some cross-compiling experiments by myself and get back to you.

@raymanfx
Copy link
Owner

Okay, so these are my findings:

  • You are using the v4l-sys feature which links against libv4l dynamically and thus uses a different code path than what was used by the other musl armv7 user: Fix compilation error against musl #14
  • Compiling against x86_64-alpine-linux-musl is fine with the default features (v4l2-sys), but not when linking against libv4l (no-default-features, v4l-sys).
  • The same goes for the armv7-unknown-linux-musleabihf target.

Other interesting bits:

  • Linux ioctl(..) looks like this: int ioctl(int fd, unsigned long request, ...) (doc)
  • musl ioctl(..) looks like this: int ioctl (int, int, ...) (src)
  • libv4l defines its own v4l2_ioctl wrapper as: int v4l2_ioctl (int fd, unsigned long int request, ...) (src)

Yikes.

I pushed a commit to the next branch to fix this: 0f3f0df. Could you please test that with your setup and let me know what happens?

@raymanfx raymanfx closed this Aug 8, 2024
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.

2 participants