apple/swift-crypto

Build failure with BUILD_LIBRARY_FOR_DISTRIBUTION=YES

chhetri-rahul opened this issue · 23 comments

When will the support for visionOS be provided, for both simulator and physical device?

We have a SDK which consumes swift-cryto as a package dependency (v 2.1.0). We are updating our codebase to support the new OS from Apple. The SDK builds for iOS and MacCatalyst on intel and M1 machines.

Right now when i build from cli with command:

xcodebuild -workspace MySDK.xcworkspace -configuration Debug -sdk xrsimulator build -derivedDataPath ./out -scheme MySDK -destination "generic/platform=visionOS Simulator,OS=latest,name=Apple Vision Pro" "ARCHS=\x86_64 \arm64

if fails with the error:

no such module 'CCryptoBoringSSL'
@_implementationOnly import CCryptoBoringSSL

Lukasa commented

v2.1.0 is very old, it was released in April 2022. Can you update to 2.6.0 and tell me if this reproduces?

After updating to v2.6.0 we are getting the following compilation error

error-img

Here you suggested to change the build setting BUILD_LIBRARY_FOR_DISTRIBUTION as false which is not possible in our case.

And regarding the consumption of these APIs we are already importing using the @_implementationOnly import statement.

Can you please guide on how to fix this?

Lukasa commented

You must change the build setting for swift-crypto to disable BUILD_LIBRARY_FOR_DISTRIBUTION: we do not have a stable ABI and we don't support this build mode.

You may subsequently link this library into a different library that you own which does have a stable ABI, which is where @_implementationOnly will be helpful.

Lukasa commented

Additionally: are you actually using _CryptoExtras? If not, you could drop the dependency.

Changing the build setting BUILD_LIBRARY_FOR_DISTRIBUTION also didn't help and it fails with the same error

I had updated this setting for both the targets (Crypto, _CryptoExtras) like below:

Screenshot 2023-08-30 at 4 10 18 PM

Also, _CryptoExtras is required by us and cannot be removed. We use _RSA.Signing.Padding from this module.

Btw this error can be seen in a standalone project as well when we try to archive it by running cli command.

Anything else that we can try?

Lukasa commented

Sorry, how do you reproduce this in a standalone project?

  1. Make a framework project from Xcode template, add the package dependency, include both Crypto and _CryptoExtras to your target.
  2. Have one file in your target where you @_implementationOnly import module is added.
  3. Run the following command on terminal

xcodebuild archive -configuration Release -sdk iphoneos -scheme MySwiftCryptoCheckSDK BUILD_LIBRARY_FOR_DISTRIBUTION=YES SKIP_INSTALL=NO -derivedDataPath ./gen/out -archivePath ./gen/Archive

Btw the failure is not related to visionOS, it fails for iphoneos as well (havent checked for other destinations) .

Lukasa commented

So I believe that BUILD_LIBRARY_FOR_DISTRIBUTION=YES may be overriding the build setting in the package. Can you provide the build log?

archive-failed.txt

I noticed the archive commands succeeds when i remove BUILD_LIBRARY_FOR_DISTRIBUTION=YES from the command. But it is one thing we can't remove.

Lukasa commented

Yeah, that setting is overriding your change to the Package. Why can't you change the build setting for the package?

Renaming the issue to reflect the issue is not related to visionOS

Yeah, that setting is overriding your change to the Package. Why can't you change the build setting for the package?

I did change the build setting for the Crypto and _CryptoExtras in my fork and used it in my code but still got the same error.

Lukasa commented

Sorry, I meant to say: why does your project require setting BUILD_LIBRARY_FOR_DISTRIBUTION=YES on all targets in your project?

Not all the targets in the project require this setting, just two of them.

Lukasa commented

Is there any reason you cannot set this setting only for those two?

@Lukasa can you help me tell how to set the build setting for individual targets?. Should i set this setting in xcode build settings ui and let terminal use the values from there or in command line i have to pass the setting to each target.

For the latter case how will the xcodebuild command look like.

Lukasa commented

You would set this in the Xcode build settings UI for the specific targets.

Thanks @Lukasa i will try what you suggested.

I also found this when looking for a solution. The archive command succeeds with this change.
archive-success.txt

Will removing @inlineable like in above cause any kind of problem in our code?

Lukasa commented

It may lead to worse performance, but that’s it

Thanks @Lukasa for being patient in answering all the questions i have and for actively replying.

The performance degrade youre saying is only during build time or when the code gets used when app is running?

Also I tried what you suggested above and it fixes the archive failure problem, the only thing i want to know now is that we have 6 targets in our workspace (framework targets, unit tests, app targets) the setting BUILD_LIBRARY_FOR_DISTRIBUTION=YES is just to be passed to the framework target right?.

We distribute xcframework so i guess only having this setting in framework target is enough but want your opinion on it.

Lukasa commented

The performance degradation will be while the app is running.

And yes, you should only need to pass that value to the framework target.

Okay Thank you very much @Lukasa 🤝🎉