# HG changeset patch # User Nathan Froyd # Date 1549401358 18000 # Tue Feb 05 16:15:58 2019 -0500 # Node ID a7b9d2f169d5f659cb815b1faa90d131c94ed0a2 # Parent 027ed877d83267f481e4f2df4acd7744268ae936 Bug 1525069 - part 3 - install 32-bit node on aarch64 devices; r=nalexander One less paper cut for frontend developers. diff --git a/python/mozboot/mozboot/mozillabuild.py b/python/mozboot/mozboot/mozillabuild.py --- a/python/mozboot/mozboot/mozillabuild.py +++ b/python/mozboot/mozboot/mozillabuild.py @@ -1,21 +1,48 @@ # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. from __future__ import absolute_import, print_function +import ctypes import os import sys import subprocess from mozboot.base import BaseBootstrapper +def is_aarch64_host(): + from ctypes import wintypes + kernel32 = ctypes.windll.kernel32 + IMAGE_FILE_MACHINE_UNKNOWN = 0 + IMAGE_FILE_MACHINE_ARM64 = 0xAA64 + + try: + iswow64process2 = kernel32.IsWow64Process2 + except Exception: + # If we can't access the symbol, we know we're not on aarch64. + return False + + currentProcess = kernel32.GetCurrentProcess() + processMachine = wintypes.USHORT(IMAGE_FILE_MACHINE_UNKNOWN) + nativeMachine = wintypes.USHORT(IMAGE_FILE_MACHINE_UNKNOWN) + + gotValue = iswow64process2(currentProcess, + ctypes.byref(processMachine), + ctypes.byref(nativeMachine)) + # If this call fails, we have no idea. + if not gotValue: + return False + + return nativeMachine.value == IMAGE_FILE_MACHINE_ARM64 + + class MozillaBuildBootstrapper(BaseBootstrapper): '''Bootstrapper for MozillaBuild to install rustup.''' def __init__(self, no_interactive=False, no_system_changes=False): BaseBootstrapper.__init__(self, no_interactive=no_interactive, no_system_changes=no_system_changes) print("mach bootstrap is not fully implemented in MozillaBuild") def which(self, name, *extra_search_dirs): @@ -44,24 +71,34 @@ class MozillaBuildBootstrapper(BaseBoots def install_mobile_android_artifact_mode_packages(self): pass def ensure_clang_static_analysis_package(self, checkout_root): self.install_toolchain_static_analysis(checkout_root) def ensure_stylo_packages(self, state_dir, checkout_root): + # On-device artifact builds are supported; on-device desktop builds are not. + if is_aarch64_host(): + raise Exception('You should not be performing desktop builds on an ' + 'AArch64 device. If you want to do artifact builds ' + 'instead, please choose the appropriate artifact build ' + 'option when beginning bootstrap.') + from mozboot import stylo self.install_toolchain_artifact(state_dir, checkout_root, stylo.WINDOWS_CLANG) self.install_toolchain_artifact(state_dir, checkout_root, stylo.WINDOWS_CBINDGEN) def ensure_node_packages(self, state_dir, checkout_root): from mozboot import node + # We don't have native aarch64 node available, but aarch64 windows + # runs x86 binaries, so just use the x86 packages for such hosts. + node_artifact = node.WIN32 if is_aarch64_host() else node.WIN64 self.install_toolchain_artifact( - state_dir, checkout_root, node.WIN64) + state_dir, checkout_root, node_artifact) def _update_package_manager(self): pass def run(self, command): subprocess.check_call(command, stdin=sys.stdin) def pip_install(self, *packages): diff --git a/python/mozboot/mozboot/windows.py b/python/mozboot/mozboot/windows.py --- a/python/mozboot/mozboot/windows.py +++ b/python/mozboot/mozboot/windows.py @@ -1,21 +1,48 @@ # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. from __future__ import absolute_import, print_function +import ctypes import os import sys import subprocess from mozboot.base import BaseBootstrapper +def is_aarch64_host(): + from ctypes import wintypes + kernel32 = ctypes.windll.kernel32 + IMAGE_FILE_MACHINE_UNKNOWN = 0 + IMAGE_FILE_MACHINE_ARM64 = 0xAA64 + + try: + iswow64process2 = kernel32.IsWow64Process2 + except Exception: + # If we can't access the symbol, we know we're not on aarch64. + return False + + currentProcess = kernel32.GetCurrentProcess() + processMachine = wintypes.USHORT(IMAGE_FILE_MACHINE_UNKNOWN) + nativeMachine = wintypes.USHORT(IMAGE_FILE_MACHINE_UNKNOWN) + + gotValue = iswow64process2(currentProcess, + ctypes.byref(processMachine), + ctypes.byref(nativeMachine)) + # If this call fails, we have no idea. + if not gotValue: + return False + + return nativeMachine.value == IMAGE_FILE_MACHINE_ARM64 + + class WindowsBootstrapper(BaseBootstrapper): '''Bootstrapper for msys2 based environments for building in Windows.''' SYSTEM_PACKAGES = [ 'mingw-w64-x86_64-make', 'mingw-w64-x86_64-python2-pip', 'mingw-w64-x86_64-perl', 'patch', @@ -71,24 +98,34 @@ class WindowsBootstrapper(BaseBootstrapp def install_mobile_android_artifact_mode_packages(self): raise NotImplementedError('We do not support building Android on Windows. Sorry!') def ensure_clang_static_analysis_package(self, checkout_root): self.install_toolchain_static_analysis(checkout_root) def ensure_stylo_packages(self, state_dir, checkout_root): + # On-device artifact builds are supported; on-device desktop builds are not. + if is_aarch64_host(): + raise Exception('You should not be performing desktop builds on an ' + 'AArch64 device. If you want to do artifact builds ' + 'instead, please choose the appropriate artifact build ' + 'option when beginning bootstrap.') + from mozboot import stylo self.install_toolchain_artifact(state_dir, checkout_root, stylo.WINDOWS_CLANG) self.install_toolchain_artifact(state_dir, checkout_root, stylo.WINDOWS_CBINDGEN) def ensure_node_packages(self, state_dir, checkout_root): from mozboot import node + # We don't have native aarch64 node available, but aarch64 windows + # runs x86 binaries, so just use the x86 packages for such hosts. + node_artifact = node.WIN32 if is_aarch64_host() else node.WIN64 self.install_toolchain_artifact( - state_dir, checkout_root, node.WIN64) + state_dir, checkout_root, node_artifact) def _update_package_manager(self): self.pacman_update() def run(self, command): subprocess.check_call(command, stdin=sys.stdin) def pacman_update(self):