Using a Brew-installed library on visionOS?

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?

Answered by DTS Engineer in 796645022

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"

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"

Can I make an xcframework out of it?

Yes you can, and we have an article for that with a section of tips for build tools like make:

Creating a multiplatform binary framework bundle

However, as Quinn said, you still need to be willing to dig around this project's configuration to locate the commands it issues to the complier, and insert the correct tuple for the different platform variations. I see also that this is building a bare dylib, and not a framework, which means you should also look to build the library as a static library instead, because bare dylbs (those outside of a framework bundle) are not supported on visionOS (nor on iOS). But once you've done those items, you can feed the built static library into an XCFramework so that you can encapsulate visionOS, visionOS Simulator, and even iOS variants into that framework bundle for sharing among your projects.

— Ed Ford,  DTS Engineer

Using a Brew-installed library on visionOS?
 
 
Q