From 732c06f74ad4cfd3119134ffc6ce344f72c998b5 Mon Sep 17 00:00:00 2001 From: slipher Date: Sun, 19 Jul 2026 19:16:32 -0500 Subject: [PATCH 1/4] Pretend native arch is x86_64 on ARM Mac This makes the deps we need get downloaded by the gclient hook. It's also used by SCons. --- pynacl/platform.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pynacl/platform.py b/pynacl/platform.py index 307ec15cb6..7d195c8594 100644 --- a/pynacl/platform.py +++ b/pynacl/platform.py @@ -130,6 +130,8 @@ def GetArch3264(machine=None): machine = 'ia32' machine = machine.lower() + if machine == 'arm64' and GetOS() == OS_MAC: + machine = ARCH3264_X86_64 # force Intel cross build assert machine in ARCH3264_DICT, "Unrecognized arch machine: %s" % machine return ARCH3264_DICT[machine] From 30246bab96acaf7ef695b5600c53ca9b95cfb01b Mon Sep 17 00:00:00 2001 From: slipher Date: Sun, 19 Jul 2026 21:31:26 -0500 Subject: [PATCH 2/4] Mac: clean up find_sdk.py vomit - Migrate to Python 3 - Allow SDK versions greater than 10.x - Don't require XCode IDE to be installed - Actually use the find_sdk.py from this repository instead of looking for it in another repository named "build" --- SConstruct | 2 +- build/mac/find_sdk.py | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/SConstruct b/SConstruct index 99f3a52eba..cf7ce59da0 100755 --- a/SConstruct +++ b/SConstruct @@ -2467,7 +2467,7 @@ def MakeMacEnv(platform=None): # This invocation matches the model in //build/config/mac/mac_sdk.gni. mac_sdk_sysroot, mac_sdk_version = subprocess.check_output([ sys.executable, - os.path.join(os.path.pardir, 'build', 'mac', 'find_sdk.py'), + os.path.join('build', 'mac', 'find_sdk.py'), '--print_sdk_path', mac_sdk_min ], encoding='utf-8').splitlines() diff --git a/build/mac/find_sdk.py b/build/mac/find_sdk.py index c94a0a9d37..6bae61ff6f 100755 --- a/build/mac/find_sdk.py +++ b/build/mac/find_sdk.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -22,7 +22,7 @@ def parse_version(version_str): """'10.6' => [10, 6]""" - return map(int, re.findall(r'(\d+)', version_str)) + return [int(s) for s in re.findall(r'(\d+)', version_str)] def main(): @@ -40,6 +40,7 @@ def main(): min_sdk_version = args[0] job = subprocess.Popen(['xcode-select', '-print-path'], + text=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) out, err = job.communicate() @@ -56,7 +57,7 @@ def main(): sdk_dir = xcode43_sdk_path else: sdk_dir = os.path.join(out.rstrip(), 'SDKs') - sdks = [re.findall('^MacOSX(10\.\d+)\.sdk$', s) for s in os.listdir(sdk_dir)] + sdks = [re.findall(r'^MacOSX(\d+\.\d+)\.sdk$', s) for s in os.listdir(sdk_dir)] sdks = [s[0] for s in sdks if s] # [['10.5'], ['10.6']] => ['10.5', '10.6'] sdks = [s for s in sdks # ['10.5', '10.6'] => ['10.6'] if parse_version(s) >= parse_version(min_sdk_version)] @@ -82,8 +83,8 @@ def main(): if options.print_sdk_path: print(subprocess.check_output( - ['xcodebuild', '-version', '-sdk', 'macosx' + best_sdk, - 'Path'], encoding='utf-8').strip()) + ['xcrun', '--sdk', 'macosx' + best_sdk, + '--show-sdk-path'], encoding='utf-8').strip()) return best_sdk From 7914707aa314ddcaf01c683e0b3ea38b193cc30a Mon Sep 17 00:00:00 2001 From: slipher Date: Mon, 20 Jul 2026 01:05:28 -0500 Subject: [PATCH 3/4] Patch build system to run on ARM Mac --- SConstruct | 14 +++++++++----- site_scons/site_tools/component_bits.py | 4 ++++ src/trusted/validator_ragel/build.scons | 9 +++++++-- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/SConstruct b/SConstruct index cf7ce59da0..bf6d485057 100755 --- a/SConstruct +++ b/SConstruct @@ -2483,14 +2483,18 @@ def MakeMacEnv(platform=None): '-mmacosx-version-min=' + mac_deployment_target] mac_env.Append(CCFLAGS=sdk_flags, ASFLAGS=sdk_flags, LINKFLAGS=sdk_flags) - subarch_flag = '-m%s' % mac_env['BUILD_SUBARCH'] + arch_map = { + '32': ['-m32'], + '64': ['-arch', 'x86_64'], + } + arch_flags = arch_map[mac_env['BUILD_SUBARCH']] mac_env.Append( # '-Wno-gnu' is required for the statement expression defining dirfd # for OSX -- otherwise, a warning is generated. - CCFLAGS=[subarch_flag, '-fPIC', '-Wno-gnu'], - CXXFLAGS=['-stdlib=libc++'], - ASFLAGS=[subarch_flag], - LINKFLAGS=[subarch_flag, '-fPIC', '-stdlib=libc++'], + CCFLAGS=[*arch_flags, '-fPIC', '-Wno-gnu'], + CXXFLAGS=[*arch_flags, '-stdlib=libc++'], + ASFLAGS=[*arch_flags], + LINKFLAGS=[*arch_flags, '-fPIC', '-stdlib=libc++'], CPPDEFINES = [# defining _DARWIN_C_SOURCE breaks 10.4 #['_DARWIN_C_SOURCE', '1'], #['__STDC_LIMIT_MACROS', '1'] diff --git a/site_scons/site_tools/component_bits.py b/site_scons/site_tools/component_bits.py index 623cfa969c..2ef08622bf 100755 --- a/site_scons/site_tools/component_bits.py +++ b/site_scons/site_tools/component_bits.py @@ -10,6 +10,7 @@ import builtins +import platform import sys import types import SCons @@ -244,6 +245,7 @@ def generate(env): exclusive_groups=('host_platform')) DeclareBit('host_mac', 'Host platform is mac.', exclusive_groups=('host_platform')) + DeclareBit('host_mac_arm64', 'Host platform is ARM-based mac.') DeclareBit('host_windows', 'Host platform is windows.', exclusive_groups=('host_platform')) @@ -259,3 +261,5 @@ def generate(env): } if HOST_PLATFORM in host_platform_to_bit: env.SetBits(host_platform_to_bit[HOST_PLATFORM]) + if env.Bit('host_mac') and platform.machine() == 'arm64': + env.SetBits('host_mac_arm64') diff --git a/src/trusted/validator_ragel/build.scons b/src/trusted/validator_ragel/build.scons index 69e92bc4b9..23db635249 100644 --- a/src/trusted/validator_ragel/build.scons +++ b/src/trusted/validator_ragel/build.scons @@ -141,10 +141,15 @@ assert bitness in [32, 64] python_can_load_dll = python_bitness == bitness and not env.Bit('asan') if python_can_load_dll: + if env.Bit('host_mac_arm64'): + # The system Python is a fat binary + python = ['arch', '-x86_64', '/usr/bin/python3'] + else: + python = ['${PYTHON}'] validator_py_test = env.AutoDepsCommand( 'validator_py_out', - ['${PYTHON}', - env.File('validator.py'), + python + + [env.File('validator.py'), validator_dll]) env.AddNodeToTestSuite( From 3e682568e20f832d9566c909580d0bcf0f3bea5e Mon Sep 17 00:00:00 2001 From: slipher Date: Wed, 22 Jul 2026 15:57:14 -0500 Subject: [PATCH 4/4] Teach run.py to find Saigo's readelf --- run.py | 17 +++++++++++------ tests/run_py/nacl.scons | 4 ++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/run.py b/run.py index 653dd50e79..e22dcd6905 100755 --- a/run.py +++ b/run.py @@ -34,6 +34,8 @@ def SetupEnvironment(): # Path to PNaCl toolchain env.pnacl_base = os.path.join(env.toolchain_base, 'pnacl_newlib') + env.saigo_base = os.path.join(env.toolchain_base, 'saigo_newlib_raw') + # QEMU env.qemu_arm_args = ['qemu-armhf', '-L', '/usr/arm-linux-gnueabihf/'] @@ -585,13 +587,16 @@ def FindReadElf(): '''Returns the path of "readelf" binary.''' candidates = [] - # Use PNaCl's if it available. - candidates.append( - os.path.join(env.pnacl_base, 'bin', 'pnacl-readelf')) - # Otherwise, look for the system readelf - for path in os.environ['PATH'].split(os.pathsep): - candidates.append(os.path.join(path, 'readelf')) + # Look for Saigo or PNaCl readelf or the system one + # The architecture the toolchain was built for generally doesn't matter. + readelves = ['x86_64-nacl-readelf', 'pnacl-readelf', 'readelf'] + toolchain_paths = [os.path.join(env.saigo_base, 'bin'), + os.path.join(env.pnacl_base, 'bin')] + + for path in toolchain_paths + os.environ['PATH'].split(os.pathsep): + for basename in readelves: + candidates.append(os.path.join(path, basename)) for readelf in candidates: if pynacl.platform.IsWindows(): diff --git a/tests/run_py/nacl.scons b/tests/run_py/nacl.scons index e8403ed17e..734379ece3 100644 --- a/tests/run_py/nacl.scons +++ b/tests/run_py/nacl.scons @@ -45,9 +45,9 @@ run_py_options = [ ] if 'TRUSTED_ENV' in env and env['TRUSTED_ENV'].Bit('windows'): - # To find readelf. Saigo also has a readelf but it's named x86_64-nacl-readelf (etc.) + # To find MinGW's readelf, but this shouldn't be needed since the NaCl toolchain has one env = env.Clone() - env.PrependENVPath('PATH', env['TRUSTED_ENV']['MINGW_BIN']) + env.AppendENVPath('PATH', env['TRUSTED_ENV']['MINGW_BIN']) node = env.CommandTest( name,