2018-07-21 01:44:44 +01:00
|
|
|
{ targetPlatform
|
2018-04-16 00:21:45 +01:00
|
|
|
, clang-unwrapped
|
|
|
|
, binutils-unwrapped
|
|
|
|
, runCommand
|
|
|
|
, stdenv
|
|
|
|
, wrapBintoolsWith
|
|
|
|
, wrapCCWith
|
|
|
|
, buildIosSdk, targetIosSdkPkgs
|
2018-05-23 20:32:15 +01:00
|
|
|
, xcode
|
2018-04-16 00:21:45 +01:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
minSdkVersion = "9.0";
|
|
|
|
|
|
|
|
iosPlatformArch = { parsed, ... }: {
|
2018-05-01 17:57:07 +01:00
|
|
|
"armv7a" = "armv7";
|
2018-04-16 00:21:45 +01:00
|
|
|
"aarch64" = "arm64";
|
|
|
|
"x86_64" = "x86_64";
|
|
|
|
}.${parsed.cpu.name};
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
rec {
|
|
|
|
sdk = rec {
|
|
|
|
name = "ios-sdk";
|
|
|
|
type = "derivation";
|
2018-06-26 03:18:23 +01:00
|
|
|
outPath = xcode + "/Contents/Developer/Platforms/${platform}.platform/Developer/SDKs/${platform}${version}.sdk";
|
2018-04-16 00:21:45 +01:00
|
|
|
|
2018-06-26 03:18:23 +01:00
|
|
|
platform = targetPlatform.xcodePlatform;
|
2018-04-16 00:21:45 +01:00
|
|
|
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
|
2018-06-26 03:18:23 +01:00
|
|
|
'' + stdenv.lib.optionalString (sdk.platform == "iPhoneSimulator") ''
|
|
|
|
echo "-mios-simulator-version-min=${minSdkVersion}" >> $out/nix-support/cc-cflags
|
|
|
|
'' + stdenv.lib.optionalString (sdk.platform == "iPhoneOS") ''
|
|
|
|
echo "-miphoneos-version-min=${minSdkVersion}" >> $out/nix-support/cc-cflags
|
2018-04-16 00:21:45 +01:00
|
|
|
'';
|
|
|
|
}) // {
|
|
|
|
inherit sdk;
|
|
|
|
};
|
|
|
|
|
|
|
|
libraries = let sdk = buildIosSdk; in runCommand "libSystem-prebuilt" {
|
|
|
|
passthru = {
|
|
|
|
inherit sdk;
|
|
|
|
};
|
|
|
|
} ''
|
|
|
|
if ! [ -d ${sdk} ]; then
|
2018-06-26 03:18:23 +01:00
|
|
|
echo "You must have version ${sdk.version} of the ${sdk.platform} sdk installed at ${sdk}" >&2
|
2018-04-16 00:21:45 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
ln -s ${sdk}/usr $out
|
|
|
|
'';
|
|
|
|
}
|