Giter Club home page Giter Club logo

termux-ndk's Introduction

Android ndk for termux, that only support aarch64 architecture

The source code from AOSP llvm-toolchain, which is consistent with the official Ndk version

At first, we don‘t need to rebuild the whole Ndk, since google already built most of it. so we only need to build the llvm toolchain, then replace the llvm inside Ndk.

For more details information, please refer to toolchain readme docs

download r23

How to build

Termux needs to install aarch64 version of Linux to download the source code, we are not using it to compile

In order to save storage , there are some prebuilts tools that do not need to be downloaded. comment out them in the llvm-toolchain/.repo/manifests/default.xml file, click here for example.

pkg install proot-distro
proot-distro install archlinux

# I assume that you have installed the ArchLinux
# install repo
pacman -S repo 

cd /data/data/com.termux/files/home 
mkdir llvm-toolchain && cd llvm-toolchain

# download the source code
repo init -u https://android.googlesource.com/platform/manifest -b llvm-toolchain

# for china
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b llvm-toolchain

# rebuild the toolchain with that manifest
cp /path/to/android/android-ndk-r23/toolchains/llvm/prebuilt/linux-x86_64/manifest_7284624.xml .repo/manifests
repo init -m manifest_7284624.xml

repo sync -c -j4

# sync finish, exit ArchLinux
exit

Install some build-essential packages, then copy or soft link it to llvm-toolchain/prebuilts

I recommend compiling on PC, because compiling on device will take a long time
If compiling on PC, we only replece the prebuilt clang toolchain

# remove clang-bootstrap 
rm -vrf llvm-toolchain/prebuilts/clang/host/linux-x86/clang-bootstrap

# extract android-ndk-r23.tar.xz to /path/to/clang-bootstrap
tar -xJvf android-ndk-r23.tar.xz -C llvm-toolchain/prebuilts/clang/host/linux-x86/clang-bootstrap

# soft link cmake to llvm-toolchain/prebuilts
ln -sf /data/data/com.termux/files/usr/bin/cmake llvm-toolchain/prebuilts/cmake/linux-x86/bin/cmake

# soft link make to llvm-toolchain/prebuilts
ln -sf /data/data/com.termux/files/usr/bin/make llvm-toolchain/prebuilts/build-tools/linux-x86/bin/make

# soft link ninja to llvm-toolchain/prebuilts
ln -sf /data/data/com.termux/files/usr/bin/ninja llvm-toolchain/prebuilts/build-tools/linux-x86/bin/ninja

# remove prebuilt python
rm -vrf llvm-toolchain/prebuilts/python/linux-x86/*
# apt download python3
# extract python_3.9.x_aarch64.deb to llvm-toolchain/prebuilts/python/linux-x86

# building golang
apt install golang
cd llvm-toolchain/prebuilts/go/linux-x86/src
./make.bash

Building start!

# no build for windows
# If it is not the first time to build, you can add options --skip-source-setup to save time
python toolchain/llvm_android/build.py --no-build windows --skip-source-setup

llvm-toolchain stage1 and stage2 compilation will take a long time.

there may be some errors during the compilation process, please solve it by yourself!


Building finish!

# test the ndk clang
NDK_TOOLCHAIN=/path/to/android-ndk-r23/toolchains/llvm/prebuilt/linux-aarch64
$NDK_TOOLCHAIN/bin/aarch64-linux-android28-clang++ test.cpp -o test

# if you want to use clang alone, you need to specify --target=<arch_api_level>
# for example android api 28 --target=aarch64-linux-android28
$NDK_TOOLCHAIN/bin/clang++ --target=aarch64-linux-android28 test.cpp -o test

# Note: <arch_api_level>-clang is recommended, instead of clang alone

Building simpleperf

# simpleperf no need to compile
cd android-ndk-r23/simpleperf/bin/linux/aarch64

ln -sf ../../android/arm64/simpleperf ./simpleperf

Building shader-tools

cd /path/to/your_dir

# clone the source code
git clone --depth=1 https://github.com/google/shaderc
cd shaderc/third_party
git clone --depth=1 https://github.com/KhronosGroup/SPIRV-Tools.git   spirv-tools
git clone --depth=1 https://github.com/KhronosGroup/SPIRV-Headers.git spirv-tools/external/spirv-headers
git clone --depth=1 https://github.com/google/googletest.git
git clone --depth=1 https://github.com/google/effcee.git
git clone --depth=1 https://github.com/google/re2.git
git clone --depth=1 https://github.com/KhronosGroup/glslang.git

# start building shaderc...

mkdir build && cd build

# setting android ndk toolchain
TOOLCHAIN=/path/to/android-ndk-r23/toolchains/llvm/prebuilt/linux-aarch64

cmake -G "Ninja" \
    -DCMAKE_C_COMPILER=$TOOLCHAIN/bin/aarch64-linux-android28-clang \
    -DCMAKE_CXX_COMPILER=$TOOLCHAIN/bin/aarch64-linux-android28-clang++ \
    -DCMAKE_SYSROOT=$TOOLCHAIN/sysroot \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/path/to/shader-tools \
    ..

ninja -j16

Building renderscript

# llvm-rs-cc and bcc_compat
cd termux-ndk/renderscript
./build.sh

Building app

building android app with termux-ndk, please refer to build-app

Building cocos2d game

building cocos2d game for android with termux-ndk, please refer to cocos2d-game

FAQ

  • I don't compile the Linux-aarch64 version only for Android.
  • Termux now has many packages, including Openjdk-17 Gradle Kotlin and so on.
    so in most cases we don't need to use proot linux.

termux-ndk's People

Contributors

lzhiyong avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.