Build fails on Android/Termux
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.
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.
https://lore.kernel.org/linux-man/israsi2qmpudilwpy2h6vj4dda7jofrc3oolhrcs4cpwvwzl5x@ur3oua7jxgs3/t/#u :v
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.
Can you try the current devel branch (at least 9e6fcd11691d01fa2e304b7a7d0fe23b859306a1)?
Can you try the current
develbranch (at least 9e6fcd1)?
Sure. That fixes the error. Now it builds correctly.
Released in v2.0.0.