nixpkgs/pkgs/by-name/ap/apple-sdk/package.nix
Randy Eckenrode 556790248f
apple-sdk: init at 10.12.2 and 11.3
This is a new packaging of the Darwin SDK. Instead of splitting
libraries and frameworks into separate packages, it provides a single
package for the whole SDK.

# Features

- Vendored files are removed from the SDK. There are 50+ different
  packages that are vendored by upstream (depending on the version);
- Components that are built in nixpkgs (either from upstream or from the
  source releases) are also removed. If they need to be included by
  default, they are propagated;
- A single SDK pattern is used to package all SDKs, and scripts are
  provided to aid updating the SDK version and its source release
  versions. This makes adding new SDKs much easier;
- SDK overrides are handled by adding the SDK version you require. If
  multiple SDKs are present, only the newest is used. It is possible to
  have different SDKs for each of build, host, and target platforms;
- Private headers are no longer provided by default unless you use the
  SDK’s `privateFrameworksHook` to add them. It does the right thing
  when multiple SDKs are in your inputs;
- Source releases for the SDK version are available via a passthru
  `sourceRelease` function. This is mostly useful for getting private
  headers for building source releases in the darwin attrset; and
- The same versions of propagated components are used on both platforms
  (e.g., the same libresult, libiconv, etc).

See `pkgs/by-name/ap/apple-sdk/README.md` for details on how the SDK
derivation is structured and how to update it.
2024-10-10 16:22:58 -04:00

121 lines
4.0 KiB
Nix

let
sdkVersions = builtins.fromJSON (builtins.readFile ./metadata/versions.json);
in
{
lib,
stdenv,
stdenvNoCC,
substitute,
# Specifies the major version used for the SDK. Uses `hostPlatform.darwinSdkVersion` by default.
darwinSdkMajorVersion ? (
if lib.versionOlder stdenv.hostPlatform.darwinSdkVersion "11" then
lib.versions.majorMinor stdenv.hostPlatform.darwinSdkVersion
else
lib.versions.major stdenv.hostPlatform.darwinSdkVersion
),
# Enabling bootstrap disables propagation. Defaults to `false` (meaning to propagate certain packages and `xcrun`)
# except in stage0 of the Darwin stdenv bootstrap.
enableBootstrap ? stdenv.name == "bootstrap-stage0-stdenv-darwin",
# Required by various phases
callPackage,
jq,
}:
let
sdkInfo =
sdkVersions.${darwinSdkMajorVersion}
or (lib.throw "Unsupported SDK major version: ${darwinSdkMajorVersion}");
sdkVersion = sdkInfo.version;
fetchSDK = callPackage ./common/fetch-sdk.nix { };
phases = lib.composeManyExtensions (
[
(callPackage ./common/add-core-symbolication.nix { })
(callPackage ./common/derivation-options.nix { })
(callPackage ./common/passthru-private-frameworks.nix { inherit sdkVersion; })
(callPackage ./common/passthru-source-release-files.nix { inherit sdkVersion; })
(callPackage ./common/remove-disallowed-packages.nix { })
]
# Only process stubs and convert them to tbd-v4 if jq is available. This can be made unconditional once
# the bootstrap tools have jq and libtapi.
++ lib.optional (jq != null) (callPackage ./common/process-stubs.nix { })
# Avoid infinite recursions by not propagating certain packages, so they can themselves build with the SDK.
++ lib.optionals (!enableBootstrap) [
(callPackage ./common/propagate-inputs.nix { })
(callPackage ./common/propagate-xcrun.nix { })
]
++ [
# These have to happen last.
(callPackage ./common/rewrite-sdk-paths.nix { inherit sdkVersion; })
(callPackage ./common/run-build-phase-hooks.nix { })
]
);
in
stdenvNoCC.mkDerivation (
lib.extends phases (finalAttrs: {
pname = "apple-sdk";
inherit (sdkInfo) version;
src = fetchSDK sdkInfo;
dontConfigure = true;
strictDeps = true;
setupHooks = [
# `role.bash` is copied from `../build-support/setup-hooks/role.bash` due to the requirements not to reference
# paths outside the package when it is in `by-name`. It needs to be kept in sync, but it fortunately does not
# change often. Once `build-support` is available as a package (or some other mechanism), it should be changed
# to whatever that replacement is.
./setup-hooks/role.bash
(substitute {
src = ./setup-hooks/sdk-hook.sh;
substitutions = [
"--subst-var-by"
"sdkVersion"
(lib.escapeShellArgs (lib.splitVersion sdkVersion))
];
})
];
installPhase =
let
sdkName = "MacOSX${lib.versions.majorMinor sdkVersion}.sdk";
sdkMajor = lib.versions.major sdkVersion;
in
''
runHook preInstall
mkdir -p "$sdkpath"
cp -rd . "$sdkpath/${sdkName}"
${lib.optionalString (lib.versionAtLeast finalAttrs.version "11.0") ''
ln -s "${sdkName}" "$sdkpath/MacOSX${sdkMajor}.sdk"
''}
ln -s "${sdkName}" "$sdkpath/MacOSX.sdk"
runHook postInstall
'';
passthru = {
sdkroot = finalAttrs.finalPackage + "/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk";
};
__structuredAttrs = true;
meta = {
description = "Frameworks and libraries required for building packages on Darwin";
homepage = "https://developer.apple.com";
maintainers = lib.teams.darwin.members;
platforms = lib.platforms.darwin;
badPlatforms =
lib.optionals (lib.versionAtLeast sdkVersion "10.15") [ lib.systems.inspect.patterns.is32bit ]
++ lib.optionals (lib.versionOlder sdkVersion "11.0") [ lib.systems.inspect.patterns.isAarch ];
};
})
)