darwin/apple-sdk: use darwin stubs

This commit is contained in:
Andrew Childs 2020-09-18 17:12:43 +09:00
parent 8e6d830423
commit 3456ef6f30
4 changed files with 211 additions and 131 deletions

View File

@ -3,7 +3,7 @@ linkSystemCoreFoundationFramework() {
# gross! many symbols (such as _OBJC_CLASS_$_NSArray) are defined in system CF, but not # gross! many symbols (such as _OBJC_CLASS_$_NSArray) are defined in system CF, but not
# in the opensource release # in the opensource release
# if the package needs private headers, we assume they also want to link with system CF # if the package needs private headers, we assume they also want to link with system CF
NIX_LDFLAGS+=" /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation" NIX_LDFLAGS+=" @out@/Library/Frameworks/CoreFoundation.framework/CoreFoundation"
} }
preConfigureHooks+=(linkSystemCoreFoundationFramework) preConfigureHooks+=(linkSystemCoreFoundationFramework)

View File

@ -1,4 +1,4 @@
{ stdenv, fetchurl, xar, cpio, pkgs, python3, pbzx, lib }: { stdenv, fetchurl, xar, cpio, pkgs, python3, pbzx, lib, darwin-stubs, print-reexports }:
let version = "10.12"; in let version = "10.12"; in
@ -42,7 +42,12 @@ let
rmdir System rmdir System
pushd lib pushd lib
ln -s -L /usr/lib/libcups*.dylib . cp ${darwin-stubs}/usr/lib/libcups*.tbd .
ln -s libcups.2.tbd libcups.tbd
ln -s libcupscgi.1.tbd libcupscgi.tbd
ln -s libcupsimage.2.tbd libcupsimage.tbd
ln -s libcupsmime.1.tbd libcupsmime.tbd
ln -s libcupsppdc.1.tbd libcupsppdc.tbd
popd popd
''; '';
@ -53,6 +58,12 @@ let
}; };
}; };
mkFrameworkSubs = name: deps:
let
deps' = deps // { "${name}" = placeholder "out"; };
substArgs = lib.concatMap (x: [ "--subst-var-by" x deps'."${x}" ]) (lib.attrNames deps');
in lib.escapeShellArgs substArgs;
framework = name: deps: stdenv.mkDerivation { framework = name: deps: stdenv.mkDerivation {
name = "apple-framework-${name}"; name = "apple-framework-${name}";
@ -63,11 +74,14 @@ let
disallowedRequisites = [ sdk ]; disallowedRequisites = [ sdk ];
nativeBuildInputs = [ print-reexports ];
extraTBDFiles = [];
installPhase = '' installPhase = ''
linkFramework() { linkFramework() {
local path="$1" local path="$1"
local nested_path="$1" local nested_path="$1"
local dest="$out/Library/Frameworks/$path"
if [ "$path" == "JavaNativeFoundation.framework" ]; then if [ "$path" == "JavaNativeFoundation.framework" ]; then
local nested_path="JavaVM.framework/Versions/A/Frameworks/JavaNativeFoundation.framework" local nested_path="JavaVM.framework/Versions/A/Frameworks/JavaNativeFoundation.framework"
fi fi
@ -80,21 +94,28 @@ let
current=A current=A
fi fi
mkdir -p "$dest" local dest="$out/Library/Frameworks/$path"
pushd "$dest" >/dev/null
# Keep track of if this is a child or a child rescue as with mkdir -p "$dest/Versions/$current"
# ApplicationServices in the 10.9 SDK pushd "$dest/Versions/$current" >/dev/null
local isChild=0
if [ -d "${sdk.out}/Library/Frameworks/$nested_path/Versions/$current/Headers" ]; then if [ -d "${sdk.out}/Library/Frameworks/$nested_path/Versions/$current/Headers" ]; then
isChild=1
cp -R "${sdk.out}/Library/Frameworks/$nested_path/Versions/$current/Headers" . cp -R "${sdk.out}/Library/Frameworks/$nested_path/Versions/$current/Headers" .
elif [ -d "${sdk.out}/Library/Frameworks/$name.framework/Versions/$current/Headers" ]; then elif [ -d "${sdk.out}/Library/Frameworks/$name.framework/Versions/$current/Headers" ]; then
current="$(readlink "/System/Library/Frameworks/$name.framework/Versions/Current")" current="$(readlink "/System/Library/Frameworks/$name.framework/Versions/Current")"
cp -R "${sdk.out}/Library/Frameworks/$name.framework/Versions/$current/Headers" . cp -R "${sdk.out}/Library/Frameworks/$name.framework/Versions/$current/Headers" .
fi fi
ln -s -L "/System/Library/Frameworks/$nested_path/Versions/$current/$name"
local tbd_source=${darwin-stubs}/System/Library/Frameworks/$nested_path/Versions/$current
if [ "${name}" != "Kernel" ]; then
cp -v $tbd_source/*.tbd .
fi
if [ -d "$tbd_source/Libraries" ]; then
mkdir Libraries
cp -v $tbd_source/Libraries/*.tbd Libraries/
fi
ln -s -L "/System/Library/Frameworks/$nested_path/Versions/$current/Resources" ln -s -L "/System/Library/Frameworks/$nested_path/Versions/$current/Resources"
if [ -f "/System/Library/Frameworks/$nested_path/module.map" ]; then if [ -f "/System/Library/Frameworks/$nested_path/module.map" ]; then
@ -110,17 +131,45 @@ let
linkFramework "$childpath" linkFramework "$childpath"
done done
if [ -d "$dest/Versions/$current" ]; then pushd ../.. >/dev/null
mv $dest/Versions/$current/* . ln -s "$current" Versions/Current
fi ln -s Versions/Current/* .
popd >/dev/null
popd >/dev/null popd >/dev/null
} }
linkFramework "${name}.framework" linkFramework "${name}.framework"
# linkFramework is recursive, the rest of the processing is not.
local tbd_source=${darwin-stubs}/System/Library/Frameworks/${name}.framework
for tbd in $extraTBDFiles; do
local tbd_dest_dir=$out/Library/Frameworks/${name}.framework/$(dirname "$tbd")
mkdir -p "$tbd_dest_dir"
cp -v "$tbd_source/$tbd" "$tbd_dest_dir"
done
# Fix and check tbd re-export references
find $out -name '*.tbd' | while read tbd; do
echo "Fixing re-exports in $tbd"
substituteInPlace "$tbd" ${mkFrameworkSubs name deps}
echo "Checking re-exports in $tbd"
print-reexports "$tbd" | while read target; do
local expected="''${target%.dylib}.tbd"
if ! [ -e "$expected" ]; then
echo -e "Re-export missing:\n\t$target\n\t(expected $expected)"
echo -e "While processing\n\t$tbd"
exit 1
else
echo "Re-exported target $target ok"
fi
done
done
''; '';
propagatedBuildInputs = deps; propagatedBuildInputs = builtins.attrValues deps;
# don't use pure CF for dylibs that depend on frameworks # don't use pure CF for dylibs that depend on frameworks
setupHook = ./framework-setup-hook.sh; setupHook = ./framework-setup-hook.sh;
@ -139,6 +188,17 @@ let
platforms = platforms.darwin; platforms = platforms.darwin;
}; };
}; };
tbdOnlyFramework = name: { private ? true }: stdenv.mkDerivation {
name = "apple-framework-${name}";
dontUnpack = true;
installPhase = ''
mkdir -p $out/Library/Frameworks/
cp -r ${darwin-stubs}/System/Library/${lib.optionalString private "Private"}Frameworks/${name}.framework \
$out/Library/Frameworks
# NOTE there's no re-export checking here, this is probably wrong
'';
};
in rec { in rec {
libs = { libs = {
xpc = stdenv.mkDerivation { xpc = stdenv.mkDerivation {
@ -168,7 +228,8 @@ in rec {
installPhase = '' installPhase = ''
mkdir -p $out/include $out/lib mkdir -p $out/include $out/lib
ln -s "${lib.getDev sdk}/include/Xplugin.h" $out/include/Xplugin.h ln -s "${lib.getDev sdk}/include/Xplugin.h" $out/include/Xplugin.h
ln -s "/usr/lib/libXplugin.1.dylib" $out/lib/libXplugin.dylib cp ${darwin-stubs}/usr/lib/libXplugin.1.tbd $out/lib
ln -s libXplugin.1.tbd $out/lib/libXplugin.tbd
''; '';
}; };
@ -193,6 +254,10 @@ in rec {
]; ];
}); });
Carbon = stdenv.lib.overrideDerivation super.Carbon (drv: {
extraTBDFiles = [ "Versions/A/Frameworks/HTMLRendering.framework/Versions/A/HTMLRendering.tbd" ];
});
CoreFoundation = stdenv.lib.overrideDerivation super.CoreFoundation (drv: { CoreFoundation = stdenv.lib.overrideDerivation super.CoreFoundation (drv: {
setupHook = ./cf-setup-hook.sh; setupHook = ./cf-setup-hook.sh;
}); });
@ -210,6 +275,10 @@ in rec {
setupHook = ./private-frameworks-setup-hook.sh; setupHook = ./private-frameworks-setup-hook.sh;
}); });
IMServicePlugIn = stdenv.lib.overrideDerivation super.IMServicePlugIn (drv: {
extraTBDFiles = [ "Versions/A/Frameworks/IMServicePlugInSupport.framework/Versions/A/IMServicePlugInSupport.tbd" ];
});
Security = stdenv.lib.overrideDerivation super.Security (drv: { Security = stdenv.lib.overrideDerivation super.Security (drv: {
setupHook = ./security-setup-hook.sh; setupHook = ./security-setup-hook.sh;
}); });
@ -228,7 +297,14 @@ in rec {
cp ${lib.getDev sdk}/include/simd/*.h $out/include/simd/ cp ${lib.getDev sdk}/include/simd/*.h $out/include/simd/
''; '';
}); });
};
WebKit = stdenv.lib.overrideDerivation super.WebKit (drv: {
extraTBDFiles = [
"Versions/A/Frameworks/WebCore.framework/Versions/A/WebCore.tbd"
"Versions/A/Frameworks/WebKitLegacy.framework/Versions/A/WebKitLegacy.tbd"
];
});
} // lib.genAttrs [ "ContactsPersistence" "UIFoundation" "GameCenter" ] (x: tbdOnlyFramework x {});
bareFrameworks = stdenv.lib.mapAttrs framework (import ./frameworks.nix { bareFrameworks = stdenv.lib.mapAttrs framework (import ./frameworks.nix {
inherit frameworks libs; inherit frameworks libs;

View File

@ -5,123 +5,125 @@
{ frameworks, libs, libobjc, }: { frameworks, libs, libobjc, }:
with frameworks; with libs; { with frameworks; with libs; {
AGL = [ Carbon OpenGL ]; AGL = { inherit Carbon OpenGL; };
AVFoundation = [ ApplicationServices CoreGraphics ]; AVFoundation = { inherit ApplicationServices CoreGraphics; };
AVKit = []; AVKit = {};
Accounts = []; Accounts = {};
AddressBook = [ Carbon ]; AddressBook = { inherit libobjc Carbon ContactsPersistence; };
AppKit = [ AudioToolbox AudioUnit Foundation QuartzCore ]; AppKit = { inherit ApplicationServices AudioToolbox AudioUnit Foundation QuartzCore UIFoundation; };
AppKitScripting = []; AppKitScripting = {};
AppleScriptKit = []; AppleScriptKit = {};
AppleScriptObjC = []; AppleScriptObjC = {};
AudioToolbox = [ CoreAudio CoreMIDI ]; AudioToolbox = { inherit CoreAudio CoreMIDI; };
AudioUnit = [ AudioToolbox Carbon CoreAudio ]; AudioUnit = { inherit AudioToolbox Carbon CoreAudio; };
AudioVideoBridging = [ Foundation ]; AudioVideoBridging = { inherit Foundation; };
Automator = []; Automator = {};
CFNetwork = []; CFNetwork = {};
CalendarStore = []; CalendarStore = {};
Cocoa = [ AppKit ]; Cocoa = { inherit AppKit CoreData; };
Collaboration = []; Collaboration = {};
# Impure version of CoreFoundation, this should not be used unless another # Impure version of CoreFoundation, this should not be used unless another
# framework includes headers that are not available in the pure version. # framework includes headers that are not available in the pure version.
CoreFoundation = []; CoreFoundation = {};
CoreAudio = [ IOKit ]; CoreAudio = { inherit IOKit; };
CoreAudioKit = [ AudioUnit ]; CoreAudioKit = { inherit AudioUnit; };
CoreData = []; CoreData = {};
CoreGraphics = [ Accelerate IOKit IOSurface SystemConfiguration ]; CoreGraphics = { inherit Accelerate IOKit IOSurface SystemConfiguration; };
CoreImage = []; CoreImage = {};
CoreLocation = []; CoreLocation = {};
CoreMIDI = []; CoreMIDI = {};
CoreMIDIServer = []; CoreMIDIServer = { inherit CoreMIDI; };
CoreMedia = [ ApplicationServices AudioToolbox AudioUnit CoreAudio CoreGraphics CoreVideo ]; CoreMedia = { inherit ApplicationServices AudioToolbox AudioUnit CoreAudio CoreGraphics CoreVideo; };
CoreMediaIO = [ CoreMedia ]; CoreMediaIO = { inherit CoreMedia; };
CoreText = [ CoreGraphics ]; CoreText = { inherit CoreGraphics; };
CoreVideo = [ ApplicationServices CoreGraphics IOSurface OpenGL ]; CoreVideo = { inherit ApplicationServices CoreGraphics IOSurface OpenGL; };
CoreWLAN = [ SecurityFoundation ]; CoreWLAN = { inherit SecurityFoundation; };
DVDPlayback = []; DVDPlayback = {};
DirectoryService = []; DirectoryService = {};
DiscRecording = [ CoreServices IOKit ]; DiscRecording = { inherit libobjc CoreServices IOKit; };
DiscRecordingUI = []; DiscRecordingUI = {};
DiskArbitration = [ IOKit ]; DiskArbitration = { inherit IOKit; };
EventKit = []; EventKit = {};
ExceptionHandling = []; ExceptionHandling = {};
FWAUserLib = []; FWAUserLib = {};
ForceFeedback = [ IOKit ]; ForceFeedback = { inherit IOKit; };
Foundation = [ libobjc CoreFoundation Security ApplicationServices SystemConfiguration ]; Foundation = { inherit libobjc CoreFoundation Security ApplicationServices SystemConfiguration; };
GLKit = []; GLKit = {};
GLUT = [ OpenGL ]; GLUT = { inherit OpenGL; };
GSS = []; GSS = {};
GameController = []; GameCenter = {};
GameKit = [ Foundation ]; GameController = {};
Hypervisor = []; GameKit = { inherit Cocoa Foundation GameCenter GameController GameplayKit Metal MetalKit ModelIO SceneKit SpriteKit; };
ICADevices = [ Carbon IOBluetooth ]; GameplayKit = {};
IMServicePlugIn = []; Hypervisor = {};
IOBluetoothUI = [ IOBluetooth ]; ICADevices = { inherit libobjc Carbon IOBluetooth; };
IOKit = []; IMServicePlugIn = {};
IOSurface = [ IOKit xpc ]; IOBluetoothUI = { inherit IOBluetooth; };
ImageCaptureCore = []; IOKit = {};
ImageIO = [ CoreGraphics ]; IOSurface = { inherit IOKit xpc; };
InputMethodKit = [ Carbon ]; ImageCaptureCore = {};
InstallerPlugins = []; ImageIO = { inherit CoreGraphics; };
InstantMessage = []; InputMethodKit = { inherit Carbon; };
JavaFrameEmbedding = []; InstallerPlugins = {};
JavaNativeFoundation = []; InstantMessage = {};
JavaRuntimeSupport = []; JavaFrameEmbedding = {};
JavaScriptCore = []; JavaNativeFoundation = {};
Kerberos = []; JavaRuntimeSupport = {};
Kernel = [ IOKit ]; JavaScriptCore = { inherit libobjc; };
LDAP = []; Kerberos = {};
LatentSemanticMapping = [ Carbon ]; Kernel = { inherit IOKit; };
LocalAuthentication = []; LDAP = {};
MapKit = []; LatentSemanticMapping = { inherit Carbon; };
MediaAccessibility = [ CoreGraphics CoreText QuartzCore ]; LocalAuthentication = {};
MediaPlayer = []; MapKit = {};
MediaToolbox = [ AudioToolbox AudioUnit CoreMedia ]; MediaAccessibility = { inherit CoreGraphics CoreText QuartzCore; };
Metal = []; MediaPlayer = {};
MetalKit = [ ModelIO Metal ]; MediaToolbox = { inherit AudioToolbox AudioUnit CoreMedia; };
ModelIO = [ ]; Metal = {};
NetFS = []; MetalKit = { inherit ModelIO Metal; };
OSAKit = [ Carbon ]; ModelIO = {};
OpenAL = []; NetFS = {};
OpenCL = [ IOSurface OpenGL ]; OSAKit = { inherit Carbon; };
OpenGL = []; OpenAL = {};
PCSC = [ CoreData ]; OpenCL = { inherit IOSurface OpenGL; };
PreferencePanes = []; OpenGL = {};
PubSub = []; PCSC = { inherit CoreData; };
QTKit = [ CoreMediaIO CoreMedia MediaToolbox QuickTime VideoToolbox ]; PreferencePanes = {};
QuickLook = [ ApplicationServices ]; PubSub = {};
SceneKit = []; QTKit = { inherit CoreMediaIO CoreMedia MediaToolbox QuickTime VideoToolbox; };
ScreenSaver = []; QuickLook = { inherit ApplicationServices; };
Scripting = []; SceneKit = {};
ScriptingBridge = []; ScreenSaver = {};
Security = [ IOKit ]; Scripting = {};
SecurityFoundation = []; ScriptingBridge = {};
SecurityInterface = [ Security ]; Security = { inherit IOKit; };
ServiceManagement = [ Security ]; SecurityFoundation = {};
Social = []; SecurityInterface = { inherit Security SecurityFoundation; };
SpriteKit = []; ServiceManagement = { inherit Security; };
StoreKit = []; Social = {};
SyncServices = []; SpriteKit = {};
SystemConfiguration = [ Security ]; StoreKit = {};
TWAIN = [ Carbon ]; SyncServices = {};
Tcl = []; SystemConfiguration = { inherit Security; };
VideoDecodeAcceleration = [ CoreVideo ]; TWAIN = { inherit Carbon; };
VideoToolbox = [ CoreMedia CoreVideo ]; Tcl = {};
WebKit = [ ApplicationServices Carbon JavaScriptCore OpenGL ]; VideoDecodeAcceleration = { inherit CoreVideo; };
VideoToolbox = { inherit CoreMedia CoreVideo; };
WebKit = { inherit libobjc ApplicationServices Carbon JavaScriptCore OpenGL; };
# Umbrellas # Umbrellas
Accelerate = [ CoreWLAN IOBluetooth ]; Accelerate = { inherit CoreWLAN IOBluetooth; };
ApplicationServices = [ CoreServices CoreText ImageIO ]; ApplicationServices = { inherit CoreGraphics CoreServices CoreText ImageIO; };
Carbon = [ ApplicationServices CoreServices Foundation IOKit Security QuartzCore ]; Carbon = { inherit libobjc ApplicationServices CoreServices Foundation IOKit Security QuartzCore; };
CoreBluetooth = []; CoreBluetooth = {};
# TODO: figure out which part of the umbrella depends on CoreFoundation and move it there. # TODO: figure out which part of the umbrella depends on CoreFoundation and move it there.
CoreServices = [ CFNetwork CoreFoundation CoreAudio CoreData DiskArbitration Security NetFS OpenDirectory ServiceManagement ]; CoreServices = { inherit CFNetwork CoreFoundation CoreAudio CoreData DiskArbitration Security NetFS OpenDirectory ServiceManagement; };
IOBluetooth = [ IOKit ]; IOBluetooth = { inherit CoreBluetooth IOKit; };
JavaVM = []; JavaVM = {};
OpenDirectory = []; OpenDirectory = {};
Quartz = [ QuickLook QTKit ]; Quartz = { inherit QuartzCore QuickLook QTKit; };
QuartzCore = [ ApplicationServices CoreVideo OpenCL CoreImage Metal ]; QuartzCore = { inherit libobjc ApplicationServices CoreVideo OpenCL CoreImage Metal; };
QuickTime = [ ApplicationServices AudioUnit Carbon CoreAudio CoreServices OpenGL QuartzCore ]; QuickTime = { inherit ApplicationServices AudioUnit Carbon CoreAudio CoreServices OpenGL QuartzCore; };
vmnet = []; vmnet = {};
} }

View File

@ -14,7 +14,9 @@ in
extraBuildInputs = []; extraBuildInputs = [];
}; };
apple_sdk = callPackage ../os-specific/darwin/apple-sdk { }; apple_sdk = callPackage ../os-specific/darwin/apple-sdk {
inherit (darwin) darwin-stubs print-reexports;
};
binutils-unwrapped = callPackage ../os-specific/darwin/binutils { binutils-unwrapped = callPackage ../os-specific/darwin/binutils {
inherit (darwin) cctools; inherit (darwin) cctools;