Skip to content

diogobalseiro/cocoapods-spm-sample

Repository files navigation

cocoapods-spm (CocoaPods + SPM)

Test License Gem

A CocoaPods plugin to add SPM dependencies to CocoaPods-based projects.

Installation

Via Bundler: Add the gem cocoapods-spm to the Gemfile of your project.

gem "cocoapods-spm"

Via RubyGems:

$ gem install cocoapods-spm

Usage

Check out the demo at: examples.

Declaring SPM packages

In a podspec

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.

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"

Using Swift Macros with cocoapods-spm

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.

Integrating macros as prebuilt binaries

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.

Using the CLI

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

Troublshooting

Refer to the troubleshooting guidelines for details.

Contribution

Refer to the contributing guidelines for details.

License

The plugin is available as open-source under the terms of the MIT License.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published