summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKen Micklas <ken.micklas@obsidian.systems>2018-04-15 19:21:45 -0400
committerKen Micklas <ken.micklas@obsidian.systems>2018-04-19 16:09:30 -0400
commitef3db7d14c90e1876d38ebc25428b4f65962ffbc (patch)
tree174e07b10781aed9b05fdf968fa57115a5509a9c
parentb1a8894a1cd386319f771998de417ce0a4a75b7c (diff)
ios-sdk-pkgs: Init from iOS SDK from XCode
-rw-r--r--lib/systems/default.nix2
-rw-r--r--pkgs/os-specific/darwin/ios-cross/default.nix61
-rw-r--r--pkgs/os-specific/darwin/ios-sdk-pkgs/default.nix68
-rw-r--r--pkgs/stdenv/cross/default.nix4
-rw-r--r--pkgs/top-level/all-packages.nix1
-rw-r--r--pkgs/top-level/darwin-packages.nix20
6 files changed, 87 insertions, 69 deletions
diff --git a/lib/systems/default.nix b/lib/systems/default.nix
index bd408e00bb14..e7346a538d35 100644
--- a/lib/systems/default.nix
+++ b/lib/systems/default.nix
@@ -44,6 +44,8 @@ rec {
};
# Misc boolean options
useAndroidPrebuilt = false;
+ useiOSPrebuilt = false;
+ isiPhoneSimulator = false;
} // mapAttrs (n: v: v final.parsed) inspect.predicates
// args;
in assert final.useAndroidPrebuilt -> final.isAndroid;
diff --git a/pkgs/os-specific/darwin/ios-cross/default.nix b/pkgs/os-specific/darwin/ios-cross/default.nix
deleted file mode 100644
index 175e9738ef9e..000000000000
--- a/pkgs/os-specific/darwin/ios-cross/default.nix
+++ /dev/null
@@ -1,61 +0,0 @@
-{ runCommand
-, lib
-, llvm
-, clang
-, binutils
-, stdenv
-, coreutils
-, gnugrep
-, buildPackages
-, hostPlatform
-, targetPlatform
-}:
-
-/* As of this writing, known-good prefix/arch/simulator triples:
- * aarch64-apple-darwin14 | arm64 | false
- * arm-apple-darwin10 | armv7 | false
- * i386-apple-darwin11 | i386 | true
- * x86_64-apple-darwin14 | x86_64 | true
- */
-
-# Apple uses somewhat non-standard names for this. We could fall back on
-# `targetPlatform.parsed.cpu.name`, but that would be a more standard one and
-# likely to fail. Better just to require something manual.
-assert targetPlatform ? arch;
-
-let
-
- prefix = targetPlatform.config;
- inherit (targetPlatform) arch;
- simulator = targetPlatform.isiPhoneSimulator or false;
-
- sdkType = if simulator then "Simulator" else "OS";
-
- sdkVer = "10.2";
-
- sdk = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhone${sdkType}.platform/Developer/SDKs/iPhone${sdkType}${sdkVer}.sdk";
-
-in (import ../../../build-support/cc-wrapper {
- inherit stdenv coreutils gnugrep runCommand buildPackages;
- nativeTools = false;
- nativeLibc = false;
- inherit binutils;
- libc = runCommand "empty-libc" {} "mkdir -p $out/{lib,include}";
- inherit (clang) cc;
- inherit hostPlatform targetPlatform;
- extraBuildCommands = ''
- if ! [ -d ${sdk} ]; then
- echo "You must have ${sdkVer} of the iPhone${sdkType} sdk installed at ${sdk}" >&2
- exit 1
- fi
- # ugh
- tr '\n' ' ' < $out/nix-support/cc-cflags > cc-cflags.tmp
- mv cc-cflags.tmp $out/nix-support/cc-cflags
- echo "-target ${prefix} -arch ${arch} -idirafter ${sdk}/usr/include ${if simulator then "-mios-simulator-version-min=7.0" else "-miphoneos-version-min=7.0"}" >> $out/nix-support/cc-cflags
-
- # Purposefully overwrite libc-ldflags-before, cctools ld doesn't know dynamic-linker and cc-wrapper doesn't do cross-compilation well enough to adjust
- echo "-arch ${arch} -L${sdk}/usr/lib ${lib.optionalString simulator "-L${sdk}/usr/lib/system "}-i${if simulator then "os_simulator" else "phoneos"}_version_min 7.0.0" > $out/nix-support/libc-ldflags-before
- '';
- }) // {
- inherit sdkType sdkVer sdk;
- }
diff --git a/pkgs/os-specific/darwin/ios-sdk-pkgs/default.nix b/pkgs/os-specific/darwin/ios-sdk-pkgs/default.nix
new file mode 100644
index 000000000000..5b9f30b62c39
--- /dev/null
+++ b/pkgs/os-specific/darwin/ios-sdk-pkgs/default.nix
@@ -0,0 +1,68 @@
+{ lib, hostPlatform, targetPlatform
+, clang-unwrapped
+, binutils-unwrapped
+, runCommand
+, stdenv
+, wrapBintoolsWith
+, wrapCCWith
+, buildIosSdk, targetIosSdkPkgs
+}:
+
+let
+
+minSdkVersion = "9.0";
+
+iosPlatformArch = { parsed, ... }: {
+ "arm" = "armv7";
+ "aarch64" = "arm64";
+ "x86_64" = "x86_64";
+}.${parsed.cpu.name};
+
+in
+
+rec {
+ # TODO(kmicklas): Make a pure version of this for each supported SDK version.
+ sdk = rec {
+ name = "ios-sdk";
+ type = "derivation";
+ outPath = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhone${sdkType}.platform/Developer/SDKs/iPhone${sdkType}${version}.sdk";
+
+ sdkType = if targetPlatform.isiPhoneSimulator then "Simulator" else "OS";
+ version = targetPlatform.sdkVer;
+ };
+
+ binutils = wrapBintoolsWith {
+ libc = targetIosSdkPkgs.libraries;
+ bintools = binutils-unwrapped;
+ extraBuildCommands = ''
+ echo "-arch ${iosPlatformArch targetPlatform}" >> $out/nix-support/libc-ldflags
+ '';
+ };
+
+ clang = (wrapCCWith {
+ cc = clang-unwrapped;
+ bintools = binutils;
+ libc = targetIosSdkPkgs.libraries;
+ extraBuildCommands = ''
+ tr '\n' ' ' < $out/nix-support/cc-cflags > cc-cflags.tmp
+ mv cc-cflags.tmp $out/nix-support/cc-cflags
+ echo "-target ${targetPlatform.config} -arch ${iosPlatformArch targetPlatform}" >> $out/nix-support/cc-cflags
+ echo "-isystem ${sdk}/usr/include -isystem ${sdk}/usr/include/c++/4.2.1/ -stdlib=libstdc++" >> $out/nix-support/cc-cflags
+ echo "${if targetPlatform.isiPhoneSimulator then "-mios-simulator-version-min" else "-miphoneos-version-min"}=${minSdkVersion}" >> $out/nix-support/cc-cflags
+ '';
+ }) // {
+ inherit sdk;
+ };
+
+ libraries = let sdk = buildIosSdk; in runCommand "libSystem-prebuilt" {
+ passthru = {
+ inherit sdk;
+ };
+ } ''
+ if ! [ -d ${sdk} ]; then
+ echo "You must have version ${sdk.version} of the iPhone${sdk.sdkType} sdk installed at ${sdk}" >&2
+ exit 1
+ fi
+ ln -s ${sdk}/usr $out
+ '';
+}
diff --git a/pkgs/stdenv/cross/default.nix b/pkgs/stdenv/cross/default.nix
index 6e3065718532..973be9831861 100644
--- a/pkgs/stdenv/cross/default.nix
+++ b/pkgs/stdenv/cross/default.nix
@@ -39,8 +39,8 @@ in lib.init bootStages ++ [
buildPlatform = localSystem;
hostPlatform = crossSystem;
targetPlatform = crossSystem;
- cc = if crossSystem.useiOSCross or false
- then buildPackages.darwin.ios-cross
+ cc = if crossSystem.useiOSPrebuilt or false
+ then buildPackages.darwin.iosSdkPkgs.clang
else if crossSystem.useAndroidPrebuilt
then buildPackages.androidenv.androidndkPkgs.gcc
else buildPackages.gcc;
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 56064138ac11..bb80c5494f17 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -9008,6 +9008,7 @@ with pkgs;
else if name == "uclibc" then uclibcCross
else if name == "musl" then targetPackages.muslCross or muslCross
else if name == "msvcrt" then targetPackages.windows.mingw_w64 or windows.mingw_w64
+ else if targetPlatform.useiOSPrebuilt then targetPackages.iosSdkPkgs.libraries
else if name == "libSystem" then darwin.xcode
else throw "Unknown libc";
diff --git a/pkgs/top-level/darwin-packages.nix b/pkgs/top-level/darwin-packages.nix
index d1d5aa470bca..d2d41792c461 100644
--- a/pkgs/top-level/darwin-packages.nix
+++ b/pkgs/top-level/darwin-packages.nix
@@ -1,4 +1,6 @@
-{ pkgs, darwin, stdenv, callPackage, callPackages, newScope }:
+{ buildPackages, pkgs, targetPackages
+, darwin, stdenv, callPackage, callPackages, newScope
+}:
let
apple-source-releases = callPackage ../os-specific/darwin/apple-source-releases { };
@@ -10,19 +12,23 @@ in
apple_sdk = callPackage ../os-specific/darwin/apple-sdk { };
+ binutils-unwrapped = callPackage ../os-specific/darwin/binutils {
+ inherit (darwin) cctools;
+ inherit (pkgs) binutils-unwrapped;
+ };
+
binutils = pkgs.wrapBintoolsWith {
libc =
if pkgs.targetPlatform != pkgs.hostPlatform
then pkgs.libcCross
else pkgs.stdenv.cc.libc;
- bintools = callPackage ../os-specific/darwin/binutils {
- inherit (darwin) cctools;
- };
+ bintools = darwin.binutils-unwrapped;
};
cctools = callPackage ../os-specific/darwin/cctools/port.nix {
inherit (darwin) libobjc maloader;
stdenv = if stdenv.isDarwin then stdenv else pkgs.libcxxStdenv;
+ libcxxabi = pkgs.libcxxabi;
xctoolchain = darwin.xcode.toolchain;
};
@@ -39,8 +45,10 @@ in
insert_dylib = callPackage ../os-specific/darwin/insert_dylib { };
- ios-cross = callPackage ../os-specific/darwin/ios-cross {
- inherit (darwin) binutils;
+ iosSdkPkgs = darwin.callPackage ../os-specific/darwin/ios-sdk-pkgs {
+ buildIosSdk = buildPackages.darwin.iosSdkPkgs.sdk;
+ targetIosSdkPkgs = targetPackages.darwin.iosSdkPkgs;
+ inherit (pkgs.llvmPackages) clang-unwrapped;
};
libobjc = apple-source-releases.objc4;