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

Build fails on Android/Termux #155

Closed
LHLaurini opened this issue Sep 4, 2023 · 6 comments
Closed

Build fails on Android/Termux #155

LHLaurini opened this issue Sep 4, 2023 · 6 comments

Comments

@LHLaurini
Copy link

LHLaurini commented Sep 4, 2023

Build fails on Termux with:

~/http $ cargo build
warning: file `/data/data/com.termux/files/home/http/src/main.rs` found to be present in multiple build targets:
  * `bin` target `http`
  * `bin` target `httplz`
   Compiling https v1.13.2 (/data/data/com.termux/files/home/http)
error[E0308]: mismatched types
    --> src/util/os/non_windows_non_macos.rs:39:47
     |
39   |             let ok = unsafe { ioctl(dev_file, BLKGETSIZE, &mut block_count as *mut c_ulong) } == 0;
     |                               -----           ^^^^^^^^^^ expected `i32`, found `u64`
     |                               |
     |                               arguments to this function are incorrect
     |
note: function defined here
    --> /data/data/com.termux/files/home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libc-0.2.147/src/unix/linux_like/android/mod.rs:3172:12
     |
3172 |     pub fn ioctl(fd: ::c_int, request: ::c_int, ...) -> ::c_int;
     |            ^^^^^
help: you can convert a `u64` to an `i32` and panic if the converted value doesn't fit
     |
39   |             let ok = unsafe { ioctl(dev_file, BLKGETSIZE.try_into().unwrap(), &mut block_count as *mut c_ulong) } == 0;
     |                                                         ++++++++++++++++++++

For more information about this error, try `rustc --explain E0308`.
error: could not compile `https` (bin "httplz") due to previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `https` (bin "http") due to previous error
~/http $

It seems the signature is different for Linux and Android. While Linux uses ::c_ulong (u64), Android uses ::c_int (i32).

The suggested fix works. I'll gladly propose a pull request if that is valid.

@nabijaczleweli
Copy link
Collaborator

Hm, apparently

musl$ git grep ioctl\(int
include/stropts.h:int ioctl(int, int, ...);
src/misc/ioctl.c:int ioctl(int fd, int req, ...)

but

glibc$ git grep ioctl\ \(int
hurd/hurdioctl.c:fioctl (int fd,
include/sys/ioctl.h:extern int __ioctl (int __fd, unsigned long int __request, ...);
manual/llio.texi:@deftypefun int ioctl (int @var{filedes}, int @var{command}, @dots{})
misc/ioctl.c:__ioctl (int fd, unsigned long int request, ...)
misc/sys/ioctl.h:extern int ioctl (int __fd, unsigned long int __request, ...) __THROW;
sysdeps/mach/hurd/ioctl.c:__ioctl (int fd, unsigned long int request, ...)
sysdeps/unix/sysv/linux/ioctl.c:__ioctl (int fd, unsigned long int request, ...)

baffling!

I think android uses bionic which is a fork of musl as libc, so this would be congruent.

@nabijaczleweli
Copy link
Collaborator

Wait, we even handle this:

    let ioctl_request_type = match &env::var("CARGO_CFG_TARGET_ENV").expect("CARGO_CFG_TARGET_ENV")[..] {
        "musl" => "libc::c_int",
        _ => "libc::c_ulong",
    };

of course, since we handle it like this instead of by autodetecting, it's bound to break when someone builds on illumos or any other non-BSD host. Cool.

@nabijaczleweli
Copy link
Collaborator

Can you try the current devel branch (at least 9e6fcd1)?

@LHLaurini
Copy link
Author

LHLaurini commented Sep 4, 2023

Can you try the current devel branch (at least 9e6fcd1)?

Sure. That fixes the error. Now it builds correctly.

amir73il pushed a commit to amir73il/man-pages that referenced this issue Oct 26, 2023
Bit me in <thecoshman/http#155>:
musl (and, thus, bionic) takes an int!

Kill the "POSIX says 'request' is int" comment;
prior to Issue 7, ioctl() is shaded STREAMS,
it's obsolescent in Issue 7,
and gone completely in Issue 8.
The POSIX interface has never been supported by Linux,
and the common ioctl() interface has never existed in POSIX or the SUS.

Note how the interface evolved in HISTORY. The NetBSD CVS has
  revision 1.1
  date: 1993-03-21 10:45:37 +0100;  author: cgd;  state: Exp;
  branches:  1.1.1;
  Initial revision
  ----------------------------
  revision 1.1.1.2
  date: 1995-02-27 11:49:43 +0100;  author: cgd;  state: Exp;  lines: +6
  -6;
  from Lite
  ----------------------------
  revision 1.1.1.1
  date: 1993-03-21 10:45:37 +0100;  author: cgd;  state: Exp;  lines: +0
  -0;
  initial import of 386bsd-0.1 sources
  ----------------------------
and it's char * in 1.1.1.1 and 1.1.1.2 but ... in 1.1, so hell knows.

Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Cc: Jakub Wilk <jwilk@jwilk.net>
[alx: ffix]
Signed-off-by: Alejandro Colomar <alx@kernel.org>
@nabijaczleweli
Copy link
Collaborator

Released in v2.0.0.

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

No branches or pull requests

2 participants