Add support for ARMv8 (64-bit) on Android

This commit is contained in:
Pedro J. Estébanez 2017-07-25 12:28:31 +02:00 committed by Xavier Sellier
parent 83d5db294d
commit 4cb50673d7
4 changed files with 41 additions and 14 deletions

View File

@ -150,6 +150,8 @@ if env['android_arch'] == 'armv6':
lib_arch_dir = 'armeabi'
elif env['android_arch'] == 'armv7':
lib_arch_dir = 'armeabi-v7a'
elif env['android_arch'] == 'arm64v8':
lib_arch_dir = 'arm64-v8a'
elif env['android_arch'] == 'x86':
lib_arch_dir = 'x86'
else:

View File

@ -22,7 +22,7 @@ def get_opts():
('ANDROID_NDK_ROOT', 'the path to Android NDK',
os.environ.get("ANDROID_NDK_ROOT", 0)),
('ndk_platform', 'compile for platform: (android-<api> , example: android-14)', "android-14"),
('android_arch', 'select compiler architecture: (armv7/armv6/x86)', "armv7"),
('android_arch', 'select compiler architecture: (armv7/armv6/arm64v8/x86)', "armv7"),
('android_neon', 'enable neon (armv7 only)', "yes"),
('android_stl', 'enable STL support in android port (for modules)', "no")
]
@ -89,7 +89,7 @@ def configure(env):
ndk_platform = env['ndk_platform']
if env['android_arch'] not in ['armv7', 'armv6', 'x86']:
if env['android_arch'] not in ['armv7', 'armv6', 'arm64v8', 'x86']:
env['android_arch'] = 'armv7'
if env['android_arch'] == 'x86':
@ -107,16 +107,19 @@ def configure(env):
env.Append(CPPPATH=['#platform/android'])
if env['android_arch'] == 'x86':
env['ARCH'] = 'arch-x86'
env.extra_suffix = ".x86" + env.extra_suffix
target_subpath = "x86-4.9"
abi_subpath = "i686-linux-android"
arch_subpath = "x86"
elif env['android_arch'] == 'armv6':
env['ARCH'] = 'arch-arm'
env.extra_suffix = ".armv6" + env.extra_suffix
target_subpath = "arm-linux-androideabi-4.9"
abi_subpath = "arm-linux-androideabi"
arch_subpath = "armeabi"
elif env["android_arch"] == "armv7":
env['ARCH'] = 'arch-arm'
target_subpath = "arm-linux-androideabi-4.9"
abi_subpath = "arm-linux-androideabi"
arch_subpath = "armeabi-v7a"
@ -124,6 +127,12 @@ def configure(env):
env.extra_suffix = ".armv7.neon" + env.extra_suffix
else:
env.extra_suffix = ".armv7" + env.extra_suffix
elif env["android_arch"] == "arm64v8":
env['ARCH'] = 'arch-arm64'
target_subpath = "aarch64-linux-android-4.9"
abi_subpath = "aarch64-linux-android"
arch_subpath = "arm64-v8a"
env.extra_suffix = ".armv8" + env.extra_suffix
mt_link = True
if (sys.platform.startswith("linux")):
@ -137,6 +146,9 @@ def configure(env):
mt_link = False
host_subpath = "windows"
if env["android_arch"] == "arm64v8":
mt_link = False
compiler_path = env["ANDROID_NDK_ROOT"] + \
"/toolchains/llvm/prebuilt/" + host_subpath + "/bin"
gcc_toolchain_path = env["ANDROID_NDK_ROOT"] + \
@ -159,11 +171,6 @@ def configure(env):
env['RANLIB'] = tools_path + "/ranlib"
env['AS'] = tools_path + "/as"
if env['android_arch'] == 'x86':
env['ARCH'] = 'arch-x86'
else:
env['ARCH'] = 'arch-arm'
common_opts = ['-fno-integrated-as', '-gcc-toolchain', gcc_toolchain_path]
lib_sysroot = env["ANDROID_NDK_ROOT"] + "/platforms/" + ndk_platform + "/" + env['ARCH']
@ -204,6 +211,11 @@ def configure(env):
else:
env.Append(CPPFLAGS=['-mfpu=vfpv3-d16'])
elif env["android_arch"] == "arm64v8":
target_opts = ['-target', 'aarch64-none-linux-android']
env.Append(CPPFLAGS=['-D__ARM_ARCH_8A__'])
env.Append(CPPFLAGS=['-mfix-cortex-a53-835769'])
env.Append(CPPFLAGS=target_opts)
env.Append(CPPFLAGS=common_opts)
@ -215,9 +227,11 @@ def configure(env):
env['SHLIBSUFFIX'] = '.so'
env['LINKFLAGS'] = ['-shared', '--sysroot=' + lib_sysroot, '-Wl,--warn-shared-textrel']
env.Append(LINKFLAGS='-Wl,--fix-cortex-a8'.split())
if env["android_arch"] == "armv7":
env.Append(LINKFLAGS=string.split('-Wl,--fix-cortex-a8'))
env.Append(LINKFLAGS='-Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now'.split())
env.Append(LINKFLAGS='-Wl,-soname,libgodot_android.so -Wl,--gc-sections'.split())
if mt_link:
env.Append(LINKFLAGS=['-Wl,--threads'])
env.Append(LINKFLAGS=target_opts)

View File

@ -217,6 +217,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
bool use_32_fb;
bool immersive;
bool export_arm;
bool export_arm64;
bool export_x86;
String apk_expansion_salt;
String apk_expansion_pkey;
@ -314,6 +315,8 @@ bool EditorExportPlatformAndroid::_set(const StringName &p_name, const Variant &
_signed = p_value;
else if (n == "architecture/arm")
export_arm = p_value;
else if (n == "architecture/arm64")
export_arm64 = p_value;
else if (n == "architecture/x86")
export_x86 = p_value;
else if (n == "screen/use_32_bits_view")
@ -387,6 +390,8 @@ bool EditorExportPlatformAndroid::_get(const StringName &p_name, Variant &r_ret)
r_ret = _signed;
else if (n == "architecture/arm")
r_ret = export_arm;
else if (n == "architecture/arm64")
r_ret = export_arm64;
else if (n == "architecture/x86")
r_ret = export_x86;
else if (n == "screen/use_32_bits_view")
@ -443,6 +448,7 @@ void EditorExportPlatformAndroid::_get_property_list(List<PropertyInfo> *p_list)
p_list->push_back(PropertyInfo(Variant::STRING, "package/icon", PROPERTY_HINT_FILE, "png"));
p_list->push_back(PropertyInfo(Variant::BOOL, "package/signed"));
p_list->push_back(PropertyInfo(Variant::BOOL, "architecture/arm"));
p_list->push_back(PropertyInfo(Variant::BOOL, "architecture/arm64"));
p_list->push_back(PropertyInfo(Variant::BOOL, "architecture/x86"));
p_list->push_back(PropertyInfo(Variant::BOOL, "screen/use_32_bits_view"));
p_list->push_back(PropertyInfo(Variant::BOOL, "screen/immersive_mode"));
@ -1122,6 +1128,10 @@ Error EditorExportPlatformAndroid::export_project(const String &p_path, bool p_d
skip = true;
}
if (file.match("lib/arm64*/libgodot_android.so") && !export_arm64) {
skip = true;
}
if (file.begins_with("META-INF") && _signed) {
skip = true;
}
@ -1772,6 +1782,7 @@ EditorExportPlatformAndroid::EditorExportPlatformAndroid() {
immersive = true;
export_arm = true;
export_arm64 = false;
export_x86 = false;
device_thread = Thread::create(_device_poll_thread, this);

View File

@ -190,7 +190,7 @@ bool JavaClass::_call_method(JavaObject *p_instance, const StringName &p_method,
argv[i].i = *p_args[i];
} break;
case ARG_TYPE_LONG: {
argv[i].j = *p_args[i];
argv[i].j = (int64_t)*p_args[i];
} break;
case ARG_TYPE_FLOAT: {
argv[i].f = *p_args[i];
@ -350,7 +350,7 @@ bool JavaClass::_call_method(JavaObject *p_instance, const StringName &p_method,
Array arr = *p_args[i];
jlongArray a = env->NewLongArray(arr.size());
for (int j = 0; j < arr.size(); j++) {
jlong val = arr[j];
jlong val = (int64_t)arr[j];
env->SetLongArrayRegion(a, j, 1, &val);
}
argv[i].l = a;
@ -460,9 +460,9 @@ bool JavaClass::_call_method(JavaObject *p_instance, const StringName &p_method,
case ARG_TYPE_LONG: {
if (method->_static) {
ret = env->CallStaticLongMethodA(_class, method->method, argv);
ret = (int64_t)env->CallStaticLongMethodA(_class, method->method, argv);
} else {
ret = env->CallLongMethodA(p_instance->instance, method->method, argv);
ret = (int64_t)env->CallLongMethodA(p_instance->instance, method->method, argv);
}
} break;
@ -679,7 +679,7 @@ bool JavaClass::_convert_object_to_variant(JNIEnv *env, jobject obj, Variant &va
} break;
case ARG_TYPE_LONG | ARG_NUMBER_CLASS_BIT: {
var = env->CallLongMethod(obj, JavaClassWrapper::singleton->Long_longValue);
var = (int64_t)env->CallLongMethod(obj, JavaClassWrapper::singleton->Long_longValue);
return true;
} break;
@ -801,7 +801,7 @@ bool JavaClass::_convert_object_to_variant(JNIEnv *env, jobject obj, Variant &va
jlong val;
env->GetLongArrayRegion((jlongArray)arr, 0, 1, &val);
ret.push_back(val);
ret.push_back((int64_t)val);
}
var = ret;