30 lines
996 B
Python

import shutil
from SCons.Script import *
def exists(env: Environment) -> bool:
return shutil.which('dxc.exe') is not None
def generate(env : Environment):
if not exists(env):
return
def _build(target, source, env):
if len(target) != 1:
env.Error('Invalid number of targets for DXC builder, must be 1.')
if len(source) != 1:
env.Error('Invalid number of sources for DXC builder, must be 1.')
ext = source[0].name.split('.')[-1]
profile = {
'vs': 'vs_6_0',
'ps': 'ps_6_0'
}.get(ext.lower())
if not profile:
env.Error(f'Could not detect DXC shader profile from extension: {ext}')
env.Execute(f'"$DXC" -O0 -Zi -E main -T {profile} -Fo "{target[0]}" -Fd "{target[0]}.pdb" "{source[0]}')
dxc_builder = Builder(
action=_build
)
env.AddMethod(_build, 'DXC')
env['DXC'] = shutil.which('dxc.exe')
env.Append(BUILDERS={'DXC': dxc_builder})