0
0
mirror of https://github.com/termux/termux-packages.git synced 2025-07-05 23:33:03 +00:00
Files
termux-packages/packages/fish/build.sh
Robert Kirkman c869d61a6d fix(main/fish): do not patch rust-lang/libc cargo crate
- Fixes https://github.com/termux/termux-packages/issues/24741

- Cherry-pick bbf678e718 to replace `libc-src-unix-linux_like-android-mod.rs.diff` (since `libandroid-spawn` does not currently work with `fish`)

- `libc-src-unix-linux_like-android.diff` is **causing** https://github.com/termux/termux-packages/issues/24741 because of the problems explained by **maurer** in https://github.com/rust-lang/libc/pull/4216#discussion_r1902125367

- I have rewritten `libc-src-unix-linux_like-android.diff` in **my own alternative way of solving [the errors](https://github.com/termux/termux-packages/pull/22609#issuecomment-2557037664)**
  - My personal belief is that these errors should be solved by **patching `fish`**, _not_ by patching the **`libc` cargo crate**.
  - The reason I believe that is because **`fish` is using the type `libc::ino_t` to represent a value for storing the `d_ino` member of a `dirent` struct, which **cannot work on 32-bit Android** because 32-bit Android's `d_ino` is **not** an `ino_t`. [It is a `uint64_t`](https://cs.android.com/android/platform/superproject/main/+/main:bionic/libc/include/dirent.h;l=64?q=d_ino&ss=android%2Fplatform%2Fsuperproject%2Fmain:bionic%2Flibc%2Finclude%2F&start=1).
  - Therefore, the logical conclusion is that any successful port of `fish` to 32-bit Android **must explicitly store the value of a `dirent` `d_ino` as a `u64` anywhere it appears in Rust code.**
  - The same concept applies to `st_mode` - `st_mode` of `stat` on 32-bit Android is **not** a `mode_t`. [It is an `unsigned int`](https://cs.android.com/android/platform/superproject/main/+/main:bionic/libc/include/sys/stat.h;l=87), and [on Android, `unsigned int` is a 32-bit integer](https://cs.android.com/android/platform/superproject/main/+/main:bionic/libc/include/stdint.h;l=42;drc=61197364367c9e404c7da6900658f1b16c42d0da;bpv=0;bpt=1?q=stdint.h&ss=android%2Fplatform%2Fsuperproject%2Fmain). Therefore, any successful port of `fish` to 32-bit Android must explicitly store the value of a `stat` `st_mode` as `u32`.
  - In C, `S_IFMT` is a pure typeless literal preprocessor definition, which is [`00170000` in Android](https://cs.android.com/android/kernel/superproject/+/common-android-mainline:common/include/uapi/linux/stat.h;l=9?q=S_IFMT), preprocessor definitions do not really exist in Rust so there is unfortunately no correct alternative to a hardcoded integer literal for this on 32-bit Android

- I previously read https://github.com/rust-lang/libc/pull/4216 in January 2025, however, I unfortunately did not have the experience necessary at the time to fully understand how to solve this specific problem, so at the time, I did not change the version written by thunder-coding because I did not know how to make a better way to bypass the errors
  - However, in April 2025, I [ported Steel Bank Common Lisp to 64-bit Android-x86](b54fa7f61e/packages/sbcl/fix-stat-st_nlink-x86.patch). In the process of doing that, I became more experienced with Android's `stat.h` and `dirent.h` files, and I have been able to use that experience to successfully create what appears to be a correct solution to https://github.com/termux/termux-packages/issues/24741

The original errors, repeated here for convenint reference by others:

```
error[E0308]: mismatched types
   --> src/wutil/dir_iter.rs:114:50
    |
114 |             self.typ.set(stat_mode_to_entry_type(s.st_mode));
    |                          ----------------------- ^^^^^^^^^ expected `u16`, found `u32`
    |                          |
    |                          arguments to this function are incorrect
    |
note: function defined here
   --> src/wutil/dir_iter.rs:151:4
    |
151 | fn stat_mode_to_entry_type(m: libc::mode_t) -> Option<DirEntryType> {
    |    ^^^^^^^^^^^^^^^^^^^^^^^ ---------------
help: you can convert a `u32` to a `u16` and panic if the converted value doesn't fit
    |
114 |             self.typ.set(stat_mode_to_entry_type(s.st_mode.try_into().unwrap()));
    |                                                           ++++++++++++++++++++

error[E0308]: mismatched types
   --> src/wutil/dir_iter.rs:292:32
    |
292 |             self.entry.inode = dent.d_ino;
    |             ----------------   ^^^^^^^^^^ expected `u32`, found `u64`
    |             |
    |             expected due to the type of this binding
```
2025-05-20 13:43:38 -05:00

50 lines
1.9 KiB
Bash

TERMUX_PKG_HOMEPAGE=https://fishshell.com/
TERMUX_PKG_DESCRIPTION="The user-friendly command line shell"
TERMUX_PKG_LICENSE="GPL-2.0"
TERMUX_PKG_MAINTAINER="@termux"
TERMUX_PKG_VERSION="4.0.2"
TERMUX_PKG_REVISION=2
TERMUX_PKG_SRCURL=https://github.com/fish-shell/fish-shell/releases/download/$TERMUX_PKG_VERSION/fish-${TERMUX_PKG_VERSION}.tar.xz
TERMUX_PKG_SHA256=6e1ecdb164285fc057b2f35acbdc20815c1623099e7bb47bbfc011120adf7e83
TERMUX_PKG_AUTO_UPDATE=true
# fish calls 'tput' from ncurses-utils, at least when cancelling (Ctrl+C) a command line.
# man is needed since fish calls apropos during command completion.
TERMUX_PKG_DEPENDS="bc, libandroid-support, libc++, ncurses, ncurses-utils, mandoc, pcre2"
TERMUX_PKG_BUILD_IN_SRC=true
TERMUX_PKG_EXTRA_CONFIGURE_ARGS="
-DBUILD_DOCS=OFF
-DFISH_USE_SYSTEM_PCRE2=ON
-DMAC_CODESIGN_ID=OFF
-DWITH_GETTEXT=OFF
"
termux_step_pre_configure() {
termux_setup_cmake
termux_setup_ninja
termux_setup_rust
# FindRust.cmake auto pick thumbv7neon-linux-androideabi
[[ "${TERMUX_ARCH}" == "arm" ]] && TERMUX_PKG_EXTRA_CONFIGURE_ARGS+=" -DCMAKE_ANDROID_ARM_MODE=ON"
# older than Android 8 dont have ctermid
"${CC}" ${CPPFLAGS} ${CFLAGS} -c ${TERMUX_PKG_BUILDER_DIR}/ctermid.c
"${AR}" cru libctermid.a ctermid.o
# cmake invokes rustc directly leaving CARGO_TARGET_*_RUSTFLAGS unused
local -u env_host="${CARGO_TARGET_NAME//-/_}"
export RUSTFLAGS=$(env | grep CARGO_TARGET_${env_host}_RUSTFLAGS | cut -d'=' -f2-)
RUSTFLAGS+=" -C link-arg=-landroid-spawn"
RUSTFLAGS+=" -L${TERMUX_PKG_BUILDDIR} -C link-arg=-l:libctermid.a"
}
termux_step_post_make_install() {
cat >> "$TERMUX_PREFIX/etc/fish/config.fish" <<-EOF
function __fish_command_not_found_handler --on-event fish_command_not_found
$TERMUX_PREFIX/libexec/termux/command-not-found \$argv[1]
end
# TODO: remove when https://github.com/termux/termux-app/pull/4417 gets released
status test-feature keyboard-protocols && set -U fish_features no-keyboard-protocols
EOF
}