├── .gitignore ├── lib ├── cocoapods_plugin.rb ├── cocoapods-static-swift-framework.rb └── cocoapods-static-swift-framework │ ├── gem_version.rb │ ├── main.rb │ └── patch │ └── static_pod.rb ├── Rakefile ├── Gemfile ├── spec ├── command │ └── framework_spec.rb └── spec_helper.rb ├── LICENSE.txt ├── cocoapods-static-swift-framework.gemspec ├── README.md └── Gemfile.lock /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | pkg 3 | .idea/ 4 | -------------------------------------------------------------------------------- /lib/cocoapods_plugin.rb: -------------------------------------------------------------------------------- 1 | require 'cocoapods-static-swift-framework/main' 2 | -------------------------------------------------------------------------------- /lib/cocoapods-static-swift-framework.rb: -------------------------------------------------------------------------------- 1 | require 'cocoapods-static-swift-framework/gem_version' 2 | -------------------------------------------------------------------------------- /lib/cocoapods-static-swift-framework/gem_version.rb: -------------------------------------------------------------------------------- 1 | module CocoapodsStaticSwiftFramework 2 | VERSION = "0.5" 3 | end 4 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in cocoapods-static-swift-framework.gemspec 4 | gemspec 5 | 6 | group :development do 7 | gem 'cocoapods' 8 | 9 | gem 'mocha' 10 | gem 'bacon' 11 | gem 'mocha-on-bacon' 12 | gem 'prettybacon' 13 | end 14 | -------------------------------------------------------------------------------- /spec/command/framework_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../../spec_helper', __FILE__) 2 | 3 | module Pod 4 | describe Command::Framework do 5 | describe 'CLAide' do 6 | it 'registers it self' do 7 | Command.parse(%w{ framework }).should.be.instance_of Command::Framework 8 | end 9 | end 10 | end 11 | end 12 | 13 | -------------------------------------------------------------------------------- /lib/cocoapods-static-swift-framework/main.rb: -------------------------------------------------------------------------------- 1 | 2 | Pod::HooksManager.register('cocoapods-static-swift-framework', :pre_install) do |installer_context| 3 | 4 | # check user_framework is on 5 | podfile = installer_context.podfile 6 | podfile.target_definition_list.each do |target_definition| 7 | next if target_definition.name == "Pods" 8 | if not target_definition.uses_frameworks? 9 | STDERR.puts "[!] Cocoapods-static-swift-framework requires `use_frameworks!`".red 10 | exit 11 | end 12 | end 13 | 14 | require_relative 'patch/static_pod' 15 | end -------------------------------------------------------------------------------- /lib/cocoapods-static-swift-framework/patch/static_pod.rb: -------------------------------------------------------------------------------- 1 | 2 | if Gem::Version.new(Pod::VERSION) < Gem::Version.new('1.7') 3 | 4 | module Pod 5 | class PodTarget 6 | def static_framework? 7 | return true 8 | end 9 | end 10 | end 11 | 12 | else 13 | 14 | # cocoapods 1.7 change the implementation of :static_framework? 15 | # The 'BuildType' contain all related things. 16 | module Pod 17 | class Target 18 | class BuildType 19 | def linkage 20 | :static 21 | end 22 | end 23 | end 24 | end 25 | 26 | end 27 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 leavez 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 | -------------------------------------------------------------------------------- /cocoapods-static-swift-framework.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-static-swift-framework/gem_version.rb' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = 'cocoapods-static-swift-framework' 8 | spec.version = CocoapodsStaticSwiftFramework::VERSION 9 | spec.authors = ['leavez'] 10 | spec.email = ['gaojiji@gmail.com'] 11 | spec.description = %q{use static framework for Swift} 12 | spec.summary = %q{use static framework for Swift for cocoapods when use_frameworks!} 13 | spec.homepage = 'https://github.com/leavez/cocoapods-static-swift-framework' 14 | spec.license = 'MIT' 15 | 16 | spec.files = `git ls-files`.split($/) 17 | spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } 18 | spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) 19 | spec.require_paths = ['lib'] 20 | 21 | spec.add_dependency "cocoapods", ">= 1.5.0", "< 2.0" 22 | 23 | spec.add_development_dependency 'bundler', '~> 1.3' 24 | spec.add_development_dependency 'rake' 25 | end 26 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cocoapods-static-swift-framework 2 | 3 | A cocoapods plugin that enables static frameworks for all pods. 4 | 5 | Cocoapods only supports static framework at pod level, which means an option in podspec and just valid for that pod. By using this plugin, we can make all pod to static framework with only one word! 6 | 7 | (There's 'swift' in the plugin name as it's originally built for swift. You can also use it for pure objc project too.) 8 | 9 | ## Usage 10 | Install via gem: 11 | 12 | ``` 13 | $ gem install cocoapods-static-swift-framework 14 | ``` 15 | 16 | Add the following to your podfile: 17 | 18 | ```ruby 19 | plugin 'cocoapods-static-swift-framework' 20 | 21 | ``` 22 | 23 | NOTE: Static frameworks is still using framework, not static library. So don't forget to add `use_frameworks!` 24 | 25 | NOTE: From cocoapods 1.7, the generated resource bundle specified with `s.resource_bundle` in podspec, will not be copied to the .framework folder. It's a default behavior of cocoapods. 26 | 27 | ## About Static framework 28 | 29 | ### Why 30 | 31 | Too many dynamic frameworks will increase app boot time dramatically, also the `Copy framework` build phase will expend unendurable time in the code-build-run loop. (There is also a dyld [crash](https://github.com/Ruenzuo/cocoapods-amimono#why-would-you-want-this-plugin-in-your-podfile)) Static framework have no these problems. 32 | 33 | ### What is a static framework 34 | 35 | First of all, what is a framework? Framework is just a bundle with specifications to organize files, for whom xcode provides convenient methods to link bianry and copy resources. 36 | 37 | Static framework, or precisely static-linking framework, has no official defination. There's only (dynamic) framework. "When linking, it found that the binary in the framework is static-linking, then it will link the binary staticaly. There's no special handling." an Apple engineer answered me at WWDC. 38 | 39 | Resources in static framework can't be copied to app's main bundle automatically. If you use cocoapods, it will handle it automatically, but not for the manual integration. 40 | 41 | The binary in the framework will be linked statically, as its name, to the main binary. There's no framework file in the `Framework` folder of the app bundle. Resources will copied to app bundle's root path. So there's a potential bug of conflict of resource file names. 42 | 43 | 44 | ## requirement 45 | 46 | - Xcode 9+ 47 | - cocoapods 1.5+ (v1.7 tested) 48 | 49 | ## License 50 | MIT 51 | 52 | Appreciate a 🌟 if you like it. Another cocoapods plugin made by me to improve pod compile time: [cocoapods-binary](https://github.com/leavez/cocoapods-binary) 53 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: . 3 | specs: 4 | cocoapods-static-swift-framework (0.4) 5 | cocoapods (>= 1.5.0, < 2.0) 6 | 7 | GEM 8 | remote: https://rubygems.org/ 9 | specs: 10 | CFPropertyList (3.0.0) 11 | activesupport (4.2.10) 12 | i18n (~> 0.7) 13 | minitest (~> 5.1) 14 | thread_safe (~> 0.3, >= 0.3.4) 15 | tzinfo (~> 1.1) 16 | atomos (0.1.2) 17 | bacon (1.2.0) 18 | claide (1.0.2) 19 | cocoapods (1.5.3) 20 | activesupport (>= 4.0.2, < 5) 21 | claide (>= 1.0.2, < 2.0) 22 | cocoapods-core (= 1.5.3) 23 | cocoapods-deintegrate (>= 1.0.2, < 2.0) 24 | cocoapods-downloader (>= 1.2.0, < 2.0) 25 | cocoapods-plugins (>= 1.0.0, < 2.0) 26 | cocoapods-search (>= 1.0.0, < 2.0) 27 | cocoapods-stats (>= 1.0.0, < 2.0) 28 | cocoapods-trunk (>= 1.3.0, < 2.0) 29 | cocoapods-try (>= 1.1.0, < 2.0) 30 | colored2 (~> 3.1) 31 | escape (~> 0.0.4) 32 | fourflusher (~> 2.0.1) 33 | gh_inspector (~> 1.0) 34 | molinillo (~> 0.6.5) 35 | nap (~> 1.0) 36 | ruby-macho (~> 1.1) 37 | xcodeproj (>= 1.5.7, < 2.0) 38 | cocoapods-core (1.5.3) 39 | activesupport (>= 4.0.2, < 6) 40 | fuzzy_match (~> 2.0.4) 41 | nap (~> 1.0) 42 | cocoapods-deintegrate (1.0.2) 43 | cocoapods-downloader (1.2.1) 44 | cocoapods-plugins (1.0.0) 45 | nap 46 | cocoapods-search (1.0.0) 47 | cocoapods-stats (1.0.0) 48 | cocoapods-trunk (1.3.0) 49 | nap (>= 0.8, < 2.0) 50 | netrc (~> 0.11) 51 | cocoapods-try (1.1.0) 52 | colored2 (3.1.2) 53 | concurrent-ruby (1.0.5) 54 | escape (0.0.4) 55 | fourflusher (2.0.1) 56 | fuzzy_match (2.0.4) 57 | gh_inspector (1.1.3) 58 | i18n (0.9.5) 59 | concurrent-ruby (~> 1.0) 60 | metaclass (0.0.4) 61 | minitest (5.11.3) 62 | mocha (1.5.0) 63 | metaclass (~> 0.0.1) 64 | mocha-on-bacon (0.2.3) 65 | mocha (>= 0.13.0) 66 | molinillo (0.6.5) 67 | nanaimo (0.2.6) 68 | nap (1.1.0) 69 | netrc (0.11.0) 70 | prettybacon (0.0.2) 71 | bacon (~> 1.2) 72 | rake (13.0.1) 73 | ruby-macho (1.2.0) 74 | thread_safe (0.3.6) 75 | tzinfo (1.2.5) 76 | thread_safe (~> 0.1) 77 | xcodeproj (1.5.9) 78 | CFPropertyList (>= 2.3.3, < 4.0) 79 | atomos (~> 0.1.2) 80 | claide (>= 1.0.2, < 2.0) 81 | colored2 (~> 3.1) 82 | nanaimo (~> 0.2.5) 83 | 84 | PLATFORMS 85 | ruby 86 | 87 | DEPENDENCIES 88 | bacon 89 | bundler (~> 1.3) 90 | cocoapods 91 | cocoapods-static-swift-framework! 92 | mocha 93 | mocha-on-bacon 94 | prettybacon 95 | rake 96 | 97 | BUNDLED WITH 98 | 1.16.1 99 | --------------------------------------------------------------------------------