Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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'],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-m32 is probably useless to begin with…

'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']
Expand Down
11 changes: 6 additions & 5 deletions build/mac/find_sdk.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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():
Expand All @@ -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()
Expand All @@ -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)]
Expand All @@ -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

Expand Down
2 changes: 2 additions & 0 deletions pynacl/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
17 changes: 11 additions & 6 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/']

Expand Down Expand Up @@ -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():
Expand Down
4 changes: 4 additions & 0 deletions site_scons/site_tools/component_bits.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


import builtins
import platform
import sys
import types
import SCons
Expand Down Expand Up @@ -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'))

Expand All @@ -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')
9 changes: 7 additions & 2 deletions src/trusted/validator_ragel/build.scons
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions tests/run_py/nacl.scons
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down