mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-22 08:18:08 +02:00
Fix building of shaders under ASAN
We cant import fast_data_types.so into the system python in that case, so build shaders by running the compiler under the kitty launcher.
This commit is contained in:
@@ -3,7 +3,9 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import runpy
|
||||||
import shutil
|
import shutil
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from contextlib import suppress
|
from contextlib import suppress
|
||||||
@@ -419,3 +421,22 @@ def compile_builtin_shaders(build_dir: str, dest_dir: str, parallel_run: Paralle
|
|||||||
# Now run all commands
|
# Now run all commands
|
||||||
parallel_run(chain(spirv_commands, glsl_commands))
|
parallel_run(chain(spirv_commands, glsl_commands))
|
||||||
fixup_opengl_files(*built_glsl_files)
|
fixup_opengl_files(*built_glsl_files)
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
setup = runpy.run_path('setup.py')
|
||||||
|
Command = setup['Command']
|
||||||
|
parallel_run = setup['parallel_run']
|
||||||
|
emphasis = setup['emphasis']
|
||||||
|
def prun(cmds: Iterable[tuple[bool, str, list[str]]]) -> None:
|
||||||
|
needed = []
|
||||||
|
for (needs_build, desc, cmd) in cmds:
|
||||||
|
if needs_build:
|
||||||
|
desc = re.sub(r'\|(.+?)\|', lambda m: emphasis(m.group(1)), desc)
|
||||||
|
needed.append(Command(desc, cmd, lambda: True))
|
||||||
|
parallel_run(needed)
|
||||||
|
compile_builtin_shaders(sys.argv[-2], sys.argv[-1], prun)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|||||||
39
setup.py
39
setup.py
@@ -45,7 +45,6 @@ def check_version_info() -> None:
|
|||||||
exit(f'kitty requires Python {minver}. Current Python version: {".".join(map(str, sys.version_info[:3]))}')
|
exit(f'kitty requires Python {minver}. Current Python version: {".".join(map(str, sys.version_info[:3]))}')
|
||||||
|
|
||||||
|
|
||||||
check_version_info()
|
|
||||||
verbose = False
|
verbose = False
|
||||||
build_dir = 'build'
|
build_dir = 'build'
|
||||||
constants = os.path.join('kitty', 'constants.py')
|
constants = os.path.join('kitty', 'constants.py')
|
||||||
@@ -87,7 +86,6 @@ class CompilationDatabase:
|
|||||||
self.incremental = incremental
|
self.incremental = incremental
|
||||||
self.compile_commands: List[Command] = []
|
self.compile_commands: List[Command] = []
|
||||||
self.link_commands: List[Command] = []
|
self.link_commands: List[Command] = []
|
||||||
self.build_shaders: Callable[[], None] = lambda: None
|
|
||||||
self.post_link_commands: List[Command] = []
|
self.post_link_commands: List[Command] = []
|
||||||
|
|
||||||
def add_command(
|
def add_command(
|
||||||
@@ -129,8 +127,6 @@ class CompilationDatabase:
|
|||||||
items.append(compile_cmd)
|
items.append(compile_cmd)
|
||||||
parallel_run(items)
|
parallel_run(items)
|
||||||
|
|
||||||
self.build_shaders()
|
|
||||||
|
|
||||||
items = []
|
items = []
|
||||||
for compile_cmd in self.post_link_commands:
|
for compile_cmd in self.post_link_commands:
|
||||||
if not self.incremental or compile_cmd.is_newer_func():
|
if not self.incremental or compile_cmd.is_newer_func():
|
||||||
@@ -1208,31 +1204,19 @@ def wrapped_kittens() -> str:
|
|||||||
raise Exception('Failed to read wrapped kittens from kitty wrapper script')
|
raise Exception('Failed to read wrapped kittens from kitty wrapper script')
|
||||||
|
|
||||||
|
|
||||||
def build_shaders(args: Options) -> None:
|
def build_shaders(args: Options, kitty_exe: str) -> None:
|
||||||
if args.skip_code_generation:
|
if args.skip_code_generation:
|
||||||
print('Skipping building of shaders due to command line option', flush=True)
|
print('Skipping building of shaders due to command line option', flush=True)
|
||||||
return
|
return
|
||||||
def do_build() -> None:
|
env = os.environ.copy()
|
||||||
ddir = 'shaders'
|
env['ASAN_OPTIONS'] = 'detect_leaks=0'
|
||||||
os.makedirs(ddir, exist_ok=True)
|
cp = subprocess.run([
|
||||||
bdir = 'build/shaders'
|
kitty_exe, '+launch', os.path.join(src_base, 'kitty/shaders/slang.py'), 'build/shaders', 'shaders',
|
||||||
os.makedirs(bdir, exist_ok=True)
|
], env=env)
|
||||||
|
if cp.returncode != 0:
|
||||||
def prun(cmds: Iterable[tuple[bool, str, list[str]]]) -> None:
|
if os.environ.get('CI') == 'true' and cp.returncode < 0 and shutil.which('coredumpctl'):
|
||||||
needed = []
|
subprocess.run(['sh', '-c', 'echo bt | coredumpctl debug'])
|
||||||
for (needs_build, desc, cmd) in cmds:
|
raise SystemExit(f'Generating shaders failed with exit code: {cp.returncode}')
|
||||||
if needs_build:
|
|
||||||
desc = re.sub(r'\|(.+?)\|', lambda m: emphasis(m.group(1)), desc)
|
|
||||||
needed.append(Command(desc, cmd, lambda: True))
|
|
||||||
parallel_run(needed)
|
|
||||||
|
|
||||||
sys.path.insert(0, os.path.abspath('kitty'))
|
|
||||||
try:
|
|
||||||
from kitty.shaders.slang import compile_builtin_shaders
|
|
||||||
compile_builtin_shaders(bdir, ddir, prun)
|
|
||||||
finally:
|
|
||||||
del sys.path[0]
|
|
||||||
args.compilation_database.build_shaders = do_build
|
|
||||||
|
|
||||||
|
|
||||||
def build(args: Options, native_optimizations: bool = True, call_init: bool = True) -> None:
|
def build(args: Options, native_optimizations: bool = True, call_init: bool = True) -> None:
|
||||||
@@ -1250,7 +1234,6 @@ def build(args: Options, native_optimizations: bool = True, call_init: bool = Tr
|
|||||||
compile_glfw(args.compilation_database, args.build_dsym)
|
compile_glfw(args.compilation_database, args.build_dsym)
|
||||||
compile_kittens(args)
|
compile_kittens(args)
|
||||||
add_builtin_fonts(args)
|
add_builtin_fonts(args)
|
||||||
build_shaders(args)
|
|
||||||
|
|
||||||
|
|
||||||
def safe_makedirs(path: str) -> None:
|
def safe_makedirs(path: str) -> None:
|
||||||
@@ -1312,6 +1295,7 @@ def build_static_kittens(
|
|||||||
raise SystemExit(f'The version of go on this system ({current_go_version}) is too old. go >= {required_go_version} is needed')
|
raise SystemExit(f'The version of go on this system ({current_go_version}) is too old. go >= {required_go_version} is needed')
|
||||||
if not for_platform:
|
if not for_platform:
|
||||||
update_go_generated_files(args, os.path.join(launcher_dir, appname))
|
update_go_generated_files(args, os.path.join(launcher_dir, appname))
|
||||||
|
build_shaders(args, os.path.join(launcher_dir, appname))
|
||||||
if args.skip_building_kitten:
|
if args.skip_building_kitten:
|
||||||
print('Skipping building of the kitten binary because of a command line option. Build is incomplete', file=sys.stderr)
|
print('Skipping building of the kitten binary because of a command line option. Build is incomplete', file=sys.stderr)
|
||||||
return ''
|
return ''
|
||||||
@@ -2363,6 +2347,7 @@ def do_build(args: Options) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
|
check_version_info()
|
||||||
global verbose, build_dir
|
global verbose, build_dir
|
||||||
if len(sys.argv) > 1 and sys.argv[1] == 'build-dep':
|
if len(sys.argv) > 1 and sys.argv[1] == 'build-dep':
|
||||||
return build_dep()
|
return build_dep()
|
||||||
|
|||||||
Reference in New Issue
Block a user