Skip to content

Android & emscripten: Make buildscript work on m1 (arm64) macOS #196

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions android/1_download_library.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ else
exit 1
fi

SDK_VERSION="9477386_latest"
SDK_VERSION="11076708_latest"
SDK_URL="https://dl.google.com/android/repository/commandlinetools-${SDK_PLATFORM}-${SDK_VERSION}.zip"
curl -sSLOR "$SDK_URL"
unzip commandlinetools-${SDK_PLATFORM}-${SDK_VERSION}.zip
Expand All @@ -53,12 +53,12 @@ msg " [2] Installing SDK and Platform-tools"
# Otherwise installed to the wrong directory
cd android-sdk

# Android SDK Build-tools, revision 33.0.0
echo "y" | ./cmdline-tools/latest/bin/sdkmanager --verbose "build-tools;33.0.0"
# Android SDK Build-tools, revision 36.0.0
echo "y" | ./cmdline-tools/latest/bin/sdkmanager --verbose "build-tools;36.0.0"
# Android SDK Platform-tools
echo "y" | ./cmdline-tools/latest/bin/sdkmanager --verbose "platform-tools"
# SDK Platform Android 13, API 33
echo "y" | ./cmdline-tools/latest/bin/sdkmanager --verbose "platforms;android-33"
# SDK Platform Android 15, API 35
echo "y" | ./cmdline-tools/latest/bin/sdkmanager --verbose "platforms;android-35"
# Android Support Library Repository
echo "y" | ./cmdline-tools/latest/bin/sdkmanager --verbose "extras;android;m2repository"
# Google Repository
Expand All @@ -68,7 +68,7 @@ echo "y" | ./cmdline-tools/latest/bin/sdkmanager --verbose "cmake;3.22.1"

msg " [3] Installing Android NDK"

echo "y" | ./cmdline-tools/latest/bin/sdkmanager --verbose "ndk;21.4.7075529"
echo "y" | ./cmdline-tools/latest/bin/sdkmanager --verbose "ndk;24.0.8215888"

cd ..

Expand Down
15 changes: 7 additions & 8 deletions android/2_build_toolchain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,12 @@ function build() {
# $2: Toolchain architecture
# $3: Android arch
# $4: host for configure
# $5: additional CPP flags

cd $WORKSPACE

echo "Preparing $1 toolchain"

export TARGET_API=16
export TARGET_API=19
if [ "$3" = "arm64" ]; then
# Minimum API 21 on ARM64
export TARGET_API=21
Expand All @@ -84,7 +83,7 @@ function build() {
export NM=$NDK_PATH/llvm-nm
export RANLIB=$NDK_PATH/llvm-ranlib

export CFLAGS="-no-integrated-as -g0 -O2 -fPIC $5"
export CFLAGS="-g0 -O2 -fPIC"
export CXXFLAGS="$CFLAGS"
export CPPFLAGS="-I$PLATFORM_PREFIX/include -I$ANDROID_NDK/sources/android/cpufeatures"
export LDFLAGS="-L$PLATFORM_PREFIX/lib"
Expand Down Expand Up @@ -125,7 +124,7 @@ function build() {
}

export SDK_ROOT=$WORKSPACE/android-sdk
export ANDROID_NDK=$SDK_ROOT/ndk/21.4.7075529
export ANDROID_NDK=$SDK_ROOT/ndk/24.0.8215888

export MAKEFLAGS="-j${nproc:-2}"

Expand All @@ -147,13 +146,13 @@ export ac_cv_func_mmap_fixed_mapped=yes
export CMAKE_SYSTEM_NAME=Android

# ARMeabi-v7a
build "ARMeabi-v7a" "armeabi-v7a" "arm" "armv7a-linux-androideabi" "-march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3"
build "ARMeabi-v7a" "armeabi-v7a" "arm" "armv7a-linux-androideabi"

# arm64-v8a
build "AArch64" "arm64-v8a" "arm64" "aarch64-linux-android" ""
build "AArch64" "arm64-v8a" "arm64" "aarch64-linux-android"

# x86
build "x86" "x86" "x86" "i686-linux-android" ""
build "x86" "x86" "x86" "i686-linux-android"

# x86_64
build "x86_64" "x86_64" "x86_64" "x86_64-linux-android" ""
build "x86_64" "x86_64" "x86_64" "x86_64-linux-android"
12 changes: 2 additions & 10 deletions emscripten/1_download_library.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ if hash emcc >/dev/null 2>&1; then
else
echo "Preparing portable SDK"

if [ $os = "Darwin" ] ; then
if [ "$(uname -m)" = "arm64" ] ; then
echo "macOS arm64 requires a preinstalled emscripten."
echo "Run 'brew install emscripten' to install it."
exit 1
fi
fi

rm -rf emsdk-portable
git_clone https://github.com/emscripten-core/emsdk.git emsdk-portable

Expand All @@ -43,8 +35,8 @@ else
touch .emscripten

# Download and install the latest SDK tools and set up the compiler configuration to point to it.
./emsdk install 3.1.74
./emsdk activate 3.1.74
./emsdk install 4.0.5
./emsdk activate 4.0.5

# Set the current Emscripten path
source ./emsdk_env.sh
Expand Down
23 changes: 11 additions & 12 deletions emscripten/2_build_toolchain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ if [ ! -f .patches-applied ]; then
autoreconf -fi
)

# Make wasm32-unknown-emscripten available
(cd $LIBOGG_DIR
autoreconf -fi
)

(cd $LIBVORBIS_DIR
autoreconf -fi
)

# disable unsupported compiler flags by emcc clang in libogg
perl -pi -e 's/-O20/-g0 -O2/g' $LIBOGG_DIR/configure

Expand Down Expand Up @@ -68,6 +77,8 @@ function set_build_flags {
export EM_PKG_CONFIG_PATH="$PLATFORM_PREFIX/lib/pkgconfig"
export CMAKE_EXTRA_ARGS="-DCMAKE_FIND_ROOT_PATH=$PLATFORM_PREFIX"

export TARGET_HOST="wasm32-unknown-emscripten"

# force mmap support in mpg123 (actually unused, but needed for building)
export ac_cv_func_mmap_fixed_mapped=yes

Expand All @@ -89,12 +100,6 @@ cd $WORKSPACE
# Install libraries
set_build_flags

if [ $os = "Darwin" ] ; then
# Workaround wrong libtool being detected
# Do not use this on Linux, fails with autoconf 2.69
export TARGET_HOST="asmjs-unknown-emscripten"
fi

install_lib_cmake $ZLIB_DIR $ZLIB_ARGS
install_lib_cmake $LIBPNG_DIR $LIBPNG_ARGS
install_lib_cmake $FREETYPE_DIR $FREETYPE_ARGS -DFT_DISABLE_HARFBUZZ=ON
Expand All @@ -116,13 +121,7 @@ install_lib_cmake $NLOHMANNJSON_DIR $NLOHMANNJSON_ARGS
install_lib_meson $INIH_DIR $INIH_ARGS
#install_lib $LHASA_DIR $LHASA_ARGS
install_lib_cmake $FMT_DIR $FMT_ARGS

# emscripten TARGET_HOST does not work for all libraries but SDL2 requires it
export TARGET_HOST="asmjs-unknown-emscripten"
rm -f config.cache
install_lib $SDL2_DIR $SDL2_ARGS --disable-assembly --disable-threads --disable-cpuinfo
rm -f config.cache
unset TARGET_HOST

install_lib_icu_cross
icu_force_data_install
Expand Down