bupstash icon indicating copy to clipboard operation
bupstash copied to clipboard

Fails to build on ARM64 (Termux)

Open unai-ndz opened this issue 3 years ago • 15 comments

Trying to build it on my phone using termux I get this error:


error[E0308]: mismatched types
   --> src/fsutil.rs:383:36
    |
383 |             unsafe { libc::makedev(major as libc::c_uint, minor as libc::c_uint) }
    |                                    ^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `u32`
    |
help: you can convert a `u32` to an `i32` and panic if the converted value doesn't fit
    |
383 |             unsafe { libc::makedev((major as libc::c_uint).try_into().unwrap(), minor as libc::c_uint) }
    |                                    +                     +++++++++++++++++++++

error[E0308]: mismatched types
   --> src/fsutil.rs:383:59
    |
383 |             unsafe { libc::makedev(major as libc::c_uint, minor as libc::c_uint) }
    |                                                           ^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `u32`
    |
help: you can convert a `u32` to an `i32` and panic if the converted value doesn't fit
    |
383 |             unsafe { libc::makedev(major as libc::c_uint, (minor as libc::c_uint).try_into().unwrap()) }
    |                                                           +                     +++++++++++++++++++++

For more information about this error, try `rustc --explain E0308`.
error: could not compile `bupstash` due to 2 previous errors

Steps to reproduce:

  • Install termux
  • Using termux execute:
pkg install git
git clone https://github.com/termux/termux-packages
cd termux-packages
./scripts/setup-termux.sh
pkg install libsodium binutils
git clone https://github.com/andrewchambers/bupstash
cd bupstash
git checkout v0.11.0
cargo build --release

I found some related issues which may be useful. Issue Commit

unai-ndz avatar May 04 '22 05:05 unai-ndz

I guess we could do .try_into() to accomodate more varations. Thanks for the report.

andrewchambers avatar May 04 '22 05:05 andrewchambers

I think this may be resolved now, let me know if it isn't.

andrewchambers avatar Sep 07 '22 13:09 andrewchambers

I haven't managed to test this in a termux environment.

@unai-ndz How did you get cargo working in termux? I didn't find a good answer here: https://github.com/termux/termux-packages/issues/261

sogaiu avatar Sep 07 '22 22:09 sogaiu

I just pkg install rust. I tried again right now and it still works but i had to reinstall termux because it wasn't downloading any packages. It got rust from this repo (you should have it by default): https://packages-cf.termux.dev/apt/termux-main stable/main

unai-ndz avatar Sep 08 '22 06:09 unai-ndz

Just a quick test but looks like building v.0.11.1 still fails with the same error.

Have you tested this in arm or maybe it fails only in termux?

unai-ndz avatar Sep 08 '22 08:09 unai-ndz

Other people have built successfully on different arm devices.

andrewchambers avatar Sep 08 '22 08:09 andrewchambers

@unai-ndz Thanks for the tip. Somehow I didn't have cargo working even with the rust package installed originally (perhaps pebkac), but when I tried again (after rm -rf ~/.cargo), cargo worked.

Building failed for me too. Will upload a log in a bit.

sogaiu avatar Sep 08 '22 09:09 sogaiu

My impression is that the output looks similar to the original report (except perhaps the line numbers). FWIW, rustc --version gives rustc 1.62.1.

   Compiling libc v0.2.120
   Compiling version_check v0.9.4
   Compiling cfg-if v1.0.0
   Compiling autocfg v1.1.0
   Compiling proc-macro2 v1.0.36
   Compiling unicode-xid v0.2.2
   Compiling syn v1.0.88
   Compiling memchr v2.4.1
   Compiling once_cell v1.10.0
   Compiling typenum v1.15.0
   Compiling serde_derive v1.0.136
   Compiling pkg-config v0.3.24
   Compiling serde v1.0.136
   Compiling crossbeam-utils v0.8.11
   Compiling regex-syntax v0.6.25
   Compiling log v0.4.14
   Compiling bitflags v1.3.2
   Compiling zstd-safe v4.1.4+zstd.1.5.2
   Compiling lazy_static v1.4.0
   Compiling fnv v1.0.7
   Compiling serde_json v1.0.79
   Compiling anyhow v1.0.56
   Compiling subtle v2.4.1
   Compiling itoa v1.0.1
   Compiling fallible-iterator v0.2.0
   Compiling constant_time_eq v0.1.5
   Compiling termcolor v1.1.3
   Compiling unicode-width v0.1.9
   Compiling same-file v1.0.6
   Compiling number_prefix v0.4.0
   Compiling smallvec v1.8.0
   Compiling arrayvec v0.7.2
   Compiling arrayref v0.3.6
   Compiling either v1.6.1
   Compiling fallible-streaming-iterator v0.1.9
   Compiling codemap v0.1.3
   Compiling ryu v1.0.9
   Compiling cfg-if v0.1.10
   Compiling rangemap v0.1.14
   Compiling humantime v2.1.0
   Compiling path-clean v0.1.0
   Compiling shlex v0.1.1
   Compiling generic-array v0.14.5
   Compiling ahash v0.7.6
   Compiling num-traits v0.2.14
   Compiling memoffset v0.6.5
   Compiling num-integer v0.1.44
   Compiling uriparse v0.6.4
   Compiling getopts v0.2.21
   Compiling walkdir v2.3.2
   Compiling itertools v0.10.3
   Compiling aho-corasick v0.7.18
   Compiling bstr v0.2.17
   Compiling quote v1.0.15
   Compiling crossbeam-channel v0.5.6
   Compiling jobserver v0.1.24
   Compiling getrandom v0.2.5
   Compiling terminal_size v0.1.17
   Compiling atty v0.2.14
   Compiling xattr v0.2.2
   Compiling filetime v0.2.15
   Compiling time v0.1.43
   Compiling nix v0.23.1
   Compiling regex v1.5.5
   Compiling console v0.15.0
   Compiling cc v1.0.73
   Compiling codemap-diagnostic v0.1.1
   Compiling tar v0.4.38
   Compiling hashbrown v0.11.2
   Compiling crypto-common v0.1.3
   Compiling block-buffer v0.10.2
   Compiling indicatif v0.16.2
   Compiling globset v0.4.8
   Compiling digest v0.10.3
   Compiling hashlink v0.7.0
   Compiling zstd-sys v1.6.3+zstd.1.5.2
   Compiling libsqlite3-sys v0.22.2
   Compiling lz4-sys v1.9.4
   Compiling blake3 v1.3.1
   Compiling bupstash v0.11.1 (/data/data/com.termux/files/home/src/bupstash)
   Compiling thiserror-impl v1.0.30
   Compiling thiserror v1.0.30
   Compiling rusqlite v0.25.4
   Compiling lz4 v1.24.0
   Compiling chrono v0.4.19
   Compiling serde_bare v0.4.0
error[E0308]: mismatched types
   --> src/fsutil.rs:189:36
    |
189 |             unsafe { libc::makedev(major as libc::c_uint, minor as libc::c_uint) }
    |                                    ^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `u32`
    |
help: you can convert a `u32` to an `i32` and panic if the converted value doesn't fit
    |
189 |             unsafe { libc::makedev((major as libc::c_uint).try_into().unwrap(), minor as libc::c_uint) }
    |                                    +                     +++++++++++++++++++++

error[E0308]: mismatched types
   --> src/fsutil.rs:189:59
    |
189 |             unsafe { libc::makedev(major as libc::c_uint, minor as libc::c_uint) }
    |                                                           ^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `u32`
    |
help: you can convert a `u32` to an `i32` and panic if the converted value doesn't fit
    |
189 |             unsafe { libc::makedev(major as libc::c_uint, (minor as libc::c_uint).try_into().unwrap()) }
    |                                                           +                     +++++++++++++++++++++

For more information about this error, try `rustc --explain E0308`.
error: could not compile `bupstash` due to 2 previous errors

sogaiu avatar Sep 08 '22 10:09 sogaiu

Poking around rust's libc crate, I see this recent commit:

On Android, change the arguments from signed to unsigned integers to match the other platforms. The C makedev is a macro, so the signededness is undefined.

I think this might be part of the relevant code.

I tried rebuilding with libc at 0.2.133 and the build completed this time with 1 warning:

~/src/bupstash $ cargo build --release
    Updating crates.io index
  Downloaded libc v0.2.133
  Downloaded 1 crate (603.3 KB) in 0.99s
   Compiling libc v0.2.133
   Compiling version_check v0.9.4
   Compiling cfg-if v1.0.0
   Compiling autocfg v1.1.0
   Compiling proc-macro2 v1.0.36
   Compiling unicode-xid v0.2.2
   Compiling syn v1.0.88
   Compiling memchr v2.4.1
   Compiling once_cell v1.10.0
   Compiling typenum v1.15.0
   Compiling serde_derive v1.0.136
   Compiling pkg-config v0.3.24
   Compiling serde v1.0.136
   Compiling crossbeam-utils v0.8.11
   Compiling regex-syntax v0.6.25
   Compiling log v0.4.14
   Compiling anyhow v1.0.56
   Compiling lazy_static v1.4.0
   Compiling bitflags v1.3.2
   Compiling zstd-safe v4.1.4+zstd.1.5.2
   Compiling serde_json v1.0.79
   Compiling fnv v1.0.7
   Compiling subtle v2.4.1
   Compiling arrayref v0.3.6
   Compiling unicode-width v0.1.9
   Compiling arrayvec v0.7.2
   Compiling number_prefix v0.4.0
   Compiling termcolor v1.1.3
   Compiling same-file v1.0.6
   Compiling smallvec v1.8.0
   Compiling fallible-iterator v0.2.0
   Compiling constant_time_eq v0.1.5
   Compiling itoa v1.0.1
   Compiling codemap v0.1.3
   Compiling either v1.6.1
   Compiling ryu v1.0.9
   Compiling fallible-streaming-iterator v0.1.9
   Compiling humantime v2.1.0
   Compiling shlex v0.1.1
   Compiling rangemap v0.1.14
   Compiling path-clean v0.1.0
   Compiling cfg-if v0.1.10
   Compiling num-traits v0.2.14
   Compiling memoffset v0.6.5
   Compiling num-integer v0.1.44
   Compiling generic-array v0.14.5
   Compiling ahash v0.7.6
   Compiling uriparse v0.6.4
   Compiling getopts v0.2.21
   Compiling walkdir v2.3.2
   Compiling itertools v0.10.3
   Compiling aho-corasick v0.7.18
   Compiling bstr v0.2.17
   Compiling quote v1.0.15
   Compiling crossbeam-channel v0.5.6
   Compiling jobserver v0.1.24
   Compiling getrandom v0.2.5
   Compiling terminal_size v0.1.17
   Compiling xattr v0.2.2
   Compiling time v0.1.43
   Compiling atty v0.2.14
   Compiling filetime v0.2.15
   Compiling nix v0.23.1
   Compiling regex v1.5.5
   Compiling cc v1.0.73
   Compiling console v0.15.0
   Compiling codemap-diagnostic v0.1.1
   Compiling tar v0.4.38
   Compiling hashbrown v0.11.2
   Compiling crypto-common v0.1.3
   Compiling block-buffer v0.10.2
   Compiling indicatif v0.16.2
   Compiling globset v0.4.8
   Compiling zstd-sys v1.6.3+zstd.1.5.2
   Compiling lz4-sys v1.9.4
   Compiling libsqlite3-sys v0.22.2
   Compiling blake3 v1.3.1
   Compiling bupstash v0.11.1 (/data/data/com.termux/files/home/src/bupstash)
   Compiling hashlink v0.7.0
   Compiling digest v0.10.3
   Compiling thiserror-impl v1.0.30
   Compiling thiserror v1.0.30
   Compiling lz4 v1.24.0
   Compiling serde_bare v0.4.0
   Compiling chrono v0.4.19
   Compiling rusqlite v0.25.4
warning: unnecessary `unsafe` block
   --> src/fsutil.rs:189:13
    |
189 |             unsafe { libc::makedev(major as libc::c_uint, minor as libc::c_uint) }
    |             ^^^^^^ unnecessary `unsafe` block
    |
    = note: `#[warn(unused_unsafe)]` on by default

warning: `bupstash` (bin "bupstash") generated 1 warning
    Finished release [optimized] target(s) in 4m 53s

On a side note, cargo test generated some errors:

~/src/bupstash $ cargo test
  Downloaded remove_dir_all v0.5.3
  Downloaded ppv-lite86 v0.2.16
  Downloaded tempfile v3.3.0
  Downloaded rand_chacha v0.3.1
  Downloaded rand v0.8.5
  Downloaded rand_core v0.6.3
  Downloaded fastrand v1.7.0
  Downloaded 7 crates (194.6 KB) in 0.95s
   Compiling libc v0.2.133
   Compiling cfg-if v1.0.0
   Compiling version_check v0.9.4
   Compiling proc-macro2 v1.0.36
   Compiling autocfg v1.1.0
   Compiling unicode-xid v0.2.2
   Compiling syn v1.0.88
   Compiling memchr v2.4.1
   Compiling once_cell v1.10.0
   Compiling typenum v1.15.0
   Compiling serde_derive v1.0.136
   Compiling pkg-config v0.3.24
   Compiling serde v1.0.136
   Compiling log v0.4.14
   Compiling crossbeam-utils v0.8.11
   Compiling regex-syntax v0.6.25
   Compiling ppv-lite86 v0.2.16
   Compiling zstd-safe v4.1.4+zstd.1.5.2
   Compiling fnv v1.0.7
   Compiling bitflags v1.3.2
   Compiling lazy_static v1.4.0
   Compiling subtle v2.4.1
   Compiling anyhow v1.0.56
   Compiling serde_json v1.0.79
   Compiling smallvec v1.8.0
   Compiling itoa v1.0.1
   Compiling arrayvec v0.7.2
   Compiling codemap v0.1.3
   Compiling fastrand v1.7.0
   Compiling same-file v1.0.6
   Compiling either v1.6.1
   Compiling arrayref v0.3.6
   Compiling ryu v1.0.9
   Compiling fallible-streaming-iterator v0.1.9
   Compiling unicode-width v0.1.9
   Compiling number_prefix v0.4.0
   Compiling fallible-iterator v0.2.0
   Compiling remove_dir_all v0.5.3
   Compiling termcolor v1.1.3
   Compiling constant_time_eq v0.1.5
   Compiling shlex v0.1.1
   Compiling cfg-if v0.1.10
   Compiling rangemap v0.1.14
   Compiling humantime v2.1.0
   Compiling path-clean v0.1.0
   Compiling generic-array v0.14.5
   Compiling ahash v0.7.6
   Compiling num-traits v0.2.14
   Compiling num-integer v0.1.44
   Compiling memoffset v0.6.5
   Compiling uriparse v0.6.4
   Compiling walkdir v2.3.2
   Compiling itertools v0.10.3
   Compiling getopts v0.2.21
   Compiling aho-corasick v0.7.18
   Compiling bstr v0.2.17
   Compiling quote v1.0.15
   Compiling crossbeam-channel v0.5.6
   Compiling jobserver v0.1.24
   Compiling getrandom v0.2.5
   Compiling terminal_size v0.1.17
   Compiling time v0.1.43
   Compiling filetime v0.2.15
   Compiling atty v0.2.14
   Compiling xattr v0.2.2
   Compiling tempfile v3.3.0
   Compiling nix v0.23.1
   Compiling regex v1.5.5
   Compiling console v0.15.0
   Compiling rand_core v0.6.3
   Compiling cc v1.0.73
   Compiling codemap-diagnostic v0.1.1
   Compiling tar v0.4.38
   Compiling hashbrown v0.11.2
   Compiling rand_chacha v0.3.1
   Compiling block-buffer v0.10.2
   Compiling crypto-common v0.1.3
   Compiling globset v0.4.8
   Compiling indicatif v0.16.2
   Compiling hashlink v0.7.0
   Compiling rand v0.8.5
   Compiling digest v0.10.3
   Compiling zstd-sys v1.6.3+zstd.1.5.2
   Compiling lz4-sys v1.9.4
   Compiling libsqlite3-sys v0.22.2
   Compiling blake3 v1.3.1
   Compiling bupstash v0.11.1 (/data/data/com.termux/files/home/src/bupstash)
   Compiling thiserror-impl v1.0.30
   Compiling lz4 v1.24.0
   Compiling thiserror v1.0.30
   Compiling rusqlite v0.25.4
   Compiling serde_bare v0.4.0
   Compiling chrono v0.4.19
error[E0425]: cannot find value `S_IEXEC` in crate `libc`
    --> src/index.rs:1072:23
     |
1072 |         assert!(libc::S_IEXEC == 64);
     |                       ^^^^^^^ not found in `libc`

error[E0425]: cannot find value `S_IWRITE` in crate `libc`
    --> src/index.rs:1073:23
     |
1073 |         assert!(libc::S_IWRITE == 128);
     |                       ^^^^^^^^ not found in `libc`

error[E0425]: cannot find value `S_IREAD` in crate `libc`
    --> src/index.rs:1074:23
     |
1074 |         assert!(libc::S_IREAD == 256);
     |                       ^^^^^^^ not found in `libc`

For more information about this error, try `rustc --explain E0425`.
error: could not compile `bupstash` due to 3 previous errors

sogaiu avatar Sep 22 '22 00:09 sogaiu

Regarding the errors for cargo test, may be it's these 3 lines:

        assert!(libc::S_IEXEC == 64);
        assert!(libc::S_IWRITE == 128);
        assert!(libc::S_IREAD == 256);

Perhaps Android doesn't have S_IEXEC, S_IWRITE or S_IREAD... just guessing based on them missing from this.

May be S_IXUSR, S_IWUSR, and S_IRUSR can be used instead (at least for android?). At least the following two things suggest those might be reasonable:

  • https://www.gnu.org/software/libc/manual/html_node/Permission-Bits.html
  • https://android.googlesource.com/platform/bionic/+/master/libc/include/sys/stat.h#128 (the link here might not be valid for too long)

Oh, I see that those 3 are already here.

sogaiu avatar Sep 22 '22 14:09 sogaiu

FWIW, once the version for libc in Cargo.toml is updated to 0.2.133 and these 3 lines are removed from index.rs, building succeeds and tests via cargo test all pass here.

sogaiu avatar Sep 22 '22 15:09 sogaiu

@unai-ndz If you are still interested and get a chance, perhaps you can see if those changes work for you?

sogaiu avatar Sep 23 '22 00:09 sogaiu

Thanks for investigating this btw - I will try to get setup later and test your investigation too.

andrewchambers avatar Sep 23 '22 00:09 andrewchambers

Is this still an issue? It may be an issue for #388

williamdes avatar Oct 11 '23 19:10 williamdes

I still see those 3 lines so although I haven't tested I suspect it still is an issue.

IIUC though, this is an Android-specific thing -- see this comment.

sogaiu avatar Oct 12 '23 02:10 sogaiu