Termux-packages: Package request: Rust and Cargo

Created on 10 May 2016  ·  46Comments  ·  Source: termux/termux-packages

As the popularity of Rust grows, Rust support in Termux would be extremely helpful to both Rust experts and beginners.

The binaries and libraries of Rust and Cargo are also shown to be compilable and buildable in ARM despite the fact that they should be compiled in Rust instead of C. Hence, building Rust and Cargo packages for Termux would seem highly feasible. A link towards the corresponding Github repo is provided below.

Thanks.

RustBuild: https://github.com/warricksothr/RustBuild

package request

Most helpful comment

@MineFuehrer
I don't know who the "she" you're referring to is (Languages don't have genders in English and it's pretty clear from my avatar that I'm a guy), but that has the appearance of an ad hominem attack, which won't win you many allies in here.

As for my comment, in case you need clarification, whatever competition Rust may have with Nim is of the "other programming languages do exist" variety, not the "Oh my God! Stop the presses! My high school rival got a point on me! I must react!" variety.

I got the impression your goal was to manipulate people to hurry up with packaging Rust by saying "Look! Your rival is beating you!" but Nim is not Rust and what Nim does has no more bearing on how the mature adults in this thread will behave than what Brainf*ck, INTERCAL, or Ook! do.... so I repeat: "They were first to be packaged? Good on them, but it's off-topic."

All 46 comments

I was about to request this. I also would love to see rust added to the collection. In fact, termux with a full compiler collection is becoming a very valuable tool.

Good news for cross-compilation of Rust and Cargo on termux :)
http://blog.rust-lang.org/2016/05/13/rustup.html

Rustup doesn't work on termux (which is not a termux bug, just pointing out that rustup is not a solution)

$ curl -sSf https://static.rust-lang.org/rustup.sh | sh
rustup: gpg available. signatures will be verified
rustup: unknown CPU type: aarch64

@andreiw, sure, but using rustup on a pc os, you can easily compile the rust compiler for arm architectures i presume :smile:

The link is pointing to the wrong place in the OP comment

https://github.com/warricksothr/RustBuild

Same with this one

http://blog.rust-lang.org/2016/05/13/rustup.html

Has anyone tested if rustup is working for ARM7 cpus? @andreiw seemed to try it on ARM64

Getting a permission denied error on rustup.sh in termux, chmod a+x doesn't help

Rust isn't a bad match. It's also using the LLVM backend, which should already be installed since Termux comes with the clang toolchain.

screenshot_20170131-233723

This happens when I run the latest rustup.sh

Edit the script and insert the correct shell path in the shebang. I think it's /system/bin/sh under android (although please check).

Trying a different approach which is still relevant to the topic:

Downloaded rustup-init (the arm7 build), copied it to /data/local, switched to su and chmod +x rustup-init, then tried to run it. I now get a different error but I think this may be more relevant.

shamu:/data/local # sh rustup-init
rustup-init: line 1: syntax error: unexpected word (expecting ")")

Edit: used this build rustup-init

I get the same error as @wrsg.

The rustup-init tool isn't available to android, yet. The only way to get rust on android will be through cross compiling it. I have tried it but I am not that familiar with their build system.

@vishalbiswas The next version of rust is switching to a new build system that requires Python, so it may be wise to wait until that version before doing any serious packaging.

just my 2 cents on my attempts at building rust,
rust requires a boot strap compiler that it downloads from rust website, but that compiler doesnt run ( I am suspecting that their build aarm64 OS has dynamic linker in different location to termux.
Hoping people can confirm or comment on my findings.
ps, i have tried new python build system as well.

@Luke-Nukem you mean 1.16 or 1.17?

@vishalbiswas I think 1.16, iirc.

You can build it without the python based build system (rustbuild) via ./configure --disable-rustbuild, so it uses a pure makefile based compilation - but this is what is being pulled out soon.

@kirillrdy

It may be worth grabbing a precompiled binary from https://static.rust-lang.org/dist/index.html to try, if this works, then you can use that to build rust with

./configure \
    --build=%{rust_triple} \
    --host=%{rust_triple} \
    --target=%{rust_triple} \
    --enable-local-rust \
    --local-rust-root=%{_prefix} \
    --prefix=%{_prefix} \
    --libdir=%{_prefix}/lib \
    --docdir=%{_docdir}/%{name} \
    --disable-rpath \
    --disable-codegen-tests \
    --disable-rustbuild \
    --enable-vendor \
    --release-channel=stable

%{xyz} is an rpm spec macro used by distros using rpm (I copy pasted this from my spec for openSUSE). rust_triple is basically the target, eg aarch64-unknown-linux-gnu. prefix is generally /usr, but this may well be different for termux.

@Luke-Nukem thanks for your reply.
the pre-compiled binary didn't work, and that's the same binary that it downloads to bootstrap itself.
here is why i think it something to do with dynamic linker.

file rustup-init
rustup-init: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 4.2.6, not stripped, with debug_info
$ ./rustup-init
-bash: ./rustup-init: No such file or directory

btw same happens when i try to run precompiled rustc, which is again what it tries to run when bootstrapping itself

@kirillrdy That rustup binary was compiled for aarch64-linux-gnueabi not aarch64-linux-androideabi.
Thats why we need to cross compile it.

I am getting this error in the latest rustup script

sTux at cmbox in ~
➜ zsh rustup.sh
info: downloading installer
run:1: no such file or directory: /data/data/com.termux/files/usr/tmp/tmp.vSrLht/rustup-init
rustup: command failed: /data/data/com.termux/files/usr/tmp/tmp.vSrLht/rustup-init
sTux at cmbox in ~

But there is no latest rustup script that works on android is there? I tried to manually cross-compile rustup but that seems to be blocked by https://github.com/rust-lang/libc/pull/511

I don't know if that only affects rustup itself and there is another way to install rustc + cargo or if that means it just doesn't work at the moment.

Seems like this may be easier once the Rust devs actually enable this as they plan to

https://github.com/rust-lang/rfcs/issues/1903
https://github.com/rust-lang/rfcs/issues/1795

It seems mozilla is providing an armv7-linux-androideabi target (but no binary release of rustc) so the only viable option at the moment is cross-compilation of rustc.

Cross-compilation of individual programs, like ripgrep, should be doable, provided you already had a working cross-compiler/ndk.

I believe the person to go to for help could be @japaric

Requires #879

Meanwhile, Nim already works beautifully in termux, see this thread:

https://forum.nim-lang.org/t/2891

@MeinFuehrer

Congrats to them. I don't see how it's relevant to mention it here though.

I'm the maintainer of openSUSE rust packaging currently, and I have it building with every arch from ARM, AARCH64, PowerPC64+, x86 etc. The version where this actually became more stable and easier is v1.13.0. Versions from 1.15.1 onwards are incredibly good now.

It's entirely possible to package rust for termux using the precompiled binaries from the dist site - I use these to bootstrap compilation on each of these architectures.

I've got a mid-semester break coming up in a week, so I'll have a good look at packaging then.

@kirillrdy I'll investigate that soon.

There's also this

Great news

Disclaimer: I know nothing about termux packaging. In fact, I just learned about this project recently. So I'm approaching the problem of making Cargo / rustc available on Android (and Chrome books?) by having official binaries installable via rustup. But if the official Rust build systems support building Cargo and rustc for Android then it should be easy to have the Termux packaging system leverage that build system to create proper Termux packages

I got both Cargo and rustc working on my Android phone (used Cross (*) and the vanilla Rust build system to build them, respectively) but I can't compile Hello World because gcc (what rustc uses to link binaries, by default) is not available for installation. clang may work but I can't try it right now because I seem to have borked my termux install and can't install anything (packages install clang does nothing)

(*) Thanks @malbarbo for adding Android support to Cross! ❤️

If clang and gcc have the exact same CLI when used as linkers then rustc should work fine when paired with clang. But if that's not the case then we'll have to patch rustc to support both gcc and clang to link Android binaries. There's some groundwork to support that scenario in rust-lang/rust#40018.

yay

wut

@japaric little hint, you can use termux-elf-cleaner to get rid of those "Unused DT entries" warnings
And try installing directly with apt install clang
So, this links against custom built llvm libs built during rust compilation?

@japaric Nice work! I have rustc and cargo working in my phone and it is capable of producing binaries (I assume it is using clang linker, because gcc in termux calls clang).

I have some PR to send to rust that adds android host builds. I'm just waiting some other changes to get merged. There is also a discussion of the minimum android api level that rust must support.

rustup 1.1 was released yesterday with android builds. To install rustup run curl https://sh.rustup.rs -sSf | sh or download and run rustup-init (arm, armv7, aarch64, i686).

When we got rust and cargo nightly for android, we will be able to install them using rustup!

@vishalbiswas Thanks for the termux-elf-cleaner hint! It removed some warnings but I'm still getting a bunch that look like this:

WARNING: linker: libterm-8aa0f90fec124b0d.so: unused DT entry: type 0xf arg 0x2f68
WARNING: linker: libterm-8aa0f90fec124b0d.so: unused DT entry: type 0x6ffffffe arg 0x418c
WARNING: linker: libterm-8aa0f90fec124b0d.so: unused DT entry: type 0x6fffffff arg 0x1

packages install clang is now working. I had messed with LD_LIBRARY_PATH and didn't realized it was already set in the termux environment. Linking is working now out of the box now! 🎉

So, this links against custom built llvm libs built during rust compilation?

Yes, I produced rustc via cross compilation and that also cross compiles LLVM as part of the build process. So this rustc is statically linked to Rust's fork of LLVM. There's an option to link against system LLVM but I think that can only be used with native builds.

@malbarbo Excellent! Can confirm that using clang as a linker works without a hitch 👍.

@japaric
https://github.com/termux/termux-packages/issues/879
LLVM should build a native llvm-config while cross compiling it. This does not work as expected for our libllvm package.
Rust uses llvm-config to get llvm libs and paths to link against. I think we could probably write a shell script to emulate its behaviour at this point. I'm getting nowhere debugging that one.
I would really like rustc to use system llvm. Otherwise, the package size is probably massive?

I made a PR to add host builders for android. This would allow installing rustc and cargo using rustup. We have a capacity issue and it is not possible to build rustc for all android archs. So I would like to ask:

Which arch support is more important to you?

Are you interest in rustc running in your phone or chomebook?

Maybe some of you can go to the PR page and write why rustc support on android is important to you.

armv7-a seems to be the most ubiquitous/compatible

my vote would be for aarch64 and if possible x86_64 ( lenovo tablet)

@ssokolow emitted this gem of wisdom:

Congrats to them. I don't see how it's relevant to mention it here though.

She's a little slow, isn't she? (on the uptake probably)

@MineFuehrer
I don't know who the "she" you're referring to is (Languages don't have genders in English and it's pretty clear from my avatar that I'm a guy), but that has the appearance of an ad hominem attack, which won't win you many allies in here.

As for my comment, in case you need clarification, whatever competition Rust may have with Nim is of the "other programming languages do exist" variety, not the "Oh my God! Stop the presses! My high school rival got a point on me! I must react!" variety.

I got the impression your goal was to manipulate people to hurry up with packaging Rust by saying "Look! Your rival is beating you!" but Nim is not Rust and what Nim does has no more bearing on how the mature adults in this thread will behave than what Brainf*ck, INTERCAL, or Ook! do.... so I repeat: "They were first to be packaged? Good on them, but it's off-topic."

Ah, my mistake! I thought it was a ship about to hit an iceberg. Can't wait, carry on!

What prevents me from installing via the shellscript?

@Serkan-devel you can try, it seems to work for some people and not others. even if it were working, this is a package request to get working binaries of rust into the termux repo.

I'm trying to install Rust via the its-pointless repo. This worked well last time I tried it, but now I get the following error:

$ pkg install rustc cargo
[...snip...]
The following packages have unmet dependencies:
 cargo : Depends: libssh2 but is not installable
E: Unable to correct problems, you have held broken packages.

This is on a Dell Chromebook 7310 (ChromeOS version 67.0.3396.99) with Intel Core i3 processor with a clean install of Termux version 0.64.

How can I install libssh2? I get the error Package libssh2 is not available, but is referred to by another package.

Fixed it
Try updating

Thanks! It works now!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ILadis picture ILadis  ·  3Comments

divyakutty picture divyakutty  ·  3Comments

reggi picture reggi  ·  4Comments

neitsab picture neitsab  ·  3Comments

Wetitpig picture Wetitpig  ·  3Comments