Product from the Remote Package Not Found

Hi. Can anyone help? I do not understand what is going on here. I can add my package into the package dependencies, like that:

.package(url: "", from: "0.0.2"),

However, I am unable to add it as a dependency to an executable target after that:

.product(name: "ReparseRuntime", package: "experimental-reparse-html")

Because if I do it like this, I am getting:

product 'ReparseRuntime' required by package 'my.server' target 'App' not found in package 'experimental-reparse-html'.

However, this product is defined in the remote package.

I feel so stupid, but I really do not know what am I doing wrong. Please advice.

Thank you for your help.

I don't think that's true. As of commit 7b1ee72 (tagged as 0.0.2) there are only targets defined in Package.swift, but no products.

Ah, I think I figured it out. The targets and products must be declared separately and explicitly…

Yes. Products are collections of targets that are publicly accessible from other packages. We can't make that implicit, since we don't know how you'd like to group your targets into products, and which of those should be private or public. As with public access control in the language, the default is "nothing is public".

1 Like

Fixed. I still have a question, though. What is the use case for multiple targets per product?

IMO "target" naming in Package.swift is unfortunate and somewhat confusing, as we have other uses of the word "target" in package managers and build systems terminology (e.g. "target triple" or "build system target").

The best way is to think of a Package.swift target as a module. Then a product is a final output that your package provides to other packages, usually an executable product or a library product. Either of those can be composed of multiple modules.

For example, consider a FancyWidgets package, that has a FancyWidgetsKit library product. Bundling all widget APIs in a single Swift module may be inconvenient or confusing to a user, as they would prefer to have granular access to each separate widget. If each widget had a separate target in the package, the user could import those one by one, with separate import FancyWidgetA and import FancyWidgetB statements.