mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-02-06 06:55:07 +00:00
Make android platform's cmake flags configurable (#3239)
Don't hardcode the cmake configurations in the Android platform's CMakeLists.txt. Fixes https://github.com/bytecodealliance/wasm-micro-runtime/issues/3238
This commit is contained in:
parent
29d83224a8
commit
76254183f9
|
@ -202,11 +202,17 @@ jobs:
|
|||
make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1"
|
||||
- make_options_run_mode: $MULTI_TIER_JIT_BUILD_OPTIONS
|
||||
make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1"
|
||||
# Fast-JIT and Multi-Tier-JIT mode don't support android(X86-32)
|
||||
# Fast-JIT and Multi-Tier-JIT mode don't support android
|
||||
- make_options_run_mode: $FAST_JIT_BUILD_OPTIONS
|
||||
platform: android
|
||||
- make_options_run_mode: $MULTI_TIER_JIT_BUILD_OPTIONS
|
||||
platform: android
|
||||
# LLVM JIT pre-built binary wasn't compiled by Android NDK
|
||||
# and isn't available for android
|
||||
- make_options_run_mode: $LLVM_LAZY_JIT_BUILD_OPTIONS
|
||||
platform: android
|
||||
- make_options_run_mode: $LLVM_EAGER_JIT_BUILD_OPTIONS
|
||||
platform: android
|
||||
include:
|
||||
- os: ubuntu-22.04
|
||||
llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2204.outputs.cache_key }}
|
||||
|
@ -232,13 +238,23 @@ jobs:
|
|||
if: endsWith(matrix.make_options_run_mode, '_JIT_BUILD_OPTIONS') && (steps.retrieve_llvm_libs.outputs.cache-hit != 'true')
|
||||
run: echo "::error::can not get prebuilt llvm libraries" && exit 1
|
||||
|
||||
- name: Build iwasm
|
||||
- name: Build iwasm for linux
|
||||
if: matrix.platform == 'linux'
|
||||
run: |
|
||||
mkdir build && cd build
|
||||
cmake .. ${{ matrix.make_options_run_mode }} ${{ matrix.make_options_feature }}
|
||||
cmake --build . --config Release --parallel 4
|
||||
working-directory: product-mini/platforms/${{ matrix.platform }}
|
||||
|
||||
- name: Build iwasm for android
|
||||
if: matrix.platform == 'android'
|
||||
run: |
|
||||
mkdir build && cd build
|
||||
cmake .. ${{ matrix.make_options_run_mode }} ${{ matrix.make_options_feature }} \
|
||||
-DWAMR_BUILD_TARGET=X86_64
|
||||
cmake --build . --config Release --parallel 4
|
||||
working-directory: product-mini/platforms/${{ matrix.platform }}
|
||||
|
||||
- name: Build and run unit tests
|
||||
run: |
|
||||
mkdir build-unittests && cd build-unittests
|
||||
|
@ -456,7 +472,7 @@ jobs:
|
|||
cmake --build . --config Debug --parallel 4
|
||||
./iwasm wasm-apps/trap.wasm | grep "#" > call_stack.txt
|
||||
./iwasm wasm-apps/trap.aot | grep "#" > call_stack_aot.txt
|
||||
bash -x ../symbolicate.sh
|
||||
bash -x ../symbolicate.sh
|
||||
|
||||
test:
|
||||
needs:
|
||||
|
@ -556,7 +572,6 @@ jobs:
|
|||
make -j AR=/opt/wasi-sdk/bin/llvm-ar NM=/opt/wasi-sdk/bin/llvm-nm CC=/opt/wasi-sdk/bin/clang THREAD_MODEL=posix
|
||||
echo "SYSROOT_PATH=$PWD/sysroot" >> $GITHUB_ENV
|
||||
|
||||
|
||||
- name: set env variable(if llvm are used)
|
||||
if: matrix.running_mode == 'aot' || matrix.running_mode == 'jit' || matrix.running_mode == 'multi-tier-jit'
|
||||
run: echo "USE_LLVM=true" >> $GITHUB_ENV
|
||||
|
|
|
@ -312,7 +312,7 @@ WAMR provides some features which can be easily configured by passing options to
|
|||
|
||||
## Android
|
||||
|
||||
able to generate a shared library support Android platform.
|
||||
Able to generate a shared library support Android platform.
|
||||
- need an [android SDK](https://developer.android.com/studio). Go and get the "Command line tools only"
|
||||
- look for a command named *sdkmanager* and download below components. version numbers might need to check and pick others
|
||||
- "build-tools;29.0.3"
|
||||
|
@ -326,7 +326,7 @@ able to generate a shared library support Android platform.
|
|||
- export ANDROID_NDK_LATEST_HOME=/the/path/of/downloaded/sdk/ndk/2x.xxx/
|
||||
- ready to go
|
||||
|
||||
Use such commands, you are able to compile with default configurations. Any compiling requirement should be satisfied by modifying product-mini/platforms/android/CMakeList.txt. For example, chaning ${WAMR_BUILD_TARGET} in CMakeList could get different libraries support different ABIs.
|
||||
Use such commands, you are able to compile with default configurations.
|
||||
|
||||
``` shell
|
||||
$ cd product-mini/platforms/android/
|
||||
|
@ -339,6 +339,15 @@ $ # include/ includes all necesary head files
|
|||
$ # lib includes libiwasm.so
|
||||
```
|
||||
|
||||
To change the target architecture and ABI, you can define `WAMR_BUILD_TARGET` or `ANDROID_ABI` respectively. To build for [supported Android ABIs](https://developer.android.com/ndk/guides/abis#sa):
|
||||
|
||||
```shell
|
||||
$ cmake .. -DWAMR_BUILD_TARGET=X86_32 -DANDROID_ABI=x86 # 32-bit Intel CPU
|
||||
$ cmake .. -DWAMR_BUILD_TARGET=X86_64 -DANDROID_ABI=x86_64 # 64-bit Intel CPU
|
||||
$ cmake .. -DWAMR_BUILD_TARGET=ARMV7A -DANDROID_ABI=armeabi-v7a # 32-bit ARM CPU
|
||||
$ cmake .. -DWAMR_BUILD_TARGET=AARCH64 -DANDROID_ABI=arm64-v8a # 64-bit ARM CPU
|
||||
```
|
||||
|
||||
## NuttX
|
||||
|
||||
WAMR is intergrated with NuttX, just enable the WAMR in Kconfig option (Application Configuration/Interpreters).
|
||||
|
|
|
@ -1,53 +1,59 @@
|
|||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
cmake_minimum_required (VERSION 3.4.1)
|
||||
|
||||
set (CMAKE_VERBOSE_MAKEFILE on)
|
||||
set (CMAKE_BUILD_TYPE Release)
|
||||
|
||||
# https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2004-Readme.md#environment-variables-3
|
||||
set (CMAKE_TOOLCHAIN_FILE "$ENV{ANDROID_NDK_LATEST_HOME}/build/cmake/android.toolchain.cmake")
|
||||
set (ANDROID_SDK $ENV{ANDROID_HOME})
|
||||
set (ANDROID_NDK $ENV{ANDROID_NDK_LATEST_HOME})
|
||||
|
||||
set (ANDROID_ABI "x86")
|
||||
set (ANDROID_LD lld)
|
||||
if (NOT DEFINED ANDROID_PLATFORM)
|
||||
set (ANDROID_PLATFORM 24)
|
||||
endif ()
|
||||
|
||||
project (iwasm)
|
||||
|
||||
set (WAMR_BUILD_PLATFORM "android")
|
||||
set (WAMR_BUILD_TARGET "X86_32")
|
||||
set (WAMR_BUILD_TYPE Release)
|
||||
set (WAMR_BUILD_INTERP 1)
|
||||
set (WAMR_BUILD_AOT 1)
|
||||
set (WAMR_BUILD_JIT 0)
|
||||
set (WAMR_BUILD_LIBC_BUILTIN 1)
|
||||
set (WAMR_BUILD_LIBC_WASI 1)
|
||||
cmake_minimum_required (VERSION 3.14)
|
||||
|
||||
# Reset default linker flags
|
||||
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
|
||||
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
|
||||
|
||||
# Set WAMR_BUILD_TARGET, currently values supported:
|
||||
# "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]", "MIPS", "XTENSA"
|
||||
if (NOT DEFINED WAMR_BUILD_TARGET)
|
||||
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
# Build as X86_64 by default in 64-bit platform
|
||||
set (WAMR_BUILD_TARGET "X86_64")
|
||||
elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
|
||||
# Build as X86_32 by default in 32-bit platform
|
||||
set (WAMR_BUILD_TARGET "X86_32")
|
||||
message (FATAL_ERROR "WAMR_BUILD_TARGET isn't set")
|
||||
endif ()
|
||||
|
||||
if (NOT (WAMR_BUILD_TARGET STREQUAL "X86_64"
|
||||
OR WAMR_BUILD_TARGET STREQUAL "X86_32"
|
||||
OR WAMR_BUILD_TARGET MATCHES "AARCH64.*"
|
||||
OR WAMR_BUILD_TARGET MATCHES "ARM.*"
|
||||
OR WAMR_BUILD_TARGET MATCHES "RISCV64.*"))
|
||||
message (FATAL_ERROR "Unsupported build target platform ${WAMR_BUILD_TARGET}!")
|
||||
endif ()
|
||||
|
||||
if (NOT DEFINED ANDROID_ABI)
|
||||
if (WAMR_BUILD_TARGET STREQUAL "X86_64")
|
||||
set (ANDROID_ABI "x86_64")
|
||||
elseif (WAMR_BUILD_TARGET STREQUAL "X86_32")
|
||||
set (ANDROID_ABI "x86")
|
||||
elseif (WAMR_BUILD_TARGET MATCHES "AARCH64.*")
|
||||
set (ANDROID_ABI "arm64-v8a")
|
||||
elseif (WAMR_BUILD_TARGET MATCHES "ARM.*")
|
||||
set (ANDROID_ABI "armeabi-v7a")
|
||||
else ()
|
||||
message(SEND_ERROR "Unsupported build target platform!")
|
||||
set (ANDROID_ABI "riscv64")
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
if (NOT DEFINED ANDROID_LD)
|
||||
set (ANDROID_LD lld)
|
||||
endif ()
|
||||
|
||||
if (NOT DEFINED ANDROID_PLATFORM)
|
||||
set (ANDROID_PLATFORM 24)
|
||||
endif ()
|
||||
|
||||
# https://android.googlesource.com/platform/ndk/+/master/build/cmake/android.toolchain.cmake
|
||||
set (CMAKE_TOOLCHAIN_FILE "$ENV{ANDROID_NDK_LATEST_HOME}/build/cmake/android.toolchain.cmake")
|
||||
set (ANDROID_SDK $ENV{ANDROID_HOME})
|
||||
set (ANDROID_NDK $ENV{ANDROID_NDK_LATEST_HOME})
|
||||
|
||||
project (iwasm)
|
||||
|
||||
set (WAMR_BUILD_PLATFORM "android")
|
||||
|
||||
set (CMAKE_VERBOSE_MAKEFILE ON)
|
||||
|
||||
if (NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE Release)
|
||||
set (CMAKE_BUILD_TYPE Release)
|
||||
endif ()
|
||||
|
||||
if (NOT DEFINED WAMR_BUILD_INTERP)
|
||||
|
@ -55,6 +61,11 @@ if (NOT DEFINED WAMR_BUILD_INTERP)
|
|||
set (WAMR_BUILD_INTERP 1)
|
||||
endif ()
|
||||
|
||||
if (NOT DEFINED WAMR_BUILD_FAST_INTERP)
|
||||
# Enable fast interpreter
|
||||
set (WAMR_BUILD_FAST_INTERP 1)
|
||||
endif ()
|
||||
|
||||
if (NOT DEFINED WAMR_BUILD_AOT)
|
||||
# Enable AOT by default.
|
||||
set (WAMR_BUILD_AOT 1)
|
||||
|
@ -75,6 +86,21 @@ if (NOT DEFINED WAMR_BUILD_LIBC_WASI)
|
|||
set (WAMR_BUILD_LIBC_WASI 1)
|
||||
endif ()
|
||||
|
||||
if (NOT DEFINED WAMR_BUILD_MULTI_MODULE)
|
||||
# Disable multiple modules by default
|
||||
set (WAMR_BUILD_MULTI_MODULE 0)
|
||||
endif ()
|
||||
|
||||
if (NOT DEFINED WAMR_BUILD_LIB_PTHREAD)
|
||||
# Disable pthread library by default
|
||||
set (WAMR_BUILD_LIB_PTHREAD 0)
|
||||
endif ()
|
||||
|
||||
if (NOT DEFINED WAMR_BUILD_LIB_WASI_THREADS)
|
||||
# Disable wasi threads library by default
|
||||
set (WAMR_BUILD_LIB_WASI_THREADS 0)
|
||||
endif()
|
||||
|
||||
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
|
||||
|
||||
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
|
||||
|
|
Loading…
Reference in New Issue
Block a user