Use FoundationEssentials when available #1081
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR replaces all occurrences of
import Foundationwith
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:
workflow_dispatchto the CI yml files to allow manually triggered runs. (This was useful for testing in the forked repo)unsafewas used in RSASecKeyTests.swift.All tests completed successfully locally on macOS using either Xcode or
swift testand 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 aswift buildandobjdump -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.