http icon indicating copy to clipboard operation
http copied to clipboard

Build fails on Android/Termux

Open LHLaurini opened this issue 10 months ago • 5 comments

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.

LHLaurini avatar Sep 04 '23 02:09 LHLaurini