I managed to get Crystal working on Termux. This means Crystal can be run on most Android devices, but it is not quite the same thing as running it on an ADB shell. To test it yourself:
- Clone this branch;
- Cross-compile Crystal with
make clean crystal && bin/crystal build --cross-compile --target aarch64-unknown-linux-android24 src/compiler/crystal.cr -Dwithout_playground. (I don’t know if the target triple always ends with
- Copy the created
crystal.ofile to Termux, somewhere under the home directory.
- Ensure you have all of Crystal’s development dependencies installed on Termux.
- On Termux run
make deps && cc crystal.o -o .build/crystal -rdynamic src/llvm/ext/llvm_ext.o `llvm-config --libs --system-libs --ldflags 2> /dev/null` -lstdc++ -lpcre -lm -lgc -lpthread -levent -lrt -ldl.
bin/crystalshould work. Back it up, then try building a second generation of the compiler with
make crystal. That should work too, including the playground.
All compiler specs pass. Most standard library specs also pass, but some limitations prevent them from getting all green:
- Android’s directory structure is different from many Linux systems, e.g. it lacks
- Hard links are not supported. Symbolic links are only supported under Termux’s own directory.
- Bionic implements only a very small subset of custom encodings: ASCII, US-ASCII, UTF-8, UTF-16LE, UTF-16BE, UTF-32LE, UTF-32BE, and WCHAR_T. Others like ISO-8859-1 and UCS-2LE will fail if any
Also the following weird error shows up when running
Failed to raise an exception: -484097664 [0x5cbf7baf28] *Exception::CallStack::print_backtrace:Nil +100 [0x5cbf79d214] __crystal_raise +52 [0x5cbf86b140] *Socket+ +140 [0x5cbf86afc0] *Socket+ +200 [0x5cbf7ad52c] ~procProc(Pointer(LibCrypto::Bio), Pointer(UInt8), UInt64, Pointer(UInt64), Int32) +560 [0x70e2feb2d0] ??? Tried to raise:: Error reading socket: Connection reset by peer (IO::Error) from src/io/evented.cr:61:9 in 'unbuffered_read' from src/io/buffered.cr:80:16 in 'read' from src/openssl/bio.cr:46:13 in '->' from ???