A CocoaPods plugin to add SPM dependencies to CocoaPods-based projects.
Via Bundler: Add the gem cocoapods-spm
to the Gemfile of your project.
gem "cocoapods-spm"
Via RubyGems:
$ gem install cocoapods-spm
Check out the demo at: examples.
In the podspec of a pod, use spm_dependency
to specify the SPM package that the pod depends on, in the following format:
s.spm_dependency "<package-name>/<ProductName>"
For example, if a pod depends on the Orcam
library of this Orcam package, you just need to declare the depenency in the podspec as follows:
Pod::Spec.new do |s|
s.name = "Foo"
s.spm_dependency "Orcam/Orcam" # <--- HERE
end
NOTE: Like pod dependencies, the SPM depenency in a podspec should not state its source. Rather, the source of an SPM package (ex. its repo, which branch, commit...) should be declared in Podfile.
The spm_pkg
method to declare the package being used. This method's usage is pretty much similar to the pod
method.
spm_pkg "Orcam", :url => "https://github.com/trinhngocthuyen/orcam.git", :branch => "main"
There are two approaches when integrating a Swift macro to a project.
First, you can integrate the macro package just like any other SPM package, by declaring it in Podfile using the spm_pkg
method, instructed in the previous section.
Another way is to integrate a macro to the project as prebuilt binary. This was inspired by the approach mentioned in this blog post. This approach helps reduce some build time. This is really beneficial because:
- It takes time to build such a macro package. swift-syntax, one of its dependencies, already takes up 10-15s.
- A macro is usually used by many dependants. This leads to delays in compiling those dependants.
By integrating macros as prebuilt binaries, the additional build time should be insignificant.
In Podfile, simply use the :macro
option when declaring a pod.
pod "MacroCodableKit", :macro => {
:git => "https://github.com/mikhailmaslo/macro-codable-kit",
:tag => "0.3.0"
}
When running pod install, the plugin prebuilds the declared macros (if not prebuilt before) from their sources.
Wanna know more about its under-the-hood? Check out this doc.
Alternatively, you can prebuild macros with the CLI. Check the subsequent section for details.
This plugin offers some CLI usages under the spm
subcommand (bundle exec pod spm
). To explore the usages, run the command with the --help
option.
As follows are some common usages.
Fetching macro sources
bundle exec pod spm macro fetch --all
The downloaded sources are put in the .spm.pods/.downloaded
folder.
Prebuilding macros
# Prebuild all macros
bundle exec pod spm macro prebuild --all
# Prebuild some macros with the given config
bundle exec pod spm macro prebuild --macros=Orcam --config=debug
Refer to the troubleshooting guidelines for details.
Refer to the contributing guidelines for details.
The plugin is available as open-source under the terms of the MIT License.