All Projects → Lzhiyong → Termux Ndk

Lzhiyong / Termux Ndk

android-ndk for termux

Projects that are alternatives of or similar to Termux Ndk

Bazel Toolchain
LLVM toolchain for bazel
Stars: ✭ 93 (+2.2%)
Mutual labels:  toolchain, clang
Cxxctp
DEPRECATED. USE INSTEAD github.com/blockspacer/flextool
Stars: ✭ 58 (-36.26%)
Mutual labels:  llvm, clang
Bugsnag Android Ndk
DEPRECATED - this project now lives at bugsnag/bugsnag-android
Stars: ✭ 42 (-53.85%)
Mutual labels:  ndk, android-ndk
Fcd
An optimizing decompiler
Stars: ✭ 622 (+583.52%)
Mutual labels:  llvm, clang
Seeless
C IDE for iOS
Stars: ✭ 71 (-21.98%)
Mutual labels:  llvm, clang
Woboq codebrowser
Woboq CodeBrowser
Stars: ✭ 837 (+819.78%)
Mutual labels:  llvm, clang
Llvm 9.0 Learner Tutorial
A blog for LLVM(v9.0.0 or v11.0.0) beginner, step by step, with detailed documents and comments. Record the way I learn LLVM and accomplish a complete project for FPGA High-Level Synthesis with it.
Stars: ✭ 58 (-36.26%)
Mutual labels:  llvm, clang
Swiftweekly.github.io
A community-driven weekly newsletter about Swift.org
Stars: ✭ 305 (+235.16%)
Mutual labels:  llvm, clang
Avalonstudio
Cross platform IDE and Shell
Stars: ✭ 1,132 (+1143.96%)
Mutual labels:  llvm, clang
Optviewer Demo
Demonstration of LLVM's opt-viewer tool
Stars: ✭ 63 (-30.77%)
Mutual labels:  llvm, clang
Enzyme
High-performance automatic differentiation of LLVM.
Stars: ✭ 418 (+359.34%)
Mutual labels:  llvm, clang
Codechecker
CodeChecker is an analyzer tooling, defect database and viewer extension for the Clang Static Analyzer and Clang Tidy
Stars: ✭ 1,209 (+1228.57%)
Mutual labels:  llvm, clang
Hp Socket
High Performance TCP/UDP/HTTP Communication Component
Stars: ✭ 4,420 (+4757.14%)
Mutual labels:  ndk, android-ndk
Llvm Vs2017 Integration
MSBuild 15.0 Toolset integration for multiple LLVM (From v5 to v8)
Stars: ✭ 84 (-7.69%)
Mutual labels:  llvm, clang
Clangkit
ClangKit provides an Objective-C frontend to LibClang. Source tokenization, diagnostics and fix-its are actually implemented.
Stars: ✭ 330 (+262.64%)
Mutual labels:  llvm, clang
C2goasm
C to Go Assembly
Stars: ✭ 1,072 (+1078.02%)
Mutual labels:  llvm, clang
Olifant
A simple programming language targeting LLVM
Stars: ✭ 58 (-36.26%)
Mutual labels:  llvm, clang
Clang Power Tools
Bringing clang-tidy magic to Visual Studio C++ developers.
Stars: ✭ 285 (+213.19%)
Mutual labels:  llvm, clang
Zapcc
zapcc is a caching C++ compiler based on clang, designed to perform faster compilations
Stars: ✭ 1,109 (+1118.68%)
Mutual labels:  llvm, clang
Meta Clang
Clang C/C++ cross compiler and runtime for OpenEmbedded/Yocto Project
Stars: ✭ 76 (-16.48%)
Mutual labels:  llvm, clang

This is Google's standard NDK, which only supports running on android devices with aarch64 architecture

the source code from AOSP llvm-toolchain master branch, because llvm is cross-platform, so we can recompile it to Android

At first, we don‘t need to rebuild the whole NDK, since google already built most of it. we only need to build llvm toolchain, then replace the llvm in the NDK. of course you can build the whole NDK, use checkbuild.py, but the source code is too huge.

For more details information, please refer to docs/Toolchains.md

download r22

How to build

Termux needs to install aarch64 version of Linux, I recommend using TermuxArch ArchLinux only downloads source code, we are not using it to compile

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

# 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

repo sync -c -j4

# sync finish, exit ArchLinux
exit


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

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

# extract android-ndk-r22.tar.xz to /path/to/clang-bootstrap
tar -xJvf android-ndk-r22.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

# copy patches/crypt.h to llvm-toolchain/prebuilts/clang/host/linux-x86/clang-bootstrap/sysroot/usr/include

# copy patches/sFile.h to llvm-toolchain/toolchain/llvm-project/lldb/include/lldb/Utility
# vim llvm-toolchain/toolchain/llvm-project/lldb/include/lldb/Utility/ReproducerInstrumentation.h
# add #include "lldb/Utility/sFile.h"


OK start compile now!

# 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 --enable-assertions --no-build windows

Building binutils

# execute python toolchain/binutils/build.py
# or you can compile it manually
# host is aarch64-linux-android
# target: arm-linux-androideabi 
#         aarch64-linux-android
#         i686-linux-android
#         x86_64-linux-android

cd binutils && mkdir build && cd build

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

../configure \                                      
    CC=$TOOLCHAIN/bin/aarch64-linux-android30-clang \                                              
    CXX=$TOOLCHAIN/bin/aarch64-linux-android30-clang++ \                                           
    CFLAGS="-fPIC -std=c11" \                       
    CXXFLAGS="-fPIC -std=c++11" \                   
    --prefix=$HOME/binutils/x86_64 \                
    --host=aarch64-linux-android \                  
    --target=x86_64-linux-android \                      
    --enable-plugins \                              
    --enable-gold \
    --enable-new-dtags \
    --disable-werror \  
    --with-system-zlib

Simpleperf no need to compile

cd android-ndk-r22/simpleperf/bin/linux/aarch64

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


Building shader-tools

cd /data/data/com.termux/files/home
git clone https://github.com/google/shaderc
cd shaderc/third_party
git clone https://github.com/KhronosGroup/SPIRV-Tools.git   spirv-tools
git clone https://github.com/KhronosGroup/SPIRV-Headers.git spirv-tools/external/spirv-headers
git clone https://github.com/google/googletest.git
git clone https://github.com/google/effcee.git
git clone https://github.com/google/re2.git
git clone https://github.com/KhronosGroup/glslang.git

# start building shaderc...

cd ~/shaderc && mkdir build && cd build

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

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

make -j16

Building renderscript (llvm-rs-cc and bcc_compat)

# slang source code
# git clone https://android.googlesource.com/platform/frameworks/compile/slang
# libbcc source code
# git clone https://android.googlesource.com/platform/frameworks/compile/libbcc
# rs souce code
# git clone https://android.googlesource.com/platform/frameworks/rs
# llvm and clang source code
# git clone https://android.googlesource.com/platform/external/llvm
# git clone https://android.googlesource.com/platform/external/clang

cd termux-ndk/renderscript
./build.sh


Building finish!

llvm-toolchain stage1 and stage2 compilation takes about 20 hours.

If your phone performance is good, the time may be shorter, but it still takes a lot of time to compile.

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


Compile simple c/c++ code with ndk clang

# note that aarch64-linux-android$API-clang++ is recommended instead of clang alone
# armv7a-linux-android$API-clang
# i686-linux-android$API-clang
# x86_64-linux-android$API-clang
NDK_TOOLCHAIN=/path/to/android-ndk-r22/toolchains/llvm/prebuilt/linux-aarch64
$NDK_TOOLCHAIN/bin/aarch64-linux-android30-clang++ test.cpp -o test

# if you want to use clang alone, you need to specify --sysroot=/path/to/sysroot
# for example --sysroot=/data/data/com.termux/files (termux default sysroot)
# if you don't specify a target, the default is --target=aarch64-unknown-linux-android
$NDK_TOOLCHAIN/bin/clang --sysroot=/path/to/sysroot hello.c -o hello

# c++ needs link flags -lc++_shared -static-libstdc++
$NDK_TOOLCHAIN/bin/clang++ --sysroot=/path/to/sysroot -lc++_shared -static-libstdc++ hello.cpp -o hello

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

Issues

  • Every NDK version has a lot of changes, direct compilation will fail, the build script are not generic, so please solve the error yourself.

  • llvm-rs-cc may have bugs, I rewrote the rs_cc_options.cpp file.

  • because RSCCOptions.inc compilation error, I can't solve it yet.

  • RSCCOptions.inc is generated by llvm-tblgen, but which has errors

  • llvm-tblgen -I=../llvm/include RSCCOptions.tb -o RSCCOptions.inc

  • if anyone konws, please submit to issue

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].