2020-04-24 23:36:52 +00:00
|
|
|
{ targetPlatform
|
|
|
|
, clang-unwrapped
|
|
|
|
, binutils-unwrapped
|
|
|
|
, runCommand
|
2021-02-05 17:12:51 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
, wrapBintoolsWith
|
|
|
|
, wrapCCWith
|
|
|
|
, buildIosSdk, targetIosSdkPkgs
|
|
|
|
, xcode
|
|
|
|
, lib
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
|
2020-10-16 20:44:37 +00:00
|
|
|
minSdkVersion = targetPlatform.minSdkVersion or "9.0";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
rec {
|
|
|
|
sdk = rec {
|
|
|
|
name = "ios-sdk";
|
|
|
|
type = "derivation";
|
|
|
|
outPath = xcode + "/Contents/Developer/Platforms/${platform}.platform/Developer/SDKs/${platform}${version}.sdk";
|
|
|
|
|
|
|
|
platform = targetPlatform.xcodePlatform;
|
|
|
|
version = targetPlatform.sdkVer;
|
|
|
|
};
|
|
|
|
|
|
|
|
binutils = wrapBintoolsWith {
|
|
|
|
libc = targetIosSdkPkgs.libraries;
|
|
|
|
bintools = binutils-unwrapped;
|
2021-03-19 17:17:44 +00:00
|
|
|
extraBuildCommands = lib.optionalString (sdk.platform == "iPhoneSimulator") ''
|
2020-10-16 20:44:37 +00:00
|
|
|
echo "-platform_version ios-sim ${minSdkVersion} ${sdk.version}" >> $out/nix-support/libc-ldflags
|
2021-02-05 17:12:51 +00:00
|
|
|
'' + lib.optionalString (sdk.platform == "iPhoneOS") ''
|
2020-10-16 20:44:37 +00:00
|
|
|
echo "-platform_version ios ${minSdkVersion} ${sdk.version}" >> $out/nix-support/libc-ldflags
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
clang = (wrapCCWith {
|
|
|
|
cc = clang-unwrapped;
|
|
|
|
bintools = binutils;
|
|
|
|
libc = targetIosSdkPkgs.libraries;
|
|
|
|
extraPackages = [ "${sdk}/System" ];
|
|
|
|
extraBuildCommands = ''
|
|
|
|
tr '\n' ' ' < $out/nix-support/cc-cflags > cc-cflags.tmp
|
|
|
|
mv cc-cflags.tmp $out/nix-support/cc-cflags
|
2021-03-19 17:17:44 +00:00
|
|
|
echo "-target ${targetPlatform.config}" >> $out/nix-support/cc-cflags
|
2020-04-24 23:36:52 +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-02-05 17:12:51 +00:00
|
|
|
'' + lib.optionalString (sdk.platform == "iPhoneSimulator") ''
|
2020-04-24 23:36:52 +00:00
|
|
|
echo "-mios-simulator-version-min=${minSdkVersion}" >> $out/nix-support/cc-cflags
|
2021-02-05 17:12:51 +00:00
|
|
|
'' + lib.optionalString (sdk.platform == "iPhoneOS") ''
|
2020-04-24 23:36:52 +00:00
|
|
|
echo "-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 ${sdk.platform} sdk installed at ${sdk}" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
ln -s ${sdk}/usr $out
|
|
|
|
'';
|
|
|
|
}
|