How to define fallback paths for package resolution?

I'm developing a project that includes two local Swift packages, which define static library targets. One of these packages depends on the other one. Presently it imports it, via .dependency("../../..")... and it just works.

But I want it to first check the github link, which isn't online yet because we're still in private development, and then if the github isn't online, fallback to using the local path. Which people are going to need to do for private dev anyway.

But... I can't for the life of me figure out how to actually have the package resolution process check more than one source for a given dependency. If it hits the github link and it's not reachable, then, package resolution simply fails.

Am I just hoping against hope here? I prefer not to have people being forced to edit the Package.swift every time just to do local development because those changes end up in commits and it's just not ideal.

Yeah you can't define fallbacks for dependencies with SwiftPM. You have two real options:

  1. if the packages are tightly coupled and you need to always edit one when you edit the other, why not merge them and just have them as separate targets?
  2. If it's not a regular thing, you can use the package edit mode (swift package edit or via the UI in VSCode. Xcode has a very convoluted process that I wrote about here. I don't think it's gotten any better)

I found a way actually. In the .dependencies section:

        useLocal
            ? .package(
                name: "MyPackage",
                path: "../../../my-package"
            )
            : .package(url: repo, from: swiftXMinVersion),

where useLocal is defined as:

/// For local development, set the environment variable USELOCAL=1 in Xcode or Terminal.
/// In this project, USELOCAL=1 is only set in the .xcproj User-Defined settings for DEBUG config.
let useLocal = ProcessInfo.processInfo.environment["USELOCAL"] != nil