vulkan-zig icon indicating copy to clipboard operation
vulkan-zig copied to clipboard

(MacOS) Errors compiling new vulkan-zig example

Open James-Riordan opened this issue 1 year ago • 4 comments

I'm on MacOS, and tested the command zig build --build-file $(pwd)/examples/build.zig run-triangle in vulkan-zig's root.

The following is the terminal output returned when trying to zig build with two different versions dev.4+c7ffdbcd4 and 0.13.0-dev.46+3648d7df1.

dev.4+c7ffdbcd4:

(shortened error):

thread 141985 panic: unable to find artifact 'vulkan-zig-generator'

(full error output):

info: available artifact: 'generator'
info: available artifact: 'triangle'
thread 141985 panic: unable to find artifact 'vulkan-zig-generator'
/Users/jamesriordan/zig/zig-macos-x86_64-0.13.0-dev.4+c7ffdbcd4/lib/std/Build.zig:1814:18: 0x108d7427d in artifact (build)
            panic("unable to find artifact '{s}'", .{name});
                 ^
/Users/jamesriordan/Workspaces/Code-Examples/vulkan-zig-master/examples/build.zig:23:60: 0x108d33961 in build (build)
    const vk_gen = b.dependency("vulkan_zig", .{}).artifact("vulkan-zig-generator");
                                                           ^
/Users/jamesriordan/zig/zig-macos-x86_64-0.13.0-dev.4+c7ffdbcd4/lib/std/Build.zig:2079:33: 0x108d16cd3 in runBuild__anon_8549 (build)
        .Void => build_zig.build(b),
                                ^
/Users/jamesriordan/zig/zig-macos-x86_64-0.13.0-dev.4+c7ffdbcd4/lib/compiler/build_runner.zig:300:29: 0x108d11ed6 in main (build)
        try builder.runBuild(root);
                            ^
/Users/jamesriordan/zig/zig-macos-x86_64-0.13.0-dev.4+c7ffdbcd4/lib/std/start.zig:511:37: 0x108d1951b in main (build)
            const result = root.main() catch |err| {
                                    ^
???:?:?: 0x7ff8022b7365 in ??? (???)
Unwind information for `???:0x7ff8022b7365` was not available, trace may be incomplete

???:?:?: 0x0 in ??? (???)
error: the following build command crashed:
/Users/jamesriordan/Workspaces/Code-Examples/vulkan-zig-master/examples/zig-cache/o/ef3e54b672e3fd41a6b0ab2daee2ee2e/build /Users/jamesriordan/zig/zig-macos-x86_64-0.13.0-dev.4+c7ffdbcd4/zig /Users/jamesriordan/Workspaces/Code-Examples/vulkan-zig-master/examples /Users/jamesriordan/Workspaces/Code-Examples/vulkan-zig-master/examples/zig-cache /Users/jamesriordan/.cache/zig --seed 0xcff622a8 -Z29695bdf4bf38ab5 run-triangle

0.13.0-dev.46+3648d7df1:

(shortened error):

error: root struct of file 'std' has no member named 'ComptimeStringMap'

(full error output):

/Users/jamesriordan/.cache/zig/p/12203dd92af51de24d95545584c376f2d76698ff0b73d5e5b1cf0e1e12bba2ca4d48/generator/vulkan/render.zig:99:26: error: root struct of file 'std' has no member named 'ComptimeStringMap'
const builtin_types = std.ComptimeStringMap([]const u8, .{
                      ~~~^~~~~~~~~~~~~~~~~~
/Users/jamesriordan/zig/zig-macos-x86_64-0.13.0-dev.46+3648d7df1/lib/std/std.zig:1:1: note: struct declared here
pub const ArrayHashMap = array_hash_map.ArrayHashMap;
^~~
referenced by:
    renderName: /Users/jamesriordan/.cache/zig/p/12203dd92af51de24d95545584c376f2d76698ff0b73d5e5b1cf0e1e12bba2ca4d48/generator/vulkan/render.zig:564:17
    renderApiConstant: /Users/jamesriordan/.cache/zig/p/12203dd92af51de24d95545584c376f2d76698ff0b73d5e5b1cf0e1e12bba2ca4d48/generator/vulkan/render.zig:477:21
    remaining reference traces hidden; use '-freference-trace' to see all reference traces

James-Riordan avatar May 02 '24 18:05 James-Riordan

Are you sure that you are on the latest version of vulkan-zig? ComptimeStringMap was removed in #129

Snektron avatar May 02 '24 18:05 Snektron

Are you sure that you are on the latest version of vulkan-zig? ComptimeStringMap was removed in #129

I downloaded a Zip from the master branch this morning just before trying, so I'd assume so.

I also ran wget https://raw.githubusercontent.com/KhronosGroup/Vulkan-Docs/main/xml/vk.xml and put a copy both in registry/ and examples/registry/ just to be safe.

Also, FWIW, I'm running Vulkan-SDK version 1.3.268.1


Edit to this comment:

I just did a CMD + F on the project to search for std.ComptimeStringMap in the render.zig file, but it doesn't exist, like you said. This is a very peculiar issue.

James-Riordan avatar May 02 '24 18:05 James-Riordan

User Error discovered. I accidentally swapped out .vulkan_zig in build.zig.zon to use an outdated version.

Regardless, with version issues fixed, I still receive the following errors:

0.13.0-dev.46+3648d7df1:

run-triangle
└─ run triangle
   └─ install
      └─ install triangle
         └─ zig build-exe triangle Debug native failure
error: error: unable to find dynamic system library 'glfw' using strategy 'paths_first'. searched paths:
  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/usr/lib/libglfw.tbd
  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/usr/lib/libglfw.dylib
  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/usr/lib/libglfw.so
  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/usr/lib/libglfw.a

error: the following command exited with error code 1:
/Users/jamesriordan/zig/zig-macos-x86_64-0.13.0-dev.46+3648d7df1/zig build-exe -lglfw -ODebug --dep vulkan --dep shaders -Mroot=/Users/jamesriordan/Workspaces/Code-Examples/vulkan-zig-master/examples/triangle.zig -Mvulkan=/Users/jamesriordan/Workspaces/Code-Examples/vulkan-zig-master/examples/zig-cache/o/a620a53e2ae7bb70b2852b2d64811abf/vk.zig -Mshaders=/Users/jamesriordan/Workspaces/Code-Examples/vulkan-zig-master/examples/zig-cache/shaders/h0G5grXZG86KQANON22yZ35X6HJ-GAcca_RGBn0wpnDB_VkZjjCUPzkfOEwwsl05 -lc --cache-dir /Users/jamesriordan/Workspaces/Code-Examples/vulkan-zig-master/examples/zig-cache --global-cache-dir /Users/jamesriordan/.cache/zig --name triangle --listen=- 
Build Summary: 3/8 steps succeeded; 1 failed (disable with --summary none)
run-triangle transitive failure
└─ run triangle transitive failure
   ├─ zig build-exe triangle Debug native failure
   └─ install transitive failure
      └─ install triangle transitive failure
         └─ zig build-exe triangle Debug native (+2 more reused dependencies)
error: the following build command failed with exit code 1:
/Users/jamesriordan/Workspaces/Code-Examples/vulkan-zig-master/examples/zig-cache/o/74e2174d1d8d2a4c0108d29b83b7abe7/build /Users/jamesriordan/zig/zig-macos-x86_64-0.13.0-dev.46+3648d7df1/zig /Users/jamesriordan/Workspaces/Code-Examples/vulkan-zig-master/examples /Users/jamesriordan/Workspaces/Code-Examples/vulkan-zig-master/examples/zig-cache /Users/jamesriordan/.cache/zig --seed 0xc92bc799 -Z60b5da14e6314465 run-triangle

0.13.0-dev.4+c7ffdbcd4:

run-triangle
└─ run triangle
   └─ zig build-exe triangle Debug native
      └─ run vulkan-zig-generator (vk.zig)
         └─ zig build-exe vulkan-zig-generator Debug native 1 errors
src/vulkan/render.zig:106:26: error: root struct of file 'std' has no member named 'StaticStringMap'
const builtin_types = std.StaticStringMap([]const u8).initComptime(.{
                      ~~~^~~~~~~~~~~~~~~~
/Users/jamesriordan/zig/zig-macos-x86_64-0.13.0-dev.4+c7ffdbcd4/lib/std/std.zig:1:1: note: struct declared here
pub const ArrayHashMap = array_hash_map.ArrayHashMap;
^~~
referenced by:
    renderName: src/vulkan/render.zig:604:17
    renderApiConstant: src/vulkan/render.zig:517:21
    remaining reference traces hidden; use '-freference-trace' to see all reference traces
error: the following command failed with 1 compilation errors:
/Users/jamesriordan/zig/zig-macos-x86_64-0.13.0-dev.4+c7ffdbcd4/zig build-exe -ODebug -Mroot=/Users/jamesriordan/Workspaces/Code-Examples/vulkan-zig-master/src/main.zig --cache-dir /Users/jamesriordan/Workspaces/Code-Examples/vulkan-zig-master/examples/zig-cache --global-cache-dir /Users/jamesriordan/.cache/zig --name vulkan-zig-generator --listen=- 
Build Summary: 1/8 steps succeeded; 1 failed (disable with --summary none)
run-triangle transitive failure
└─ run triangle transitive failure
   ├─ zig build-exe triangle Debug native transitive failure
   │  └─ run vulkan-zig-generator (vk.zig) transitive failure
   │     └─ zig build-exe vulkan-zig-generator Debug native 1 errors
   └─ install transitive failure
      └─ install triangle transitive failure
         └─ zig build-exe triangle Debug native (+2 more reused dependencies)
error: the following build command failed with exit code 1:
/Users/jamesriordan/Workspaces/Code-Examples/vulkan-zig-master/examples/zig-cache/o/bb7b12f38710e2aafd46fe8ef991cfc5/build /Users/jamesriordan/zig/zig-macos-x86_64-0.13.0-dev.4+c7ffdbcd4/zig /Users/jamesriordan/Workspaces/Code-Examples/vulkan-zig-master/examples /Users/jamesriordan/Workspaces/Code-Examples/vulkan-zig-master/examples/zig-cache /Users/jamesriordan/.cache/zig --seed 0x4f061167 -Z8174ad513090a2b2 run-triangle

James-Riordan avatar May 02 '24 19:05 James-Riordan

0.13.0-dev.4+c7ffdbcd4:

This build is too old, it was before the change relevant to #129. Regarding the other issue, well, it can't find GLFW. I'm not too familiar with how dependencies work on Mac OS to be honest, so I doubt that I can be of much help. Its not downloaded automatically by Zig at least - it needs to be provided by your system.

Snektron avatar May 02 '24 19:05 Snektron

I'm able to build it but it cannot start.

➜  vulkan-zig git:(master) zig build --build-file $(pwd)/examples/build.zig run-triangle
error: IncompatibleDriver
???:?:?: 0x10494d3ef in _vk.BaseWrapperWithCustomDispatch(vk.BaseDispatch).createInstance (???)
???:?:?: 0x10494c88f in _graphics_context.GraphicsContext.init (???)
???:?:?: 0x10495fbf3 in _triangle.main (???)
run-triangle
└─ run triangle failure
error: the following command exited with error code 1:
/Users/nico/Development/vulkan-zig/examples/zig-out/bin/triangle 
Build Summary: 7/9 steps succeeded; 1 failed
run-triangle transitive failure
└─ run triangle failure
error: the following build command failed with exit code 1:
/Users/nico/Development/vulkan-zig/examples/.zig-cache/o/e39283aa27ab6cf7bb938f9d61438eff/build /Users/nico/Library/Application Support/Code/User/globalStorage/ziglang.vscode-zig/zig/macos-aarch64-0.14.0/zig /Users/nico/Library/Application Support/Code/User/globalStorage/ziglang.vscode-zig/zig/macos-aarch64-0.14.0/lib /Users/nico/Development/vulkan-zig/examples /Users/nico/Development/vulkan-zig/examples/.zig-cache /Users/nico/.cache/zig --seed 0x50b288d5 -Zefea5c1c87a2d157 run-triangle

I have the vukan sdk installed and according to https://github.com/KhronosGroup/MoltenVK?tab=readme-ov-file#developing-vulkan-applications-for-macos-ios-tvos-and-visionos it should work. I'll take a look and see if I can find the issue

nicoabie avatar May 04 '25 14:05 nicoabie

Image

The problem is described in https://vulkan.lunarg.com/doc/sdk/1.3.290.0/mac/getting_started.html

Encountered VK_ERROR_INCOMPATIBLE_DRIVER: Beginning with the 1.3.216 Vulkan SDK, the Vulkan Loader is strictly enforcing the new VK_KHR_PORTABILITY_subset extension. The most likely cause of this error message on instance creation is failure to adhere to this extension, which prevents applications on all platforms from selecting by default a non-conformant Vulkan implementation without opting in. MoltenVK is currently not fully conformant, and thus supporting this extension is necessary for building robust and portable Vulkan-based applications that are good citizens in the Vulkan ecosystem.

Opting in is simple. First add the VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR bit to your VkInstanceCreateInfo structure's .flags member, then add two instance extensions to your instance extensions list: VK_KHR_portability_enumeration, and VK_KHR_get_physical_device_properties2.

Typically the code to add support for instance extensions looks something like this:

std::vector<const char*> extNames.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME); extNames.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME);

VkInstanceCreateInfo inst_info = {}; ins_info.flags = VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR; inst_info.enabledExtensionCount = static_cast<uint32_t>(extNames.size()); inst_info.ppEnabledExtensionNames = extNames.data(); Note that support for the VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME is only required for Vulkan version 1.0.

I'll try to create a PR soon so we can close this issue

nicoabie avatar May 04 '25 18:05 nicoabie

Image The problem is described in https://vulkan.lunarg.com/doc/sdk/1.3.290.0/mac/getting_started.html

Encountered VK_ERROR_INCOMPATIBLE_DRIVER: Beginning with the 1.3.216 Vulkan SDK, the Vulkan Loader is strictly enforcing the new VK_KHR_PORTABILITY_subset extension. The most likely cause of this error message on instance creation is failure to adhere to this extension, which prevents applications on all platforms from selecting by default a non-conformant Vulkan implementation without opting in. MoltenVK is currently not fully conformant, and thus supporting this extension is necessary for building robust and portable Vulkan-based applications that are good citizens in the Vulkan ecosystem. Opting in is simple. First add the VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR bit to your VkInstanceCreateInfo structure's .flags member, then add two instance extensions to your instance extensions list: VK_KHR_portability_enumeration, and VK_KHR_get_physical_device_properties2. Typically the code to add support for instance extensions looks something like this: std::vector<const char*> extNames.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME); extNames.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME); VkInstanceCreateInfo inst_info = {}; ins_info.flags = VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR; inst_info.enabledExtensionCount = static_cast<uint32_t>(extNames.size()); inst_info.ppEnabledExtensionNames = extNames.data(); Note that support for the VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME is only required for Vulkan version 1.0.

I'll try to create a PR soon so we can close this issue

I didn't actually look into what you're doing here or your progress. All I'll say is that if you're trying to get vulkan-zig working on Mac, good luck! The hardest thing I've ever tried to do. Never made any progress

James-Riordan avatar May 05 '25 00:05 James-Riordan

The example is working now.

  1. clone this repo
  2. install zig 14 stable
  3. install vulkan sdk for mac https://vulkan.lunarg.com/sdk/home
  4. apply my pr https://github.com/Snektron/vulkan-zig/pull/185

It works, make sure to follow the steps in https://vulkan.lunarg.com/doc/sdk/1.3.290.0/mac/getting_started.html

nicoabie avatar May 05 '25 01:05 nicoabie

Fixed by https://github.com/Snektron/vulkan-zig/pull/185 - thanks!

Snektron avatar May 05 '25 19:05 Snektron