Skip to content

Conversation

@lemonmojo
Copy link

@lemonmojo lemonmojo commented Oct 17, 2025

This PR replaces all occurrences of

import Foundation

with

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

The benefit is that for platforms that do support FoundationEssentials (ie. non-Apple platforms), it results in less Swift library dependencies and ultimately in a smaller file size of the final distributable package.

There are two additional changes in this PR that could be removed if so desired:

  1. Adds workflow_dispatch to the CI yml files to allow manually triggered runs. (This was useful for testing in the forked repo)
  2. Fixes an issue (probably with newer Swift/Xcode versions) that lead to a compilation issue because the reserved keyword unsafe was used in RSASecKeyTests.swift.

All tests completed successfully locally on macOS using either Xcode or swift test and on Github's CI machines.

Update 1:
So to check if libFoundation.so is actually not(!) linked in on Linux I switched the output type of the target to .dynamic, did a swift build and objdump -p libCryptoSwift.so. Unfortunately it was still there. So I investigated and found out that this is caused by copying the PrivacyInfo.xcprivacy file. It very much sounds like a Swift/SPM bug to me. As soon as I remove the resource, only libFoundationEssentials.so is linked, not libFoundation.so. So I made another change, this time to Package.swift to exclude that file when compiling for non-Apple platforms. Unfortunately, the change is pretty hacky as it will not work when cross-compiling from macOS to Linux for instance.
If anyone knows why this is happening or has a better idea on how to handle this, I'm all ears.

Update 2:
Refactored the resources to be contained in a separate target which is added as a dependency of CryptoSwift only for Apple platforms. This gets rid of the cross-compilation issue from Update 1.

- Create a new target that just includes PrivacyInfo.xcprivacy as a resource
- Add that target as a dependency of CryptoSwift but only when targeting Apple platforms

Reason: On non-Apple platforms, when resources are copied, it drags in libFoundation even though non of the source files import Foundation but use FoundationEssentials instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant