2018-07-21 01:44:44 +01:00
|
|
|
{ targetPlatform
|
2018-04-16 00:21:45 +01:00
|
|
|
, clang-unwrapped
|
|
|
|
, binutils-unwrapped
|
|
|
|
, runCommand
|
2021-01-25 08:26:54 +00:00
|
|
|
|
2018-04-16 00:21:45 +01:00
|
|
|
, wrapBintoolsWith
|
|
|
|
, wrapCCWith
|
|
|
|
, buildIosSdk, targetIosSdkPkgs
|
2018-05-23 20:32:15 +01:00
|
|
|
, xcode
|
2019-11-26 04:50:21 +00:00
|
|
|
, lib
|
2018-04-16 00:21:45 +01:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
|
2020-07-22 16:54:11 +01:00
|
|
|
minSdkVersion = targetPlatform.minSdkVersion or "9.0";
|
2018-04-16 00:21:45 +01:00
|
|
|
|
|
|
|
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;
|
2020-12-12 06:49:48 +00:00
|
|
|
extraBuildCommands = lib.optionalString (sdk.platform == "iPhoneSimulator") ''
|
2020-07-22 16:54:11 +01:00
|
|
|
echo "-platform_version ios-sim ${minSdkVersion} ${sdk.version}" >> $out/nix-support/libc-ldflags
|
2021-01-15 14:45:37 +00:00
|
|
|
'' + lib.optionalString (sdk.platform == "iPhoneOS") ''
|
2020-07-22 16:54:11 +01:00
|
|
|
echo "-platform_version ios ${minSdkVersion} ${sdk.version}" >> $out/nix-support/libc-ldflags
|
2018-04-16 00:21:45 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
clang = (wrapCCWith {
|
|
|
|
cc = clang-unwrapped;
|
|
|
|
bintools = binutils;
|
|
|
|
libc = targetIosSdkPkgs.libraries;
|
2019-02-26 01:01:14 +00:00
|
|
|
extraPackages = [ "${sdk}/System" ];
|
2018-04-16 00:21:45 +01:00
|
|
|
extraBuildCommands = ''
|
|
|
|
tr '\n' ' ' < $out/nix-support/cc-cflags > cc-cflags.tmp
|
|
|
|
mv cc-cflags.tmp $out/nix-support/cc-cflags
|
2020-12-12 06:49:48 +00:00
|
|
|
echo "-target ${targetPlatform.config}" >> $out/nix-support/cc-cflags
|
2019-11-26 04:50:21 +00:00
|
|
|
echo "-isystem ${sdk}/usr/include${lib.optionalString (lib.versionAtLeast "10" sdk.version) " -isystem ${sdk}/usr/include/c++/4.2.1/ -stdlib=libstdc++"}" >> $out/nix-support/cc-cflags
|
2021-01-15 14:45:37 +00:00
|
|
|
'' + lib.optionalString (sdk.platform == "iPhoneSimulator") ''
|
2018-06-26 03:18:23 +01:00
|
|
|
echo "-mios-simulator-version-min=${minSdkVersion}" >> $out/nix-support/cc-cflags
|
2021-01-15 14:45:37 +00:00
|
|
|
'' + lib.optionalString (sdk.platform == "iPhoneOS") ''
|
2018-06-26 03:18:23 +01:00
|
|
|
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
|
|
|
|
'';
|
|
|
|
}
|