Updated recipe for Glslang to build it via Scons instead of CMake so it is compiled with the same options (e.g. safe iterators) as the main project.

This commit is contained in:
Patrick 2023-11-04 22:34:41 +01:00
parent 7050ec5e43
commit 7f11cd544a
2 changed files with 44 additions and 5 deletions

View File

@ -35,6 +35,16 @@ def _inject_dependency(dependency, kwargs: dict) -> None:
_inject_list(kwargs, dependency, 'LIBPATH')
_inject_list(kwargs, dependency, 'LIBS')
def _rglob(env: Environment, root_path: str, pattern: str, **kwargs):
result_nodes = []
paths = [root_path]
while paths:
path = paths.pop()
all_nodes = env.Glob(f'{path}/*', **kwargs)
paths.extend(entry for entry in all_nodes if entry.isdir() or (entry.srcnode() and entry.srcnode().isdir())) # `srcnode()` must be used because `isdir()` doesn't work for entries in variant dirs which haven't been copied yet.
result_nodes.extend(env.Glob(f'{path}/{pattern}', **kwargs))
return sorted(result_nodes)
def _wrap_builder(builder, is_lib: bool = False):
def _wrapped(env, dependencies = [], *args, **kwargs):
if 'CPPPATH' not in kwargs:
@ -43,6 +53,8 @@ def _wrap_builder(builder, is_lib: bool = False):
kwargs['CPPDEFINES'] = copy.copy(env['CPPDEFINES'])
if 'LIBPATH' not in kwargs:
kwargs['LIBPATH'] = copy.copy(env['LIBPATH'])
if 'LIBS' not in kwargs and 'LIBS' in env:
kwargs['LIBS'] = copy.copy(env['LIBS'])
for dependency in dependencies:
_inject_dependency(dependency, kwargs)
result = builder(*args, **kwargs)
@ -257,7 +269,6 @@ if env['COMPILER_FAMILY'] == 'gcc' or env['COMPILER_FAMILY'] == 'clang':
env.Append(CXXFLAGS = ['-std=c++20'])
if build_type != 'release':
env.Append(LINKFLAGS = [f'-Wl,-rpath,{env["LIB_DIR"]}'])
env['LINKCOM'] = env['LINKCOM'].replace('$_LIBFLAGS', '-Wl,--start-group $_LIBFLAGS -Wl,--end-group')
if env['COMPILER_FAMILY'] == 'gcc':
# GCC complains about missing initializer for "<anonymous>" that doesn't exist :/
@ -304,6 +315,7 @@ elif env['COMPILER_FAMILY'] == 'clang':
env.AddMethod(_cook, 'Cook')
env.AddMethod(_parse_lib_conf, 'ParseLibConf')
env.AddMethod(_rglob, 'RGlob')
env.AddMethod(_wrap_builder(env.Library, is_lib = True), 'Library')
env.AddMethod(_wrap_builder(env.StaticLibrary, is_lib = True), 'StaticLibrary')
env.AddMethod(_wrap_builder(env.SharedLibrary, is_lib = True), 'SharedLibrary')

View File

@ -2,6 +2,7 @@
from SCons.Script import *
import os
import platform
import subprocess
import sys
@ -14,10 +15,36 @@ def cook(env: Environment, remote: str = 'github', git_ref: str = '') -> dict:
# TODO: windows?
subprocess.run(('/usr/bin/env', 'python3', 'update_glslang_sources.py'), cwd=checkout_root, stdout=sys.stdout, stderr=sys.stderr, check=True)
build_result = env.Cook('CMakeProject', project_root=checkout_root, generate_args = ['-DBUILD_TESTING=OFF'])
# build_result = env.Cook('CMakeProject', project_root=checkout_root, generate_args = ['-DBUILD_TESTING=OFF'])
# generator_script = os.path.join(repo['checkout_root'], 'gen_extension_headers.py')
# generator_script_input = os.path.join(repo['checkout_root'], 'glslang/ExtensionHeaders')
# generator_script_output = os.path.join(repo['checkout_root'], 'glslang/glsl_intrinsic_header.h')
# env.Command(
# target = generator_script_output,
# source = [generator_script, os.path.join(repo['checkout_root'], 'glslang/ExtensionHeaders/GL_EXT_shader_realtime_clock.glsl')],
# action = f'"$PYTHON" "{generator_script}" -i "{generator_script_input}" -o "$TARGET"'
# )
platform_source_dir = {
'Linux': 'Unix',
'Windows': 'Windows',
'Darwin': 'Unix'
}.get(platform.system(), 'Unix')
glslang_source_files = env.RGlob(os.path.join(repo['checkout_root'], 'glslang/GenericCodeGen/'), '*.cpp') \
+ env.RGlob(os.path.join(repo['checkout_root'], 'glslang/MachineIndependent/'), '*.cpp') \
+ env.RGlob(os.path.join(repo['checkout_root'], 'glslang/OGLCompilersDLL/'), '*.cpp') \
+ env.RGlob(os.path.join(repo['checkout_root'], 'glslang/ResourceLimits/'), '*.cpp') \
+ env.RGlob(os.path.join(repo['checkout_root'], 'glslang/SPIRV/'), '*.cpp') \
+ env.RGlob(os.path.join(repo['checkout_root'], f'glslang/OSDependent/{platform_source_dir}/'), '*.cpp')
env.StaticLibrary(
CPPPATH = repo['checkout_root'],
target = env['LIB_DIR'] + '/glslang_full',
source = glslang_source_files
)
return {
'LIBPATH': [os.path.join(build_result['install_dir'], 'glslang')],
'CPPPATH': build_result['CPPPATH'],
'LIBS': ['glslang', 'glslang-default-resource-limits', 'MachineIndependent']
'CPPPATH': [checkout_root],
'LIBS': ['glslang_full']
}