Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

darwin.apple_sdk_12_3: init at 12.3 #326406

Merged
merged 3 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions pkgs/os-specific/darwin/apple-sdk-12.3/CLTools_Executables.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
stdenvNoCC,
fetchurl,
cpio,
pbzx,
version,
}:

let
releases = builtins.fromJSON (builtins.readFile ./apple-sdk-releases.json);
in
stdenvNoCC.mkDerivation (finalAttrs: {
pname = "CLTools_Executables";
inherit version;

src = fetchurl releases.${version}.${finalAttrs.pname};

nativeBuildInputs = [
cpio
pbzx
];

buildCommand = ''
pbzx $src | cpio -idm
mv Library/Developer/CommandLineTools $out
'';
})
28 changes: 28 additions & 0 deletions pkgs/os-specific/darwin/apple-sdk-12.3/CLTools_macOSNMOS_SDK.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
lib,
stdenvNoCC,
fetchurl,
cpio,
pbzx,
version,
}:

let
releases = builtins.fromJSON (builtins.readFile ./apple-sdk-releases.json);
in
stdenvNoCC.mkDerivation (finalAttrs: {
pname = "CLTools_macOSNMOS_SDK";
inherit version;

src = fetchurl releases.${version}.${finalAttrs.pname};

nativeBuildInputs = [
cpio
pbzx
];

buildCommand = ''
pbzx $src | cpio -idm
mv Library/Developer/CommandLineTools/SDKs/MacOSX${lib.versions.majorMinor version}.sdk $out
'';
})
20 changes: 20 additions & 0 deletions pkgs/os-specific/darwin/apple-sdk-12.3/apple-sdk-releases.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"12.3": {
"CLTools_Executables": {
"hash": "sha256-XlxHwCq+rtBF3Yyfdob3UEHN7YKzb7JF84lRmZbB/50=",
"url": "https://swcdn.apple.com/content/downloads/24/42/002-83793-A_74JRE8GVAT/rlnkct919wgc5c0pjq986z5bb9h62uvni2/CLTools_Executables.pkg"
},
"CLTools_macOSLMOS_SDK": {
"hash": "sha256-mY9YTlyTujV6R89WaNmkJrfOQatXnoSW8gKxnawQz5Q=",
"url": "https://swcdn.apple.com/content/downloads/24/42/002-83793-A_74JRE8GVAT/rlnkct919wgc5c0pjq986z5bb9h62uvni2/CLTools_macOSLMOS_SDK.pkg"
},
"CLTools_macOSNMOS_SDK": {
"hash": "sha256-Tr9VCeCP5udmh09U/zPQG2c4ky1LXscBwPfgpRy8uds=",
"url": "https://swcdn.apple.com/content/downloads/24/42/002-83793-A_74JRE8GVAT/rlnkct919wgc5c0pjq986z5bb9h62uvni2/CLTools_macOSNMOS_SDK.pkg"
},
"CLTools_macOS_SDK": {
"hash": "sha256-2xwYLfiYuEdck7/8NY3iqiPKvoG9HAjXt8Ewyp9c0Es=",
"url": "https://swcdn.apple.com/content/downloads/24/42/002-83793-A_74JRE8GVAT/rlnkct919wgc5c0pjq986z5bb9h62uvni2/CLTools_macOS_SDK.pkg"
}
}
}
49 changes: 49 additions & 0 deletions pkgs/os-specific/darwin/apple-sdk-12.3/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
lib,
newScope,
overrideCC,
pkgs,
stdenv,
stdenvNoCC,
}:

let
version = "12.3";

MacOSX-SDK = callPackage ./CLTools_macOSNMOS_SDK.nix { inherit version; };
callPackage = newScope (pkgs.darwin // packages);

packages = {
# Make sure we pass our special `callPackage` instead of using packages.callPackage which
# does not have necessary attributes in scope.
frameworks = callPackage ./frameworks { inherit callPackage; };
libs = callPackage ./libs { inherit callPackage; };

CLTools_Executables = callPackage ./CLTools_Executables.nix { inherit version; };
Libsystem = callPackage ./libSystem.nix { };
LibsystemCross = callPackage ./libSystem.nix { };
libunwind = callPackage ./libunwind.nix { };
libnetwork = callPackage ./libnetwork.nix { };
libpm = callPackage ./libpm.nix { };
# Avoid introducing a new objc4 if stdenv already has one, to prevent
# conflicting LLVM modules.
objc4 = stdenv.objc4 or (callPackage ./libobjc.nix { });

darwin-stubs = stdenvNoCC.mkDerivation {
pname = "darwin-stubs";
inherit (MacOSX-SDK) version;

preferLocalBuild = true;
allowSubstitutes = false;

buildCommand = ''
mkdir -p "$out"
ln -s ${MacOSX-SDK}/System "$out/System"
ln -s ${MacOSX-SDK}/usr "$out/usr"
'';
};

sdkRoot = pkgs.callPackage ../apple-sdk/sdkRoot.nix { sdkVersion = version; };
};
in
packages
146 changes: 146 additions & 0 deletions pkgs/os-specific/darwin/apple-sdk-12.3/frameworks/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
{
reckenrode marked this conversation as resolved.
Show resolved Hide resolved
lib,
stdenvNoCC,
buildPackages,
# macOS things
callPackage,
darwin-stubs,
}:

let
inherit (darwin-stubs) version;
fixup-frameworks = callPackage ./fixups.nix { };
private-frameworks = callPackage ./private.nix { };
public-frameworks = callPackage ./public.nix { };

mkDepsRewrites =
deps:
let
mergeRewrites = x: y: {
prefix = lib.mergeAttrs (x.prefix or { }) (y.prefix or { });
const = lib.mergeAttrs (x.const or { }) (y.const or { });
};

rewriteArgs =
{
prefix ? { },
const ? { },
}:
lib.concatLists (
(lib.mapAttrsToList (from: to: [
"-p"
"${from}:${to}"
]) prefix)
++ (lib.mapAttrsToList (from: to: [
"-c"
"${from}:${to}"
]) const)
);

rewrites =
depList:
lib.fold mergeRewrites { } (
map (dep: dep.tbdRewrites) (lib.filter (dep: dep ? tbdRewrites) depList)
);
in
lib.escapeShellArgs (rewriteArgs (rewrites (lib.attrValues deps)));

mkFramework =
{
name,
deps,
private ? false,
}:
let
standardFrameworkPath =
name: private:
"/System/Library/${lib.optionalString private "Private"}Frameworks/${name}.framework";

self = stdenvNoCC.mkDerivation {
pname = "apple-${lib.optionalString private "private-"}framework-${name}";
inherit (darwin-stubs) version;

# because we copy files from the system
preferLocalBuild = true;

dontUnpack = true;
dontBuild = true;

disallowedRequisites = [ darwin-stubs ];

nativeBuildInputs = [ buildPackages.darwin.rewrite-tbd ];

installPhase = ''
mkdir -p $out/Library/Frameworks

cp -r ${darwin-stubs}${standardFrameworkPath name private} $out/Library/Frameworks

if [[ -d ${darwin-stubs}/usr/lib/swift/${name}.swiftmodule ]]; then
mkdir -p $out/lib/swift
cp -r -t $out/lib/swift \
${darwin-stubs}/usr/lib/swift/${name}.swiftmodule \
${darwin-stubs}/usr/lib/swift/libswift${name}.tbd
fi

# Fix and check tbd re-export references
chmod u+w -R $out
find $out -name '*.tbd' -type f | while IFS=$'\n' read tbd; do
echo "Fixing re-exports in $tbd"
rewrite-tbd \
-p ${standardFrameworkPath name private}/:$out/Library/Frameworks/${name}.framework/ \
-p /usr/lib/swift/:$out/lib/swift/ \
${mkDepsRewrites deps} \
-r ${builtins.storeDir} \
"$tbd"
done
'';

propagatedBuildInputs = lib.attrValues deps;

passthru.tbdRewrites.prefix."${standardFrameworkPath name private}/" = "${self}/Library/Frameworks/${name}.framework/";

meta = with lib; {
description = "Apple SDK framework ${name}";
maintainers = with maintainers; [ ];
platforms = platforms.darwin;
};
};
in
self;

# Helper functions for creating framework derivations.
framework =
name: deps:
mkFramework {
inherit name deps;
private = false;
};

# Helper functions for creating private framework derivations.
privateFramework =
name: deps:
mkFramework {
inherit name deps;
private = true;
};

# Merge addToFrameworks into public-frameworks and remove elements of removeFromFrameworks.
deps =
let
inherit (fixup-frameworks) addToFrameworks removeFromFrameworks;
fixupDeps =
name: deps:
lib.pipe deps [
# Add dependencies from addToFrameworks.
(deps: lib.recursiveUpdate deps (addToFrameworks.${name} or { }))
# Keep dependencies not in removeFromFrameworks.
(lib.filterAttrs (depName: _: !(removeFromFrameworks.${name}.${depName} or false)))
];
in
lib.mapAttrs fixupDeps public-frameworks;

# Create derivations and add private frameworks.
bareFrameworks =
(lib.mapAttrs framework deps) // (lib.mapAttrs privateFramework private-frameworks);
in
bareFrameworks // fixup-frameworks.overrideFrameworks bareFrameworks
Loading