6

I'm trying to add SPM support for my library. I need to define unsafeFlags for one of my library's targets (In order to import Swift code into Objective-C++):

.target(name: "MyLibrary",
        dependencies: ["MyOtherTarget"],
        cSettings: [
            .unsafeFlags(["-fmodules", "-fcxx-modules"]),
            .define("BUILDING_FOR_SPM")
        ]
),

The resulting package builds. But when I import it into a host app, it fails to build because

The package product 'MyLibrary' cannot be used as a dependency of this target because it uses unsafe build flags.

According to this post and the corresponding pull request, the issue was addressed in Swift 4. I'm using Xcode 12.5 and Swift 5.

So what's going on?

2 Answers 2

9

.unsafeFlags are not allowed for dependencies specified with a version. The workaround is to specify the version with a commit hash.

Detailed discussion and another workaround for monorepos at https://forums.swift.org/t/override-for-unsafeflags-in-swift-package-manager/45273

Sign up to request clarification or add additional context in comments.

Worth mentioning that you should clean the project before recompiling again with the commit hash option.
2

Just had the same issue where our own package was failing to resolve:

xcodebuild: error: Could not resolve package dependencies:
the target '_a_target_A' in product '_a_product' contains unsafe build flags
the target '_a_target_B' in product '_a_product' contains unsafe build flags

The solution was to define the exact revision of the package to pull in:

.package(
  url: "https://[email protected]/.../OurProject/_git/OurOwnPackageName",
  revision: ".....complete_hash_of_version_commit......"
)

Comments

Your Answer

Draft saved
Draft discarded

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.