Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android standalone toolchains are not longer necessary #874

Merged
merged 9 commits into from
Feb 25, 2019
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could relax this requirement for users not building Android?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about it but wanted to keep things simple.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the Android build should check for this requirement explicitly and fail with a useful message. The build errors I got were very opaque with cmake 3.10 and I took a circuitous route to get here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

build.sh now makes the check.

- 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
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 @@ -635,9 +584,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 @@ -700,10 +646,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
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
16 changes: 12 additions & 4 deletions build/toolchain-arm7-linux-android.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,29 @@ set(CMAKE_SYSTEM_NAME Linux)
# this one not so much
set(CMAKE_SYSTEM_VERSION 1)

# android
set(API_LEVEL 21)

# architecture
set(ARCH arm-linux-androideabi)
set(ARCH armv7a-linux-androideabi)
set(AR_ARCH arm-linux-androideabi)
set(DIST_ARCH armeabi-v7a)

# 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/${AR_ARCH}-ar${COMPILER_SUFFIX})
set(CMAKE_RANLIB ${TOOLCHAIN}/bin/${AR_ARCH}-ranlib${COMPILER_SUFFIX})
set(CMAKE_STRIP ${TOOLCHAIN}/bin/${AR_ARCH}-strip${COMPILER_SUFFIX})

# where is the target environment
set(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN}/sysroot)
Expand Down
13 changes: 10 additions & 3 deletions build/toolchain-x86-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 i686-linux-android)
set(DIST_ARCH x86)

# 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
13 changes: 10 additions & 3 deletions build/toolchain-x86_64-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 x86_64-linux-android)
set(DIST_ARCH x86_64)

# 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