Posts

Post not yet marked as solved
0 Replies
307 Views
We have a set of Swift Packages with dependencies from one to another, and we need to build xcframeworks out of those. We currently iterate over each package and xcodebuild archives out of them, but this is really slow. It also seems that the dependencies are rebuilt for every package, and we're looking for a way to avoid that. More precisely, say we have the following packages CoreFoundation Feature1, depending on CoreFoundation We need to turn this into corefoundation.xcframework and feature1.xcframework. The problem is that when calling xcodebuild on Feature1, it seems to be rebuilding CoreFoundation even though it's already been built when building corefoundation.xcframework. Anyone knows of a better way to do that ? Lumping it all together in a single xcframework doesn't seem to be possible. Thanks for any input :)
Posted
by glaurent.
Last updated
.
Post not yet marked as solved
1 Replies
927 Views
This post is meant to provide useful information on how to build a set of xcframeworks from a hierarchy of Swift Packages containing a mix of ObjC and Swift. If you only want to build a single xcframework from a Swift Package, as this is not obvious either, you should find some useful info too. Stuff that needs to be done for building an XCFramework from a Swift Package through xcodebuild set library type to .dynamic in Package.swift set SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES OTHER_SWIFT_FLAGS="-no-verify-emitted-module-interface" in xcodebuild command no need to use 'archive' xcodebuild command, xcodebuild alone is enough In generated framework : copy public headers (in case of ObjC package) copy (or create) module.modulemap file, or copy .swiftmodule file copy umbrella header FooPackage-Swift.h from derived data (use -derivedDataPath xcodebuild option to retrieve it) in case of Swift Package, otherwise won't be useable from ObjC copy resource bundle (if any) In many cases I found that people are using xcodebuild archive for this task, but I find that not necessary. The archive doesn't contain anything more than what you get from xcodebuild only. Here's the script I ended up writing : build_xcframework_from_swift_package.sh Setup A set of Swift Packages, containing Swift and ObjC code, with dependencies. We need to use these Packages in an app and also to create XCFrameworks from them. The (simplified) dependencies are as follows : CommonObjC <- Common <- Package1, Package2... <- GlobalPackage <- MainApp Problems encountered, and their solutions Many of these problems come from the fact that we need to use these modules both as Swift Packages and as XCFrameworks. xcodebuild needs the library defined in the Swift Package to be explicitly declared of type .dynamic, otherwise only a .o is generated for a package But if all libs are dynamic, then, in the Swift Package usecase, symbols in CommonObjC won't be visible from MainApp. If CommonObjC is explicitly added to MainApp's linked frameworks, Xcode issues a build error saying "CommonObjC is linked as a static library but cannot be built dynamically because there is a package product with the same name". Solution : since we don't want libs to be dynamic for the case where the Swift Packages are used directly, have the library type set depending on a Environment var. There doesn't seem to be a way to pass Swift Compiler flags (-DFOO) to xcodebuild so that they are used when evaluating a Package.swift file. This works : func runtimeLibType() -> Product.Library.LibraryType? { return ProcessInfo.processInfo.environment["SPM_GENERATE_FRAMEWORK"] != nil ? .dynamic : nil } and then let package = Package( name: "FooPackage", products: [ .library( name: "FooPackage", type: runtimeLibType(), targets: ["FooPackage"]), ], ... Symbols from a package Foo's dependency are not visible from another package or app using package Foo. If Package Foo is in Swift, the solution is to use '@_exported' in the import statement for the dependency : PackageFoo/SomeFile.swift : @_exported import Dependency then in App : import PackageFoo -> symbols from Dependency will be visible. There is no equivalent solution in ObjC Symbol export issues with "composed" package (ie a package built from two targets) Solution is simply to not do that. Stick to one package being built from one target. Importing a 2nd-level dependency in a public header works when building from SPM, but not when an app is importing the resulting xcframework (dependencies are not transient in this case) For instance : PackageRT depends on PackageCore which depends on PackageCoreObjC PackageRT/include/public_header.h can '@import' PackageCoreObjC. It works as long as you build from SPM, but when you build PackageRT into an xcframework, importing the resulting xcframework will fail because the @import PackageCoreObjC in PackageRT/include/public_header.h fails because PackageCoreObjC module is not found. Solution is to explicitly add PackageCoreObjC as a dependency to PackageRT.
Posted
by glaurent.
Last updated
.
Post not yet marked as solved
0 Replies
1k Views
I have a simple CloudKit query over a given record type, with a sort descriptor for one of the attribute, which is of type String, and the results come out in the wrong order. This is even visible in the CloudKit console (see screenshot, ordering is by title). Can anyone explains what happens here ? I've checked that there wasn't any weird characters in the attributes. Thanks.
Posted
by glaurent.
Last updated
.
Post not yet marked as solved
0 Replies
1.4k Views
Hi all,I'm working on an app which relies on Data Protection to, well, protect the user's data from being accessed externally. We need to validate the encryption of the data, so we'd like to see the sqlite file in its encrypted state. However, if we download the app's container from Xcode, we get a regular sqlite file with all data in clear. We tried to get the same sqlite file throught iExplorer while the app is not running, and in this case we get a file of the same size, which sqlite3 can open correctly, but on which all queries do not return anything. Checking the file's contents with /usr/bin/strings shows that while the table names and schema is still visible, the actual data content is not.This looks ok but we'd rather make sure that we're not missing something and that the file is actually encrypted in its "normal" state. How can we check that ?
Posted
by glaurent.
Last updated
.
Post not yet marked as solved
1 Replies
827 Views
I'm currently working on an app which requires Full Disk Access. Exporting the app as a bundle, copying it to /Applications and giving it Full Disk Access privilege works fine, but I can't find a way to run it in Xcode with those privileges. I tried adding the bundle generated in Xcode's Derived Data folder, but that doesn't help, the app is still denied access when I launch it from Xcode. So how am I supposed to do this ?
Posted
by glaurent.
Last updated
.