Skip to content

Commit

Permalink
Statically link libz, libgcc & libstdc++
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenzzer committed Oct 4, 2024
1 parent 2c74bcc commit 951b655
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "breakpad"]
path = third_party/breakpad
url = https://github.com/google/breakpad.git
[submodule ".\\third_party\\zlib"]
path = .\\third_party\\zlib
url = https://github.com/madler/zlib.git
11 changes: 10 additions & 1 deletion AMBuildScript
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class AcceleratorConfig(object):
self.mms_root = None
self.sm_root = None
self.extension = None
self.libz = None
self.libbreakpad_client = None
self.libbreakpad = None
self.libdisasm = None
Expand Down Expand Up @@ -118,7 +119,7 @@ class AcceleratorConfig(object):
'-Wno-implicit-exception-spec-mismatch'
]

cxx.postlink += ['-pthread', '-lz']
cxx.postlink += ['-pthread', '-static-libstdc++', '-static-libgcc']

if builder.options.opt == '1':
cxx.cflags += ['-O3']
Expand Down Expand Up @@ -161,6 +162,14 @@ class AcceleratorConfig(object):
os.path.join(self.sm_root, 'sourcepawn', 'include')
]

def link_libz(self, compiler, context):
for task in self.libz:
if task.target.arch == compiler.target.arch:
compiler.postlink += [os.path.join(context.buildPath, task.binary.path)]
compiler.linkdeps += [task.binary]
return
raise Exception('No suitable build of libz was found.')

def link_libbreakpad_client(self, compiler, context):
for task in self.libbreakpad_client:
if task.target.arch == compiler.target.arch:
Expand Down
30 changes: 29 additions & 1 deletion third_party/AMBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,33 @@ def AddSourceFilesFromDir(path, files):
list.append(os.path.join(path, file))
return list

builder.SetBuildFolder('./third_party/breakpad')
builder.SetBuildFolder('./third_party')

libz = builder.StaticLibraryProject('libz')
libz.sources = AddSourceFilesFromDir(os.path.join(builder.currentSourcePath, 'zlib'),[
'adler32.c',
'compress.c',
'crc32.c',
'deflate.c',
'gzclose.c',
'gzlib.c',
'gzread.c',
'gzwrite.c',
'infback.c',
'inffast.c',
'inflate.c',
'inftrees.c',
'trees.c',
'uncompr.c',
'zutil.c'
])

for cxx in Accelerator.targets:
if cxx.target.platform == 'linux':
binary = Accelerator.ConfigureLibrary(libz, cxx, builder)
binary.compiler.cflags += ['-Wno-implicit-function-declaration']

Accelerator.libz = builder.Add(libz)

libbreakpad_client = builder.StaticLibraryProject('libbreakpad_client')
libbreakpad_client.sources = AddSourceFilesFromDir(os.path.join(builder.currentSourcePath, 'breakpad', 'src'),[
Expand Down Expand Up @@ -130,6 +156,8 @@ for cxx in Accelerator.targets:
compiler.sourcedeps += Accelerator.breakpad_patch

if compiler.target.platform == 'linux':
# Link against our zlib if linux
Accelerator.link_libz(cxx, builder)
binary.sources += linux_src
if compiler.target.platform == 'windows':
binary.sources += windows_src
Expand Down
1 change: 1 addition & 0 deletions third_party/zlib
Submodule zlib added at d47682

0 comments on commit 951b655

Please sign in to comment.