I have following Package.swift file:
import PackageDescription
let package = Package(
name: "MultiTargetTest",
products: [
.executable(
name: "MultiTargetTest",
targets: ["MultiTargetTest"]),
],
dependencies: [
.package(url: "https://github.com/SwiftyJSON/SwiftyJSON.git", from: "4.0.0")
],
targets: [
.target(
name: "MultiTargetTest",
dependencies: ["SwiftyJSON", "IndependentTarget"]),
.target(
name: "IndependentTarget",
dependencies: []),
.testTarget(
name: "MultiTargetTestTests",
dependencies: ["MultiTargetTest"]),
]
)
Here I don't want any dependency on IndependentTarget target, but actually in code I can import SwiftyJSON in IndependentTarget target without any problem.
Here is my code structure:
Here Demo.swift is in IndependentTarget and I have access to SwiftyJSON framework.
How should I define the target IndependentTarget so that it should not have access to dependencies in different target?
Update: I noticed that for first time when I run swift build it gives error but after that it runs fine.
Here's screenshot:
Related
I am creating a custom swift package that depends on firebase. I followed different tutorial but I struggling with an error.
This is my package description:
import PackageDescription
let package = Package(
name: "FirebaseAuthManagment",
products: [
.library(
name: "FirebaseAuthManagment",
targets: ["FirebaseAuthManagment"]),
],
dependencies: [
.package(url: "https://github.com/firebase/firebase-ios-sdk.git", from: "9.6.0")
],
targets: [
.target(
name: "FirebaseAuthManagment",
dependencies: [
.product(name: "FirebaseAuth", package: "Firebase")
]),
.testTarget(
name: "FirebaseAuthManagmentTests",
dependencies: ["FirebaseAuthManagment"]),
]
)
This is the error unknown package 'Firebase' in dependencies of target 'FirebaseAuthManagment'; valid packages are: 'firebase-ios-sdk'. The Package name is FirebaseAuthManagment.
The problem is on the product specification .product(name: "FirebaseAuth", package: "Firebase"). If this line is avoided I can find different Firebase packages like FirebaseStorage, FirebaseAnalytics and others but not FirebaseAuth.
I used SPM to add packages to my project/App. In the package file
I wanted to set target to a dependency. I get this error anytime the app tries to build.
// swift-tools-version:5.5
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "Sycra",
products: [
.library(
name: "Sycra",
targets: ["Sycra"]),
],
dependencies: [
.package(url: "https://github.com/NordicSemiconductor/IOS-nRF-Mesh-Library", .upToNextMinor(from: "3.2.0"))
],
targets: [
define a module or a test suite.
.target(
name: "Sycra",
dependencies: ["NordicMesh"]),
.testTarget(
name: "SycraTests",
dependencies: ["Sycra"]),
]
)
FILE STRUCTURE
ERORR
dependency 'NordicMesh' in target 'Sycra' requires explicit declaration; reference the package in the target dependency with '.product(name: "NordicMesh", package: "IOS-nRF-Mesh-Library")'
Actually the error message already tells you what you have to do:
add
.product(name: "NordicMesh", package: "IOS-nRF-Mesh-Library")
to the dependencies array:
... dependencies: [
.product(name: "NordicMesh", package: "IOS-nRF-Mesh-Library") //<<< like this
//other dependencies
]),
I'm using Xcode12.5 and swift version 5.4. When I try to build my project I get this error: The loaded '_InternalSwiftSyntaxParser' library is from a toolchain that is not compatible with this version of SwiftSyntax.
My Package.swift file:
import PackageDescription
let package = Package(
name: "NeedleFoundation",
products: [
.library(name: "NeedleFoundation", targets: ["NeedleFoundation"]),
.library(name: "NeedleFoundationTest", targets: ["NeedleFoundationTest"])
],
dependencies: [],
targets: [
.target(
name: "NeedleFoundation",
dependencies: []),
.testTarget(
name: "NeedleFoundationTests",
dependencies: ["NeedleFoundation"],
exclude: []),
.target(
name: "NeedleFoundationTest",
dependencies: ["NeedleFoundation"]),
.testTarget(
name: "NeedleFoundationTestTests",
dependencies: ["NeedleFoundationTest"],
exclude: []),
],
swiftLanguageVersions: [.v5]
)
#if compiler(>=5.4)
package.dependencies += [
.package(url: "https://github.com/apple/swift-format", .branch("swift-5.4-branch"))
]
#elseif compiler(>=5.3)
package.dependencies += [
.package(url: "https://github.com/apple/swift-format", .branch("swift-5.3-branch"))
]
#endif
And then I run : swift run swift-format
After that when I try to build my project I receive the same error:
The loaded '_InternalSwiftSyntaxParser' library is from a toolchain that is not compatible with this version of SwiftSyntax.
Am I missing something?
From my research so far on this same problem, the issue is that whatever swift tool you are running (swift-format in this case) depends in the SwiftSyntax package and is not compatible with whatever version of Xcode (toolchain) you are using. You likely need to downgrade the version of Xcode you are using/the tool looks for. Still not sure what the best way to do that is though.
I'm trying to expose a Mocks module alongside my Helpers module. Can a single Swift Package expose sibling modules like this?
Here's what my package manifest looks like:
// swift-tools-version:5.2
import PackageDescription
let package = Package(
name: "Helpers",
products: [
.library(
name: "Helpers",
targets: ["Helpers"]),
.library(
name: "Mocks",
targets: ["Mocks"]),
],
dependencies: [
.package(name: "Parent", url: "foo/bar/Parent.git", .upToNextMinor(from: "0.1.0")),
],
targets: [
.target(
name: "Helpers",
dependencies: ["Parent"]),
.target(
name: "Mocks",
dependencies: ["Parent", "Helpers"]),
.testTarget(
name: "HelpersTests",
dependencies: ["Helpers", "Mocks"]),
]
)
This manifest allows me to import and use both Helpers and Mocks from within HelpersTests. But a project that declares this package as a dependency (using Xcode 11's UI) can only see the Helpers module to import it. Mocks throws an error that there is "no such module." Is this intended behavior? Am I doing something wrong, or is there no way to expose both libraries from one package?
Im trying to learn the ropes of Twilio. The goal is to send text messages from my app. Im following this getting started guide
At the last step is to run this command in terminal: (yes I have changed SwiftSMSwith my own project name)
swift build && ./.build/debug/SwiftSMS
This command results in the following:
MyMac:MyProject MyName$ swift build && ./.build/debug/myProject Compile
Swift Module 'myProject' (1 sources)
/Volumes/myProject/myProject/Sources/myProject/main.swift:2:8: error:
no such module 'Alamofire'
import Alamofire
^ error: terminated(1): /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build-tool
-f /Volumes/myProject/myProject/.build/debug.yaml main output:
I have not done any config with Twilio in Xcode yet. As far as I can understand from the guide should this send a message without doing anything in Xcode?
EDIT*:
Package.swift:
// swift-tools-version:4.2
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "myProject",
dependencies: [
.package(url: "https://github.com/Alamofire/Alamofire.git", from: "4.0.0")
],
targets: [
.target(
name: "myProject",
dependencies: ["Alamofire"]),
.testTarget(
name: "myProjectTests",
dependencies: ["Alamofire"]),
]
)
Use this as your Package.swift - you can't simply say "Alamofire" and expect SPM to magically know where to get the sources from.
import PackageDescription
let package = Package(
name: "myProject",
dependencies: [
.package(url: "https://github.com/Alamofire/Alamofire.git", from: "4.0.0")
],
targets: [
.target(
name: "myProject",
dependencies: ["Alamofire"]),
.testTarget(
name: "myProject Tests",
dependencies: ["Alamofire"]),
]
)