Skip to content

Commit

Permalink
Build universal binaries for spcomp on macOS.
Browse files Browse the repository at this point in the history
  • Loading branch information
dvander committed Nov 5, 2023
1 parent f4cef31 commit 71c9250
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions AMBuildScript
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,17 @@ import copy
import os
import subprocess
import sys
from ambuild2.frontend.system import System

def Normalize(path):
return os.path.abspath(os.path.normpath(path))

class LipoEntry(object):
def __init__(self, binary, target, type):
self.binary = binary
self.target = target
self.type = type

def SetArchFlags(compiler):
if compiler.like('gcc'):
if compiler.target.arch == 'x86':
Expand Down Expand Up @@ -327,7 +334,7 @@ class SourcePawn(object):
'SP': self,
}
self.spshell = {}
self.spcomp = {}
self.spcomp = []
self.zlib = None
self.libamtl = None
self.static_libsp = {}
Expand All @@ -343,6 +350,8 @@ class SourcePawn(object):
for cxx in self.root.targets:
builder.CallBuilder(lambda builder: self.BuildCoreForArch(cxx, builder))

builder.CallBuilder(lambda builder: self.BuildFatSpcomp(builder))

def SetupBinForArch(self, binary, builder):
if binary.compiler.like('gcc'):
binary.compiler.cflags += [
Expand Down Expand Up @@ -430,7 +439,7 @@ class SourcePawn(object):
self.AddStaticLibraries(binary)

cppnodes = builder.Add(binary)
self.spcomp[builder.cxx.target.arch] = cppnodes
self.spcomp.append(cppnodes)

def BuildSpshell(self, builder):
binary = self.root.Program(builder, 'spshell')
Expand Down Expand Up @@ -476,6 +485,34 @@ class SourcePawn(object):
if binary.compiler.linker.like('gcc') and binary.compiler.target.platform == 'linux':
binary.compiler.linkflags += ['-Wl,--end-group']

def BuildFatSpcomp(self, builder):
# Building fat binaries is currently only supported on macOS hosts
# building macOS targets.
if builder.host.platform != 'mac':
return

mac_targets = []
for spcomp in self.spcomp:
if spcomp.target.platform == 'mac':
mac_targets.append(spcomp.binary)

if len(mac_targets) == 0:
return

lipo_argv = [
'lipo', '-create',
]
for spcomp in mac_targets:
lipo_argv += [os.path.join(builder.buildPath, spcomp.path)]
lipo_argv += ['-output', 'spcomp']

out = builder.AddCommand(inputs = mac_targets,
argv = lipo_argv,
outputs = ['spcomp'],
folder = builder.AddFolder('spcomp/mac-universal'))

self.spcomp.append(LipoEntry(out, System('mac', 'universal'), 'program'))

def BuildSuite(self):
self.BuildCore()

Expand Down Expand Up @@ -520,7 +557,6 @@ class SourcePawn(object):
builder.cxx = None
return rvalue


if builder.parent is None:
root = Config()
root.configure()
Expand Down

0 comments on commit 71c9250

Please sign in to comment.