Skip to content

Commit

Permalink
Fix macOS scripting SDK build.
Browse files Browse the repository at this point in the history
This also enables universal spcomp binaries with arm64 support.
  • Loading branch information
dvander committed Nov 5, 2023
1 parent 7bfd5e5 commit 4b2d8b5
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 39 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/scripting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
41 changes: 31 additions & 10 deletions AMBuildScript
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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']

Expand Down Expand Up @@ -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++',
]
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion sourcepawn
34 changes: 8 additions & 26 deletions tools/buildbot/PackageHelpers
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -70,4 +52,4 @@ class PackageHelpers:

self.CopyFiles('plugins/include', target_folder, '.inc')

SM.package_helpers = PackageHelpers(builder)
SM.package_helpers = PackageHelpers(builder)

0 comments on commit 4b2d8b5

Please sign in to comment.