yonaskolb / Mint

A package manager that installs and runs executable Swift packages

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support SPM resource bundles

djbe opened this issue · comments

As documented in the Mint readme, SPM now supports resource bundles (since 5.3).

With SwiftGen 6.5 we've switched over to fully using SPM for this, but apparently during installation Mint is getting rid of the resource bundles:

Tried it locally as well, and indeed the build folder only contains:

-rwxr-xr-x  1 davidjennes  admin   5.0M Oct  4 15:23 swiftgen

Where it should contain:

drwxr-xr-x  3 davidjennes  admin    96B Oct  4 15:15 SwiftGen_SwiftGenCLI.bundle
-rwxr-xr-x  1 davidjennes  admin   5.2M Oct  4 15:15 swiftgen

To make things a bit spicier, we don't control the name of the bundle, we just use Bundle.module in Swift code. And in this specific case, it is a resource bundle for a framework the binary depends on (called SwiftGenCLI). It is defined here in Package.swift.

Do note that for Homebrew, we had some trouble because they didn't like that we were installing the binary + the bundle in the bin folder. Apparently they have some validation for that. Not sure if Mint also wants to avoid polluting the bin path like that.

We couldn't just move the bundle somewhere else, the (relative) path to the bundle is hardcoded in the binary (and controlled by Apple/Swift). We ended up installing everything in libexec, and then creating a shim in bin. Initially we tried a symlink, but that doesn't work in all cases.

See these Homebrew PRs for the relevant discussions: Homebrew/homebrew-core#86408 and Homebrew/homebrew-core#86446.

As a temporary workaround, we re-added our Package.resources but this time pointing it to the generated bundle in the .build/ folder. Props to @tid-kijyun for the fix.

SwiftGen/SwiftGen#885

I am working to resolve this issue at tid-kijyun/Mint.
It's already working in SwiftGen and my sample project, but I will do some more testing and create a PR.


SPM outputs a file named [package name]_[target name].bundle when resources is specified as a target in Package.swift. If resources is specified for multiple targets, multiple bundles will be output, so Mint needs to figure out the dependency graph and copy only what it needs.