Termux-packages: Linuxbrew in Termux? [Package Request] [Help Wanted]

Created on 27 Jan 2018  ·  28Comments  ·  Source: termux/termux-packages

Hi there,
I heard Linuxbrew is available for 32-bit ARM.
is it possible to install Linuxbrew in Termux?
I tried their primary installation method, but it shows error.
After installing brew using their alternative installation method, I tried to open brew but it shows CANNOT LINK EXECUTABLE: library "libandroid-support.so" not found
Can anyone help me about it?
Also adding a brew package in the repository would be great.

screenshot_20180128-032256

Thanks.

packaging

Most helpful comment

@sdrausty I have a small number of linuxbrew packages compiling successfully using this method: https://github.com/Linuxbrew/brew/wiki/Android

All 28 comments

"Alternative installation method" means that you compiled it on device?

You can fix this type of error by export LDFLAGS=" -landroid-support" and the recompile the package.

@Grimler91 i think the alternative install is the sudoless one to the $HOME directory
i'm interested in this one too was casually updating a zsh plugin but it looks like the install script has been updated much more recently, note to self to review that
if other quirks/environment variables/etc come up (and/or you want to add to my sample size of ~1 using that plugin 😅 ) lmk

@grayalias did you figure out how to make it work? don't denvercoder9 me!!
https://xkcd.com/979/

DEAR PEOPLE FROM THE FUTURE: here's what i've figured out so far ...

i think the issue is something with the $(brew --prefix)/lib/ld.so not being there

symlinking /bin/false to it prevented an earlier error, but then things break later with the following

CANNOT LINK EXECUTABLE /usr/bin/gcc-7: library libandroid-support.so not found
CANNOT LINK EXECUTABLE /usr/bin/clang: library libLLVM-5.0.so not found
Error: hello cannot be built with any available compilers.
Install Clang or brew install gcc

i found some things about how on android it's /system/bin/linker{,64} instead of ld.so but symlinking those instead also didn't work :cry:

@emanresusername unfortunately no. 🙁

Hi, all. I maintain Linuxbrew. I don't have an Android system on which to test, but I can chime in with a few observations. These are all completely untested. Let me know if anyone tries this out and gets it working! See also https://github.com/Linuxbrew/brew/wiki/Chromebook-Install-Instructions. I don't have a Chromebook and haven't tested these instructions myself. Feel free to edit the Wiki.

Symlink the dynamic linker

See https://github.com/termux/termux-packages#android-dynamic-linker
and https://github.com/Linuxbrew/brew/blob/ed30aa3789a127f03b8fffe07ee1391550797ec4/Library/Homebrew/cmd/install.rb#L322

ln -s /system/bin/linker64 $HOME/.linuxbrew/lib/ld.so || ln -s /system/bin/linker $HOME/.linuxbrew/lib/ld.so

Use DT_RUNPATH rather than DT_RPATH

Apparently the dynamic linker does not support DT_RPATH.
See https://github.com/termux/termux-packages#android-dynamic-linker
and https://android.googlesource.com/platform/bionic/+/nougat-mr1-release/linker/linker.cpp#3910
Note the conspicuous absence of DT_RPATH. Someone who cared enough could add support to the Android dynamic linker for DT_RPATH.
For Linuxbrew, see https://github.com/Linuxbrew/brew/issues/598
and https://github.com/Linuxbrew/brew/blob/master/Library/Homebrew/shims/linux/super/cc#L258
Add the option ld --enable-new-dtags to use DT_RUNPATH rather than the default DT_RPATH.
Alternatively you can use patchelf --shrink-rpath which has the side effect of changing DT_RPATH to DT_RUNPATH.

@sjackman In my testing (if I remember correctly) Homebrew already creates the necessary linker symlink.
The actual cause of the reported problem is that the brew shell script blanks LD_LIBRARY_PATH which all termux binaries use to find libandroid.so.

Converting termux from leaning on LD_LIBRARY_PATH to using RUNPATH will fix this. The fix is pretty simple. When compiling termux binaries, they need to add the options -Wl,--enable-new-dtags -Wl,-rpath=\\\$ORIGIN/../lib. The $ORIGIN there signifies the final location of the binary, and the value of rpath= should resolve to the location of libandroid.so.

Another nice side-effect is that the resulting userspace is relocatable, which will play quite nicely with termux-chroot.

Ah, got it. Yes, big thumbs up for using RUNPATH rather than LD_LIBRARY_PATH. An existing installation of termux could be modified using patchelf to test it.

is this more of an install script thing/brew thing? or a termux thing?
i'm pretty far out of my depth in either pool 😅 ... but ftr, this did not work :(

@sjackman To be very clear, RPATH is never going to work, since the Android linker doesn't support it. I'm sure this was originally tried, then the current LD_LIBRARY_PATH system was chosen when it didn't work. RUNPATH should work correctly however.

@emanresusername We need a core termux maintainer to change how all termux binaries are built.

Note that the Android dynamic linker is open source, and someone who were sufficiently motivated could add support for DT_RPATH to Android. See https://android.googlesource.com/platform/bionic/+/nougat-mr1-release/linker/linker.cpp#3910
Adding hacktastic support for DT_RPATH that had the same behaviour as DT_RUNPATH should be pretty easy. Possibly as easy as…

-      case DT_RUNPATH:
+      case DT_RUNPATH: case DT_RPATH:

though emulating the GNU dynamic linker behaviour of DT_RPATH would probably be better.

Note that RUNPATH requires android 7.0 or later, while Termux currently supports Android 5.0 or later. I'm thinking of droppping 5.0 support in the near future, while 6.0 will be supported longer, so we cannot do the LD_LIBRARY_PATH-> RUNPATH transition just yet.

You could use RUNPATH if available on Android 7+ and fall back to LD_LIBRARY_PATH for Android <7.

droppping 5.0 support in the near future

Why are you thinking about this? What is the motivation?

We have RUNPATH by default in binutils now (#2255). How do I rebuild clang under this change?

@fornwall A brief description to help me jumpstart would be very useful.

Did you think Termux packages are built with toolchain in Termux? Coz they are not but built with toolchain in the NDK.

No, I didn't assume such a thing.

What do you mean by "How do I rebuild clang under this change?" then?

Ah, okay, yes, I did think this would change how clang would be compiled.
I'll open another, separate ticket for compiling clang with --enable-new-dtags.

Significant 'git bloat' at 14kb/s:

Press RETURN to continue or any other key to abort
==> Downloading and installing Linuxbrew...

remote: Counting objects: 107017, done.
remote: Compressing objects: 100% (208/208), done.
error: RPC failed; curl 18 transfer closed with outstanding read data remaining
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
Failed during: git fetch origin master:refs/remotes/origin/master --tags --force

Trying again in TermuxArch. Thank you for bringing this project to my attention @grayalias. The catch interrupt is way cool 😎 and I 💘 love the way it refuses to run as root user.
screenshot_2018-03-21-18-46-41
How about you?

@sdrausty I have a small number of linuxbrew packages compiling successfully using this method: https://github.com/Linuxbrew/brew/wiki/Android

Also, what about Entware? I don't think of it as a Linuxbrew alternative but it might help avoid building some packages....

Also, what about Entware?
it might help avoid building some packages....

Yes, it can help to avoid building of some packages, but only those that don't use config files or external data as paths are hardcoded - this is in case if packages are not rebuilt from source with proper patching/configuration.

I have a small number of linuxbrew packages compiling successfully using this method: https://github.com/Linuxbrew/brew/wiki/Android

Should we still be using this method after the Homebrew 2.0 release and its merge with Linuxbrew, @bukzor ?

Perhaps relevant, Homebrew on Linux (aka Linuxbrew) now supports AArch 64 (aka 64-bit ARM or armv8) as well as 32-bit ARM (armv6).

I’d like to say that I tried to run sudo cmd (sudocomes from here), however, I get this error:

CANNOT LINK EXECUTABLE "cmd": cannot locate symbol "XzUnpacker_Construct" referenced by "/system/lib64/libunwind.so"...

I believe that it is connected with this issue.

Btw, I’d like to run Android apps directly from Termux, this is how I noticed this error.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

roycebank picture roycebank  ·  3Comments

divyakutty picture divyakutty  ·  3Comments

am11 picture am11  ·  3Comments

jackbrycesmith picture jackbrycesmith  ·  3Comments

Zuccace picture Zuccace  ·  3Comments