Skip to content

Commit cfbae29

Browse files
committed
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.
1 parent 6f0fac3 commit cfbae29

2 files changed

Lines changed: 33 additions & 27 deletions

File tree

kitty/shaders/slang.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
import os
55
import re
6+
import runpy
67
import shutil
8+
import sys
79
import time
810
from collections import OrderedDict
911
from contextlib import suppress
@@ -419,3 +421,22 @@ def compile_builtin_shaders(build_dir: str, dest_dir: str, parallel_run: Paralle
419421
# Now run all commands
420422
parallel_run(chain(spirv_commands, glsl_commands))
421423
fixup_opengl_files(*built_glsl_files)
424+
425+
426+
def main() -> None:
427+
setup = runpy.run_path('setup.py')
428+
Command = setup['Command']
429+
parallel_run = setup['parallel_run']
430+
emphasis = setup['emphasis']
431+
def prun(cmds: Iterable[tuple[bool, str, list[str]]]) -> None:
432+
needed = []
433+
for (needs_build, desc, cmd) in cmds:
434+
if needs_build:
435+
desc = re.sub(r'\|(.+?)\|', lambda m: emphasis(m.group(1)), desc)
436+
needed.append(Command(desc, cmd, lambda: True))
437+
parallel_run(needed)
438+
compile_builtin_shaders(sys.argv[-2], sys.argv[-1], prun)
439+
440+
441+
if __name__ == '__main__':
442+
main()

setup.py

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ def check_version_info() -> None:
4545
exit(f'kitty requires Python {minver}. Current Python version: {".".join(map(str, sys.version_info[:3]))}')
4646

4747

48-
check_version_info()
4948
verbose = False
5049
build_dir = 'build'
5150
constants = os.path.join('kitty', 'constants.py')
@@ -87,7 +86,6 @@ def __init__(self, incremental: bool = False):
8786
self.incremental = incremental
8887
self.compile_commands: List[Command] = []
8988
self.link_commands: List[Command] = []
90-
self.build_shaders: Callable[[], None] = lambda: None
9189
self.post_link_commands: List[Command] = []
9290

9391
def add_command(
@@ -129,8 +127,6 @@ def sort_key(compile_cmd: Command) -> int:
129127
items.append(compile_cmd)
130128
parallel_run(items)
131129

132-
self.build_shaders()
133-
134130
items = []
135131
for compile_cmd in self.post_link_commands:
136132
if not self.incremental or compile_cmd.is_newer_func():
@@ -1208,31 +1204,19 @@ def wrapped_kittens() -> str:
12081204
raise Exception('Failed to read wrapped kittens from kitty wrapper script')
12091205

12101206

1211-
def build_shaders(args: Options) -> None:
1207+
def build_shaders(args: Options, kitty_exe: str) -> None:
12121208
if args.skip_code_generation:
12131209
print('Skipping building of shaders due to command line option', flush=True)
12141210
return
1215-
def do_build() -> None:
1216-
ddir = 'shaders'
1217-
os.makedirs(ddir, exist_ok=True)
1218-
bdir = 'build/shaders'
1219-
os.makedirs(bdir, exist_ok=True)
1220-
1221-
def prun(cmds: Iterable[tuple[bool, str, list[str]]]) -> None:
1222-
needed = []
1223-
for (needs_build, desc, cmd) in cmds:
1224-
if needs_build:
1225-
desc = re.sub(r'\|(.+?)\|', lambda m: emphasis(m.group(1)), desc)
1226-
needed.append(Command(desc, cmd, lambda: True))
1227-
parallel_run(needed)
1228-
1229-
sys.path.insert(0, os.path.abspath('kitty'))
1230-
try:
1231-
from kitty.shaders.slang import compile_builtin_shaders
1232-
compile_builtin_shaders(bdir, ddir, prun)
1233-
finally:
1234-
del sys.path[0]
1235-
args.compilation_database.build_shaders = do_build
1211+
env = os.environ.copy()
1212+
env['ASAN_OPTIONS'] = 'detect_leaks=0'
1213+
cp = subprocess.run([
1214+
kitty_exe, '+launch', os.path.join(src_base, 'kitty/shaders/slang.py'), 'build/shaders', 'shaders',
1215+
], env=env)
1216+
if cp.returncode != 0:
1217+
if os.environ.get('CI') == 'true' and cp.returncode < 0 and shutil.which('coredumpctl'):
1218+
subprocess.run(['sh', '-c', 'echo bt | coredumpctl debug'])
1219+
raise SystemExit(f'Generating shaders failed with exit code: {cp.returncode}')
12361220

12371221

12381222
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
12501234
compile_glfw(args.compilation_database, args.build_dsym)
12511235
compile_kittens(args)
12521236
add_builtin_fonts(args)
1253-
build_shaders(args)
12541237

12551238

12561239
def safe_makedirs(path: str) -> None:
@@ -1312,6 +1295,7 @@ def build_static_kittens(
13121295
raise SystemExit(f'The version of go on this system ({current_go_version}) is too old. go >= {required_go_version} is needed')
13131296
if not for_platform:
13141297
update_go_generated_files(args, os.path.join(launcher_dir, appname))
1298+
build_shaders(args, os.path.join(launcher_dir, appname))
13151299
if args.skip_building_kitten:
13161300
print('Skipping building of the kitten binary because of a command line option. Build is incomplete', file=sys.stderr)
13171301
return ''
@@ -2363,6 +2347,7 @@ def do_build(args: Options) -> None:
23632347

23642348

23652349
def main() -> None:
2350+
check_version_info()
23662351
global verbose, build_dir
23672352
if len(sys.argv) > 1 and sys.argv[1] == 'build-dep':
23682353
return build_dep()

0 commit comments

Comments
 (0)