spp_recipes/recipes/dxc/recipe.py

42 lines
1.4 KiB
Python

import os
import re
import shutil
from SCons.Script import *
def _git_cook(env: Environment, repo: dict) -> dict:
checkout_root = repo['checkout_root']
build_result = env.CMakeProject(checkout_root, generate_args = [
f'-C{repo['checkout_root']}/cmake/caches/PredefinedParams.cmake',
'-DLLVM_INSTALL_TOOLCHAIN_ONLY=ON', '-DHLSL_INCLUDE_TESTS=OFF', '-DLLVM_INCLUDE_TESTS=OFF',
'-DSPIRV_BUILD_TESTS=OFF'
])
link_flags = []
if env['COMPILER_FAMILY'] in ('gcc', 'clang') and env['BUILD_TYPE'] != 'release':
link_flags.append(f'-Wl,-rpath,{build_result["LIBPATH"][0]}')
elif env['COMPILER_FAMILY'] == 'cl':
# for some reason CMake doesn't copy the .lib file
lib_src = os.path.join(build_result['build_dir'], 'lib/dxcompiler.lib')
lib_dst = os.path.join(build_result['LIBPATH'][0], 'dxcompiler.lib')
if not os.path.exists(lib_dst):
shutil.copy(lib_src, lib_dst)
return {
'CPPPATH': build_result['CPPPATH'],
'LIBS': [env.FindLib('dxcompiler', type='shared', paths=build_result['LIBPATH'])],
'LINKFLAGS': link_flags
}
env.GitRecipe(
globals = globals(),
repo_name = 'dxc',
repo_url = 'https://github.com/microsoft/DirectXShaderCompiler.git',
tag_pattern = re.compile(r'^v([0-9]+)\.([0-9]+)\.([0-9]+)$'),
tag_fn = lambda version: f'v{version[0]}.{version[1]}.{version[2]}',
cook_fn = _git_cook
)