Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
exababy authored Feb 10, 2024
1 parent 39b44a0 commit 43f99dd
Show file tree
Hide file tree
Showing 3 changed files with 273 additions and 1 deletion.
4 changes: 3 additions & 1 deletion configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
help='Plugin alias')
parser.options.add_argument('--hl2sdk-root', type=str, dest='hl2sdk_root', default=None,
help='Root search folder for HL2SDKs')
parser.options.add_argument('--hl2sdk-manifests', type=str, dest='hl2sdk_manifests', default=None,
help='HL2SDK manifests source tree folder')
parser.options.add_argument('--mms_path', type=str, dest='mms_path', default=None,
help='Metamod:Source source tree folder')
parser.options.add_argument('--enable-debug', action='store_const', const='1', dest='debug',
Expand All @@ -36,4 +38,4 @@
'comma-delimited list of engine names (default: "all")')
parser.options.add_argument('--targets', type=str, dest='targets', default=None,
help="Override the target architecture (use commas to separate multiple targets).")
parser.Configure()
parser.Configure()
212 changes: 212 additions & 0 deletions hl2sdk-manifests/SdkHelpers.ambuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
# vim: set sts=2 ts=8 sw=2 tw=99 et ft=python:
import json
import os

class SdkTarget(object):
def __init__(self, sdk, cxx, protoc):
self.sdk = sdk
self.cxx = cxx
self.protoc = protoc

class SdkHelpers(object):
def __init__(self):
self.sdks = {}
self.sdk_manifests = []
self.sdk_filter = None
self.find_sdk_path = None
self.sdk_targets = []

# find_sdk_path must be set to use.
def findSdks(self, builder, cxx_list, sdk_list):
not_found = []
sdk_remaining = set(sdk_list)
for sdk_name, sdk in SdkHelpers.getSdks(builder):
self.sdk_manifests.append(sdk)
# Skip SDKs that weren't specified or are not supported.
if not self.shouldFindSdk(sdk, sdk_list):
continue
# Skip SDKs that won't build on any targets.
if not SdkHelpers.sdkHasBuildTargets(sdk, cxx_list):
continue

sdk_path = self.find_sdk_path(sdk_name)
if sdk_path is None:
if SdkHelpers.shouldRequireSdk(sdk_name, sdk_list):
raise Exception('Could not find a valid path for {0}'.format(sdk_name))
not_found.append(sdk_name)
continue

sdk_remaining.discard(sdk_name)

sdk['path'] = sdk_path
self.sdks[sdk_name] = sdk

for cxx in cxx_list:
if SdkHelpers.shouldBuildSdk(sdk, cxx):
protoc = None
rel_protoc_path = sdk[cxx.target.platform].get('protoc_path', None)
if rel_protoc_path:
protoc_path = os.path.join(sdk['path'], rel_protoc_path)
protoc = builder.DetectProtoc(path = protoc_path)
for path in sdk['include_paths']:
protoc.includes += [os.path.join(sdk['path'], path)]
self.sdk_targets += [SdkTarget(sdk, cxx, protoc)]

if 'present' in sdk_list:
for sdk in not_found:
print('Warning: hl2sdk-{} was not found, and will not be included in build.'.format(sdk))
elif len(sdk_remaining) and 'all' not in sdk_list:
for sdk in sdk_remaining:
print('Error: hl2sdk-{} was not found.'.format(sdk))
raise Exception('Missing hl2sdks: {}'.format(','.join(sdk_remaining)))

if not len(self.sdk_targets) and len(sdk_list):
raise Exception('No buildable SDKs were found, nothing to build.')

@staticmethod
def shouldRequireSdk(sdk_name, sdk_list):
if 'all' in sdk_list:
return sdk_name != 'mock'
if sdk_name in sdk_list:
return True
return 'present' in sdk_list

def shouldFindSdk(self, sdk, sdk_list):
# Remove SDKs that the project doesn't support.
if self.sdk_filter and not self.sdk_filter(sdk):
return False
if 'all' in sdk_list or 'present' in sdk_list:
return True
return sdk['name'] in sdk_list

@staticmethod
def sdkHasBuildTargets(sdk, cxx_list):
for cxx in cxx_list:
if SdkHelpers.shouldBuildSdk(sdk, cxx):
return True
return False

@staticmethod
def shouldBuildSdk(sdk, cxx):
if cxx.target.platform in sdk['platforms']:
if cxx.target.arch in sdk['platforms'][cxx.target.platform]:
return True
return False

@staticmethod
def addLists(sdk, list_name, cxx):
result = SdkHelpers.getLists(sdk, list_name, cxx)
cxx_list = getattr(cxx, list_name)
cxx_list.extend(result)

@staticmethod
def getLists(sdk, list_name, cxx):
result = SdkHelpers.getListsImpl(sdk, list_name, cxx)
if Project in sdk:
result += SdkHelpers.getListsImpl(sdk[Project], list_name, cxx)
return result

@staticmethod
def getListsImpl(info, list_name, cxx):
result = []
if cxx.target.platform in info:
platform_info = info[cxx.target.platform]
result += platform_info.get(list_name, [])
if cxx.target.arch in platform_info:
arch_info = platform_info[cxx.target.arch]
result += arch_info.get(list_name, [])
return result

@staticmethod
def getSdks(builder):
sdk_manifest_dir = os.path.join(builder.sourcePath, 'hl2sdk-manifests',
'manifests')

out = []
for sdk_manifest in os.listdir(sdk_manifest_dir):
sdk_name, _ = os.path.splitext(sdk_manifest)
sdk_manifest_path = os.path.join(sdk_manifest_dir, sdk_manifest)
with open(sdk_manifest_path, 'rt') as fp:
sdk = json.load(fp)
builder.AddConfigureFile(sdk_manifest_path)
out.append((sdk_name, sdk))
return out

@staticmethod
def configureCxx(context, binary, sdk):
cxx = binary.compiler

# Includes/defines.
cxx.defines += ['SOURCE_ENGINE={}'.format(sdk['code'])]

if sdk['name'] in ['sdk2013', 'bms', 'pvkii'] and cxx.like('gcc'):
# The 2013 SDK already has these in public/tier0/basetypes.h
rm_defines = [
'stricmp=strcasecmp', '_stricmp=strcasecmp',
'_snprintf=snprintf', '_vsnprintf=vsnprintf,'
]
for rm_define in rm_defines:
if rm_define in cxx.defines:
cxx.defines.remove(rm_define)

if cxx.family == 'msvc':
cxx.defines += ['COMPILER_MSVC']
if cxx.target.arch == 'x86':
cxx.defines += ['COMPILER_MSVC32']
elif cxx.target.arch == 'x86_64':
cxx.defines += ['COMPILER_MSVC64']

if cxx.version >= 1900:
cxx.linkflags += ['legacy_stdio_definitions.lib']
else:
cxx.defines += ['COMPILER_GCC']

if cxx.target.arch == 'x86_64':
cxx.defines += ['X64BITS', 'PLATFORM_64BITS']

SdkHelpers.addLists(sdk, 'defines', cxx)
SdkHelpers.addLists(sdk, 'linkflags', cxx)

for path in sdk['include_paths']:
cxx.cxxincludes += [os.path.join(sdk['path'], path)]

# Link steps.
for lib in SdkHelpers.getLists(sdk, 'libs', cxx):
cxx.linkflags += [os.path.join(sdk['path'], lib)]
for lib in SdkHelpers.getLists(sdk, 'postlink_libs', cxx):
cxx.postlink += [os.path.join(sdk['path'], lib)]

if cxx.target.platform == 'linux':
cxx.linkflags[0:0] = ['-lm']
elif cxx.target.platform == 'mac':
cxx.linkflags.append('-liconv')

dynamic_libs = SdkHelpers.getLists(sdk, 'dynamic_libs', cxx)
for library in dynamic_libs:
file_name = os.path.split(library)[1]
source_path = os.path.join(sdk['path'], library)
output_path = os.path.join(binary.localFolder, file_name)

context.AddFolder(binary.localFolder)
output = context.AddSymlink(source_path, output_path)

cxx.weaklinkdeps += [output]
cxx.linkflags[0:0] = [file_name]

if cxx.target.platform == 'linux':
if sdk[cxx.target.platform]['uses_system_cxxlib']:
cxx.linkflags.remove('-static-libstdc++')
cxx.linkflags += ['-lstdc++']
elif cxx.target.platform == 'mac':
if sdk[cxx.target.platform]['cxxlib'] == 'stdc++':
# Switch libc++ to libstdc++ for protobuf linkage.
cxx.cxxflags.remove('-stdlib=libc++')
cxx.linkflags.remove('-stdlib=libc++')
cxx.linkflags.remove('-lc++')

cxx.cxxflags += ['-stdlib=libstdc++']
cxx.linkflags += ['-stdlib=libstdc++']
cxx.linkflags += ['-lstdc++']


rvalue = SdkHelpers()
58 changes: 58 additions & 0 deletions hl2sdk-manifests/manifests/cs2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"name": "cs2",
"env_var": "HL2SDKCS2",
"extension": "2.cs2",
"code": 25,
"define": "CS2",
"platforms": {
"windows": [
"x86_64"
],
"linux": [
"x86_64"
]
},
"source2": true,
"include_paths": [
"thirdparty/protobuf-3.21.8/src",
"public",
"public/engine",
"public/mathlib",
"public/vstdlib",
"public/tier0",
"public/tier1",
"public/entity2",
"public/game/server",
"game/server",
"game/shared",
"common"
],
"linux": {
"x86_64": {
"postlink_libs": [
"lib/linux64/tier1.a",
"lib/linux64/interfaces.a",
"lib/linux64/release/libprotobuf.a"
],
"dynamic_libs": [
"lib/linux64/libtier0.so"
]
},
"defines": [
"_GLIBCXX_USE_CXX11_ABI=0"
],
"uses_system_cxxlib": true,
"protoc_path": "devtools/bin/linux/protoc"
},
"windows": {
"x86_64": {
"libs": [
"lib/public/win64/2015/libprotobuf.lib",
"lib/public/win64/tier0.lib",
"lib/public/win64/tier1.lib",
"lib/public/win64/interfaces.lib"
]
},
"protoc_path": "devtools/bin/protoc.exe"
}
}

0 comments on commit 43f99dd

Please sign in to comment.