Professional Documents
Culture Documents
Description
Termux is an Android terminal app and Linux environment.
Here I describe a process to build Mono 6.0 from source on an Android arm64 device.
Also, it's not possible to build the class libraries on device as you need a
runnable Mono or Monolite to bootstrap.
tar xf mono-6.0.0.319.tar.xz
cd mono-6.0.0.319
make
make install
cd ..
ln -s /system/lib64/libc.so /data/data/com.termux/files/usr/local/lib/libc.so.6
Add usr/local/bin to system environment variable PATH.
Install MSBuild
Don't try to build from source, it depends on a .Net Core version which is not
shipped with Visual Studio and is very difficult to compile both on Windows or on
Linux. Just download the pre-compiled binary from Mono. It contains only
portable .Net binaries.
#!/bin/sh
MONO_GC_PARAMS="nursery-size=64m,$MONO_GC_PARAMS" exec
/data/data/com.termux/files/usr/local/bin/mono $MONO_OPTIONS
/data/data/com.termux/files/usr/local/lib/mono/msbuild/15.0/bin/MSBuild.dll "$@"
Roslyn is buggy on Mono on arm64 as it assumes the legacy x86/x86_64 memory model
which grants memory access order in some situations on the metal.
https://preshing.com/20120930/weak-vs-strong-memory-models/
https://github.com/dotnet/roslyn/issues/24932
https://github.com/mono/mono/issues/12632
https://xamarin.github.io/bugzilla-archives/56/56546/bug.html
https://news.ycombinator.com/item?id=14318877
This problem can not really be fixed in Mono, as there is a huge performance
penalty. To workaround this problem, we have to force Roslyn to run single-
threaded.
sed -i 's|"@(Compile)"|"@(Compile);/parallel-"|g'
/data/data/com.termux/files/usr/local/lib/mono/msbuild/Current/bin/Roslyn/Microsoft
.CSharp.Core.targets
sed -i 's|"@(Compile)"|"@(Compile);/parallel-"|g'
/data/data/com.termux/files/usr/local/lib/mono/msbuild/Current/bin/Roslyn/Microsoft
.VisualBasic.Core.targets
Backup and Recover
All these can be packed for later use.
cd /data/data/com.termux/files/usr
tar cfJ mono-termux.6.0.0.319.tar.xz local
To recover, execute the following commands and don't forget to add usr/local/bin to
PATH.
cd /data/data/com.termux/files/usr
tar xf mono-termux.6.0.0.319.tar.xz