Integrating a remote Swift Package that has local Swift Packages: how to avoid invalidManifestFormat errors? - TagMerge
4Integrating a remote Swift Package that has local Swift Packages: how to avoid invalidManifestFormat errors?Integrating a remote Swift Package that has local Swift Packages: how to avoid invalidManifestFormat errors?

Integrating a remote Swift Package that has local Swift Packages: how to avoid invalidManifestFormat errors?

Asked 10 months ago
0
4 answers

This isn't intended to be possible. If you look at the 5th bullet in the Proposed Solution section of the local packages proposal (https://github.com/apple/swift-evolution/blob/main/proposals/0201-package-manager-local-dependencies.md) it says that it's not intended for a remote package to be allowed to depend on a local package.

I expect its because there's the possibility that you could have both a versioned package with a given name and a local package with the same name; if so how would SPM resolve the conflict?

It is unfortunate though since allowing this would allow for more options in how people organize their packages, I agree.

Source: link

0

I have found this proposal which was implemented in Swift 5, but when I go to root of my project and run:
$ swift package config set-mirror --package-url <original URL> --mirror-url <mirror URL>
I get this error:
error: root manifest not found

Source: link

0

A library package contains code which other packages can use and depend on. To get started, create a directory and run swift package init:
$ mkdir MyPackage
$ cd MyPackage
$ swift package init # or swift package init --type library
$ swift build
$ swift test
SwiftPM can create native binaries which can be executed from the command line. To get started:
$ mkdir MyExecutable
$ cd MyExecutable
$ swift package init --type executable
$ swift build
$ swift run
Hello, World!
To depend on a package, define the dependency and the version in the manifest of your package, and add a product from that package as a dependency, e.g., if you want to use https://github.com/apple/example-package-playingcard as a dependency, add the GitHub URL in the dependencies of Package.swift:
import PackageDescription

let package = Package(
    name: "MyPackage",
    dependencies: [
        .package(url: "https://github.com/apple/example-package-playingcard.git", from: "3.0.4"),
    ],
    targets: [
        .target(
            name: "MyPackage",
            dependencies: ["PlayingCard"]
        ),
        .testTarget(
            name: "MyPackageTests",
            dependencies: ["MyPackage"]
        ),
    ]
)
To publish a package, create and push a semantic version tag:
$ git init
$ git add .
$ git remote add origin [github-URL]
$ git commit -m "Initial Commit"
$ git tag 1.0.0
$ git push origin master --tags
First, create a directory called example, and initialize it as a package that builds an executable:
$ mkdir example
$ cd example
example$ swift package init --type executable

Source: link

0

First of all, please check your Swift version on your device before we jump in this tutorial will only work with the latest toolchain, so you'll need Swift 5.2 or newer.
Apple Swift version 5.2.2 (swiftlang-1103.0.32.6 clang-1103.0.32.51)
Target: x86_64-apple-darwin19.4.0
All the hard work is done by the swift package command. You can enter that into a terminal window and see the available subcommands. To generate a new package you should go with the init command, if you don't provide a type flag, by default it'll create a library, but this time we'd like to make an executable application.
swift package init --type executable
swift build
swift run my-app
We start with the init command, but this time we don't specify the type. We actually could enter swift package init --type library but that's way too may words to type. 😜 Also because we're making a library, the SPM tool is gona provide us some basic tests, let's run them too with the swift test command.
swift package init
swift test
# swift test --help
# swift test --filter <test-target>.<test-case>/<test>
First of all if you want to support the new manifest file format (aka. Swift 4 version), you have to set the swift-tools-version as comment in your manifest file.
// swift-tools-version:5.2
Let's just add our library as a dependency for the main application first by creating a new package dependency inside the Package.swift file. The first argument is a package url string, which can be a local file path or a remote url (usually a github repo link). Note that you should add your dependency to the targets as well. Usually the specific name of a package is defined inside the library manifest file.
// swift-tools-version:5.2
import PackageDescription

let package = Package(
    name: "my-app",
    dependencies: [
        .package(url: "../my-lib", .branch("master")),
    ],
    targets: [
        .target(name: "my-app", dependencies: [
            .product(name: "my-lib", package: "my-lib"),
        ]),
    ]
)

Source: link

Recent Questions on swift

    Programming Languages