diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /python/mozboot/mozboot/windows.py | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'python/mozboot/mozboot/windows.py')
-rw-r--r-- | python/mozboot/mozboot/windows.py | 167 |
1 files changed, 167 insertions, 0 deletions
diff --git a/python/mozboot/mozboot/windows.py b/python/mozboot/mozboot/windows.py new file mode 100644 index 0000000000..784449fd08 --- /dev/null +++ b/python/mozboot/mozboot/windows.py @@ -0,0 +1,167 @@ +# 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, unicode_literals + +import ctypes +import os +import sys +import subprocess + +from mozboot.base import BaseBootstrapper +from mozfile import which + + +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-perl", + "patch", + "patchutils", + "diffutils", + "tar", + "zip", + "unzip", + "mingw-w64-x86_64-toolchain", # TODO: Remove when Mercurial is installable from a wheel. + "mingw-w64-i686-toolchain", + ] + + BROWSER_PACKAGES = [ + "mingw-w64-x86_64-nasm", + "mingw-w64-x86_64-yasm", + "mingw-w64-i686-nsis", + ] + + MOBILE_ANDROID_COMMON_PACKAGES = ["wget"] + + def __init__(self, **kwargs): + if ( + "MOZ_WINDOWS_BOOTSTRAP" not in os.environ + or os.environ["MOZ_WINDOWS_BOOTSTRAP"] != "1" + ): + raise NotImplementedError( + "Bootstrap support for Windows is under development. For " + "now use MozillaBuild to set up a build environment on " + "Windows. If you are testing Windows Bootstrap support, " + "try `export MOZ_WINDOWS_BOOTSTRAP=1`" + ) + BaseBootstrapper.__init__(self, **kwargs) + if not which("pacman"): + raise NotImplementedError( + "The Windows bootstrapper only works with msys2 with " + "pacman. Get msys2 at http://msys2.github.io/" + ) + print("Using an experimental bootstrapper for Windows.") + + def install_system_packages(self): + self.pacman_install(*self.SYSTEM_PACKAGES) + + def upgrade_mercurial(self, current): + self.pip_install("mercurial") + + def install_browser_packages(self, mozconfig_builder): + self.pacman_install(*self.BROWSER_PACKAGES) + + def install_mobile_android_packages(self, mozconfig_builder): + raise NotImplementedError( + "We do not support building Android on Windows. Sorry!" + ) + + def install_mobile_android_artifact_mode_packages(self, mozconfig_builder): + raise NotImplementedError( + "We do not support building Android on Windows. Sorry!" + ) + + def ensure_clang_static_analysis_package(self, state_dir, checkout_root): + from mozboot import static_analysis + + self.install_toolchain_static_analysis( + state_dir, checkout_root, static_analysis.WINDOWS_CLANG_TIDY + ) + + 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_nasm_packages(self, state_dir, checkout_root): + from mozboot import nasm + + self.install_toolchain_artifact(state_dir, checkout_root, nasm.WINDOWS_NASM) + + 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_artifact) + + def _update_package_manager(self): + self.pacman_update() + + def run(self, command): + subprocess.check_call(command, stdin=sys.stdin) + + def pacman_update(self): + command = ["pacman", "--sync", "--refresh"] + self.run(command) + + def pacman_upgrade(self): + command = ["pacman", "--sync", "--refresh", "--sysupgrade"] + self.run(command) + + def pacman_install(self, *packages): + command = ["pacman", "--sync", "--needed"] + if self.no_interactive: + command.append("--noconfirm") + + command.extend(packages) + self.run(command) + + def pip_install(self, *packages): + command = ["pip", "install", "--upgrade"] + command.extend(packages) + self.run(command) |