├── .gitignore ├── Gemfile ├── Gemfile.lock ├── LICENSE ├── README.md ├── Rakefile ├── cocoapods-chillax-swift.gemspec └── lib ├── cocoapods-chillax-swift.rb ├── cocoapods_plugin.rb ├── installer.rb └── plugin.rb /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | *.rbc 3 | /.config 4 | /coverage/ 5 | /InstalledFiles 6 | /pkg/ 7 | /spec/reports/ 8 | /test/tmp/ 9 | /test/version_tmp/ 10 | /tmp/ 11 | 12 | ## Specific to RubyMotion: 13 | .dat* 14 | .repl_history 15 | build/ 16 | 17 | ## Documentation cache and generated files: 18 | /.yardoc/ 19 | /_yardoc/ 20 | /doc/ 21 | /rdoc/ 22 | 23 | ## Environment normalisation: 24 | /.bundle/ 25 | /lib/bundler/man/ 26 | 27 | # for a library or gem, you might want to ignore these files since the code is 28 | # intended to run in multiple environments; otherwise, check them in: 29 | # Gemfile.lock 30 | # .ruby-version 31 | # .ruby-gemset 32 | 33 | # unless supporting rvm < 1.11.0 or doing something fancy, ignore this: 34 | .rvmrc 35 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in cocoapods-chillax-swift.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: . 3 | specs: 4 | cocoapods-chillax-swift (0.0.1) 5 | 6 | GEM 7 | remote: https://rubygems.org/ 8 | specs: 9 | rake (10.4.2) 10 | 11 | PLATFORMS 12 | ruby 13 | 14 | DEPENDENCIES 15 | bundler (~> 1.3) 16 | cocoapods-chillax-swift! 17 | rake (~> 10.3) 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Ash Furrow 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | CocoaPods' "Chillax, Swift" Plugin 2 | ================================== 3 | 4 | A CocoaPods plugin to disable all compiler optimizations for specific pods. 5 | 6 | Why? 7 | ---- 8 | 9 | So you're writing a hit new app and need an external dependency. The library you want to use is available as a CocoaPod – awesome! But it's written in Swift. Good thing CocoaPods 0.36 Beta 1 version support Swift pods! Using the beta version of CocoaPods, you install the library, try to compile, then BAM the compiler segfaults. 10 | 11 | ``` 12 | Command failed due to signal: Segmentation fault: 11 13 | 14 | 0 swift 0x0000000104a9bb68 llvm::sys::PrintStackTrace(__sFILE*) + 40 15 | 1 swift 0x0000000104a9c054 SignalHandler(int) + 452 16 | 2 libsystem_platform.dylib 0x00007fff8d815f1a _sigtramp + 26 17 | 3 libsystem_platform.dylib 0x00007fae8cf15028 _sigtramp + 4285526312 18 | 4 swift 0x000000010482a69f (anonymous namespace)::SimplifyCFGOpt::run(llvm::BasicBlock*) + 3487 19 | 5 swift 0x00000001048298ef llvm::SimplifyCFG(llvm::BasicBlock*, llvm::TargetTransformInfo const&, llvm::DataLayout const*) + 31 20 | 6 swift 0x000000010478cdc3 (anonymous namespace)::CFGSimplifyPass::runOnFunction(llvm::Function&) + 2051 21 | 7 swift 0x00000001049aeced llvm::FPPassManager::runOnFunction(llvm::Function&) + 301 22 | 8 swift 0x00000001049aeedb llvm::FPPassManager::runOnModule(llvm::Module&) + 43 23 | 9 swift 0x00000001049af39f llvm::legacy::PassManagerImpl::run(llvm::Module&) + 975 24 | 10 swift 0x0000000103e8d1f4 performIRGeneration(swift::IRGenOptions&, swift::Module*, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, unsigned int) + 3828 25 | 11 swift 0x0000000103e8d473 swift::performIRGeneration(swift::IRGenOptions&, swift::SourceFile&, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, unsigned int) + 51 26 | 12 swift 0x0000000103de26f4 frontend_main(llvm::ArrayRef, char const*, void*) + 5444 27 | 13 swift 0x0000000103ddfa6d main + 1677 28 | 14 libdyld.dylib 0x00007fff923b15c9 start + 1 29 | ``` 30 | 31 | This problem is often caused by the Swift compiler's opimizations. Disabling them fixes the segfault. 32 | 33 | ![This is how you make me feel sometimes, Swift](http://gifs.ashfurrow.com/angry.gif) 34 | 35 | Doncha wish that you could just tell Swift to Chillax? Well, now you can. 36 | 37 | How? 38 | ---- 39 | 40 | This plugin requires version 0.36 Beta 1 of CocoaPods. Create or modify a file named `Gemfile` in the root of your project's directory: 41 | 42 | ```ruby 43 | source 'https://rubygems.org' 44 | 45 | gem 'cocoapods', :git => 'https://github.com/CocoaPods/CocoaPods.git', :tag => '0.36.0.beta.1' 46 | gem 'cocoapods-chillax-swift', '~> 0.2.0' 47 | ``` 48 | 49 | Great! Now from the command line in the same directory as the `Gemfile`, run `bundle install` to install both the pre-release version of CocoaPods and this plugin. You've installed the plugin, but you still need to tell CocoaPods which pods are segfaulting the compiler. Open your Podfile and add the following lines. 50 | 51 | ```ruby 52 | plugin 'cocoapods-chillax-swift', { 53 | :pods => ['XCGLogger'] 54 | } 55 | ``` 56 | 57 | In this example, we're disabling compiler optimizations for [XCGLogger](https://github.com/DaveWoodCom/XCGLogger). 58 | 59 | *Important*: from now on, instead of typing `pod install`, you *must* type `bundle exec pod install`. If you don't, then you're running the version of CocoaPods installed for the entire system instead of the version specified in the `Gemfile`. 60 | 61 | OK, next time you `bundle exec pod install`, you'll get a little extra message at the end of the process. 62 | 63 | ``` 64 | > bundle exec pod install 65 | Analyzing dependencies 66 | Downloading dependencies 67 | Using XCGLogger (0.0.1) 68 | Generating Pods project 69 | Integrating client project 70 | Disabling select compiler optimizations 71 | ``` 72 | 73 | And you're good to go! 74 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'bundler/gem_tasks' 2 | -------------------------------------------------------------------------------- /cocoapods-chillax-swift.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-chillax-swift.rb' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = "cocoapods-chillax-swift" 8 | spec.version = CocoaPodsChillaxSwift::VERSION 9 | spec.authors = ["Ash Furrow"] 10 | spec.email = ["ash@ashfurrow.com"] 11 | spec.description = %q{A CocoaPods plugin to disable compiler optimizations on certain pods.} 12 | spec.summary = %q{Given an opt-in whitelist of pod names, this plugin disbles compiler optimization on those pods' targets. This is useful while the Swift compiler is still segfaulting on certain libraries when optimizations are enabled, which they are by default.} 13 | spec.homepage = "https://github.com/ashfurrow/cocoapods-chillax-swift" 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_development_dependency "bundler", "~> 1.3" 22 | spec.add_development_dependency "rake", "~> 10.3" 23 | end 24 | -------------------------------------------------------------------------------- /lib/cocoapods-chillax-swift.rb: -------------------------------------------------------------------------------- 1 | module CocoaPodsChillaxSwift 2 | VERSION = "0.2.0" 3 | end 4 | -------------------------------------------------------------------------------- /lib/cocoapods_plugin.rb: -------------------------------------------------------------------------------- 1 | require_relative 'plugin' 2 | -------------------------------------------------------------------------------- /lib/installer.rb: -------------------------------------------------------------------------------- 1 | module CocoaPodsChillaxSwift 2 | class Installer 3 | def initialize(sandbox_root, user_options) 4 | @sandbox_root = sandbox_root 5 | @options = user_options 6 | end 7 | 8 | def install! 9 | 10 | Pod::UI.section 'Disabling select compiler optimizations' do 11 | 12 | project = Xcodeproj::Project.open File.join(@sandbox_root, 'Pods.xcodeproj') 13 | 14 | unoptimized_pod_names = @options["pods"] 15 | 16 | targets = project.targets.select { |target| 17 | unoptimized_pod_names.select { |pod_name| 18 | target.display_name.end_with? pod_name 19 | }.count > 0 20 | } 21 | 22 | targets.each do |target| 23 | target.build_configurations.each do |config| 24 | config.build_settings['SWIFT_OPTIMIZATION_LEVEL'] = '-Onone' 25 | config.build_settings['GCC_OPTIMIZATION_LEVEL'] = '0' 26 | end 27 | end 28 | 29 | project.save 30 | end 31 | end 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /lib/plugin.rb: -------------------------------------------------------------------------------- 1 | module CocoaPodsChillaxSwift 2 | Pod::HooksManager.register('cocoapods-chillax-swift', :post_install) do |context, user_options| 3 | require_relative 'installer' 4 | 5 | Installer.new(context.sandbox_root, user_options).install! 6 | end 7 | end 8 | --------------------------------------------------------------------------------