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

Conversation

reckenrode
Copy link
Contributor

Description of changes

This PR extracts the 12.3 SDK from #229210 by @ConnorBaker.

Note that it does not replace the refactor work I plan to do nor does it integrate the Apple OSS releases to provide headers, but I am adding the 12.3 SDK for packages that need it before the rework can land. To use the 12.3 SDK, use overrideSDK. See the MoltenVK derivation for an example. The apple_sdk.callPackage pattern is not supported.

Testing was done by updating MoltenVK to build with the 12.3 SDK.

$ nix build .#darwin.moltenvk^out
$ nix shell .#darwin.binutils --command otool -l ./result/lib/libMoltenVK.dylib | rg LC_BUILD_VERSION -A7
       cmd LC_BUILD_VERSION
   cmdsize 32
  platform 1
       sdk 12.3
     minos 11.0
    ntools 1
      tool 3
   version 951.9
$ nix build .#darwin.moltenvk^out --system x86_64-darwin
$ nix shell .#darwin.binutils --command otool -l ./result/lib/libMoltenVK.dylib | rg LC_BUILD_VERSION -A7
       cmd LC_BUILD_VERSION
   cmdsize 32
  platform 1
       sdk 12.3
     minos 10.15
    ntools 1
      tool 3
   version 951.9
$ diff -u 11.0.log 12.3.log # to show that it is using the version of MSL corresponding to the newer SDK.
--- 11.0.log	2024-07-11 20:05:24.096319472 -0400
+++ 12.3.log	2024-07-11 20:01:22.596312512 -0400
@@ -119,7 +119,7 @@
 		GPU memory available: 36864 MB
 		GPU memory used: 0 MB
 	supports the following Metal Versions, GPU's and Feature Sets:
-		Metal Shading Language 2.3
+		Metal Shading Language 2.4
 		GPU Family Apple 7
 		GPU Family Apple 6
 		GPU Family Apple 5

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@ofborg ofborg bot added the 6.topic: darwin Running or building packages on Darwin label Jul 12, 2024
Copy link
Contributor

@paparodeo paparodeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i skipped some files but from what i can tell this downloads some tarballs and unpacks them then a bunch of derivations just copies files or creates symlinks from the unpacked tarballs.

so there are just some minor nits to align with the contribution guidelines like adding pre/post hooks if the Phase is overridden.

and then it seems that many of the derivations can just be using runCommandLocal as they are just copying files out of the unpacked SDK tarball.

I marked some but the comments are about the same on every derivation so i stopped.

pkgs/os-specific/darwin/apple-sdk-12.3/libcharset.nix Outdated Show resolved Hide resolved
pkgs/os-specific/darwin/apple-sdk-12.3/libcharset.nix Outdated Show resolved Hide resolved
@ofborg ofborg bot added 10.rebuild-darwin: 101-500 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux labels Jul 12, 2024
@paparodeo
Copy link
Contributor

shouldn't there be a meta and license info somewhere in the derivations that download the sdk?

@reckenrode
Copy link
Contributor Author

shouldn't there be a meta and license info somewhere in the derivations that download the sdk?

There hasn’t been historically, and that’s not a can of worms I want to open. Putting a non-free license on big chunks of the SDK would make it effectively useless.

@reckenrode reckenrode force-pushed the darwin-sdk-12.3 branch 2 times, most recently from ff7d3eb to 7fb3f6f Compare July 12, 2024 02:36
@reckenrode
Copy link
Contributor Author

I also dropped the CoreVideo and System framework overrides since they’re not necessary anymore.

Copy link
Contributor

@paparodeo paparodeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using stdenvNoCC to be uniform across the derivations. does it actually matter? doubt it.

pkgs/os-specific/darwin/apple-sdk-12.3/libs/Xplugin.nix Outdated Show resolved Hide resolved
pkgs/os-specific/darwin/apple-sdk-12.3/libs/libDER.nix Outdated Show resolved Hide resolved
pkgs/os-specific/darwin/apple-sdk-12.3/libs/sandbox.nix Outdated Show resolved Hide resolved
pkgs/os-specific/darwin/apple-sdk-12.3/libs/simd.nix Outdated Show resolved Hide resolved
pkgs/os-specific/darwin/apple-sdk-12.3/libs/utmp.nix Outdated Show resolved Hide resolved
pkgs/os-specific/darwin/apple-sdk/default.nix Outdated Show resolved Hide resolved
pkgs/os-specific/darwin/apple-sdk-12.3/libs/xpc.nix Outdated Show resolved Hide resolved
@reckenrode reckenrode force-pushed the darwin-sdk-12.3 branch 2 times, most recently from 0054f17 to 9dbafcf Compare July 12, 2024 03:29
Making it fail at build time allows it to be used unversioned with `overrideSDK`. Unlike the QuickTime framework, which is present in the base SDK and was later removed, simd was added later.
Copy link
Contributor

@paparodeo paparodeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i started going over fframeworks/default.nix but realized large chunks are copy / paste from the sdk-11 framework (which perhaps is copy and pasted from the 10.12).

could the common code get pulled out? then i don't have to review it.

Comment on lines +22 to +25
# Below this comment are entries migrated from before the generator was
# added. If, for a given framework, you are able to reverify the extra
# deps are really necessary on top of the generator deps, move it above
# this comment (and maybe document your findings).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems unfortunate that these are not verified -- tho the top comment seems to say they are as it notes trial / error.

@reckenrode
Copy link
Contributor Author

could the common code get pulled out? then i don't have to review it.

#229210 did that, but I wanted to keep this PR narrowly scoped by not touching the other SDKs if I could avoid it.

Copy link
Contributor

@paparodeo paparodeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok -- i am not going to review frameworks/default.nix since it is copy / paste. everything else LGTM

@reckenrode
Copy link
Contributor Author

reckenrode commented Jul 12, 2024

After the change to using buildCommand, propagated build inputs stopped propagating. I added recordPropagatedDependencies manually to restore them.

I switched the derivations with hooks and propagated inputs back to using installPhase. I also dropped libcharset because that dylib is provided by libiconv.

Additionally, specify a 10.15 deployment target. According to the upstream documentation, 10.15 is the minimum macOS release supported at runtime.
@reckenrode
Copy link
Contributor Author

Pushed one last round of cleanups. Confirmed that MoltenVK builds again on x86_64-darwin.

@khaneliman
Copy link
Contributor

khaneliman commented Jul 12, 2024

Result of nixpkgs-review pr 326406 run on aarch64-darwin 1

172 packages marked as broken and skipped:
  • airshipper
  • ajour
  • ani-cli
  • anilibria-winmaclinux
  • anki
  • anki.dist
  • anki.doc
  • anki.man
  • arcan
  • arcan.dev
  • arcan.lib
  • arcan.man
  • ares
  • colloid-kde
  • colloid-kde.sddm
  • cplay-ng
  • cplay-ng.dist
  • curseradio
  • curseradio.dist
  • dmlive
  • dra-cla
  • dwl
  • dwl.man
  • eyewitness
  • ff2mpv-go
  • flet-client-flutter
  • flet-client-flutter.debug
  • flet-client-flutter.pubcache
  • flycast
  • fooyin
  • gonic
  • graphite-kde-theme
  • gruvbox-gtk-theme
  • gtk-pipe-viewer
  • gtk-pipe-viewer.devdoc
  • hydrus
  • hydrus.doc
  • invidtui
  • jellyfin-mpv-shim
  • jellyfin-mpv-shim.dist
  • kaffeine
  • ki
  • ki.dist
  • klipperscreen
  • kodiPackages.inputstream-adaptive
  • kodiPackages.inputstream-ffmpegdirect
  • kodiPackages.inputstream-rtmp
  • kodiPackages.joystick
  • kodiPackages.libretro
  • kodiPackages.libretro-2048
  • kodiPackages.libretro-fuse
  • kodiPackages.libretro-genplus
  • kodiPackages.libretro-mgba
  • kodiPackages.libretro-nestopia
  • kodiPackages.libretro-snes9x
  • kodiPackages.pvr-hdhomerun
  • kodiPackages.pvr-hts
  • kodiPackages.pvr-iptvsimple
  • kodiPackages.pvr-vdr-vnsi
  • kodiPackages.steam-controller
  • kodiPackages.vfs-libarchive
  • kodiPackages.vfs-rar
  • kodiPackages.vfs-sftp
  • kodiPackages.visualization-fishbmc
  • kodiPackages.visualization-goom
  • kodiPackages.visualization-matrix
  • kodiPackages.visualization-pictureit
  • kodiPackages.visualization-projectm
  • kodiPackages.visualization-shadertoy
  • kodiPackages.visualization-spectrum
  • kodiPackages.visualization-starburst
  • kodiPackages.visualization-waveform
  • kphotoalbum
  • labwc
  • labwc.man
  • latte-dock
  • layan-kde
  • libsForQt5.bismuth
  • libsForQt5.krohnkite
  • libsForQt5.kwin-dynamic-workspaces
  • libsForQt5.kwin-tiling
  • libsForQt5.kzones
  • libsForQt5.parachute
  • libsForQt5.tokodon
  • lightly-boehs
  • lightly-qt
  • ludusavi
  • mate.mate-wayland-session
  • mesa-demos
  • mnemosyne
  • mnemosyne.dist
  • mojave-gtk-theme
  • mov-cli
  • mov-cli.dist
  • mpc-qt
  • mpv-unwrapped
  • mpv-unwrapped.dev
  • mpv-unwrapped.doc
  • mpv-unwrapped.man
  • nightfox-gtk-theme
  • nordic
  • nordic.sddm
  • photoqt
  • pipe-viewer
  • pipe-viewer.devdoc
  • plasma5Packages.bismuth
  • plasma5Packages.krohnkite
  • plasma5Packages.kwin-dynamic-workspaces
  • plasma5Packages.kwin-tiling
  • plasma5Packages.kzones
  • plasma5Packages.parachute
  • plasma5Packages.tokodon
  • python311Packages.flet
  • python311Packages.flet-runtime
  • python311Packages.flet-runtime.dist
  • python311Packages.flet.dist
  • python311Packages.mpv
  • python311Packages.mpv.dist
  • python311Packages.py3status
  • python311Packages.py3status.dist
  • python311Packages.python-vlc
  • python311Packages.python-vlc.dist
  • python311Packages.qtile-extras
  • python311Packages.qtile-extras.dist
  • python312Packages.flet
  • python312Packages.flet-runtime
  • python312Packages.flet-runtime.dist
  • python312Packages.flet.dist
  • python312Packages.mpv
  • python312Packages.mpv.dist
  • python312Packages.py3status
  • python312Packages.py3status.dist
  • python312Packages.python-vlc
  • python312Packages.python-vlc.dist
  • python312Packages.qtile-extras
  • python312Packages.qtile-extras.dist
  • qogir-kde
  • rivercarro
  • scenefx
  • shairport-sync
  • snapshot
  • somafm-cli
  • sublime-music
  • sublime-music.dist
  • subtitleedit
  • supersonic
  • sway-contrib.grimshot
  • sway-contrib.grimshot.man
  • tokyonight-gtk-theme
  • tomato-c
  • utterly-nord-plasma
  • vimix-gtk-themes
  • vulkan-caps-viewer
  • waybox
  • wayfire
  • wayfirePlugins.firedecor
  • wayfirePlugins.focus-request
  • wayfirePlugins.wayfire-plugins-extra
  • wayfirePlugins.wayfire-shadows
  • wayfirePlugins.wcm
  • wayfirePlugins.wf-shell
  • wayfirePlugins.windecor
  • wayfirePlugins.wwp-switcher
  • whitesur-gtk-theme
  • whitesur-kde
  • wio
  • wtwitch
  • xarcan
  • youtube-tui
  • ytfzf
  • ytui-music
  • zed-editor
1 package failed to build:
  • rerun
22 packages built:
  • bite
  • darwin.moltenvk
  • darwin.moltenvk.bin
  • darwin.moltenvk.dev
  • dolphin-emu
  • fastfetch
  • fastfetch.man
  • gfxstream
  • halloy
  • koboldcpp
  • libplacebo
  • libplacebo_5
  • moonlight-qt
  • ncnn
  • rbdoom-3-bfg
  • realesrgan-ncnn-vulkan
  • rutabaga_gfx
  • vkquake
  • vulkan-loader
  • vulkan-loader.dev
  • vulkan-tools
  • wgpu-utils
Executing cargoCheckHook
++ cargo test -j 10 --profile release --target aarch64-apple-darwin --offline -p rerun --workspace --exclude=crates/rerun/src/lib.rs -- --test-threads=10
warning: `/private/tmp/nix-build-rerun-0.13.0.drv-0/.cargo/config` is deprecated in favor of `config.toml`
note: if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml`
warning: `/private/tmp/nix-build-rerun-0.13.0.drv-0/.cargo/config` is deprecated in favor of `config.toml`
note: if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml`
error: package ID specification `crates/rerun/src/lib.rs` looks like a file path, maybe try file:///private/tmp/nix-build-rerun-0.13.0.drv-0/source/crates/rerun/src/lib.rs

@paparodeo
Copy link
Contributor

paparodeo commented Jul 12, 2024

Result of nixpkgs-review pr 326406 run on aarch64-darwin 1
172 packages marked as broken and skipped:
1 package failed to build:
22 packages built:

rerun, the failed build, is broken on master

$ hydra-check rerun --arch aarch64-darwin --short --channel master
Build Status for rerun.aarch64-darwin on master
✖ (Failed) rerun-0.13.0 from 2024-07-07 - https://hydra.nixos.org/build/265352979

@khaneliman
Copy link
Contributor

khaneliman commented Jul 12, 2024

Result of nixpkgs-review pr 326406 run on aarch64-darwin 1
172 packages marked as broken and skipped:
1 package failed to build:
22 packages built:

rerun, the failed build, is broken on master

$ hydra-check rerun --arch aarch64-darwin --short --channel master
Build Status for rerun.aarch64-darwin on master
✖ (Failed) rerun-0.13.0 from 2024-07-07 - https://hydra.nixos.org/build/265352979

Sounds good, thanks for double checking (and thanks for a new cli tool i need to use more often)

@reckenrode reckenrode merged commit d8fb075 into NixOS:master Jul 12, 2024
24 of 26 checks passed
@reckenrode reckenrode deleted the darwin-sdk-12.3 branch July 12, 2024 20:12
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/darwin-updates-news/42249/14

@gador
Copy link
Member

gador commented Jul 31, 2024

I just tried to use the 12.3 apple_sdk in a python package by replacing darwin.apple_sdk.frameworks with darwin.apple_sdk_12_3.frameworks for Cocoa. Unfortunatly I got an error:

/nix/store/cnadxdgni5j0kavkis3q32wb1l7vsdnq-apple-framework-CoreData-12.3/Library/Frameworks/CoreData.framework/Headers/NSPersistentCloudKitContainerOptions.h:12:9: fatal error: 'CloudKit/CKDatabase.h' file not found

Do you have an idea? Fixed by manually adding CloudKit to the buildInputs

Now I'm getting the following error:

/nix/store/izq09jq3hyh53y2ha8x3hn7bfhivz6w5-apple-framework-IOKit-12.3/Library/Frameworks/IOKit.framework/Headers/OSMessageNotification.h:120:53: error: expected ';' after top level declarator

Maybe you have an idea?

@gador
Copy link
Member

gador commented Jul 31, 2024

just found your comment #329653 (comment) on the same issue with IOKit. Is this the same issue here as it is with rust?

@reckenrode
Copy link
Contributor Author

reckenrode commented Jul 31, 2024

CoreData should probably include CloudKit as one of its propagated frameworks. I submitted #331378 to fix that. The IOKit issue is probably the same as the Rust issue. Are you using overrideSDK?

@gador
Copy link
Member

gador commented Aug 1, 2024

Are you using overrideSDK?

No, I used:

buildPythonPackage rec {
[...]
  buildInputs =
    [...]
    ++ lib.optionals stdenv.isDarwin (
      with darwin.apple_sdk_12_3.frameworks;
      [
        Cocoa
      ]
    )

(from materialx)

@reckenrode
Copy link
Contributor Author

overrideSDK needs to be used to override the SDK version in the stdenv. It will replace all dependencies with the correct versions. Otherwise, Python will use a clang with an incompatible libSystem, which is causes the failures you’re seeing with IOKit. In your derivation, you can set the result to if stdenv.isDarwin then overrideSDK stdenv "12.3" else stdenv;.

See https://discourse.nixos.org/t/darwin-updates-news/42249/14 for more on using overrideSDK with the 12.3 SDK.

@gador
Copy link
Member

gador commented Aug 2, 2024

@reckenrode thanks. I've read through your article and through the code example. However I am not sure how to apply that to buildPythonPackage. My understanding is that I'll need stdenv.mkDerivation to use overrideSDK, right?

@reckenrode
Copy link
Contributor Author

buildPythonPackage takes a stdenv argument. You can override the stdenv used by it that way. pybind11 is an example (though it probably should be updated to use overrideSDK).

@gador
Copy link
Member

gador commented Aug 3, 2024

thanks! That was helpful. I did override stdenv but the error stayed the same. Maybe it is something unrelated to this SDK?
For reference, this is what I did:

let
  stdenv' =
    if stdenv.isDarwin then overrideSDK stdenv "12.3" else stdenv;
in
buildPythonPackage rec {
[...]
  stdenv = stdenv';
[...]

When building, it builds all the 12_3 related frameworks, so I'm pretty sure it overrides the stdenv as it should

@reckenrode
Copy link
Contributor Author

That looks right. Is the package materialx or a different one you’re working on? I‘m working on a Darwin refactor that changes how the SDKs work quite a bit. I’m looking for test cases if this is one that doesn’t work with overrideSDK.

(I realize this doesn’t help with your problem. What you’re doing should be update the stdenv, but it’s clearly still using the wrong libSystem, which is breaking your build. It may be this is another case that will be fixed once the refactor lands.)

@datner
Copy link

datner commented Aug 4, 2024

I'm sorry if its unrelated, I am quite confident it is but I am also not savvy enough with nix to know with certainty.
I am developing an application that needs some very new apple-sdk features, specifically webview proxy api from the NetworkExtension framework (I guess technically the Network framework, extended), thats my context.
I am willing to introduce impurity or whatever else is necessary to just link my system framework to my nix env. Is the refactor related solving cases like mine so that no workaround would be required? Is there something I can do until it lands?
Again, sorry if I'm totally off here

@gador
Copy link
Member

gador commented Aug 4, 2024

That looks right. Is the package materialx or a different one you’re working on?

Yes, it's materialx.

I‘m working on a Darwin refactor that changes how the SDKs work quite a bit. I’m looking for test cases if this is one that doesn’t work with overrideSDK.

(I realize this doesn’t help with your problem. What you’re doing should be update the stdenv, but it’s clearly still using the wrong libSystem, which is breaking your build. It may be this is another case that will be fixed once the refactor lands.)

I have time. I just follow your darwin Updates thread in discourse and thought I give it a try. materialx (and some packages related to blender) benefit from newer frameworks to access hardware based acceleration and I give it a try from time to time 😉
Maybe materialx would be a good test case. If I can help test stuff, just let me know 👍

@reckenrode
Copy link
Contributor Author

Is the refactor related solving cases like mine so that no workaround would be required? Is there something I can do until it lands?

As part of the Darwin refactor, the following SDKs will be added: 10.12.2, 10.13.2, 10.14.6, 10.15.6, 11.3, 12.3, 13.3, 14.4. I assume one of those should have the APIs you need.

There are two parts to the refactor:

  1. Moving all SDKs to a common pattern. This is where the “refactor” originates. There are currently three different ways of building the SDKs, and only one of them incorporates any of the source releases. Historically, updating the SDK is very difficult. The new pattern makes this easier and incorporates the source releases in all SDKs.
  2. Improving the usability of non-default SDKs. There are two ways to do it currently: apple_sdk_11_0.callPackage and overrideSDK. Neither is capable of working generally for all cases. That’s what motivated me to expand the refactor from just consolidating SDKs to a common pattern to improving the way they are used in nixpkgs.

Once the refactor lands, overriding SDKs will work by adding the required SDK as a build input. The SDK has all the required frameworks and xcrun. If multiple SDKs are used (e.g., propagated from a dependency), the highest one will be used. It is also possible to set the deployment target. The hook follows the same rules to determine which version is set (e.g., Qt could propagate an 11.0 deployment target because it requires 11.0). The old frameworks will be kept for compatibility, but they’ll be stubs. They’ll be deprecated and removed over the next few years to minimize breakage.

buildInputs = lib.optionals stdenv.isDarwin [ apple-sdk_14 (darwinMinVersionHook "10.15") ];

Unfortunately, there’s probably not much you can do until this lands. You might be able to use xcodeenv, but I’m not very familiar with it.

I have time. I just follow your darwin Updates thread in discourse and thought I give it a try. materialx (and some packages related to blender) benefit from newer frameworks to access hardware based acceleration and I give it a try from time to time 😉
Maybe materialx would be a good test case. If I can help test stuff, just let me know 👍

I confirmed that MaterialX built using the above build inputs. Checking the shared objects in the result shows they are linked against the 14.4 SDK.

I have the SDKs building and some packages building with them (now including MaterialX). It’s possible the refactor could make the next staging-next cycle, but that’s very unlikely. The one after is more likely, and making 24.11 is almost definitely. I still need to implement the hooks to implement resolution and get the bootstrap working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: darwin Running or building packages on Darwin 10.rebuild-darwin: 101-500 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants