Skip to content

Instantly share code, notes, and snippets.

@drhuffman12
Last active September 25, 2021 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drhuffman12/2c1857fc76c213a1ef5ca6bd9da4a420 to your computer and use it in GitHub Desktop.
Save drhuffman12/2c1857fc76c213a1ef5ca6bd9da4a420 to your computer and use it in GitHub Desktop.
# See also: https://forum.crystal-lang.org/t/running-crystal-on-termux/3880
# Termux
pkg install -y \
automake \
build-essential \
clang \
git \
libbsd* \
libedit* \
libevent* \
libgc* \
libgmp* \
libpcre* \
libssh* \
libtool* \
libxml2* \
libyaml* \
libllvm* \
lld* \
# libgmpxx4ldbl \
# ln -sf /usr/bin/ld.lld-8 /usr/bin/ld.lld
# zip up `crystal` folder and copy to device
# cd ~/storage/shared/Android/data/com.termux/files
# tar xvzf file.tar.gz
# aka: data/data/com.termux/files/home/storage/shared/Android/data/com.termux/files
# copy crystal
cp crystal.tar.gz ~/
PATH=/data/data/com.termux/files/usr/bin:$PATH
cd ~/
tar xvzf crystal.tar.gz
cd crystal
# LLVM_CONFIG=$(which llvm-config) make deps
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
@drhuffman12
Copy link
Author

drhuffman12 commented Sep 25, 2021

Gets stuck at:

~/crystal $ 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
/data/data/com.termux/files/usr/bin/ld: src/llvm/ext/llvm_ext.o: Relocations in generic ELF (EM: 62)
/data/data/com.termux/files/usr/bin/ld: src/llvm/ext/llvm_ext.o: Relocations in generic ELF (EM: 62)
...
/data/data/com.termux/files/usr/bin/ld: src/llvm/ext/llvm_ext.o: Relocations in generic ELF (EM: 62)                                /data/data/com.termux/files/usr/bin/ld: src/llvm/ext/llvm_ext.o: error adding symbols: file in wrong format                         clang-12: error: linker command failed with exit code 1 (use -v to see invocation)
~/crystal $

@drhuffman12
Copy link
Author

drhuffman12 commented Sep 25, 2021

Note: After copying files to device , on the device you must remove llvm_ext.o from device and re-run make deps and then run cc crystal ...:

$ find -name llvm_ext.o
./src/llvm/ext/llvm_ext.o

$ rm ./src/llvm/ext/llvm_ext.o

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

~/crystal $ bin/crystal -v
bin/crystal: 153: crystal: not found
Using compiled compiler at .build/crystal
Crystal 1.2.0-dev ()

LLVM: 12.0.0
Default target: aarch64-unknown-linux-android24

~/crystal $ bin/crystal eval "puts(1+2)"
bin/crystal: 153: crystal: not found
Using compiled compiler at .build/crystal
3

~/crystal $ bin/crystal eval "puts Time.utc""
> "
bin/crystal: 153: crystal: not found
Using compiled compiler at .build/crystal
2021-09-25 15:33:44 UTC

@drhuffman12
Copy link
Author

Now to rebuild Crystal on device and run specs:

# backup
mv bin/crystal bin/crystal.OLD

# rebuild
make clean crystal


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment