1

I tried to build static library this way:

swift build -c release -Xswiftc "-sdk" -Xswiftc "`xcrun --sdk iphoneos --show-sdk-path`" -Xswiftc "-target" -Xswiftc "arm64-apple-ios14.0"

But I can't import any classes from the .a file after linking it to the project. It says "No such module 'myLibNameHere'"

What is the correct way to build library than can be given to customer to link in his iOS project? The main conditions are:

  • customer shouldn't see the sources of my library
  • the library must support real devices (iPhones from iOS 14.0) and simulators

After all. Should I build one more lib (for simulator) with:

swift build -c release -Xswiftc "-sdk" -Xswiftc "`xcrun --sdk iphonesimulator --show-sdk-path`" -Xswiftc "-target" -Xswiftc "x86_64-apple-ios14.0-simulator"

and join it with previously built library with lipo? Or Swift package provides another way like:

swift build -c release --arch arm64

or something like that?

badadin
  • 507
  • 1
  • 5
  • 18
  • You will need to make it an xcframework or it becomes a lot of obnoxious build and linker flags. I had it figured out once long ago but no longer remember how to do it. I would use the create-xcframework (https://github.com/unsignedapps/swift-create-xcframework) if you can. – bscothern Sep 23 '21 at 15:54
  • @bscothern, thanks, I've read about xcframeworks, but I hoped that it will be possible to build lib only with SPM – badadin Sep 24 '21 at 04:45
  • 1
    It is possible but you will need to dig into the depths of swiftc linker settings and it is going to be a terrible experience for people to consume. They will need to be the exact same version of swift as you (so same Xcode) and it is multiple files they will need to correctly place and pass around. – bscothern Sep 24 '21 at 04:54
  • @bscothern, oh, I didn't know, thank you! – badadin Sep 24 '21 at 05:01

0 Answers0