chromium,chromedriver: 129.0.6668.91 -> 129.0.6668.100
[NixPkgs.git] / pkgs / os-specific / darwin / apple-sdk / default.nix
blob1cd5afe193016fecdd2a2f307b4e09ebb81c2b6f
1 { stdenv, stdenvNoCC, fetchurl, cpio, pbzx, pkgs, lib, darwin-stubs, print-reexports }:
3 let
4   # sadly needs to be exported because security_tool needs it
5   sdk = stdenv.mkDerivation rec {
6     pname = "MacOS_SDK";
7     version = "10.12";
9     # This URL comes from https://swscan.apple.com/content/catalogs/others/index-10.12.merged-1.sucatalog, which we found by:
10     #  1. Google: site:swscan.apple.com and look for a name that seems appropriate for your version
11     #  2. In the resulting file, search for a file called DevSDK ending in .pkg
12     #  3. ???
13     #  4. Profit
14     src = fetchurl {
15       url    = "http://swcdn.apple.com/content/downloads/33/36/041-90419-A_7JJ4H9ZHO2/xs88ob5wjz6riz7g6764twblnvksusg4ps/DevSDK_OSX1012.pkg";
16       sha256 = "13xq34sb7383b37hwy076gnhf96prpk1b4087p87xnwswxbrisih";
17     };
19     nativeBuildInputs = [ cpio pbzx ];
21     outputs = [ "out" "dev" "man" ];
23     unpackPhase = ''
24       pbzx $src | cpio -idm
25     '';
27     sourceRoot = ".";
29     installPhase = ''
30       mkdir -p $out
32       cp -R System/Library $out
33       cp -R usr/* $out
35       pushd $out/lib
36       cp ${darwin-stubs}/usr/lib/libcups*.tbd .
37       ln -s libcups.2.tbd      libcups.tbd
38       ln -s libcupscgi.1.tbd   libcupscgi.tbd
39       ln -s libcupsimage.2.tbd libcupsimage.tbd
40       ln -s libcupsmime.1.tbd  libcupsmime.tbd
41       ln -s libcupsppdc.1.tbd  libcupsppdc.tbd
42       popd
43     '';
45     meta = with lib; {
46       description = "Apple SDK ${version}";
47       maintainers = with maintainers; [ copumpkin ];
48       platforms   = platforms.darwin;
49     };
50   };
52   mkFrameworkSubs = name: deps:
53   let
54     deps' = deps // { "${name}" = placeholder "out"; };
55     substArgs = lib.concatMap (x: [ "--subst-var-by" x deps'."${x}" ]) (lib.attrNames deps');
56   in lib.escapeShellArgs substArgs;
58   framework = name: deps: stdenv.mkDerivation {
59     name = "apple-framework-${name}";
61     dontUnpack = true;
63     # because we copy files from the system
64     preferLocalBuild = true;
66     disallowedRequisites = [ sdk ];
68     nativeBuildInputs = [ print-reexports ];
70     extraTBDFiles = [];
72     installPhase = ''
73       linkFramework() {
74         local path="$1"
75         local nested_path="$1"
76         if [ "$path" == "JavaNativeFoundation.framework" ]; then
77           local nested_path="JavaVM.framework/Versions/A/Frameworks/JavaNativeFoundation.framework"
78         fi
79         if [ "$path" == "JavaRuntimeSupport.framework" ]; then
80           local nested_path="JavaVM.framework/Versions/A/Frameworks/JavaRuntimeSupport.framework"
81         fi
82         local name="$(basename "$path" .framework)"
83         local current="$(readlink "/System/Library/Frameworks/$nested_path/Versions/Current")"
84         if [ -z "$current" ]; then
85           current=A
86         fi
88         local dest="$out/Library/Frameworks/$path"
90         mkdir -p "$dest/Versions/$current"
91         pushd "$dest/Versions/$current" >/dev/null
93         if [ -d "${sdk.out}/Library/Frameworks/$nested_path/Versions/$current/Headers" ]; then
94           cp -R "${sdk.out}/Library/Frameworks/$nested_path/Versions/$current/Headers" .
95         elif [ -d "${sdk.out}/Library/Frameworks/$name.framework/Versions/$current/Headers" ]; then
96           current="$(readlink "/System/Library/Frameworks/$name.framework/Versions/Current")"
97           cp -R "${sdk.out}/Library/Frameworks/$name.framework/Versions/$current/Headers" .
98         fi
100         local tbd_source=${darwin-stubs}/System/Library/Frameworks/$nested_path/Versions/$current
101         if [ "${name}" != "Kernel" ]; then
102           # The Kernel.framework has headers but no actual library component.
103           cp -v $tbd_source/*.tbd .
104         fi
106         if [ -d "$tbd_source/Libraries" ]; then
107           mkdir Libraries
108           cp -v $tbd_source/Libraries/*.tbd Libraries/
109         fi
111         ln -s -L "/System/Library/Frameworks/$nested_path/Versions/$current/Resources"
113         if [ -f "/System/Library/Frameworks/$nested_path/module.map" ]; then
114           ln -s "/System/Library/Frameworks/$nested_path/module.map"
115         fi
117         pushd "${sdk.out}/Library/Frameworks/$nested_path/Versions/$current" >/dev/null
118         local children=$(echo Frameworks/*.framework)
119         popd >/dev/null
121         for child in $children; do
122           childpath="$path/Versions/$current/$child"
123           linkFramework "$childpath"
124         done
126         pushd ../.. >/dev/null
127         ln -s "$current" Versions/Current
128         ln -s Versions/Current/* .
129         popd >/dev/null
131         popd >/dev/null
132       }
134       linkFramework "${name}.framework"
136       # linkFramework is recursive, the rest of the processing is not.
138       local tbd_source=${darwin-stubs}/System/Library/Frameworks/${name}.framework
139       for tbd in $extraTBDFiles; do
140         local tbd_dest_dir=$out/Library/Frameworks/${name}.framework/$(dirname "$tbd")
141         mkdir -p "$tbd_dest_dir"
142         cp -v "$tbd_source/$tbd" "$tbd_dest_dir"
143       done
145       # Fix and check tbd re-export references
146       find $out -name '*.tbd' | while read tbd; do
147         echo "Fixing re-exports in $tbd"
148         substituteInPlace "$tbd" ${mkFrameworkSubs name deps}
150         echo "Checking re-exports in $tbd"
151         print-reexports "$tbd" | while read target; do
152           local expected="''${target%.dylib}.tbd"
153           if ! [ -e "$expected" ]; then
154             echo -e "Re-export missing:\n\t$target\n\t(expected $expected)"
155             echo -e "While processing\n\t$tbd"
156             exit 1
157           else
158             echo "Re-exported target $target ok"
159           fi
160         done
161       done
162     '';
164     propagatedBuildInputs = builtins.attrValues deps;
166     meta = with lib; {
167       description = "Apple SDK framework ${name}";
168       maintainers = with maintainers; [ copumpkin ];
169       platforms   = platforms.darwin;
170     };
171   };
173   tbdOnlyFramework = name: { private ? true }: stdenv.mkDerivation {
174     name = "apple-framework-${name}";
175     dontUnpack = true;
176     installPhase = ''
177       mkdir -p $out/Library/Frameworks/
178       cp -r ${darwin-stubs}/System/Library/${lib.optionalString private "Private"}Frameworks/${name}.framework \
179         $out/Library/Frameworks
181       cd $out/Library/Frameworks/${name}.framework
183       versions=(./Versions/*)
184       if [ "''${#versions[@]}" != 1 ]; then
185         echo "Unable to determine current version of framework ${name}"
186         exit 1
187       fi
188       current=$(basename ''${versions[0]})
190       chmod u+w -R .
191       ln -s "$current" Versions/Current
192       ln -s Versions/Current/* .
194       # NOTE there's no re-export checking here, this is probably wrong
195     '';
196   };
197 in rec {
198   libs = {
199     xpc = stdenv.mkDerivation {
200       name   = "apple-lib-xpc";
201       dontUnpack = true;
203       installPhase = ''
204         mkdir -p $out/include
205         pushd $out/include >/dev/null
206         cp -r "${lib.getDev sdk}/include/xpc" $out/include/xpc
207         cp "${lib.getDev sdk}/include/launch.h" $out/include/launch.h
208         popd >/dev/null
209       '';
210     };
212     Xplugin = stdenv.mkDerivation {
213       name   = "apple-lib-Xplugin";
214       dontUnpack = true;
216       # Not enough
217       __propagatedImpureHostDeps = [ "/usr/lib/libXplugin.1.dylib" ];
219       propagatedBuildInputs = with frameworks; [
220         OpenGL ApplicationServices Carbon IOKit CoreGraphics CoreServices CoreText
221       ];
223       installPhase = ''
224         mkdir -p $out/include $out/lib
225         ln -s "${lib.getDev sdk}/include/Xplugin.h" $out/include/Xplugin.h
226         cp ${darwin-stubs}/usr/lib/libXplugin.1.tbd $out/lib
227         ln -s libXplugin.1.tbd $out/lib/libXplugin.tbd
228       '';
229     };
231     utmp = stdenv.mkDerivation {
232       name   = "apple-lib-utmp";
233       dontUnpack = true;
235       installPhase = ''
236         mkdir -p $out/include
237         pushd $out/include >/dev/null
238         ln -s "${lib.getDev sdk}/include/utmp.h"
239         ln -s "${lib.getDev sdk}/include/utmpx.h"
240         popd >/dev/null
241       '';
242     };
244     sandbox = stdenv.mkDerivation {
245       name = "apple-lib-sandbox";
246       dontUnpack = true;
248       installPhase = ''
249         mkdir -p $out/include $out/lib
250         ln -s "${lib.getDev sdk}/include/sandbox.h" $out/include/sandbox.h
251         cp "${darwin-stubs}/usr/lib/libsandbox.1.tbd" $out/lib
252         ln -s libsandbox.1.tbd $out/lib/libsandbox.tbd
253       '';
254     };
256     simd = stdenvNoCC.mkDerivation {
257       name = "apple-lib-simd";
259       preferLocalBuild = true;
260       allowSubstitutes = false;
262       buildCommand = "echo 'simd library not available in the 10.12 SDK'; exit 1";
263     };
264   };
266   overrides = super: {
267     AppKit = lib.overrideDerivation super.AppKit (drv: {
268       __propagatedImpureHostDeps = drv.__propagatedImpureHostDeps or [] ++ [
269         "/System/Library/PrivateFrameworks/"
270       ];
271     });
273     Carbon = lib.overrideDerivation super.Carbon (drv: {
274       extraTBDFiles = [ "Versions/A/Frameworks/HTMLRendering.framework/Versions/A/HTMLRendering.tbd" ];
275     });
277     CoreFoundation = lib.overrideDerivation super.CoreFoundation (drv: {
278       setupHook = ./cf-setup-hook.sh;
279     });
281     CoreMedia = lib.overrideDerivation super.CoreMedia (drv: {
282       __propagatedImpureHostDeps = drv.__propagatedImpureHostDeps or [] ++ [
283         "/System/Library/Frameworks/CoreImage.framework"
284       ];
285     });
287     CoreMIDI = lib.overrideDerivation super.CoreMIDI (drv: {
288       __propagatedImpureHostDeps = drv.__propagatedImpureHostDeps or [] ++ [
289         "/System/Library/PrivateFrameworks/"
290       ];
291       setupHook = ./private-frameworks-setup-hook.sh;
292     });
294     IMServicePlugIn = lib.overrideDerivation super.IMServicePlugIn (drv: {
295       extraTBDFiles = [ "Versions/A/Frameworks/IMServicePlugInSupport.framework/Versions/A/IMServicePlugInSupport.tbd" ];
296     });
298     Security = lib.overrideDerivation super.Security (drv: {
299       setupHook = ./security-setup-hook.sh;
300     });
302     QuartzCore = lib.overrideDerivation super.QuartzCore (drv: {
303       installPhase = drv.installPhase + ''
304         f="$out/Library/Frameworks/QuartzCore.framework/Headers/CoreImage.h"
305         substituteInPlace "$f" \
306           --replace "QuartzCore/../Frameworks/CoreImage.framework/Headers" "CoreImage"
307       '';
308     });
310     MetalKit = lib.overrideDerivation super.MetalKit (drv: {
311       installPhase = drv.installPhase + ''
312         mkdir -p $out/include/simd
313         cp ${lib.getDev sdk}/include/simd/*.h $out/include/simd/
314       '';
315     });
317     System = lib.overrideDerivation super.System (drv: {
318       installPhase = ''
319         mkdir -p $out/Library/Frameworks/System.framework/Versions/B
320         ln -s $out/Library/Frameworks/System.framework/Versions/{B,Current}
321         ln -s ${pkgs.darwin.Libsystem}/lib/libSystem.B.tbd $out/Library/Frameworks/System.framework/Versions/B/System.tbd
322         ln -s $out/Library/Frameworks/System.framework/{Versions/Current/,}System.tbd
323       '';
324     });
326     WebKit = lib.overrideDerivation super.WebKit (drv: {
327       extraTBDFiles = [
328         "Versions/A/Frameworks/WebCore.framework/Versions/A/WebCore.tbd"
329         "Versions/A/Frameworks/WebKitLegacy.framework/Versions/A/WebKitLegacy.tbd"
330       ];
331     });
332   } // lib.genAttrs [
333     "ContactsPersistence"
334     "CoreSymbolication"
335     "DebugSymbols"
336     "DisplayServices"
337     "GameCenter"
338     "MultitouchSupport"
339     "SkyLight"
340     "UIFoundation"
341   ]
342     (x: tbdOnlyFramework x {});
344   bareFrameworks = lib.mapAttrs framework (import ./frameworks.nix {
345     inherit frameworks libs;
346     inherit (pkgs.darwin) libobjc;
347   });
349   frameworks = bareFrameworks // overrides bareFrameworks;
351   inherit darwin-stubs;
353   objc4 = pkgs.darwin.libobjc;
355   sdkRoot = pkgs.callPackage ./sdkRoot.nix { sdkVersion = "10.12.4"; };
357   inherit (pkgs.darwin) Libsystem;
359   inherit sdk;