Skip to content

Commit

Permalink
Android standalone toolchains are not longer necessary (#874)
Browse files Browse the repository at this point in the history
* Android standalone toolchains are not longer necessary

The latest NDK (19) contains ABI/API level specific command line
tools making standalone toolchains unnecessary. This change adapts
to the new model which greatly simplifies the build script and
ensures the latest version of the tools is being used.

Note that this requires a fairly recent version of CMake which fixes
a bug related to ranlib. This change was tested with CMake 3.13
(CMake 3.7 does not work).

* Modify CI build script to fetch recent CMake

* Remove dependency on standalone toolchains in Windows README

* Use correct CMake path

* Update NDK to latest

* Only download CMake and NDK for Android builds

* Add version constant for ninja

* Make output more quiet
  • Loading branch information
romainguy authored Feb 25, 2019
1 parent 2378e64 commit b3284ed
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 188 deletions.
81 changes: 4 additions & 77 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ and tools.

To build Filament, you must first install the following tools:

- CMake 3.4 (or more recent)
- CMake 3.13 (or more recent)
- clang 7.0 (or more recent)
- [ninja 1.8](https://github.com/ninja-build/ninja/wiki/Pre-built-Ninja-packages) (or more recent)

Expand All @@ -169,7 +169,7 @@ To build Filament for Android you must also install the following:

- Android Studio 3.3
- Android SDK
- Android NDK
- Android NDK 19 or higher

### Environment variables

Expand Down Expand Up @@ -334,10 +334,9 @@ Install the following components:

- [Windows 10 SDK](https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk)
- [Visual Studio 2015 or 2017](https://www.visualstudio.com/downloads)
- [Clang 6](http://releases.llvm.org/download.html)
- [Clang 7](http://releases.llvm.org/download.html)
- [Python 3.7](https://www.python.org/ftp/python/3.7.0/python-3.7.0.exe)
- [Git 2.16.1 or later](https://github.com/git-for-windows/git/releases/download/v2.16.1.windows.4/PortableGit-2.16.1.4-64-bit.7z.exe)
- [Cmake 3.11 or later](https://cmake.org/files/v3.11/cmake-3.11.0-rc1-win64-x64.msi)
- [Cmake 3.13 or later](https://github.com/Kitware/CMake/releases/download/v3.13.4/cmake-3.13.4-win64-x64.msi)

If you're using Visual Studio 2017, you'll also need to install the [LLVM Compiler
Toolchain](https://marketplace.visualstudio.com/items?itemName=LLVMExtensions.llvm-toolchain)
Expand Down Expand Up @@ -463,24 +462,6 @@ Run `build.sh -h` for more information.

#### ARM 64-bit target (arm64-v8a)

##### Linux toolchain

```
$ $SDK/ndk-bundle/build/tools/make_standalone_toolchain.py --arch arm64 --api 21 \
--stl libc++ --force \
--install-dir toolchains/Linux/aarch64-linux-android-4.9
```

##### Darwin toolchain

```
$ $SDK/ndk-bundle/build/tools/make_standalone_toolchain.py --arch arm64 --api 21 \
--stl libc++ --force \
--install-dir toolchains/Darwin/aarch64-linux-android-4.9
```

##### Compiling

Then invoke CMake in a build directory of your choice, inside of filament's directory:

```
Expand Down Expand Up @@ -508,24 +489,6 @@ binaries should be found in `out/android-release/filament/lib/arm64-v8a`.

#### ARM 32-bit target (armeabi-v7a)

##### Linux toolchain

```
$ $SDK/ndk-bundle/build/tools/make_standalone_toolchain.py --arch arm --api 21 \
--stl libc++ --force \
--install-dir toolchains/Linux/arm-linux-androideabi-4.9
```

##### Darwin toolchain

```
$ $SDK/ndk-bundle/build/tools/make_standalone_toolchain.py --arch arm --api 21 \
--stl libc++ --force \
--install-dir toolchains/Darwin/arm-linux-androideabi-4.9
```

##### Compiling

Then invoke CMake in a build directory of your choice, inside of filament's directory:

```
Expand Down Expand Up @@ -553,24 +516,6 @@ binaries should be found in `out/android-release/filament/lib/armeabi-v7a`.

#### Intel 64-bit target (x86_64)

##### Linux toolchain

```
$ $SDK/ndk-bundle/build/tools/make_standalone_toolchain.py --arch x86_64 --api 21 \
--stl libc++ --force \
--install-dir toolchains/Linux/x86_64-linux-android-4.9
```

##### Darwin toolchain

```
$ $SDK/ndk-bundle/build/tools/make_standalone_toolchain.py --arch x86_64 --api 21 \
--stl libc++ --force \
--install-dir toolchains/Darwin/x86_64-linux-android-4.9
```

##### Compiling

Then invoke CMake in a build directory of your choice, sibling of filament's directory:

```
Expand Down Expand Up @@ -598,24 +543,6 @@ binaries should be found in `out/android-release/filament/lib/x86_64`.

#### Intel 32-bit target (x86)

##### Linux toolchain

```
$ $SDK/ndk-bundle/build/tools/make_standalone_toolchain.py --arch x86 --api 21 \
--stl libc++ --force \
--install-dir toolchains/Linux/i686-linux-android-4.9
```

##### Darwin toolchain

```
$ $SDK/ndk-bundle/build/tools/make_standalone_toolchain.py --arch x86 --api 21 \
--stl libc++ --force \
--install-dir toolchains/Darwin/i686-linux-android-4.9
```

##### Compiling

Then invoke CMake in a build directory of your choice, sibling of filament's directory:

```
Expand Down
37 changes: 0 additions & 37 deletions android/Windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,43 +39,6 @@ ninja matc resgen cmgen
The build should succeed and a `ImportExecutables-Release.cmake` file should automatically be
created at Filament's root directory.

## Toolchains

Generate a toolchain for each Android architecture you're interested in building for.

From Filament's root directory, run the NDK `make_standalone_toolchain.py` script for each
architecture.

```
python %ANDROID_HOME%\ndk-bundle\build\tools\make_standalone_toolchain.py ^
--arch arm64 ^
--api 21 ^
--stl libc++ ^
--force ^
--install-dir "toolchains/Windows/aarch64-linux-android-4.9"
python %ANDROID_HOME%\ndk-bundle\build\tools\make_standalone_toolchain.py ^
--arch arm ^
--api 21 ^
--stl libc++ ^
--force ^
--install-dir "toolchains/Windows/arm-linux-androideabi-4.9"
python %ANDROID_HOME%\ndk-bundle\build\tools\make_standalone_toolchain.py ^
--arch x86_64 ^
--api 21 ^
--stl libc++ ^
--force ^
--install-dir "toolchains/Windows/x86_64-linux-android-4.9"
python %ANDROID_HOME%\ndk-bundle\build\tools\make_standalone_toolchain.py ^
--arch x86 ^
--api 21 ^
--stl libc++ ^
--force ^
--install-dir "toolchains/Windows/x86-linux-android-4.9"
````
## Build

1. Create the build directories.
Expand Down
60 changes: 1 addition & 59 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/bin/bash
set -e

# NDK API level
API_LEVEL=21
# Host tools required by Android, WebGL, and iOS builds
MOBILE_HOST_TOOLS="matc resgen cmgen"
WEB_HOST_TOOLS="${MOBILE_HOST_TOOLS} mipgen filamesh"
Expand Down Expand Up @@ -31,10 +29,8 @@ function print_help {
echo " -p platform1,platform2,..."
echo " Where platformN is [desktop|android|ios|webgl|all]."
echo " Platform(s) to build, defaults to desktop."
echo " Building for Android or iOS will automatically generate / download"
echo " Building for iOS will automatically generate / download"
echo " the toolchains if needed and perform a partial desktop build."
echo " -t"
echo " Generate the Android toolchain, requires \$ANDROID_HOME to be set."
echo " -u"
echo " Run all unit tests, will trigger a debug build if needed."
echo " -v"
Expand Down Expand Up @@ -100,8 +96,6 @@ ENABLE_JAVA=ON

INSTALL_COMMAND=

GENERATE_TOOLCHAINS=false

VULKAN_ANDROID_OPTION="-DFILAMENT_SUPPORTS_VULKAN=OFF"

BUILD_FILAMAT_ANDROID=false
Expand All @@ -116,8 +110,6 @@ BUILD_CUSTOM_TARGETS=
UNAME=`echo $(uname)`
LC_UNAME=`echo ${UNAME} | tr '[:upper:]' '[:lower:]'`

TOOLCHAIN_SCRIPT=${ANDROID_HOME}/ndk-bundle/build/tools/make_standalone_toolchain.py

# Functions

function build_clean {
Expand All @@ -127,43 +119,6 @@ function build_clean {
rm -Rf android/filament-android/.externalNativeBuild
}

function generate_toolchain {
local ARCH=$1
local ARCH_NAME=$2
local TOOLCHAIN_NAME=toolchains/${UNAME}/${ARCH_NAME}-4.9

if [ -z "$ANDROID_HOME" ]; then
echo "The environment variable \$ANDROID_HOME is not set." >&2
exit 1
fi

if [ ! -f "$TOOLCHAIN_SCRIPT" ]; then
echo "The NDK is not properly installed in $ANDROID_HOME." >&2
exit 1
fi

if [ -d "$TOOLCHAIN_NAME" ]; then
echo "Removing existing $ARCH toolchain..."
rm -Rf ${TOOLCHAIN_NAME}
fi

echo "Generating $ARCH toolchain..."

${TOOLCHAIN_SCRIPT} \
--arch ${ARCH} \
--api ${API_LEVEL} \
--stl libc++ \
--force \
--install-dir ${TOOLCHAIN_NAME}
}

function generate_toolchains {
generate_toolchain "arm64" "aarch64-linux-android"
generate_toolchain "arm" "arm-linux-androideabi"
generate_toolchain "x86_64" "x86_64-linux-android"
generate_toolchain "x86" "i686-linux-android"
}

function build_desktop_target {
local LC_TARGET=`echo $1 | tr '[:upper:]' '[:lower:]'`
local BUILD_TARGETS=$2
Expand Down Expand Up @@ -319,12 +274,6 @@ function build_android_target {
function build_android_arch {
local ARCH=$1
local ARCH_NAME=$2
local TOOLCHAIN_ARCH=$3
local TOOLCHAIN_NAME=toolchains/${UNAME}/${ARCH_NAME}-4.9

if [ ! -d "$TOOLCHAIN_NAME" ]; then
generate_toolchain ${TOOLCHAIN_ARCH} ${ARCH_NAME}
fi

if [ "$ISSUE_DEBUG_BUILD" == "true" ]; then
build_android_target "Debug" "$ARCH"
Expand Down Expand Up @@ -636,9 +585,6 @@ while getopts ":hacfijmp:tuvsl" opt; do
esac
done
;;
t)
GENERATE_TOOLCHAINS=true
;;
u)
ISSUE_DEBUG_BUILD=true
RUN_TESTS=true
Expand Down Expand Up @@ -701,10 +647,6 @@ if [ "$ISSUE_CLEAN" == "true" ]; then
build_clean
fi

if [ "$GENERATE_TOOLCHAINS" == "true" ]; then
generate_toolchains
fi

if [ "$ISSUE_DESKTOP_BUILD" == "true" ]; then
build_desktop
fi
Expand Down
2 changes: 2 additions & 0 deletions build/android/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ set -x
UNAME=`echo $(uname)`
LC_UNAME=`echo $UNAME | tr '[:upper:]' '[:lower:]'`

FILAMENT_ANDROID_CI_BUILD=true

# build-common.sh will generate the following variables:
# $GENERATE_ARCHIVES
# $BUILD_DEBUG
Expand Down
25 changes: 23 additions & 2 deletions build/linux/ci-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,34 @@
CLANG_VERSION=7
# version of libcxx and libcxxabi we want to use
CXX_VERSION=7.0.0
# version of CMake to use instead of the default one
CMAKE_VERSION=3.13.4
# version of ninja to use
NINJA_VERSION=1.8.2

# Steps specific to our CI environment
# CI runs on Ubuntu 14.04, we need to install clang-6.0 and the
# CI runs on Ubuntu 14.04, we need to install clang-7.0 and the
# appropriate libc++ ourselves
if [ "$KOKORO_BUILD_ID" ]; then
sudo ln -s /usr/include/x86_64-linux-gnu/asm /usr/include/asm

if [ "$FILAMENT_ANDROID_CI_BUILD" ]; then
# Update NDK
yes | $ANDROID_HOME/tools/bin/sdkmanager "ndk-bundle" > /dev/null

# Install CMake
mkdir -p cmake
cd cmake

sudo wget https://github.com/Kitware/CMake/releases/download/v$CMAKE_VERSION/cmake-$CMAKE_VERSION-Linux-x86_64.sh
sudo chmod +x ./cmake-$CMAKE_VERSION-Linux-x86_64.sh
sudo ./cmake-$CMAKE_VERSION-Linux-x86_64.sh --skip-license > /dev/null
sudo update-alternatives --install /usr/bin/cmake cmake `pwd`/bin/cmake 1 --force

cd ..
fi

# Install clang
# This may or may not be needed...
# sudo apt-key adv --keyserver apt.llvm.org --recv-keys 15CF4D18AF4F7421
sudo apt-add-repository "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-$CLANG_VERSION main"
Expand Down Expand Up @@ -68,6 +89,6 @@ if [ "$KOKORO_BUILD_ID" ]; then
export FILAMENT_REQUIRES_CXXABI=false
fi

wget -q https://github.com/ninja-build/ninja/releases/download/v1.8.2/ninja-linux.zip
wget -q https://github.com/ninja-build/ninja/releases/download/v$NINJA_VERSION/ninja-linux.zip
unzip -q ninja-linux.zip
export PATH="$PWD:$PATH"
13 changes: 10 additions & 3 deletions build/toolchain-aarch64-linux-android.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,28 @@ set(CMAKE_SYSTEM_NAME Linux)
# this one not so much
set(CMAKE_SYSTEM_VERSION 1)

# android
set(API_LEVEL 21)

# architecture
set(ARCH aarch64-linux-android)
set(DIST_ARCH arm64-v8a)

# toolchain
set(TOOLCHAIN ${CMAKE_SOURCE_DIR}/toolchains/${CMAKE_HOST_SYSTEM_NAME}/${ARCH}-4.9)
string(TOLOWER ${CMAKE_HOST_SYSTEM_NAME} HOST_NAME_L)
set(TOOLCHAIN $ENV{ANDROID_HOME}/ndk-bundle/toolchains/llvm/prebuilt/${HOST_NAME_L}-x86_64/)

# specify the cross compiler
set(COMPILER_SUFFIX)
if(WIN32)
set(COMPILER_SUFFIX ".cmd")
set(CMAKE_AR ${TOOLCHAIN}/bin/${ARCH}-ar.exe CACHE FILEPATH "Archiver")
endif()
set(CMAKE_C_COMPILER ${TOOLCHAIN}/bin/${ARCH}-clang${COMPILER_SUFFIX})
set(CMAKE_CXX_COMPILER ${TOOLCHAIN}/bin/${ARCH}-clang++${COMPILER_SUFFIX})
set(CMAKE_C_COMPILER ${TOOLCHAIN}/bin/${ARCH}${API_LEVEL}-clang${COMPILER_SUFFIX})
set(CMAKE_CXX_COMPILER ${TOOLCHAIN}/bin/${ARCH}${API_LEVEL}-clang++${COMPILER_SUFFIX})
set(CMAKE_AR ${TOOLCHAIN}/bin/${ARCH}-ar${COMPILER_SUFFIX})
set(CMAKE_RANLIB ${TOOLCHAIN}/bin/${ARCH}-ranlib${COMPILER_SUFFIX})
set(CMAKE_STRIP ${TOOLCHAIN}/bin/${ARCH}-strip${COMPILER_SUFFIX})

# where is the target environment
set(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN}/sysroot)
Expand Down
Loading

0 comments on commit b3284ed

Please sign in to comment.