darwin/apple-sdk-11.0: inject an sdk for macOS 11

This commit is contained in:
Andrew Childs 2020-11-19 17:14:51 +09:00
parent 0ba7a04743
commit fe0d5a54c1
9 changed files with 574 additions and 0 deletions

View File

@ -0,0 +1,147 @@
{ lib, stdenvNoCC, buildPackages, fetchurl, xar, cpio, pkgs, python3, pbzx, MacOSX-SDK }:
# TODO: reorganize to make this just frameworks, and move libs to default.nix
let
stdenv = stdenvNoCC;
standardFrameworkPath = name: private:
"/System/Library/${lib.optionalString private "Private"}Frameworks/${name}.framework";
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 (builtins.attrValues deps)));
mkFramework = { name, deps, private ? false }:
let self = stdenv.mkDerivation {
pname = "apple-${lib.optionalString private "private-"}framework-${name}";
version = MacOSX-SDK.version;
dontUnpack = true;
# because we copy files from the system
preferLocalBuild = true;
disallowedRequisites = [ MacOSX-SDK ];
nativeBuildInputs = [ buildPackages.darwin.rewrite-tbd ];
installPhase = ''
mkdir -p $out/Library/Frameworks
cp -r ${MacOSX-SDK}${standardFrameworkPath name private} $out/Library/Frameworks
# Fix and check tbd re-export references
chmod u+w -R $out
find $out -name '*.tbd' -type f | while read tbd; do
echo "Fixing re-exports in $tbd"
rewrite-tbd \
-p ${standardFrameworkPath name private}/:$out/Library/Frameworks/${name}.framework/ \
${mkDepsRewrites deps} \
-r ${builtins.storeDir} \
"$tbd"
done
'';
propagatedBuildInputs = builtins.attrValues deps;
passthru = {
tbdRewrites = {
prefix."${standardFrameworkPath name private}/" = "${self}/Library/Frameworks/${name}.framework/";
};
};
meta = with lib; {
description = "Apple SDK framework ${name}";
maintainers = with maintainers; [ copumpkin ];
platforms = platforms.darwin;
};
};
in self;
framework = name: deps: mkFramework { inherit name deps; private = false; };
privateFramework = name: deps: mkFramework { inherit name deps; private = true; };
in rec {
libs = {
xpc = stdenv.mkDerivation {
name = "apple-lib-xpc";
dontUnpack = true;
installPhase = ''
mkdir -p $out/include
pushd $out/include >/dev/null
cp -r "${MacOSX-SDK}/usr/include/xpc" $out/include/xpc
cp "${MacOSX-SDK}/usr/include/launch.h" $out/include/launch.h
popd >/dev/null
'';
};
Xplugin = stdenv.mkDerivation {
name = "apple-lib-Xplugin";
dontUnpack = true;
propagatedBuildInputs = with frameworks; [
OpenGL ApplicationServices Carbon IOKit CoreGraphics CoreServices CoreText
];
installPhase = ''
mkdir -p $out/include $out/lib
ln -s "${MacOSX-SDK}/include/Xplugin.h" $out/include/Xplugin.h
cp ${MacOSX-SDK}/usr/lib/libXplugin.1.tbd $out/lib
ln -s libXplugin.1.tbd $out/lib/libXplugin.tbd
'';
};
utmp = stdenv.mkDerivation {
name = "apple-lib-utmp";
dontUnpack = true;
installPhase = ''
mkdir -p $out/include
pushd $out/include >/dev/null
ln -s "${MacOSX-SDK}/include/utmp.h"
ln -s "${MacOSX-SDK}/include/utmpx.h"
popd >/dev/null
'';
};
libDER = stdenv.mkDerivation {
name = "apple-lib-libDER";
dontUnpack = true;
installPhase = ''
mkdir -p $out/include
cp -r ${MacOSX-SDK}/usr/include/libDER $out/include
'';
};
};
overrides = super: {};
bareFrameworks = (
lib.mapAttrs framework (import ./frameworks.nix {
inherit frameworks libs;
inherit (pkgs.darwin) libobjc Libsystem;
inherit (pkgs.darwin.apple_sdk) libnetwork;
})
) // (
lib.mapAttrs privateFramework (import ./private-frameworks.nix {
inherit frameworks;
})
);
frameworks = bareFrameworks // overrides bareFrameworks;
}

View File

@ -0,0 +1,58 @@
{ stdenvNoCC, fetchurl, newScope, pkgs
, xar, cpio, python3, pbzx }:
let
MacOSX-SDK = stdenvNoCC.mkDerivation rec {
pname = "MacOSX-SDK";
version = "11.0.0";
# https://swscan.apple.com/content/catalogs/others/index-10.16.merged-1.sucatalog
src = fetchurl {
url = "http://swcdn.apple.com/content/downloads/58/37/001-75138-A_59RXKDS8YM/12ksm19hgzscfc7cau3yhecz4vpkps7wbq/CLTools_macOSNMOS_SDK.pkg";
sha256 = "0n51ba926ckwm62w5c8lk3w5hj4ihk0p5j02321qi75wh824hl8m";
};
dontBuild = true;
darwinDontCodeSign = true;
nativeBuildInputs = [ cpio pbzx ];
outputs = [ "out" ];
unpackPhase = ''
pbzx $src | cpio -idm
'';
installPhase = ''
cd Library/Developer/CommandLineTools/SDKs/MacOSX11.0.sdk
mkdir $out
cp -r System usr $out/
'';
passthru = {
inherit version;
};
};
callPackage = newScope (packages // pkgs.darwin // { inherit MacOSX-SDK; });
packages = {
inherit (callPackage ./apple_sdk.nix {}) frameworks libs;
# TODO: this is nice to be private. is it worth the callPackage above?
# Probably, I don't think that callPackage costs much at all.
inherit MacOSX-SDK;
Libsystem = callPackage ./libSystem.nix {};
LibsystemCross = pkgs.darwin.Libsystem;
libcharset = callPackage ./libcharset.nix {};
libunwind = callPackage ./libunwind.nix {};
libnetwork = callPackage ./libnetwork.nix {};
objc4 = callPackage ./libobjc.nix {};
# questionable aliases
configd = pkgs.darwin.apple_sdk.frameworks.SystemConfiguration;
IOKit = pkgs.darwin.apple_sdk.frameworks.IOKit;
};
in packages

View File

@ -0,0 +1,193 @@
{ frameworks, libs, libobjc, Libsystem, libnetwork }: with frameworks; with libs;
{
AGL = { inherit Carbon OpenGL; };
AVFoundation = { inherit ApplicationServices AVFCapture AVFCore CoreGraphics; };
AVKit = {};
Accelerate = { inherit CoreWLAN IOBluetooth; };
Accessibility = {};
Accounts = {};
AdSupport = {};
AddressBook = { inherit AddressBookCore Carbon ContactsPersistence libobjc; };
AppKit = { inherit ApplicationServices AudioToolbox AudioUnit Foundation QuartzCore UIFoundation; };
AppTrackingTransparency = {};
AppleScriptKit = {};
AppleScriptObjC = {};
ApplicationServices = { inherit ColorSync CoreGraphics CoreServices CoreText ImageIO; };
AudioToolbox = { inherit AudioToolboxCore CoreAudio CoreMIDI; };
AudioUnit = { inherit AudioToolbox Carbon CoreAudio; };
AudioVideoBridging = { inherit Foundation; };
AuthenticationServices = {};
AutomaticAssessmentConfiguration = {};
Automator = {};
BackgroundTasks = {};
BusinessChat = {};
CFNetwork = {};
CalendarStore = {};
CallKit = {};
Carbon = { inherit ApplicationServices CoreServices Foundation IOKit QuartzCore Security libobjc; };
ClassKit = {};
CloudKit = {};
Cocoa = { inherit AppKit CoreData; };
Collaboration = {};
ColorSync = {};
Combine = {};
Contacts = {};
ContactsUI = {};
CoreAudio = { inherit IOKit; };
CoreAudioKit = { inherit AudioUnit; };
CoreAudioTypes = {};
CoreBluetooth = {};
CoreData = {};
CoreDisplay = {};
CoreFoundation = { inherit libobjc; };
CoreGraphics = { inherit Accelerate IOKit IOSurface SystemConfiguration; };
CoreHaptics = {};
CoreImage = {};
CoreLocation = {};
CoreMIDI = {};
CoreMIDIServer = { inherit CoreMIDI; };
CoreML = {};
CoreMedia = { inherit ApplicationServices AudioToolbox AudioUnit CoreAudio CoreGraphics CoreVideo; };
CoreMediaIO = { inherit CoreMedia; };
CoreMotion = {};
CoreServices = { inherit CFNetwork CoreAudio CoreData CoreFoundation DiskArbitration NetFS OpenDirectory Security ServiceManagement; };
CoreSpotlight = {};
CoreTelephony = {};
CoreText = { inherit CoreGraphics; };
CoreVideo = { inherit ApplicationServices CoreGraphics IOSurface OpenGL; };
CoreWLAN = { inherit SecurityFoundation; };
CryptoKit = {};
CryptoTokenKit = {};
DVDPlayback = {};
DeveloperToolsSupport = {};
DeviceCheck = {};
DirectoryService = {};
DiscRecording = { inherit CoreServices IOKit libobjc; };
DiscRecordingUI = {};
DiskArbitration = { inherit IOKit; };
DriverKit = {};
EventKit = {};
ExceptionHandling = {};
ExecutionPolicy = {};
ExternalAccessory = {};
FWAUserLib = {};
FileProvider = {};
FileProviderUI = {};
FinderSync = {};
ForceFeedback = { inherit IOKit; };
Foundation = { inherit ApplicationServices CoreFoundation Security SystemConfiguration libobjc; };
GLKit = {};
GLUT = { inherit OpenGL; };
GSS = {};
GameController = {};
GameKit = { inherit Cocoa Foundation GameCenterFoundation GameCenterUI GameCenterUICore GameController GameplayKit Metal MetalKit ModelIO ReplayKit SceneKit SpriteKit; };
GameplayKit = {};
HIDDriverKit = {};
Hypervisor = {};
ICADevices = { inherit Carbon IOBluetooth libobjc; };
IMServicePlugIn = {};
IOBluetooth = { inherit CoreBluetooth IOKit; };
IOBluetoothUI = { inherit IOBluetooth; };
IOKit = {};
IOSurface = { inherit IOKit xpc; };
IOUSBHost = {};
IdentityLookup = {};
ImageCaptureCore = {};
ImageIO = { inherit CoreGraphics; };
InputMethodKit = { inherit Carbon; };
InstallerPlugins = {};
InstantMessage = {};
Intents = {};
JavaNativeFoundation = {};
JavaRuntimeSupport = {};
JavaScriptCore = { inherit libobjc; };
Kerberos = {};
Kernel = { inherit IOKit; };
KernelManagement = {};
LDAP = {};
LatentSemanticMapping = { inherit Carbon; };
LinkPresentation = { inherit URLFormatting; };
LocalAuthentication = {};
MLCompute = {};
MapKit = {};
MediaAccessibility = { inherit CoreGraphics CoreText QuartzCore; };
MediaLibrary = {};
MediaPlayer = {};
MediaToolbox = { inherit AudioToolbox AudioUnit CoreMedia; };
Message = {};
Metal = {};
MetalKit = { inherit Metal ModelIO; };
MetalPerformanceShaders = {};
MetalPerformanceShadersGraph = {};
MetricKit = { inherit SignpostMetrics; };
ModelIO = {};
MultipeerConnectivity = {};
NaturalLanguage = {};
NearbyInteraction = {};
NetFS = {};
Network = { inherit libnetwork; };
NetworkExtension = { inherit Network; };
NetworkingDriverKit = {};
NotificationCenter = {};
OSAKit = { inherit Carbon; };
OSLog = {};
OpenAL = {};
OpenCL = { inherit IOSurface OpenGL; };
OpenDirectory = {};
OpenGL = {};
PCIDriverKit = {};
PCSC = { inherit CoreData; };
PDFKit = {};
ParavirtualizedGraphics = {};
PassKit = { inherit PassKitCore; };
PencilKit = {};
Photos = {};
PhotosUI = {};
PreferencePanes = {};
PushKit = {};
Python = {};
QTKit = { inherit CoreMedia CoreMediaIO MediaToolbox VideoToolbox; };
Quartz = { inherit QTKit QuartzCore QuickLook PDFKit; };
QuartzCore = { inherit ApplicationServices CoreImage CoreVideo Metal OpenCL libobjc; };
QuickLook = { inherit ApplicationServices; };
QuickLookThumbnailing = {};
RealityKit = {};
ReplayKit = {};
Ruby = {};
SafariServices = {};
SceneKit = {};
ScreenSaver = {};
ScreenTime = {};
ScriptingBridge = {};
Security = { inherit IOKit libDER; };
SecurityFoundation = { inherit Security; };
SecurityInterface = { inherit Security SecurityFoundation; };
SensorKit = {};
ServiceManagement = { inherit Security; };
Social = {};
SoundAnalysis = {};
Speech = {};
SpriteKit = {};
StoreKit = {};
SwiftUI = {};
SyncServices = {};
System = {};
SystemConfiguration = { inherit Security; };
SystemExtensions = {};
TWAIN = { inherit Carbon; };
Tcl = {};
Tk = {};
USBDriverKit = {};
UniformTypeIdentifiers = {};
UserNotifications = {};
UserNotificationsUI = {};
VideoDecodeAcceleration = { inherit CoreVideo; };
VideoSubscriberAccount = {};
VideoToolbox = { inherit CoreMedia CoreVideo; };
Virtualization = {};
Vision = {};
WebKit = { inherit ApplicationServices Carbon JavaScriptCore OpenGL libobjc; };
WidgetKit = {};
iTunesLibrary = {};
vmnet = {};
}

View File

@ -0,0 +1,78 @@
{ stdenvNoCC, buildPackages, MacOSX-SDK }:
stdenvNoCC.mkDerivation {
pname = "libSystem";
version = MacOSX-SDK.version;
dontBuild = true;
dontUnpack = true;
nativeBuildInputs = [ buildPackages.darwin.rewrite-tbd ];
includeDirs = [
"CommonCrypto" "_types" "architecture" "arpa" "atm" "bank" "bsd" "bsm"
"corecrypto" "corpses" "default_pager" "device" "dispatch" "hfs" "i386"
"iokit" "kern" "libkern" "mach" "mach-o" "mach_debug" "machine" "malloc"
"miscfs" "net" "netinet" "netinet6" "netkey" "nfs" "os" "osfmk" "pexpert"
"platform" "protocols" "pthread" "rpc" "rpcsvc" "secure" "security"
"servers" "sys" "uuid" "vfs" "voucher" "xlocale"
] ++ [
"arm" "xpc" "arm64"
];
csu = [
"bundle1.o" "crt0.o" "crt1.10.5.o" "crt1.10.6.o" "crt1.o" "dylib1.10.5.o"
"dylib1.o" "gcrt1.o" "lazydylib1.o"
];
installPhase = ''
mkdir -p $out/{include,lib}
for dir in $includeDirs; do
from=${MacOSX-SDK}/usr/include/$dir
if [ -e "$from" ]; then
cp -dr $from $out/include
else
echo "Header directory '$from' doesn't exist: skipping"
fi
done
cp -d \
${MacOSX-SDK}/usr/include/*.h \
$out/include
rm $out/include/tk*.h $out/include/tcl*.h
cp -dr \
${MacOSX-SDK}/usr/lib/libSystem.* \
${MacOSX-SDK}/usr/lib/system \
$out/lib
# Extra libraries
for name in c dbm dl info m mx poll proc pthread rpcsvc util gcc_s.1 resolv; do
cp -d \
${MacOSX-SDK}/usr/lib/lib$name.tbd \
${MacOSX-SDK}/usr/lib/lib$name.*.tbd \
$out/lib
done
for f in $csu; do
from=${MacOSX-SDK}/usr/lib/$f
if [ -e "$from" ]; then
cp -d $from $out/lib
else
echo "Csu file '$from' doesn't exist: skipping"
fi
done
chmod u+w -R $out/lib
find $out -name '*.tbd' -type f | while read tbd; do
rewrite-tbd \
-c /usr/lib/libsystem.dylib:$out/lib/libsystem.dylib \
-p /usr/lib/system/:$out/lib/system/ \
-r ${builtins.storeDir} \
"$tbd"
done
'';
}

View File

@ -0,0 +1,16 @@
{ stdenvNoCC, buildPackages, MacOSX-SDK }:
stdenvNoCC.mkDerivation {
pname = "libcharset";
version = MacOSX-SDK.version;
dontUnpack = true;
dontBuild = true;
nativeBuildInputs = [ buildPackages.darwin.checkReexportsHook ];
installPhase = ''
mkdir -p $out/{include,lib}
cp ${MacOSX-SDK}/usr/lib/libcharset* $out/lib
'';
}

View File

@ -0,0 +1,20 @@
{ stdenvNoCC, buildPackages, MacOSX-SDK }:
let self = stdenvNoCC.mkDerivation {
pname = "libnetwork";
version = MacOSX-SDK.version;
dontUnpack = true;
dontBuild = true;
installPhase = ''
mkdir -p $out/lib
cp ${MacOSX-SDK}/usr/lib/libnetwork* $out/lib
'';
passthru = {
tbdRewrites = {
const."/usr/lib/libnetwork.dylib" = "${self}/lib/libnetwork.dylib";
};
};
}; in self

View File

@ -0,0 +1,21 @@
{ stdenvNoCC, MacOSX-SDK, libcharset }:
let self = stdenvNoCC.mkDerivation {
pname = "libobjc";
version = MacOSX-SDK.version;
dontUnpack = true;
dontBuild = true;
installPhase = ''
mkdir -p $out/{include,lib}
cp -r ${MacOSX-SDK}/usr/include/objc $out/include
cp ${MacOSX-SDK}/usr/lib/libobjc* $out/lib
'';
passthru = {
tbdRewrites = {
const."/usr/lib/libobjc.A.dylib" = "${self}/lib/libobjc.A.dylib";
};
};
}; in self

View File

@ -0,0 +1,24 @@
{ stdenvNoCC, buildPackages, MacOSX-SDK }:
stdenvNoCC.mkDerivation {
pname = "libunwind";
version = MacOSX-SDK.version;
dontUnpack = true;
dontBuild = true;
nativeBuildInputs = [ buildPackages.darwin.checkReexportsHook ];
installPhase = ''
mkdir -p $out/include/mach-o
cp \
${MacOSX-SDK}/usr/include/libunwind.h \
${MacOSX-SDK}/usr/include/unwind.h \
$out/include
cp \
${MacOSX-SDK}/usr/include/mach-o/compact_unwind_encoding.h \
$out/include/mach-o
'';
}

View File

@ -0,0 +1,17 @@
{ frameworks }: with frameworks;
# generated by hand to avoid exposing all private frameworks
# frameworks here are only the necessary ones used by public frameworks.
{
AVFCapture = {};
AVFCore = {};
AddressBookCore = { inherit ContactsPersistence; };
AudioToolboxCore = {};
ContactsPersistence = {};
UIFoundation = {};
GameCenterFoundation = {};
GameCenterUI = {};
GameCenterUICore = {};
URLFormatting = {};
SignpostMetrics = {};
PassKitCore = {};
}