I've been working on a Swift PM wrapper for the libtiff
library, which I installed on my Mac via Brew. So far so good. But I just tried adding it to my visionOS project. and it complained that it was trying to link against a library built for macOS:
building for 'visionOS-simulator', but linking in dylib (/opt/homebrew/Cellar/libtiff/4.6.0/lib/libtiff.6.dylib) built for 'macOS'
I wish Brew would build universal libraries, but it doesn’t, and they have no interest in doing so. What are my options?
If I build libtiff
from sources, it’s still a bit of a pain to build against a different SDK. libtiff
has its own Makefile I’d rather not try to edit.
Can I make an xcframework out of it? Can I statically link it into my Swit wrapper library? Do I need to hack together a C build target in my Package and copy the source files over to it?
First up, I want to point you to An Apple Library Primer. This explains a lot of backstory and clarifies key terminology, like the different between platform and architecture.
There is no reliably way to build a library for one platform and run it on another. The issue is that our tools have knowledge of the target platform and can make assumptions based on that platform. For example, every version of visionOS includes the Swift concurrency runtime, so the tools don’t have to emit any compatibility goo.
If you want to do something wildly unsupported you can change a library’s platform using vtool
(I explain how to use this tool, in a very different context, in Notarisation and the macOS 10.9 SDK). However, I can’t recommend that you go down that path. It’s one of those things that seems like it might work and then everything falls apart after some otherwise innocuous change in our tooling.
The correct answer here is to build your open source library from source, passing the correct tuple to the compiler so that it generates code for your target platform.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"