From 6e4c394d70b44f2126d1e623c4b57b6e8b8583bb Mon Sep 17 00:00:00 2001 From: antono2 Date: Fri, 6 Nov 2026 22:19:34 +0100 Subject: [PATCH] fix: preserve C names for opaque Vulkan basetypes --- .github/workflows/historical-registry-ci.yml | 25 +++++++++++++++++++- src/vgenerator.py | 5 +++- test/opaque_basetype/main.c.v | 9 +++++++ 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 test/opaque_basetype/main.c.v diff --git a/.github/workflows/historical-registry-ci.yml b/.github/workflows/historical-registry-ci.yml index ea9ec90..52b91a1 100644 --- a/.github/workflows/historical-registry-ci.yml +++ b/.github/workflows/historical-registry-ci.yml @@ -36,7 +36,7 @@ jobs: strategy: fail-fast: false matrix: - version: [v1.4.363, v1.4.364] + version: [v1.4.363, v1.4.364, v1.4.368] steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 @@ -61,6 +61,29 @@ jobs: v fmt -w src/vulkan.v src/vulkan_video.v v fmt -verify src/vulkan.v src/vulkan_video.v git diff --check + - name: Check out module support files for the opaque-pointer ABI probe + if: matrix.version == 'v1.4.368' + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + with: + repository: antono2/vulkan + path: abi-modules/antono2/vulkan + - name: Check out matching C headers + if: matrix.version == 'v1.4.368' + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + with: + repository: KhronosGroup/Vulkan-Headers + ref: ${{ matrix.version }} + path: abi-headers + - name: Compile and run the generated opaque-pointer ABI probe + if: matrix.version == 'v1.4.368' + env: + VMODULES: ${{ github.workspace }}/abi-modules + V_C_ERROR_BUG_REPORT_DISABLED: '1' + run: | + set -euo pipefail + cp src/vulkan.v src/vulkan_video.v abi-modules/antono2/vulkan/ + cp -R abi-headers/include/. abi-modules/antono2/vulkan/c/vendor/include/ + v -cc gcc run test/opaque_basetype windows-generator: name: Windows generator setup diff --git a/src/vgenerator.py b/src/vgenerator.py index 89f9943..5e77b0c 100644 --- a/src/vgenerator.py +++ b/src/vgenerator.py @@ -797,7 +797,10 @@ def genVType(self, typeinfo, name, alias): elif v_value and v_text and category == 'basetype': if not self.should_emit_external_basetype(v_value): return - body = 'pub type ' + v_value + ' = C.' + v_value + '\n@[typedef]\npub struct C.' + v_value + ' {}' + # The V alias drops Vk, but the C typedef must keep its registry name. + # Opaque pointer basetypes such as VkInternalHandleNV are not C structs + # named InternalHandleNV. + body = 'pub type ' + v_value + ' = C.' + name + '\n@[typedef]\npub struct C.' + name + ' {}' else: if category == 'include' or category == 'define': #NOTE: Since video structs are translated to V in vulkan_video.v, diff --git a/test/opaque_basetype/main.c.v b/test/opaque_basetype/main.c.v new file mode 100644 index 0000000..d39acc9 --- /dev/null +++ b/test/opaque_basetype/main.c.v @@ -0,0 +1,9 @@ +// Verify that the generated opaque alias resolves to the actual C pointer typedef. +module main + +import antono2.vulkan as vk + +fn main() { + assert sizeof(vk.InternalHandleNV) == sizeof(voidptr) + println('Opaque Vulkan internal handle has pointer-sized C ABI.') +}