Idiomatic way to compile a host executable and use it in the build

Hi all! I'd like to compile a Swift command-line tool, then use that tool in a Swift project targeting iOS. I'm using macOS and Xcode, so ideally everything should be driven from Xcode (e.g. a 'Run Script' phase).

SPM lets you declare an executable as a package output, but doesn't seem to distinguish between host executables and target executables.

Is the answer to use Mint to build/install host executables? One of the tools I'm interested in using (SwiftyMocky-CLI) uses Mint, but it invokes Mint recursively at runtime(!) which causes problems in our CI. I suspect that can be improved, but Mint itself doesn't distinguish between host and target executables either, so the solution isn't obvious.

Any advice appreciated!

In the future, extensible build tools will be the right tool for this use case.

Until then you will have to manage it manually. My current strategy usually involves a command line target that can be run in order to generate files, and then those files are checked in and used by the main target. Having it in the package graph seems better than an externally installed tool, because other contributors don’t have to hunt it down or clutter their system.

1 Like

Thanks Jeremy! Yes, extensible build tools sounds like the piece that's missing — looking forward to seeing that proposal implemented.

In the meantime, I think I've found a workaround for that recursive Mint call, which should make the CI happier. We'll continue to use Mint at the top level for now.

Terms of Service

Privacy Policy

Cookie Policy