rattler
rattler copied to clipboard
Add support for Android
So I'd like to try and get some conda-based package management on android using termux. I was going to try compiling micromamba from scratch statically compiling it with bionic and lo-and-behold, it requires a conda-compatible environment. But, In the documentatiotn somwehre I saw pixi mentioned and it only requires Cargo! So, I spin up terumux (first try on Windows subsystem for Android, but tried again on Galaxy S21 Ultra), pkg install rust and then use the "cargo install --locked pixi" (or from the github link, I've tried both), and I get the error below for both. Is there any reason that we can't add android to this for Pixi/Rattler? If this is too big an ask, I understand, but it should be do-able, since Pixi is fully cargo compile-able. Previous error came with "aarch64-linux-android-ar" or "x86_64-linux-android-ar" not being installed and that can be fixed by installing binutils (gnu) or by running "AR=llvm-ar cargo install --locked pixi" for llvm. The build on android fails under both conditions with the errors below. I suspect it's almost likley to work with some small change to the code, but I haven't had time enough to learn rust enough to dig into the details. I'm wondering if someone with a little bit more expertise than me would be willing to try and confirm if this would be a do-able thing for pixi (and/or rattler?). If this is better in the pixi repo, please close this advising and I'll re-issue under the pixi repo.
v0.12.0 error: unsupported target os --> /data/data/com.termux/files/home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rattler_virtual_packages-0.12.0/src/cuda.rs:133:5 | 133 | compile_error!("unsupported target os"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: unsupported target os --> /data/data/com.termux/files/home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rattler_virtual_packages-0.12.0/src/cuda.rs:204:5 | 204 | compile_error!("unsupported target os"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0425]: cannot find value FILENAMES in this scope
--> /data/data/com.termux/files/home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rattler_virtual_packages-0.12.0/src/cuda.rs:134:5
|
134 | FILENAMES
| ^^^^^^^^^ not found in this scope
error[E0425]: cannot find value FILENAMES in this scope
--> /data/data/com.termux/files/home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rattler_virtual_packages-0.12.0/src/cuda.rs:205:5
|
205 | FILENAMES
| ^^^^^^^^^ not found in this scope
For more information about this error, try rustc --explain E0425.
error: could not compile rattler_virtual_packages (lib) due to 4 previous errors
warning: build failed, waiting for other jobs to finish...
error: failed to compile pixi v0.7.0, intermediate artifacts can be found at /data/data/com.termux/files/usr/tmp/cargo-installHhMhf6.
To reuse those artifacts with a future compilation, set the environment variable CARGO_TARGET_DIR to that path.
The errors are raised because we have no code to check for Cuda support on platforms other than macOS, Linux and Windows. If I understand it correctly, android is a different target_os. I do not have access to an Android device, nor do I know the platform at all so this is going to be hard for me to fix properly. Does android run on glibc as well?
The code where the compiler errors comes from specifies a few locations where some Cuda libraries could possibly be found. As I understand it Android also supports Cuda? Would you happen to know where those libraries will be located on android?
In the meantime I created a PR to at least get rid of the compiler error. This also wont detect Cuda on android but I guess that is better than not being able to compile at all! :)
But I assume there will be more problems along the way since we (and I believe conda in general) don't really support Android in any way. Android is also not a supported conda platform so I dont think there will be any packages available for it. It would be a very interesting target to add though!
Awesome effort, @2themaxx – would love to learn more about what you are trying. While Android is not a "proper" platform yet, I guess one could pretend by compiling for linux-aarch64 and use a separate channel with the right android libraries.
Btw. there is some effort here: https://github.com/codelv/conda-mobile for Android, and I believe there is something similar for iOS but would have to search more for it.
@baszalmstra , Thanks! I'll try this later today. A few technical bits. My whole goal is to get access to conda packages and test what works and what doesn't. I'm not sure what will work (maybe nothing), but I'm trying to build a path for data scientists to be able to use Android devices easily for prototyping. The link about conda-mobile looks cool, but isn't exactly what I'm trying to do. I'll check it out and see if it works, but I'd like to see what I can access directly from conda interfaces first.
- Android DOESN'T use glibc, but a special version of Android's own libc (c++ maybe?) Called bionic. That library is provided with Android's native development kit (ndk). Generally as long as you're not making certain syscalls, almost everything will cross compile without issue. I have access to both clang and gcc using termux that are compiled for Android. Please see (https://wiki.termux.com/wiki/Differences_from_Linux) [here] and (https://github.com/termux/termux-packages/wiki/Common-porting-problems) [here]
I tried micromamba for aarch64 and run into the exact issues mentioned in these links. My first thought was to cross-compile micromamba with bionic using the ndk on Android using termux, but compiling micromamba requires a conda compatible environment. I could do it manually, but then I stumbled into pixi/rattler.
-
I tried building on 2 targets using the same shell, but different architecture: x86_64 and my Galaxy s21 ultra which should be aarch64. For the X86_64 I'm using Windows subsystem for Android: [https://learn.microsoft.com/en-us/windows/android/wsa/] (WSA) from Microsoft. If you have access to a Windows 11 machine, you could use it that way. I'm specifically using a prebuilt version with the (
https://github.com/MustardChef/WSABuilds)[Google Play store built in], but not using the root solutions. For all intents and purposes behaves just like my phone. I am using WSA on a Windows system that has an NVidia card with graphics acceleration turned on, but I also get the same error on my phone in the same location with no Nvidia hardware. I'm not familiar with how to use cuda on Android and don't think the WSA detects the NVidia hardware but uses Vulkan and openCL providing acceleration that way. Either way it shouldn't cause the compilation to urp. -
I also saw a reference to pipx and condax, so I tried those. Pipx installs directly using termux's pip, but condax doesn't install. I think that's due to dependency issues.
I'll give the new PR a spin and let you know. It may be that none of the aarch64 stuff on conda-forge will work, but it's worth a try. I suppose I could manually download and try the packages, but interfacing with conda seems like a better long-term solution. If I could add a new OS to conda-forge and we could provide a recipe for feedstock to target bionic, then all the other work already done by package maintainers should allow us easy access to anything that just compiles easily. But... We'd need access to a method of getting conda packages on the system to begin with, hence Android with micromamba-bionic or pixi....
Sorry, I didn't mean to forget this. I have been thinking about this but haven't posted here. I tried posting and messaging in the Pixi discord and didn't hear back (may have uninstalled discord after that).
The issue is a chicken and egg problem with Android. Rattler builds, but there's no glibc in Android so it can't execute anything off of conda-forge. Android doesn't allow static compilation without root, so that's out (i.e. micromamba). Can we use an Alpine build of any tools (i.e. micromamba and Pixi) and a pure rust example from conda-forge to bootstrap building rust against bionic (does it rely on libc?).
Termux provides packages using a build.sh style recipes for all it's packages, so if we could just get one (or a few) recipe example with Android's bionic libc into conda-forge (Python, rust, micromamba and Pixi) we should be able to build the rest using Termux-packages as a guide (and hopefully minimum effort for everything that is already supported). Note: if you do this by running the
BTW, here's the output from the rattler example for cowpy from the gif on the repo (using termux-packages compiled against bionic to start:
... (All rust build stuff for cowpy):
Running target/release/rattler create cowpy target prefix: "/data/data/com.termux/files/home/rattler/.prefix" installing for platform: Unknown INFO fetch_repo_data{cache_path=/data/data/com.termux/files/home/.cache/rattler/cache/repodata}: rattler_repodata_gateway::fetch::jlap: fetching JLAP state from https://conda.anaconda.org/conda-forge/noarch/repodata.jlap (bytes=0-) ERROR fetch_repo_data{cache_path=/data/data/com.termux/files/home/.cache/rattler/cache/repodata}: rattler_repodata_gateway::fetch: error=repodata not found WARN fetch_repo_data{cache_path=/data/data/com.termux/files/home/.cache/rattler/cache/repodata}: rattler_repodata_gateway::fetch: Error during JLAP request: No matching hashes can be found in the JLAP file ✔ conda-forge/noarch [00:00:09] Done virtual packages: [] Error: Cannot solve the request because of: nothing provides python needed by cowpy-1.1.0-py_1 ~/rattler $ which python
/data/data/com.termux/files/usr/bin/python
Any thoughts on how to proceed?
Edited to add, someone got scikit-learn running on termux, and they provide pytorch, so we should have all the examples to get some basic packages within conda-forge on Android. They also show his they compile python-pip....
https://github.com/termux/termux-packages/blob/06f6de8defec5bec235abbcee6f9de0574fed8c0/scripts/build/setup/termux_setup_python_pip.sh https://github.com/termux/termux-packages/issues/19681
So rattler complies on Android but errors out on Python (see above) so cowpy can't run. I installed the rattler requirements using packages installed by termux.
And Pixi needs something not provided by bionic/musl(?). Apparently some of the termux packages use musl.
Trying to compile Pixi results in this error:
Compiling rattler_installs_packages v0.8.1
Compiling pixi v0.15.2
error[E0425]: cannot find function ptsname_r in this scope
--> /data/data/com.termux/files/home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pixi-0.15.2/src/unix/pty_process.rs:76:26
|
76 | let slave_name = ptsname_r(&master_fd)?;
| ^^^^^^^^^ not found in this scope
|
help: consider importing one of these items
|
1 + use crate::unix::pty_process::nix::pty::ptsname_r;
|
1 + use libc::ptsname_r;
|
1 + use nix::pty::ptsname_r;
|
For more information about this error, try rustc --explain E0425.
error: could not compile pixi (lib) due to previous error
warning: build failed, waiting for other jobs to finish...
error: failed to compile pixi v0.15.2, intermediate artifacts can be found at /data/data/com.termux/files/usr/tmp/cargo-installba07Fh.
To reuse those artifacts with a future compilation, set the environment variable CARGO_TARGET_DIR to that path.
What is a good pure-rust project I can try installing from conda-forge? Maybe uv?
Pure rust .. hmm .. maybe bat?
So uv is a bust:
$ cd rattler/
~/rattler $ cargo run --release create uv
Finished release [optimized] target(s) in 2.58s
Running target/release/rattler create uv
target prefix: "/data/data/com.termux/files/home/rattler/.prefix"
installing for platform: Unknown
INFO fetch_repo_data{cache_path=/data/data/com.termux/files/home/.cache/rattler/cache/repodata}: rattler_repodata_gateway::fetch::jlap: fetching JLAP state from https://conda.anaconda.org/conda-forge/noarch/repodata.jlap (bytes=0-)
ERROR fetch_repo_data{cache_path=/data/data/com.termux/files/home/.cache/rattler/cache/repodata}: rattler_repodata_gateway::fetch: error=repodata not found INFO rattler_repodata_gateway::fetch::jlap: parsing cached repodata.json as JSON INFO rattler_repodata_gateway::fetch::jlap: applying patches #1462 through #1463
INFO rattler_repodata_gateway::fetch::jlap: converting patched JSON back to repodata
INFO rattler_repodata_gateway::fetch::jlap: writing patched repodata to disk
INFO fetch_repo_data{cache_path=/data/data/com.termux/files/home/.cache/rattler/cache/repodata}: rattler_repodata_gateway::fetch: fetched JLAP patches successfully
✔ conda-forge/noarch [00:00:15] Done virtual packages: []
Error: Cannot solve the request because of: nothing provides requested uv
Please note, I can get Pixi to compile if I use the Alpine underneath termux. That's probably a way forward, but then you still run into the musl-libc issue (but you guys do have an Alpine version now 🤔)
Alpine under termux here: https://github.com/Hax4us/TermuxAlpine
The libc is a problem for both Alpine (on Android) and termux though (certain things just won't work if pulled from conda-forge). So this does require maybe a bit of attention.
If you can point me to your build process for Alpine and how you can get it conda-forge, I'll work on replicating the same steps for Android.
Does conda-forge need an Android OS target for this to work?
Same issue with bat as uv. Do we need an OS target in conda-forge?
~/rattler $ cargo run --release create bat
Finished release [optimized] target(s) in 2.77s
Running target/release/rattler create bat
target prefix: "/data/data/com.termux/files/home/rattler/.prefix"
installing for platform: Unknown
ERROR fetch_repo_data{cache_path=/data/data/com.termux/files/home/.cache/rattler/cache/repodata}: rattler_repodata_gateway::fetch: error=repodata not found ✔ conda-forge/unknown [00:00:00] Not Found ✔ conda-forge/noarch [00:00:00] Using cache virtual packages: []
Error: Cannot solve the request because of: nothing provides requested bat
~/rattler $
Btw. there is some effort here: https://github.com/codelv/conda-mobile for Android, and I believe there is something similar for iOS but would have to search more for it.
I missed this comment. I'll take a look and see if I can get stuff running. I haven't seen anything on conda-forge and the repo seems abandoned or at least not updated for 2 years.
Yep, that is correct. There are no android or ios packages on conda-forge. The first step would be to come up with the correct "architecture" IMO. For example, android-arm64 or something like that? Or ios-arm64 for iOS.
You could start experimenting by building your own packages first. We have the following tool: https://github.com/prefix-dev/rattler-build/
If you want to start with some Rust stuff, you could take some inspiration from recipes like these: https://github.com/wolfv/rust-forge
Happy to walk you through the initial steps some day if you want!
@wolfv YES! I would like a walkthrough or something. I would really just like to do python for now. The rust stuff was only because I had a termux-packages compiled rust that was capable of building rattler.
For android, I think android-am64 AND android-x86 would be good architecture targets. There are several chromebooks that run android-x86 targets and a few linux-y installs as well, but I would want to start on android-arm64.
The other and perhaps easier question that comes up is alpine with musl. I note that there's an open issue over on the miniforge: https://github.com/conda-forge/miniforge/issues/219
And that issue is like 2-3 years old. Solving the alpine issue with musl and then adding android-arm64 using bionic and getting that into the conda-forge would be a path towards what I'm thinking. I do believe this could benefit the community and it's not just my random request.
I think I can run jupyter lab on my phone using the termux-packages, but I'd rather pull things from conda-forge if at all possible.
Also wanting to note there's an issue with pixi compiling on both termux and alpine-termux with a dependency on something. Should I create an issue over there, or leave it until I get something built myself.
Also, is there a link to how you got pixi compiled for alpine, was it a static compile against glibc-compat? If it's actually compiled against musl, then getting pixi-alpine on conda-forge would be my first direction because that would show me how to use a different libc.