Created
December 9, 2012 16:54
-
-
Save kizzx2/4246030 to your computer and use it in GitHub Desktop.
Rake task to easily package iOS static library into .framework bundle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This assumes you have placed your public header files in the `Headers` | |
# directory in your output directory. You can satisfy that easily by creating a | |
# "Copy Files" build phase. See | |
# http://image.bayimg.com/9cf4804007f7a7b59505de345ad2bbc388499475.jpg | |
# Usage: | |
# | |
# 1. Change `PROJECT_NAME` below. E.g. if you have `Calculator.xcodeproj`, change it to `"Calculator"` | |
# 2. Put this beside your `.xcodeproj` file, then just run `rake` | |
task :default => :build | |
SDKS = %w(iphonesimulator iphoneos).freeze | |
CONFIGS = %w(Debug Release).freeze | |
BUILD_DIR = "build".freeze | |
PROJECT_NAME = "MyCoolFramework".freeze | |
def run(command) | |
puts "> #{command}" | |
system(command) | |
fail "Command \`#{command}\` failed with exit status #{$?}" if !$?.success? | |
end | |
task :build do | |
CONFIGS.each do |config| | |
fat_lib = File.join(BUILD_DIR, config, "lib#{PROJECT_NAME}.a") | |
FileUtils.mkdir_p(File.join(BUILD_DIR, config)) | |
SDKS.each do |sdk| | |
run "xcodebuild -sdk #{sdk} -configuration #{config}" | |
end | |
inputs = SDKS.map do |sdk| | |
File.join(BUILD_DIR, "#{config}-#{sdk}", "lib#{PROJECT_NAME}.a") | |
end | |
run "lipo -create #{inputs.join(' ')} -output #{fat_lib}" | |
end | |
CONFIGS.product(SDKS).each do |config, sdk| | |
fat_lib = File.join(BUILD_DIR, config, "lib#{PROJECT_NAME}.a") | |
headers_dir = File.join(BUILD_DIR, "#{config}-#{sdk}", "Headers") | |
framework_dir = File.join(BUILD_DIR, config, "#{PROJECT_NAME}.framework") | |
version_a_dir = File.join(framework_dir, "Versions", "A") | |
FileUtils.mkdir_p(version_a_dir) | |
FileUtils.cp_r(headers_dir, version_a_dir, :preserve => true) | |
FileUtils.cp(fat_lib, File.join(version_a_dir, PROJECT_NAME)) | |
FileUtils.rm_f(File.join(framework_dir, "Versions", "Current")) | |
FileUtils.ln_sf("A", File.join(framework_dir, "Versions", "Current")) | |
FileUtils.rm_f(File.join(framework_dir, "Headers")) | |
FileUtils.rm_f(File.join(framework_dir, PROJECT_NAME)) | |
FileUtils.ln_sf(File.join("Versions", "Current", "Headers"), framework_dir) | |
FileUtils.ln_sf(File.join("Versions", "Current", PROJECT_NAME), framework_dir) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment