floooh / sokol-zig

Zig bindings for the sokol headers (https://github.com/floooh/sokol)
zlib License
341 stars 46 forks source link

When building for darwin, differentiate between iOS and macOS frameworks #46

Closed geooot closed 9 months ago

geooot commented 9 months ago

When trying to use sokol-zig with an iOS target, Cocoa and QuartzCore frameworks are incorrectly included during linking. This change aims to make it such that only correct frameworks are linked depending on the target.

Referenced libSokol in pacman.zig to make this PR.

floooh commented 9 months ago

Thanks! I actually haven't paid much attention to iOS yet, but since you opened that can of worms :D ... I think a few more changes are needed for using the GL backends. Maybe you could add those?

Here's how it should look like:

Basically as pseudo code

if (macOS or iOS) {
  => Foundation, AudioToolbox
  if (Metal) {
    => Metal, MetalKit
  }
  if (iOS) {
    => UIKit, AVFoundation
    if (GL) {
      => OpenGLES, GLKit
    }
  }
  if (macOS) {
    => Cocoa, QuartzCore
    if (GL) {
      => OpenGL
    }
}

...I think that's it.

geooot commented 9 months ago

Ah that pseudo code makes sense! I totally ignored OpenGL lol. I went ahead and implemented it and confirmed that the GL build for macOS works.

I noticed that GLKit is a macOS framework as well. Should that be included for macOS targets as well?

▶ ls /System/Library/Frameworks/ | grep GL
AGL.framework
GLKit.framework
GLUT.framework
OpenGL.framework
floooh commented 9 months ago

I noticed that GLKit is a macOS framework as well.

Nope, GLKit is only used in the iOS code path.

floooh commented 9 months ago

Ok merged, many thanks!