And, since the Xcode project is git ignored, you don’t have to deal with conflicts and updates to it - you simply just re-generate it when needed. The good news is that SPM can easily generate an Xcode project for you based on the file system. In order to get proper code completion and be able to easily run/debug your command line tool - you probably want to use Xcode. Next, update Package.swift to define two targets - one for the CommandLineTool module and one for CommandLineToolCore: import PackageDescriptionĪs you can see above, we make the executable depend on the framework. One really nice aspect of SPM is that it uses the file system as its “source of truth”, so simply creating new folders enables you to define new modules. To make this happen, first, create two folders in Sources, one for the executable and one for the framework, like this: $ cd Sources This will make testing a lot easier, and will also (and this is really cool) enable your command line tool to also be used as a dependency in other tools. One thing I’d recommend that you do right away is to create two modules for your sources - one framework and one executable. ![]() Splitting your code up into a framework and an executable build) and any Xcode projects you’ll generate ignored by source control. gitignore file, which will make SPM’s build folder (. A Tests folder, where you put your testing code.It will initially contain a main.swift file, which is the entry point to your command line tool (you can’t rename that file). A Sources folder, where you put your source code.A Package.swift file, which defines your package (even command line tools are packages) and its dependencies.What’s in the box?Īfter initializing your directory, it will have the following contents: The type executable above tells SPM that you want to build a command line tool, rather than a framework. ![]() To start building a command line tool, make a new directory and initialize it using SPM: $ mkdir CommandLineTool So hopefully this post will make it easier for anyone looking to build their own tooling using Swift. But it does have somewhat of a learning curve. I personally really like the Swift Package Manager (which I will from now on refer to as ‘SPM’ to save me some typing □) and how easy it is to use once you get up and running. This week, I’d like to provide a step-by-step tutorial for the setup that I use to build command line tools using the Swift Package Manager.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |