nixpkgs/pkgs/os-specific/darwin/xcode/sdk-pkgs.nix
Matthew Bauer 95eabdfd5f xcode/sdk-pkgs.nix: set -platform_version in addition to -miphoneos-version-min
The App Store looks at LC_VERSION_MIN_IPHONEOS to verify you have a
new enough SDK version. This is not just the minimum version, but also
the sdk version used. When the linker can’t figure it out, it tries to
infer it from the sdk path[1]. When no sdk version is found, it
defaults to just using the -miphoneos-version-min value[2]. So, to make
sure we don’t rely on inference (which doesn’t work in the current
directory structure), we have to specify -platform_version.

[1]:
43f32a4c61/cctools/ld64/src/ld/Options.cpp (L5355-L5376)
[2]: 43f32a4c61/cctools/ld64/src/ld/ld.hpp (L58)
2020-07-23 10:44:51 -05:00

78 lines
2.4 KiB
Nix

{ targetPlatform
, clang-unwrapped
, binutils-unwrapped
, runCommand
, stdenv
, wrapBintoolsWith
, wrapCCWith
, buildIosSdk, targetIosSdkPkgs
, xcode
, lib
}:
let
minSdkVersion = targetPlatform.minSdkVersion or "9.0";
iosPlatformArch = { parsed, ... }: {
armv7a = "armv7";
aarch64 = "arm64";
x86_64 = "x86_64";
}.${parsed.cpu.name};
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;
extraBuildCommands = ''
echo "-arch ${iosPlatformArch targetPlatform}" >> $out/nix-support/libc-ldflags
'' + stdenv.lib.optionalString (sdk.platform == "iPhoneSimulator") ''
echo "-platform_version ios-sim ${minSdkVersion} ${sdk.version}" >> $out/nix-support/libc-ldflags
'' + stdenv.lib.optionalString (sdk.platform == "iPhoneOS") ''
echo "-platform_version ios ${minSdkVersion} ${sdk.version}" >> $out/nix-support/libc-ldflags
'';
};
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
echo "-target ${targetPlatform.config} -arch ${iosPlatformArch targetPlatform}" >> $out/nix-support/cc-cflags
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
'' + 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
'';
}) // {
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
'';
}