iOS support
diff --git a/.travis.yml b/.travis.yml
index f58a60e..837025f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -34,6 +34,12 @@
     - os: linux
       env: TARGET=aarch64-unknown-linux-gnu
       rust: nightly-2015-09-08
+    - os: osx
+      env: TARGET=i386-apple-ios
+      rust: nightly-2015-09-08
+    - os: osx
+      env: TARGET=x86_64-apple-ios
+      rust: nightly-2015-09-08
 notifications:
   email:
     on_success: never
diff --git a/README.md b/README.md
index 2b57d7e..a1c8fde 100644
--- a/README.md
+++ b/README.md
@@ -17,7 +17,7 @@
   *  `x86_64-unknown-linux-musl`
   *  `arm-unknown-linux-gnueabihf`
   *  `arm-linux-androideabi`
-  *  `{i686,x86_64}-apple-darwin`
+  *  `{i686,x86_64}-apple-{darwin,ios}`
 
 Untested:
   * `{i686,x86_64}-unknown-freebsd`
diff --git a/ci/README.md b/ci/README.md
index 6aebb43..8e4729e 100644
--- a/ci/README.md
+++ b/ci/README.md
@@ -57,7 +57,7 @@
   *  `x86_64-unknown-linux-musl`
   *  `arm-unknown-linux-gnueabihf`
   *  `arm-linux-androideabi`
-  *  `{i686,x86_64}-apple-darwin`
+  *  `{i686,x86_64}-apple-{darwin,ios}`
 
 The Windows triples are all pretty standard, they just set up their environment
 then run tests, no need for downloading any extra target libs (we just download
@@ -74,6 +74,8 @@
   actually verify the tests pass.
 * The MUSL build just has to download a MUSL compiler and target libraries and
   then otherwise runs tests normally.
+* iOS builds need an extra linker flag currently, but beyond that they're built
+  as standard as everything else.
 
 Hopefully that's at least somewhat of an introduction to everything going on
 here, and feel free to ping @alexcrichton with questions!
diff --git a/ci/run-travis.sh b/ci/run-travis.sh
index 0bebd42..ee58b88 100644
--- a/ci/run-travis.sh
+++ b/ci/run-travis.sh
@@ -47,6 +47,10 @@
     export CC=aarch64-linux-gnu-gcc
     ;;
 
+  *-apple-ios)
+    curl -s $EXTRA_TARGETS/$TARGET.tar.gz | tar xzf - -C $HOME/rust/lib/rustlib
+    ;;
+
   mips-unknown-linux-gnu)
     # Download pre-built and custom MIPS libs and then also instsall the MIPS
     # compiler according to this post:
diff --git a/ci/run.sh b/ci/run.sh
index b0d4726..6a4b4b1 100644
--- a/ci/run.sh
+++ b/ci/run.sh
@@ -6,7 +6,16 @@
 set -ex
 
 TARGET=$1
-cargo build --manifest-path libc-test/Cargo.toml --target $TARGET
+case "$TARGET" in
+  *-apple-ios)
+    cargo rustc --manifest-path libc-test/Cargo.toml --target $TARGET -- \
+        -C link-args=-mios-simulator-version-min=7.0
+    ;;
+
+  *)
+    cargo build --manifest-path libc-test/Cargo.toml --target $TARGET
+    ;;
+esac
 
 case "$TARGET" in
   arm-linux-androideabi)
@@ -29,6 +38,10 @@
       libc-test/target/$TARGET/debug/libc-test
     ;;
 
+  *-apple-ios)
+    libc-test/target/$TARGET/debug/libc-test
+    ;;
+
   *)
     cargo run --manifest-path libc-test/Cargo.toml --target $TARGET
     ;;
diff --git a/libc-test/build.rs b/libc-test/build.rs
index 530d10b..b4eb70c 100644
--- a/libc-test/build.rs
+++ b/libc-test/build.rs
@@ -10,10 +10,10 @@
     let mingw = target.contains("windows-gnu");
     let linux = target.contains("unknown-linux");
     let android = target.contains("android");
-    let darwin = target.contains("apple-darwin");
+    let apple = target.contains("apple");
     let musl = target.contains("musl");
     let freebsd = target.contains("freebsd");
-    let bsdlike = freebsd || darwin;
+    let bsdlike = freebsd || apple;
     let mut cfg = ctest::TestGenerator::new();
 
     // Pull in extra goodies on linux/mingw
@@ -92,11 +92,13 @@
         }
     }
 
-    if darwin {
+    if apple {
         cfg.header("mach-o/dyld.h");
         cfg.header("mach/mach_time.h");
         cfg.header("malloc/malloc.h");
-        cfg.header("crt_externs.h");
+        if target.starts_with("x86") {
+            cfg.header("crt_externs.h");
+        }
     }
 
     if linux || android {
@@ -150,7 +152,7 @@
             // Our stat *_nsec fields normally don't actually exist but are part
             // of a timeval struct
             s if s.ends_with("_nsec") && struct_ == "stat" => {
-                if target2.contains("apple-darwin") {
+                if target2.contains("apple") {
                     s.replace("_nsec", "spec.tv_nsec")
                 } else if target2.contains("android") {
                     s.to_string()
diff --git a/src/unix/bsd/apple/mod.rs b/src/unix/bsd/apple/mod.rs
index 7b5b043..a9697ce 100644
--- a/src/unix/bsd/apple/mod.rs
+++ b/src/unix/bsd/apple/mod.rs
@@ -626,11 +626,6 @@
 pub const SIGSTKSZ: ::size_t = 131072;
 
 extern {
-    pub fn _NSGetExecutablePath(buf: *mut ::c_char,
-                                bufsize: *mut ::uint32_t) -> ::c_int;
-    pub fn _NSGetArgc() -> *mut ::c_int;
-    pub fn _NSGetArgv() -> *mut *mut *mut ::c_char;
-    pub fn _NSGetEnviron() -> *mut *mut *mut ::c_char;
     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
                link_name = "mprotect$UNIX2003")]
     pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int)
diff --git a/src/unix/bsd/mod.rs b/src/unix/bsd/mod.rs
index 3b8c4fb..c994d9c 100644
--- a/src/unix/bsd/mod.rs
+++ b/src/unix/bsd/mod.rs
@@ -49,7 +49,7 @@
         pub pw_shell: *mut ::c_char,
         pub pw_expire: ::time_t,
 
-        #[cfg(not(target_os = "macos"))]
+        #[cfg(not(any(target_os = "macos", target_os = "ios")))]
         pub pw_fields: ::c_int,
     }
 
diff --git a/src/unix/mod.rs b/src/unix/mod.rs
index e8a1669..c7c7d4a 100644
--- a/src/unix/mod.rs
+++ b/src/unix/mod.rs
@@ -333,7 +333,8 @@
     pub fn getrusage(resource: c_int, usage: *mut rusage) -> c_int;
 
     pub fn getdtablesize() -> c_int;
-    #[cfg_attr(target_os = "macos", link_name = "realpath$DARWIN_EXTSN")]
+    #[cfg_attr(any(target_os = "macos", target_os = "ios"),
+               link_name = "realpath$DARWIN_EXTSN")]
     pub fn realpath(pathname: *const ::c_char, resolved: *mut ::c_char)
                     -> *mut ::c_char;
 
@@ -523,6 +524,7 @@
         mod notbsd;
         pub use self::notbsd::*;
     } else if #[cfg(any(target_os = "macos",
+                        target_os = "ios",
                         target_os = "freebsd",
                         target_os = "dragonfly",
                         target_os = "openbsd",