Skip to content

Commit

Permalink
Bug 1739701 - Add support for the arm64 Android emulator. r=gbrown,calu
Browse files Browse the repository at this point in the history
My understanding is that this is the only version of the emulator that is
supported on Apple silicon.

Differential Revision: https://phabricator.services.mozilla.com/D130510
  • Loading branch information
agi committed Nov 9, 2021
1 parent 00c83aa commit ea465ff
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 15 deletions.
8 changes: 4 additions & 4 deletions mobile/android/mach_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,13 +536,13 @@ def gradle_install_REMOVED(command_context):
@CommandArgument(
"--version",
metavar="VERSION",
choices=["arm", "x86_64"],
choices=["arm", "arm64", "x86_64"],
help="Specify which AVD to run in emulator. "
'One of "arm" (Android supporting armv7 binaries), or '
'One of "arm" (Android supporting armv7 binaries), '
'"arm64" (for Apple Silicon), or '
'"x86_64" (Android supporting x86 or x86_64 binaries, '
"recommended for most applications). "
'By default, "arm" will be used if the current build environment '
'architecture is arm; otherwise "x86_64".',
"By default, the value will match the current build environment.",
)
@CommandArgument("--wait", action="store_true", help="Wait for emulator to be closed.")
@CommandArgument("--gpu", help="Over-ride the emulator -gpu argument.")
Expand Down
27 changes: 27 additions & 0 deletions python/mozboot/mozboot/android-avds/arm64.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"emulator_package": "system-images;android-30;default;arm64-v8a",
"emulator_avd_name": "mozemulator-arm64",
"emulator_extra_args": [
"-skip-adb-auth",
"-verbose",
"-show-kernel",
"-ranchu",
"-selinux", "permissive",
"-memory", "3072",
"-cores", "4",
"-skin", "800x1280",
"-gpu", "on",
"-no-snapstorage",
"-no-snapshot",
"-no-window",
"-no-accel",
"-prop", "ro.test_harness=true"
],
"emulator_extra_config": {
"hw.keyboard": "yes",
"hw.lcd.density": "320",
"disk.dataPartition.size": "4000MB",
"sdcard.size": "600M"
},
"emulator_prewarm": false
}
22 changes: 21 additions & 1 deletion python/mozboot/mozboot/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

MACOS_X86_64_ANDROID_AVD = "linux64-android-avd-x86_64-repack"
MACOS_ARM_ANDROID_AVD = "linux64-android-avd-arm-repack"
MACOS_ARM64_ANDROID_AVD = "linux64-android-avd-arm64-repack"

WINDOWS_X86_64_ANDROID_AVD = "linux64-android-avd-x86_64-repack"
WINDOWS_ARM_ANDROID_AVD = "linux64-android-avd-arm-repack"
Expand All @@ -42,6 +43,9 @@
AVD_MANIFEST_ARM = os.path.abspath(
os.path.join(os.path.dirname(__file__), "android-avds/arm.json")
)
AVD_MANIFEST_ARM64 = os.path.abspath(
os.path.join(os.path.dirname(__file__), "android-avds/arm64.json")
)

ANDROID_NDK_EXISTS = """
Looks like you have the correct version of the Android NDK installed at:
Expand Down Expand Up @@ -77,7 +81,7 @@
# For regular phones, no --target is needed.
# For x86 emulators (and x86 devices, which are uncommon):
# ac_add_options --target=i686
# For newer phones.
# For newer phones or Apple silicon
# ac_add_options --target=aarch64
# For x86_64 emulators (and x86_64 devices, which are even less common):
# ac_add_options --target=x86_64
Expand Down Expand Up @@ -320,6 +324,7 @@ def ensure_dir(dir):

def ensure_android(
os_name,
os_arch,
artifact_mode=False,
ndk_only=False,
system_images_only=False,
Expand Down Expand Up @@ -361,6 +366,7 @@ def ensure_android(
ensure_android_sdk_and_ndk(
mozbuild_path,
os_name,
os_arch,
sdk_path=sdk_path,
sdk_url=sdk_url,
ndk_path=ndk_path,
Expand All @@ -378,10 +384,16 @@ def ensure_android(
if avd_manifest_path is not None:
with open(avd_manifest_path) as f:
avd_manifest = json.load(f)
# Some AVDs cannot be prewarmed in CI because they cannot run on linux64
# (like the arm64 AVD).
if "emulator_prewarm" in avd_manifest:
prewarm_avd = prewarm_avd and avd_manifest["emulator_prewarm"]

# We expect the |sdkmanager| tool to be at
# ~/.mozbuild/android-sdk-$OS_NAME/tools/cmdline-tools/$CMDLINE_TOOLS_VERSION_STRING/bin/sdkmanager. # NOQA: E501
ensure_android_packages(
os_name,
os_arch,
sdkmanager_tool=sdkmanager_tool(sdk_path),
emulator_only=emulator_only,
system_images_only=system_images_only,
Expand Down Expand Up @@ -409,6 +421,7 @@ def ensure_android(
def ensure_android_sdk_and_ndk(
mozbuild_path,
os_name,
os_arch,
sdk_path,
sdk_url,
ndk_path,
Expand Down Expand Up @@ -600,6 +613,8 @@ def run_prewarm_avd(


def ensure_android_packages(
os_name,
os_arch,
sdkmanager_tool,
emulator_only=False,
system_images_only=False,
Expand Down Expand Up @@ -631,6 +646,9 @@ def ensure_android_packages(
print(INSTALLING_ANDROID_PACKAGES % "\n".join(packages))

args = [sdkmanager_tool]
if os_name == "macosx" and os_arch == "arm64":
# Support for Apple Silicon is still in nightly
args.append("--channel=3")
args.extend(packages)

if not no_interactive:
Expand Down Expand Up @@ -769,8 +787,10 @@ def main(argv):
"NDK) on {0} yet!".format(platform.system())
)

os_arch = platform.machine()
ensure_android(
os_name,
os_arch,
artifact_mode=options.artifact_mode,
ndk_only=options.ndk_only,
system_images_only=options.system_images_only,
Expand Down
12 changes: 9 additions & 3 deletions python/mozboot/mozboot/linux_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

from __future__ import absolute_import, print_function, unicode_literals

import os
import platform


def is_non_x86_64():
return os.uname()[4] != "x86_64"
return platform.machine() != "x86_64"


class SccacheInstall(object):
Expand Down Expand Up @@ -127,18 +127,24 @@ def __init__(self, **kwargs):
def install_mobile_android_packages(self, mozconfig_builder, artifact_mode=False):
from mozboot import android

os_arch = platform.machine()
android.ensure_android(
"linux", artifact_mode=artifact_mode, no_interactive=self.no_interactive
"linux",
os_arch,
artifact_mode=artifact_mode,
no_interactive=self.no_interactive,
)
android.ensure_android(
"linux",
os_arch,
artifact_mode=artifact_mode,
no_interactive=self.no_interactive,
system_images_only=True,
avd_manifest_path=android.AVD_MANIFEST_X86_64,
)
android.ensure_android(
"linux",
os_arch,
artifact_mode=artifact_mode,
no_interactive=self.no_interactive,
system_images_only=True,
Expand Down
13 changes: 12 additions & 1 deletion python/mozboot/mozboot/mozillabuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import ctypes
import os
import platform
import sys
import subprocess

Expand Down Expand Up @@ -157,18 +158,28 @@ def install_mobile_android_packages(self, mozconfig_builder, artifact_mode=False

from mozboot import android

os_arch = platform.machine()
if os_arch == "AMD64":
# On Windows, x86_64 is reported as AMD64 but we use x86_64
# everywhere else, so let's normalized it here.
os_arch = "x86_64"
android.ensure_android(
"windows", artifact_mode=artifact_mode, no_interactive=self.no_interactive
"windows",
os_arch,
artifact_mode=artifact_mode,
no_interactive=self.no_interactive,
)
android.ensure_android(
"windows",
os_arch,
system_images_only=True,
artifact_mode=artifact_mode,
no_interactive=self.no_interactive,
avd_manifest_path=android.AVD_MANIFEST_X86_64,
)
android.ensure_android(
"windows",
os_arch,
system_images_only=True,
artifact_mode=artifact_mode,
no_interactive=self.no_interactive,
Expand Down
12 changes: 9 additions & 3 deletions python/mozboot/mozboot/osx.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from __future__ import absolute_import, print_function, unicode_literals

import os
import platform
import subprocess
import sys
import tempfile
Expand Down Expand Up @@ -162,8 +163,8 @@ def install_mobile_android_packages(self, mozconfig_builder, artifact_mode=False
casks = ["adoptopenjdk8"]
self._ensure_homebrew_casks(casks)

is_64bits = sys.maxsize > 2 ** 32
if not is_64bits:
os_arch = platform.machine()
if os_arch != "x86_64" and os_arch != "arm64":
raise Exception(
"You need a 64-bit version of Mac OS X to build "
"GeckoView/Firefox for Android."
Expand All @@ -176,17 +177,22 @@ def install_mobile_android_packages(self, mozconfig_builder, artifact_mode=False
from mozboot import android

android.ensure_android(
"macosx", artifact_mode=artifact_mode, no_interactive=self.no_interactive
"macosx",
os_arch,
artifact_mode=artifact_mode,
no_interactive=self.no_interactive,
)
android.ensure_android(
"macosx",
os_arch,
system_images_only=True,
artifact_mode=artifact_mode,
no_interactive=self.no_interactive,
avd_manifest_path=android.AVD_MANIFEST_X86_64,
)
android.ensure_android(
"macosx",
os_arch,
system_images_only=True,
artifact_mode=artifact_mode,
no_interactive=self.no_interactive,
Expand Down
16 changes: 16 additions & 0 deletions taskcluster/ci/toolchain/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ linux64-android-avd-arm-repack:
toolchain-artifact: public/build/android-avd-linux.tar.zst
toolchain-alias: android-avd-arm-linux

linux64-android-avd-arm64-repack:
attributes:
local-toolchain: true
description: "Android AVD (Linux) repack toolchain build"
treeherder:
symbol: TL(avd-arm64-linux)
run-on-projects: [trunk]
run:
script: repack-android-avd-linux.sh
arguments:
- 'python/mozboot/mozboot/android-avds/arm64.json'
resources:
- 'python/mozboot/**/*android*'
toolchain-artifact: public/build/android-avd-linux.tar.zst
toolchain-alias: android-avd-arm64-linux

linux64-android-system-image-x86_64-repack:
description: "Android System Images (Linux) repack toolchain build"
treeherder:
Expand Down
32 changes: 29 additions & 3 deletions testing/mozbase/mozrunner/mozrunner/devices/android_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,31 @@ def __init__(self, description, name, extra_args, x86):
],
False,
),
"arm64": AvdInfo(
"Android arm64",
"mozemulator-arm64",
[
"-skip-adb-auth",
"-verbose",
"-show-kernel",
"-ranchu",
"-selinux",
"permissive",
"-memory",
"3072",
"-cores",
"4",
"-skin",
"800x1280",
"-gpu",
"on",
"-no-snapstorage",
"-no-snapshot",
"-prop",
"ro.test_harness=true",
],
False,
),
"x86_64": AvdInfo(
"Android x86_64",
"mozemulator-x86_64",
Expand Down Expand Up @@ -844,9 +869,10 @@ def _get_avd_type(self, requested):
if requested in AVD_DICT.keys():
return requested
if self.substs:
if not self.substs["TARGET_CPU"].startswith("arm"):
return "x86_64"
else:
target_cpu = self.substs["TARGET_CPU"]
if target_cpu == "aarch64":
return "arm64"
elif target_cpu.startswith("arm"):
return "arm"
return "x86_64"

Expand Down

0 comments on commit ea465ff

Please sign in to comment.