I like the SE-0339 feature very much. However, I found it not always applicable to use moduleAliases
in some situations, here is an example:
In the first place, we have a bottom-layer package, described as follows
let package = Package(
name: "Game",
products: [
.library(name: "Game", targets: ["Game"]),
.library(name: "Utils", targets: ["Utils"]),
],
targets: [
.target(name: "Game"),
.target(name: "Utils")
]
)
It just declares 2 independent targets and the corresponding products.
This package is then being used by an upper-layer package, described as follows
let package = Package(
name: "App",
dependencies: [.package(path: "../Game")],
targets: [
.executableTarget(
name: "App",
dependencies: [
.target(name: "Utils"),
.product(name: "Game", package: "Game")
]
),
.target(name: "Utils"),
]
)
This package declares a target Utils
, which has the same name with the one in the bottom-layer package. However, package App
never references Game/Utils
, so theoretically, there should not be two targets sharing a same name in the dependency graph.
Nevertheless, when we run swift build
for the above example, there will be an error:
error: multiple packages ('app', 'game') declare targets with a conflicting name: 'Utils’;
target names need to be unique across the package graph
What's worse, there's no way to workaround this issue, because there's no place to pass a moduleAliases
argument to SwiftPM. If we try to do that in package App
by writing
.product(name: "Game", package: "Game", moduleAliases: ["Utils": "GameUtils"])
that'll only create one additional warning, saying
warning: module alias for target 'Utils', declared in package 'app',
does not match any recursive target dependency of product 'Game' from package 'Game'
So, is this just a bug, or a temporary implementation limitation?