Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A few build issues on macOS #33

Open
lhoward opened this issue Jun 28, 2023 · 0 comments
Open

A few build issues on macOS #33

lhoward opened this issue Jun 28, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@lhoward
Copy link

lhoward commented Jun 28, 2023

% xcodebuild -version
Xcode 14.2
Build version 14C18

A couple of build issues.

Firstly, assumption that Vulkan is installed in /usr/local but brew installs them into /opt/homebrew. This is probably related to the fact that the setup-vulkan-macOS Makefile target (in SwiftVulkan) doesn't work because the apenngrace/vulkan/vulkan-sdk cask cannot be found. Instead I used the regular Homebrew install, which didn't even seem to compile (not all headers were installed, had to hand-edit vulkan_core.h to remove H264/5 dependencies).

Then I ran into an issue where SDL_KeyCode couldn't be used as a dictionary key in virtualKeyMap.

diff --git a/Sources/FirebladePAL/Platform/SDL/SDLKeys.swift b/Sources/FirebladePAL/Platform/SDL/SDLKeys.swift
index ee13545..717f611 100644
--- a/Sources/FirebladePAL/Platform/SDL/SDLKeys.swift
+++ b/Sources/FirebladePAL/Platform/SDL/SDLKeys.swift
@@ -9,6 +9,8 @@
 
     @_implementationOnly import SDL2
 
+    extension SDL_KeyCode: Hashable {}
+
     extension KeyCode {
         public init?(scancode: UInt) {
             guard let keyCode = Self.physicalKeyMap[SDL_Scancode(rawValue: SDL_Scancode.RawValue(scancode))] else {

fixed it.

Then building a package that depends on it, I got:

Building for debugging...
ld: warning: Could not find or use auto-linked library 'vulkan'
Undefined symbols for architecture arm64:
  "_vkCreateInstance", referenced from:
      _$s12FirebladePAL19SDLVLKWindowSurfaceC14createInstance6layers10extensionss13OpaquePointerVSaySSG_AItKFZAHSRySPys4Int8VGSgGKXEfU_AhNKXEfU_ in SDLVLKWindowSurface.swift.o
  "_vkDestroySurfaceKHR", referenced from:
      _$s12FirebladePAL19SDLVLKWindowSurfaceC7destroyyyF in SDLVLKWindowSurface.swift.o
ld: symbol(s) not found for architecture arm64
ld: warning: Could not find or use auto-linked library 'vulkan'
Undefined symbols for architecture arm64:
  "_vkCreateInstance", referenced from:
      _$s12FirebladePAL19SDLVLKWindowSurfaceC14createInstance6layers10extensionss13OpaquePointerVSaySSG_AItKFZAHSRySPys4Int8VGSgGKXEfU_AhNKXEfU_ in SDLVLKWindowSurface.swift.o
  "_vkDestroySurfaceKHR", referenced from:
      _$s12FirebladePAL19SDLVLKWindowSurfaceC7destroyyyF in SDLVLKWindowSurface.swift.o
ld: symbol(s) not found for architecture arm64

even after sym-linking libvulkan.dylib from /opt/homebrew/lib into /usr/local/lib.

diff --git a/Package.swift b/Package.swift
index 16ae1a4..3654af0 100644
--- a/Package.swift
+++ b/Package.swift
@@ -122,7 +122,8 @@ let package = Package(
                 .vulkan,
                 .nfd,
             ],
-            swiftSettings: swiftSettings
+            swiftSettings: swiftSettings,
+            linkerSettings: [.unsafeFlags(["-L/opt/homebrew/lib","-lvulkan"])]
         ),
         .target(
             name: "CPUBackendDemoApp",

fixed that.

Finally, I also needed to make the SDL dependency on SDL instead of SDL2.

After all of this, it builds and tests pass, although VulkanBackendDemoApp does trap with:

FirebladePAL/SDLWindow.swift:79: Fatal error: vkInstanceCreationFailed(__C.VkResult(rawValue: -6))
@lhoward lhoward added the bug Something isn't working label Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant