[Xiaomi Poco F3 / Xiaomi Mi 11X / Redmi K40] samantas5855:
Some of you wanted to compile Turnip on Termux so here's a tutorial.

You are going to need an arm64 phone and Termux from https://f-droid.org/en/packages/com.termux/. If you have Termux from PlayStore delete it since it no longer works and it uses a different signature so it can't be updated either.

Once you install Termux go to your phone's app settings and give it storage permissions manually then launch it.

You must run some pkg commands, answer Y if it asks you to.

First update the repositories and upgrade the packages using

pkg update

Next you must install some dependencies

pkg install binutils bison flex git ninja patchelf python wget zip

The pip version Termux provides isn't always the latest so it must be updated too using

/data/data/com.termux/files/usr/bin/python3 -m pip install --upgrade pip

You will use pip3 to install the rest of the dependencies

pip3 install mako meson

Since you aren't cross compiling you need to create the path that hosts the native file

mkdir -p ~/.local/share/meson/native

and then download the native file for meson using

curl https://pastebin.com/raw/zdVCZASL>~/.local/share/meson/native/mesa

This file is made for android-ndk-r23b so if a new version gets released use nano to edit it and replace all occurencies of android-ndk-r23b.

You need to download the latest Termux-NDK

(at the moment of writing this the latest is android-ndk-r23b if that changes obviously replace the commands of the guide with the new name and the url bellow)

wget https://github.com/Lzhiyong/termux-ndk/releases/download/android-ndk/android-ndk-r23b-aarch64.zip

then extract it

unzip android-ndk-r23b-aarch64.zip

and remove the archive since it isn't needed anymore

rm android-ndk-r23b-aarch64.zip

Then you need to download libdrm for arm64 from the alarm project's repositories. Simply go to https://archlinuxarm.org/packages/aarch64/libdrm, hold the Download button and copy the url. At the moment the latest one is the one below so change the commands depending on the latest version.

wget http://mirror.archlinuxarm.org/aarch64/extra/libdrm-2.4.109-1-aarch64.pkg.tar.xz

Then you need to extract it

tar -xf libdrm-2.4.109-1-aarch64.pkg.tar.xz -C android-ndk-r23b

You then delete the archive since it's no longer of use

rm libdrm-2.4.109-1-aarch64.pkg.tar.xz

Now you must change the prefix of the libdrm pc file to point to our local pkgconfig

sed -i 's#prefix=#&/data/data/com.termux/files/home/android-ndk-r23b#g' ~/android-ndk-r23b/usr/lib/pkgconfig/libdrm.pc

You may now clone the mesa repository

git clone https://gitlab.freedesktop.org/mesa/mesa.git

and get inside it

cd ~/mesa

Configure the build environment using the meson command below

meson build-android-aarch64 --native-file mesa -Dbuildtype=release -Dplatforms=android -Dplatform-sdk-version=31 -Dandroid-stub=true -Dgallium-drivers= -Dvulkan-drivers=freedreno -Dfreedreno-kgsl=true -Dcpp_rtti=false -Db_lto=true

and then compile

ninja -C build-android-aarch64

Linking might take some time but once it's finished go back to Termux' home directory using

cd ~

Now download the template for the Magisk Driver package

wget https://cdn.discordapp.com/attachments/894694753684320296/943268696426684456/mesa_lto.zip

and extract it

unzip mesa_lto.zip -d mesa_lto

then cd inside

cd mesa_lto

and copy the blob you compiled

cp ~/mesa/build-android-aarch64/src/freedreno/vulkan/libvulkan_freedreno.so ./system/vendor/lib64/hw/

If you are building for another phone you have to run termux on that other phone and get the name of the vulkan library using

ls /system/vendor/lib64/hw/|grep vulkan

and then run patchelf and rename the blob.

If not, you can just run these commands that will fetch the name of your phone's library and perform elf name patching

patchelf --set-soname $(ls /system/vendor/lib64/hw/|grep vulkan) system/vendor/lib64/hw/libvulkan_freedreno.so

and renaming

mv system/vendor/lib64/hw/libvulkan_freedreno.so system/vendor/lib64/hw/$(ls /system/vendor/lib64/hw/|grep vulkan)

Finally zip the package

zip -r ../mesa_lto.zip *

and go back to Termux' home directory

cd ..

Delete the extracted folder, it's not needed anymore

rm -rf mesa_lto

Push the Magisk package to your phone's home folder

cp mesa_lto.zip /storage/emulated/0

Close Termux

exit

Flash with Magisk and reboot.

If you have other Magisk driver packages, disable them.

If you want to compile again you don't have to reclone, just cd into the mesa directory and do

git pull

You may also have to delete the build-android-aarch64 folder.