├── .gitignore ├── Gemfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── cocoapods-wholemodule.gemspec ├── lib ├── cocoapods-wholemodule.rb ├── cocoapods-wholemodule │ ├── gem_version.rb │ └── post_install.rb └── cocoapods_plugin.rb └── spec └── spec_helper.rb /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | .DS_Store 3 | pkg 4 | .idea/ 5 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gemspec 4 | 5 | group :development do 6 | gem 'cocoapods', >= 1.0.0 7 | gem 'bacon' 8 | end 9 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Jed Lewison 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cocoapods-wholemodule 2 | 3 | A CocoaPods plugin to use Whole Module Optimization for Swift files when compiling in release mode. 4 | 5 | CocoaPods sensibly uses Apple's defaults for the Pods project, which means that if you want your pods to run with Whole Module Optimization enabled in release mode, you need to add a post install hook. The `cocoapods-wholemodule` plugin takes care of the boilerplate so you can add that in just one line. 6 | 7 | ## Installation 8 | 9 | ```bash 10 | $ gem install cocoapods-wholemodule 11 | ``` 12 | 13 | ## Usage with default configuration names 14 | 15 | Add cocoapods-wholemodule to your Podfile: 16 | 17 | ```ruby 18 | plugin 'cocoapods-wholemodule' 19 | ``` 20 | 21 | Now, for configurations named `Release`, your Swift files will automatically be compiled with Whole Module Optimization enabled. 22 | 23 | ## Usage with custom configuration names 24 | 25 | Add an option specificying which configuration names should be compiled with Whole Module Optimization enabled: 26 | 27 | ```ruby 28 | plugin 'cocoapods-wholemodule', :wholemodule => 'CustomRelease' 29 | ``` 30 | 31 | Now, for configurations named `CustomRelease`, your Swift files will automatically be compiled with Whole Module Optimization enabled. 32 | 33 | To specify multiple configuration names, supply an array of names: 34 | 35 | ```ruby 36 | plugin 'cocoapods-wholemodule', :wholemodule => ['CustomRelease', 'SpecialName'] 37 | ``` 38 | 39 | Now, for configurations named `CustomRelease` and `SpecialName`, your Swift files will automatically be compiled with Whole Module Optimization enabled. 40 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'bundler/gem_tasks' 2 | 3 | def specs(dir) 4 | FileList["spec/#{dir}/*_spec.rb"].shuffle.join(' ') 5 | end 6 | 7 | desc 'Runs all the specs' 8 | task :specs do 9 | sh "bundle exec bacon #{specs('**')}" 10 | end 11 | 12 | task :default => :specs 13 | 14 | -------------------------------------------------------------------------------- /cocoapods-wholemodule.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'cocoapods-wholemodule/gem_version.rb' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = 'cocoapods-wholemodule' 8 | spec.version = CocoaPodsWholeModule::VERSION 9 | spec.authors = ['Jed Lewison'] 10 | spec.email = ['jed@magicappfactory.com'] 11 | spec.summary = %q{Adds CocoaPods post-install action to use Whole Module Optimization for Swift files in release mode.} 12 | spec.homepage = 'https://github.com/jedlewison/cocoapods-wholemodule' 13 | spec.license = 'MIT' 14 | spec.files = `git ls-files`.split($/) 15 | spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } 16 | spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) 17 | spec.require_paths = ['lib'] 18 | 19 | spec.add_development_dependency 'bundler', '~> 1.3' 20 | spec.add_development_dependency 'rake', '~> 0' 21 | end 22 | -------------------------------------------------------------------------------- /lib/cocoapods-wholemodule.rb: -------------------------------------------------------------------------------- 1 | require 'cocoapods-wholemodule/gem_version' 2 | -------------------------------------------------------------------------------- /lib/cocoapods-wholemodule/gem_version.rb: -------------------------------------------------------------------------------- 1 | module CocoaPodsWholeModule 2 | VERSION = "0.0.1" 3 | end 4 | -------------------------------------------------------------------------------- /lib/cocoapods-wholemodule/post_install.rb: -------------------------------------------------------------------------------- 1 | require 'cocoapods-core' 2 | 3 | module CocoaPodsWholeModule 4 | 5 | Pod::HooksManager.register('cocoapods-wholemodule', :post_install) do |installer, options| 6 | whole_module_configs = ['Release'] 7 | if options[:wholemodule].is_a?(Array) 8 | whole_module_configs = options[:wholemodule] 9 | elsif options[:wholemodule].is_a?(String) 10 | whole_module_configs = [options[:wholemodule]] 11 | end 12 | 13 | installer.pods_project.targets.each do |target| 14 | target.build_configurations.each do |config| 15 | if whole_module_configs.include?(config.name) 16 | config.build_settings['SWIFT_OPTIMIZATION_LEVEL'] = '-Owholemodule' 17 | else 18 | config.build_settings['SWIFT_OPTIMIZATION_LEVEL'] = '-Onone' 19 | end 20 | end 21 | end 22 | installer.pods_project.save 23 | 24 | end 25 | 26 | end -------------------------------------------------------------------------------- /lib/cocoapods_plugin.rb: -------------------------------------------------------------------------------- 1 | require 'cocoapods-wholemodule/post_install.rb' 2 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'pathname' 2 | ROOT = Pathname.new(File.expand_path('../../', __FILE__)) 3 | $:.unshift((ROOT + 'lib').to_s) 4 | $:.unshift((ROOT + 'spec').to_s) 5 | 6 | require 'bundler/setup' 7 | require 'bacon' 8 | require 'mocha-on-bacon' 9 | require 'pretty_bacon' 10 | require 'pathname' 11 | require 'cocoapods' 12 | 13 | Mocha::Configuration.prevent(:stubbing_non_existent_method) 14 | 15 | require 'cocoapods_plugin' 16 | 17 | #-----------------------------------------------------------------------------# 18 | 19 | module Pod 20 | 21 | # Disable the wrapping so the output is deterministic in the tests. 22 | # 23 | UI.disable_wrap = true 24 | 25 | # Redirects the messages to an internal store. 26 | # 27 | module UI 28 | @output = '' 29 | @warnings = '' 30 | 31 | class << self 32 | attr_accessor :output 33 | attr_accessor :warnings 34 | 35 | def puts(message = '') 36 | @output << "#{message}\n" 37 | end 38 | 39 | def warn(message = '', actions = []) 40 | @warnings << "#{message}\n" 41 | end 42 | 43 | def print(message) 44 | @output << message 45 | end 46 | end 47 | end 48 | end 49 | 50 | #-----------------------------------------------------------------------------# 51 | --------------------------------------------------------------------------------