Skip to content
This repository was archived by the owner on Oct 25, 2022. It is now read-only.

Commit 00c3a79

Browse files
committed
Major overhaul; kill shell scripts and use ruby
* Adds truckload of options * No longer requires edition of the scripts to change small things on the build * Adaptative packing of output binaries (based on the architectures you chose to build for) * Accepts user input for setup * Colors!
1 parent a1393f3 commit 00c3a79

15 files changed

+738
-138
lines changed

.gitignore

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
.DS_Store
2-
bin
3-
src
4-
include
5-
lib
6-
*.tar.*
2+
build
3+
curl

README.md

+18-13
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
Curl iOS build script
2-
=====================
1+
Curl iOS build utility
2+
======================
33

44
Script to build curl for iOS. Supports:
55

66
- iPhoneSimulator (i386)
7-
- newer iPhones/iPads (arm v7)
7+
- newer iPhones/iPads (arm v7/7s)
88

99
Curl version `7.27.0` and above now supports native (Dawrwin) SSL so the other alternatives (GnuTLS and OpenSSL) have been removed. The script now compiles `libcurl.a` with SSL support at no additional binary size (yay!).
1010

11-
> **NOTES**
12-
> 1. These scripts **no longer compile for armv6**, you must manually change the files if you wish to add support.
11+
To list all possible options and flags, run `./build_curl --help`.
1312

1413

1514
## Default configuration
1615

1716
The script is configured to produce the smallest binary possible, with Curl being configured only to support HTTP and HTTPS protocols (no FTP, DICT, FILE, etc).
1817

19-
Make sure you take a peek at `build.sh` and change the vars according to your needs.
18+
Run `./build_curl --help` to list out all the options.
2019

2120

2221
## Using on your project
@@ -35,20 +34,26 @@ You need to add the following frameworks:
3534

3635
## Optimizing for space on your apps
3736

38-
The scripts generates three binary files:
37+
The scripts generates different binary files, depending on how you configure it:
3938

40-
1. One with all the architectures combined (i386 and armv7), recommended for iOS development (runs both on simulator and phones);
41-
2. One with just i386, to use on OSX development;
42-
3. One with just armv7, to use on phones;
39+
* A binary output file for each architecture
40+
* A binary with all arm architectures together (if you compile with armv6 and armv7, you'll get a single arm binary that contains both architectures)
41+
* A binary output file with i386 only (unless you don't build for i386)
42+
* A binary output file with all of the architectures combined
4343

44-
When you're about to build the final release (to submit to the app store), you should use the third one, as it is slightly smaller in size.
44+
When you're about to build the final release (to submit to the AppStore), you should use the combined arm binary. The i386 binary is only required for the simulator, so keeping it off the AppStore build means you can shave off a couple hundred KBs on your final package.
4545

4646
> **ProTip™**
4747
> Use different build targets, and include different variations of the above files in each of them so this process is automatic.
4848
4949

5050
## Acknowledgments
5151

52-
These scripts are based on the excellent work of [Felix Schulze (x2on)](https://github.com/x2on), with some help from [Bob](http://stackoverflow.com/questions/9039554/using-libcurl-on-ios-5-as-an-alternative-to-nsurlconnection/9528936#9528936).
52+
This repository has dramatically changed over time, having begun with a bunch of shell scripts and evolving to a streamlined ruby script. The original scripts were based on the excellent work of [Felix Schulze (x2on)](https://github.com/x2on), with some help from [Bob](http://stackoverflow.com/questions/9039554/using-libcurl-on-ios-5-as-an-alternative-to-nsurlconnection/9528936#9528936).
5353

54-
Also huge thanks to [Jonas Schnelli](https://github.com/jonasschnelli) for the pull request that included native Darwin SSL support.
54+
Also **huge** thanks to [Jonas Schnelli](https://github.com/jonasschnelli) for the pull request that included native Darwin SSL support.
55+
56+
57+
## License
58+
59+
Seriously? ...

build-libcurl.sh

-118
This file was deleted.

build_curl

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env ruby
2+
require_relative 'lib/curl_builder'
3+
4+
module CurlBuilder
5+
class Orchestrator
6+
include CurlBuilder::Logging
7+
8+
def build
9+
configuration = Parser.new.parse(ARGV)
10+
return if configuration[:setup][:clean_and_exit]
11+
12+
CurlBuilder.logger.level = Logger.const_get(configuration[:setup][:log_level].upcase.to_sym)
13+
14+
# Start building
15+
Preparer.new(configuration: configuration).prepare
16+
compiled_archs = Compiler.new(configuration: configuration).compile
17+
error { 'Compilation failed for all requested architectures.' } if compiled_archs.empty?
18+
return if compiled_archs.empty?
19+
20+
packed = Packer.new(configuration: configuration).pack(compiled_archs)
21+
if packed.empty?
22+
error { 'Unable to pack any of the output binaries' }
23+
error { "To determine the cause, please run again with '#{param('--log-level debug --verbose')}'." }
24+
else
25+
cenas = packed.collect { |k, v| "#{k} (#{v.join(', ')})" }.join(', ')
26+
info { "Build complete with output binaries: #{param(cenas)}" }
27+
info { "Output can be found on the '#{param('curl')}' folder" }
28+
end
29+
rescue Errors::TaskError => e
30+
error { "Build failed, output follows:\n#{black('----')}\n#{gray(e.message)}\n#{black('----')}" }
31+
ensure
32+
Cleaner.new(configuration: configuration).cleanup unless configuration.nil?
33+
end
34+
35+
def log_id
36+
' BUILD '
37+
end
38+
end
39+
end
40+
41+
CurlBuilder::Orchestrator.new.build

clean.sh

-2
This file was deleted.

lib/curl_builder.rb

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
require 'logger'
2+
require 'optparse'
3+
require 'fileutils'
4+
require 'open3'
5+
6+
7+
require_relative 'curl_builder/errors'
8+
require_relative 'curl_builder/paths'
9+
require_relative 'curl_builder/logging'
10+
require_relative 'curl_builder/configurable_step'
11+
12+
# Steps
13+
require_relative 'curl_builder/parser'
14+
require_relative 'curl_builder/preparer'
15+
require_relative 'curl_builder/compiler'
16+
require_relative 'curl_builder/packer'
17+
require_relative 'curl_builder/cleaner'
18+
19+
20+
# Phases
21+
# 1. Read stdin: Parser
22+
# 2. Download lib and create folders: Preparer
23+
# 3. For each arch, compile: Compiler
24+
# 4. Create output: Wrapper
25+
# 5. Cleanup: Cleaner
26+
27+
module CurlBuilder
28+
extend self
29+
30+
31+
# Defaults
32+
33+
DEFAULT_PROTOCOLS = {
34+
'http' => true,
35+
'rtsp' => false,
36+
'ftp' => false,
37+
'file' => false,
38+
'ldap' => false,
39+
'ldaps' => false,
40+
'rtsp' => false,
41+
'dict' => false,
42+
'telnet' => false,
43+
'tftp' => false,
44+
'pop3' => false,
45+
'imap' => false,
46+
'smtp' => false,
47+
'gopher' => false
48+
}
49+
50+
DEFAULT_FLAGS = {
51+
'darwinssl' => true,
52+
'ssl' => false,
53+
'libssh2' => false,
54+
'librtmp' => false,
55+
'libidn' => false,
56+
'ca-bundle' => false
57+
}
58+
59+
DEFAULT_SETUP = {
60+
log_level: 'info', # debug, info, warn, error
61+
verbose: false,
62+
sdk_version: '6.0',
63+
libcurl_version: '7.27.0',
64+
architectures: %w(i386 armv7 armv7s),
65+
xcode_home: '/Applications/Xcode.app/Contents/Developer',
66+
run_on_dir: Dir::pwd,
67+
work_dir: 'build',
68+
result_dir: 'curl',
69+
clean_and_exit: false,
70+
cleanup: true,
71+
}
72+
73+
VALID_ARGS = {
74+
architectures: %w(i386 armv6 armv7 armv7s)
75+
}
76+
77+
78+
attr_accessor :logger
79+
80+
81+
def logger
82+
@logger ||= Logger.new($stdout)
83+
end
84+
85+
86+
# Helper functions
87+
88+
def build_protocols(protocols)
89+
protocols.collect { |protocol, enabled| enabled ? "--enable-#{protocol}" : "--disable-#{protocol}" }
90+
end
91+
92+
def build_flags(flags)
93+
flags.collect { |flag, enabled| enabled ? "--with-#{flag}" : "--without-#{flag}" }
94+
end
95+
96+
def filter_valid_archs(archs)
97+
VALID_ARGS[:architectures] & archs
98+
end
99+
end

lib/curl_builder/cleaner.rb

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
module CurlBuilder
2+
class Cleaner < ConfigurableStep
3+
include Paths
4+
include Logging
5+
6+
7+
# Creation
8+
9+
def initialize(options = {})
10+
super options
11+
end
12+
13+
14+
# ConfigurableStep
15+
16+
def log_id
17+
' CLEAN '
18+
end
19+
20+
21+
# Interface
22+
23+
def cleanup
24+
unless setup(:cleanup)
25+
debug { "Skipping cleanup..." }
26+
return
27+
end
28+
29+
info { "Cleaning up..." }
30+
FileUtils.rm_rf work_dir
31+
32+
FileUtils.rm_rf result_dir if setup(:clean_and_exit)
33+
end
34+
end
35+
end

0 commit comments

Comments
 (0)