Build the Linux kit against pinned Vulkan headers and without #embed, and try the compiler before the long steps.

A player's AppImage build of 0.7.1 stopped in its compile step after eight minutes of RomFS work: four
files did not compile, because the kit builds with the system's compiler and headers and theirs were
older than the runtime needs. vk_pipeline.c and vk_device.c name VK_KHR_pipeline_binary,
VK_KHR_dynamic_rendering_local_read and VK_KHR_shader_maximal_reconvergence, which their Vulkan headers
did not declare, and ui/menu.cpp takes its font in with #embed, which clang has from version 19.

- Vulkan headers: tools/vulkan_pin.py holds the release the other builds use (1.4.363, the archive and
  hash tools/make_release_linux.py already pinned, which now reads them from there). The AppImage carries
  its C headers in toolchain/vulkan-headers and builds against them whatever the system has; a kit or a
  source checkout uses the system's when they are at least that release and fetches the pinned ones
  otherwise (build_game.py vulkan_include). Their folder goes first on the include path of the runtime's
  sources only, so the lifted code's objects keep their keys, and a runtime object compiled before
  against the system's headers is taken over instead of compiled again. AppRun no longer asks for the
  system's Vulkan headers.
- #embed: tools/build_shaders.py also writes the font's bytes as runtime/ui/roboto_ttf.h (ignored by git,
  carried by a kit), and menu.cpp includes that where the compiler has no __has_embed. With #embed
  nothing changes.
- Before its long steps a Linux build that will compile now checks every runtime source that needs no
  header of the install with the compile step's own command (clang -fsyntax-only) and links an empty
  program against the game's libraries (make_game.py preflight): an old compiler, an old header or a
  missing development package stops it in the first seconds with the compiler's own errors. A failed
  compile names every file that failed, not only the three whose errors it prints.

Checked on Windows: tests/launcher_test.py passes with four new tests (117); the header of bytes and
#embed give the same 162,588 bytes, and both branches of menu.cpp compile; the early check passes on the
Windows file set with clang 23 and stops on files made to fail; the 34 local headers of release 363 are
the upstream tag's files by git blob id. Not run: anything on Linux, the pinned archive's download, a
compiler older than 23.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-10 12:42:17 -05:00
parent 005d30a29c
commit 61cd4784f8
13 changed files with 465 additions and 38 deletions

View File

@@ -1870,6 +1870,131 @@ class MakeGameTest(Tmp):
self.assertNotEqual(self.mg.object_key(plain, src, dst, cache, 'id', sysroot=True),
self.mg.object_key(fast, src, dst, cache, 'id', sysroot=True))
def test_vulkan_headers_go_first_for_the_runtime_only(self):
"""The folder of the pinned Vulkan headers goes ahead of every other include folder for the runtime's sources,
so that no folder that also is a system one answers for <vulkan/vulkan.h>; the lifted code's command, which is
part of its objects' keys, is the one it was."""
inc = ['-I', 'rt', '-I', '/usr/include']
with_vk = self.mg.runtime_cmd('clang', 'clang++', inc, 3, first=['-I', 'kit/vulkan'])
without = self.mg.runtime_cmd('clang', 'clang++', inc, 3)
guest = (Path('lift/main_0001.c'), Path('obj/main_main_0001.o'))
self.assertEqual(with_vk(*guest), without(*guest))
for src in (Path('rt/vk_device.c'), Path('rt/ui/menu.cpp')):
cmd, plain = with_vk(src, Path('obj/rt_x.o')), without(src, Path('obj/rt_x.o'))
self.assertEqual(cmd.count('-I'), plain.count('-I') + 1)
self.assertLess(cmd.index('kit/vulkan'), cmd.index('rt'))
self.assertLess(cmd.index('kit/vulkan'), cmd.index('/usr/include'))
def test_early_check_tries_the_runtime_before_the_long_steps(self):
"""The check of a Linux build runs the compile step's own command with -fsyntax-only on each source and links
an empty program against the game's libraries. When files fail it stops with every one of them named (the
compile step named three of four), and a missing header is told from an old one."""
srcs = [self.tmp / n for n in ('good.c', 'bad1.c', 'bad2.c', 'bad3.c', 'bad4.cpp')]
for s in srcs:
s.write_text('int x;\n')
ran = []
def compiler(errors):
def run(cmd, **kw):
ran.append([str(c) for c in cmd])
name = next((Path(c).name for c in cmd if Path(str(c)).name.startswith(('good', 'bad'))), '')
bad = name.startswith('bad')
return subprocess.CompletedProcess(cmd, 1 if bad else 0, '', errors.get(name, 'error: old') if bad else '')
return run
def check(errors, sources):
ran.clear()
err = io.StringIO()
with mock.patch.multiple(self.mg, toolchain=lambda msys: (Path('clang'), Path('clang++'), {}, Path('vma')),
clang_version=lambda clang, env: 'clang version 18.1.3',
vulkan_headers=lambda clang, env: ['-I', 'kit/vulkan'],
runtime_headers=lambda rt: None, EVENTS=False), \
mock.patch.object(self.mg.subprocess, 'run', compiler(errors)), \
contextlib.redirect_stdout(io.StringIO()), contextlib.redirect_stderr(err):
try:
self.mg.preflight(self.msys, 2, sources)
return None, err.getvalue()
except SystemExit:
return 'stopped', err.getvalue()
stopped, text = check({}, srcs)
self.assertEqual(stopped, 'stopped')
self.assertIn('did not compile: bad1.c, bad2.c, bad3.c, bad4.cpp', text)
self.assertIn('4 of the runtime\'s 5 files', text)
self.assertIn('clang version 18.1.3', text)
self.assertIn('kit/vulkan', text) # where the Vulkan headers came from
compiles = [c for c in ran if '-fsyntax-only' in c]
self.assertEqual(len(compiles), 5)
for c in compiles:
self.assertEqual(c[1], '-fsyntax-only')
self.assertFalse({'-c', '-o'} & set(c))
self.assertLess(c.index('kit/vulkan'), c.index(str(self.mg.KIT / 'runtime')))
self.assertEqual(len(ran), 5) # no link is tried once sources failed
stopped, text = check({'bad1.c': "bad1.c:1:10: fatal error: 'SDL3/SDL.h' file not found"}, srcs[:2])
self.assertIn('These headers are missing: SDL3/SDL.h', text)
# every source passes: the empty program is linked against the game's libraries
stopped, text = check({}, srcs[:1])
self.assertIsNone(stopped)
link = ran[-1]
self.assertNotIn('-fsyntax-only', link)
self.assertEqual(link[-len(self.mg.LINK_LIBS):], self.mg.LINK_LIBS)
def test_pinned_vulkan_headers(self):
"""tools/vulkan_pin.py keeps the C headers and the licence note of the pinned archive and nothing else, takes
no other archive, and says the folder holds them only once the last file is written."""
import vulkan_pin
buf = io.BytesIO()
with tarfile.open(fileobj=buf, mode='w:gz') as tar:
for name, data in (('include/vulkan/vulkan_core.h', b'#define VK_HEADER_VERSION 363\n'),
('include/vulkan/vulkan.h', b'#include "vulkan_core.h"\n'),
('include/vk_video/vulkan_video_codecs_common.h', b'\n'),
('include/vulkan/vulkan.hpp', b'// C++\n'), ('registry/vk.xml', b'<registry/>'),
('include/vulkan/../../outside.h', b'x'), ('LICENSE.md', b'Apache-2.0 OR MIT\n')):
info = tarfile.TarInfo(vulkan_pin.TOP + name)
info.size = len(data)
tar.addfile(info, io.BytesIO(data))
archive = self.tmp / 'headers.tar.gz'
archive.write_bytes(buf.getvalue())
dest = self.tmp / 'toolchain' / 'vulkan-headers'
with self.assertRaises(SystemExit), contextlib.redirect_stdout(io.StringIO()):
vulkan_pin.resolve(dest, archive) # not the pinned archive
self.assertFalse(vulkan_pin.have(dest))
pinned = (vulkan_pin.SOURCE[0], hashlib.sha256(buf.getvalue()).hexdigest())
with mock.patch.object(vulkan_pin, 'SOURCE', pinned):
self.assertEqual(vulkan_pin.resolve(dest, archive), dest)
files = sorted(f.relative_to(dest).as_posix() for f in dest.rglob('*') if f.is_file())
self.assertEqual(files, ['LICENSE.md', 'include/vk_video/vulkan_video_codecs_common.h',
'include/vulkan/vulkan.h', 'include/vulkan/vulkan_core.h', vulkan_pin.STAMP])
self.assertFalse((self.tmp / 'outside.h').exists() or (self.tmp / 'toolchain' / 'outside.h').exists())
self.assertTrue(vulkan_pin.have(dest))
self.assertEqual(vulkan_pin.resolve(dest), dest) # there already: nothing is fetched
self.assertEqual(vulkan_pin.header_version((dest / 'include' / 'vulkan' / 'vulkan_core.h').read_text()), 363)
self.assertEqual(vulkan_pin.header_version('#define VK_HEADER_VERSION_COMPLETE 1\n'), 0)
(dest / vulkan_pin.STAMP).unlink() # a folder cut short while it was written
self.assertFalse(vulkan_pin.have(dest))
def test_embedded_file_as_a_header_of_bytes(self):
"""tools/build_shaders.py writes the menu font's bytes as a header for compilers without #embed: the numbers
are the file's bytes, and the header is stale once the file changes."""
import build_shaders
rt = self.tmp / 'runtime'
font = rt / 'ui' / 'fonts' / 'Roboto-Medium.ttf'
font.parent.mkdir(parents=True)
data = bytes(range(256)) * 3 + b'\r\n\x00tail'
font.write_bytes(data)
header = rt / 'ui' / 'roboto_ttf.h'
with mock.patch.object(build_shaders, 'ASSEMBLED', {}), contextlib.redirect_stdout(io.StringIO()):
self.assertEqual(build_shaders.stale(rt), [font])
self.assertEqual(build_shaders.build(rt), 1)
self.assertEqual(build_shaders.stale(rt), [])
numbers = ''.join(ln for ln in header.read_text(encoding='utf-8').splitlines() if not ln.startswith('//'))
self.assertEqual(bytes(int(n) for n in numbers.split(',') if n), data)
font.write_bytes(data + b'!')
self.assertEqual(build_shaders.stale(rt), [font])
menu = (ROOT / 'runtime' / 'ui' / 'menu.cpp').read_text(encoding='utf-8')
self.assertIn('#ifdef __has_embed\n#embed "fonts/Roboto-Medium.ttf"\n#else\n#include "roboto_ttf.h"\n#endif', menu)
self.assertEqual(build_shaders.EMBEDDED, {'ui/fonts/Roboto-Medium.ttf': 'ui/roboto_ttf.h'})
def test_objects_of_an_earlier_version_are_taken_over(self):
"""An entry under a key an earlier version gave the same compile is re-recorded under the new key when its
files read as they did; a header in the earlier kit's folder is read in this kit's (that folder may be gone)."""