Fix macOS scripting SDK build.

This also enables universal spcomp binaries with arm64 support.
This commit is contained in:
David Anderson 2023-11-04 22:41:47 -07:00
parent 7bfd5e521e
commit 4b2d8b53fa
4 changed files with 42 additions and 39 deletions

View File

@ -41,9 +41,9 @@ jobs:
python -m pip install --upgrade pip setuptools wheel
pip install git+https://github.com/alliedmodders/ambuild
- name: Build only for x64 on macOS
- name: Build universal x64/arm64 on macOS
if: startsWith(runner.os, 'macOS')
run: echo "ARCH=x86_64" >> $GITHUB_ENV
run: echo "ARCH=x86_64,arm64" >> $GITHUB_ENV
- name: Install Linux dependencies
if: startsWith(runner.os, 'Linux')

View File

@ -123,7 +123,7 @@ class SMConfig(object):
self.mms_root = None
self.mysql_root = {}
self.spcomp = None
self.spcomp_bins = None
self.spcomp_bins = []
self.smx_files = {}
self.versionlib = None
self.all_targets = []
@ -243,7 +243,14 @@ class SMConfig(object):
def configure(self):
builder.AddConfigureFile('pushbuild.txt')
if not set(self.target_archs).issubset(['x86', 'x86_64']):
allowed_archs = ['x86_64']
if builder.host.platform == 'mac':
if getattr(builder.options, 'scripting_only', False):
allowed_archs += ['arm64']
else:
allowed_archs += ['x86']
if not set(self.target_archs).issubset(allowed_archs):
raise Exception('Unknown target architecture: {0}'.format(self.target_archs))
for cxx in self.all_targets:
@ -313,9 +320,10 @@ class SMConfig(object):
'-Wno-unused',
'-Wno-switch',
'-Wno-array-bounds',
'-msse',
'-fvisibility=hidden',
]
if cxx.target.arch in ['x86', 'x86_64']:
cxx.cflags += ['-msse']
cxx.cxxflags += ['-std=c++17']
@ -462,9 +470,9 @@ class SMConfig(object):
def configure_mac(self, cxx):
cxx.defines += ['OSX', '_OSX', 'POSIX', 'KE_ABSOLUTELY_NO_STL']
cxx.cflags += ['-mmacosx-version-min=10.7']
cxx.cflags += ['-mmacosx-version-min=10.15']
cxx.linkflags += [
'-mmacosx-version-min=10.7',
'-mmacosx-version-min=10.15',
'-stdlib=libc++',
'-lc++',
]
@ -810,11 +818,24 @@ SP = builder.Build('sourcepawn/AMBuildScript', {
'external_amtl': os.path.join(builder.sourcePath, 'public', 'amtl'),
'external_build': SP_build_parts,
})
if len(SP.spcomp) > 1:
SM.spcomp = SP.spcomp['x86']
else:
SM.spcomp = SP.spcomp[list(SP.spcomp.keys())[0]]
SM.spcomp_bins = list(SP.spcomp.values())
def IsBetterDefaultSpcomp(spcomp, other):
if other is None:
return True
if spcomp.target.arch == 'universal':
return True
if other.target.arch == 'universal':
return False
return spcomp.target.arch == 'x86'
for spcomp in SP.spcomp:
if IsBetterDefaultSpcomp(spcomp, SM.spcomp):
SM.spcomp = spcomp
SM.spcomp_bins.append(spcomp)
# If we have a universal binary, ignore all other spcomps.
if SM.spcomp.target.arch == 'universal':
SM.spcomp_bins = [SM.spcomp]
if not getattr(builder.options, 'scripting_only', False):
for cxx in SM.all_targets:

@ -1 +1 @@
Subproject commit 032a9ac082a47b6a8c0231044ab295ae9d1b07b6
Subproject commit d59a51b5741823903ecbe8c014632ee1f8aad65d

View File

@ -14,32 +14,14 @@ class PackageHelpers:
self.folder_map[folder] = self.builder.AddFolder(norm_folder)
return self.folder_map
def lipo(self, binaries, outFolder):
bins = []
binPaths = []
for b in binaries:
bins.append(b.binary)
binPaths.append(os.path.join(self.builder.buildPath, b.binary.path))
argv = ['lipo', '-create']
binary = os.path.basename(binPaths[0])
outputPath = os.path.join(self.builder.buildPath, self.builder.buildFolder, outFolder, binary)
self.builder.AddCommand(
argv = argv + binPaths + ['-output', outputPath],
inputs = bins,
outputs = [os.path.join(outFolder, binary)],
)
def CopySpcomp(self, target_folder):
if self.builder.host.platform == 'mac' and len(SM.target_archs) > 1:
self.lipo(SM.spcomp_bins, target_folder)
else:
for bin_task in SM.spcomp_bins:
if bin_task.target.arch == 'x86_64':
root, ext = os.path.splitext(os.path.basename(bin_task.binary.path))
file = root + '64' + ext
self.builder.AddCopy(bin_task.binary, os.path.join(target_folder, file))
else:
self.builder.AddCopy(bin_task.binary, self.folder_map[target_folder])
for bin_task in SM.spcomp_bins:
if bin_task.target.arch == 'x86_64':
root, ext = os.path.splitext(os.path.basename(bin_task.binary.path))
file = root + '64' + ext
self.builder.AddCopy(bin_task.binary, os.path.join(target_folder, file))
else:
self.builder.AddCopy(bin_task.binary, self.folder_map[target_folder])
if self.builder.host.platform == 'windows':
self.CopyFiles('tools/batchtool', target_folder, '.exe')
@ -70,4 +52,4 @@ class PackageHelpers:
self.CopyFiles('plugins/include', target_folder, '.inc')
SM.package_helpers = PackageHelpers(builder)
SM.package_helpers = PackageHelpers(builder)