Skip to content

Commit

Permalink
Fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
accelerator74 committed Jul 16, 2024
1 parent 0b744a0 commit 8db9118
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: build

on:
workflow_dispatch:
push:
branches:
- main
Expand Down Expand Up @@ -29,6 +30,7 @@ jobs:
matrix:
os:
- ubuntu-latest
- ubuntu-20.04
- windows-latest

sm_version:
Expand All @@ -47,6 +49,9 @@ jobs:
- os: ubuntu-latest
os_short: linux

- os: ubuntu-20.04
os_short: oldlinux

- os: windows-latest
os_short: win

Expand Down
35 changes: 26 additions & 9 deletions AMBuildScript
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# vim: set sts=2 ts=8 sw=2 tw=99 et ft=python:
import os, sys
import os, sys, shutil

class SDK(object):
def __init__(self, sdk, ext, aDef, name, platform, dir):
Expand Down Expand Up @@ -103,6 +103,7 @@ class ExtensionConfig(object):
self.sm_root = None
self.all_targets = []
self.target_archs = set()
self.libsafetyhook = {}

if builder.options.targets:
target_archs = builder.options.targets.split(',')
Expand Down Expand Up @@ -563,14 +564,15 @@ class ExtensionConfig(object):
def AddCDetour(self, binary):
sm_public_path = os.path.join(self.sm_root, 'public')

if os.path.exists(os.path.join(sm_public_path, 'safetyhook', 'safetyhook.cpp')):
binary.sources += [
os.path.join(sm_public_path, 'CDetour', 'detours.cpp'),
os.path.join(sm_public_path, 'safetyhook', 'safetyhook.cpp'),
os.path.join(sm_public_path, 'safetyhook', 'Zydis.c')
]
binary.compiler.cxxincludes += [ os.path.join(sm_public_path, 'safetyhook') ]
binary.compiler.includes += [ os.path.join(sm_public_path, 'safetyhook') ]
if os.path.exists(os.path.join(sm_public_path, 'safetyhook')):
binary.sources += [ os.path.join(sm_public_path, 'CDetour', 'detours.cpp') ]
binary.compiler.cxxincludes += [ os.path.join(builder.sourcePath, 'safetyhook', 'include') ]

for task in self.libsafetyhook:
if task.target.arch == binary.compiler.target.arch:
binary.compiler.linkflags += [task.binary]
return
raise Exception('No suitable build of safetyhook was found.')
else:
binary.sources += [
os.path.join(sm_public_path, 'CDetour', 'detours.cpp'),
Expand Down Expand Up @@ -606,6 +608,11 @@ class ExtensionConfig(object):
self.ConfigureForExtension(context, binary.compiler)
return binary

class SafetyHookShim(object):
def __init__(self):
self.all_targets = {}
self.libsafetyhook = {}

if getattr(builder, 'target', None) is not None:
sys.stderr.write("Your output folder was configured for AMBuild 2.1.\n")
sys.stderr.write("Please remove your output folder and reconfigure to continue.\n")
Expand All @@ -615,6 +622,16 @@ Extension = ExtensionConfig()
Extension.detectSDKs()
Extension.configure()

if os.path.exists(os.path.join(Extension.sm_root, 'public', 'safetyhook')):
# we need to pull safetyhook in locally because ambuild does not take kindly to outside relpaths
safetyhook_dest = Normalize(builder.sourcePath + '/safetyhook/')
shutil.copytree(os.path.join(Extension.sm_root, 'public', 'safetyhook'), safetyhook_dest, dirs_exist_ok=True)

SafetyHook = SafetyHookShim()
SafetyHook.all_targets = Extension.all_targets
builder.Build('safetyhook/AMBuilder', {'SafetyHook': SafetyHook })
Extension.libsafetyhook = SafetyHook.libsafetyhook

# This will clone the list and each cxx object as we recurse, preventing child
# scripts from messing up global state.
builder.targets = builder.CloneableList(Extension.all_targets)
Expand Down

0 comments on commit 8db9118

Please sign in to comment.