Skip to content

Commit

Permalink
mpv: enable swift support
Browse files Browse the repository at this point in the history
  • Loading branch information
stephank committed Nov 15, 2022
1 parent 60377b2 commit 4ce183c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions pkgs/applications/video/mpv/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
, sdl2Support ? true, SDL2
, sixelSupport ? false, libsixel
, speexSupport ? true, speex
, swiftSupport ? false, swift
, swiftSupport ? stdenv.isDarwin, swift, xcbuild
, theoraSupport ? true, libtheora
, vaapiSupport ? stdenv.isLinux, libva
, vapoursynthSupport ? false, vapoursynth
Expand Down Expand Up @@ -100,6 +100,11 @@ in stdenv.mkDerivation rec {
NIX_LDFLAGS = lib.optionalString x11Support "-lX11 -lXext "
+ lib.optionalString stdenv.isDarwin "-framework CoreFoundation";

preConfigure = lib.optionalString swiftSupport ''
# Ensure we reference 'lib' (not 'out') of Swift.
export SWIFT_LIB_DYNAMIC=${swift.swift.lib}/lib/swift/macosx

This comment has been minimized.

Copy link
@Atemu

Atemu Dec 7, 2022

Would every package needs this?

This comment has been minimized.

Copy link
@stephank

stephank Dec 11, 2022

Author Owner

I hope not, but it does depend a little on what we end up packaging in Nixpkgs. It works out of the box for builds that link with the Swift compiler or builds that use SwiftPM, but I expect those are only simple cli tools and daemons written in Swift. We don't yet do any Xcode project builds, but I hope we can also support those out-of-the-box. That would also cover native Swift GUI apps.

MPV's case is a custom build system where Swift is used to build some objects, then the link step is something separate. So MPVs build system is responsible for finding and linking Swift stdlib. Its default behavior is to do a lookup relative to swift. (EDIT: Should point out, this does just work, but adds the Swift compiler to the closure.)

I believe that sort of check is broken, but it's not necessarily MPVs fault. Swift sets some precendent for doing things this way. It even does it in SwiftPMs own code, which I patched. So that's annoying.

As for what is the proper way to detect the stdlib location, I think that should be swift -frontend -print-target-info. But I don't think the format is decently specified anywhere, and JSON isn't really straight-forward to consume from shell scripts.

So the situation is kind of meh. I don't know how many MPV-style builds we'll encounter in Nixpkgs in the future, but it also doesn't sound unusual for the category 'portable FOSS' that MPV fits in. If we opened up the path to packaging a whole bunch of native Mac FOSS, though, I expect more smooth sailing.

This comment has been minimized.

Copy link
@Atemu

Atemu Dec 11, 2022

Thank you for the insight!

'';

# These flags are not supported and cause the build
# to fail, even when cross compilation itself works.
dontAddWafCrossFlags = true;
Expand All @@ -120,8 +125,7 @@ in stdenv.mkDerivation rec {
(lib.enableFeature vaapiSupport "vaapi")
(lib.enableFeature waylandSupport "wayland")
(lib.enableFeature stdenv.isLinux "dvbin")
] # Disable whilst Swift isn't supported
++ lib.optional (!swiftSupport) "--disable-macos-cocoa-cb";
] ++ lib.optional (!swiftSupport) "--disable-macos-cocoa-cb";

nativeBuildInputs = [
addOpenGLRunpath
Expand All @@ -131,7 +135,7 @@ in stdenv.mkDerivation rec {
python3
wafHook
which
] ++ lib.optionals swiftSupport [ swift ]
] ++ lib.optionals swiftSupport [ swift xcbuild.xcrun ]
++ lib.optionals waylandSupport [ wayland-scanner ];

buildInputs = [
Expand Down
4 changes: 2 additions & 2 deletions pkgs/os-specific/darwin/apple-sdk-11.0/frameworks.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ frameworks, libs, libobjc, libnetwork }: with frameworks; with libs;
{
AGL = { inherit Carbon OpenGL; };
AVFoundation = { inherit ApplicationServices AVFCapture AVFCore CoreGraphics simd UniformTypeIdentifiers; };
AVFoundation = { inherit ApplicationServices AVFCapture AVFCore CoreGraphics CoreMedia simd UniformTypeIdentifiers; };
AVKit = {};
Accelerate = { inherit CoreWLAN IOBluetooth; };
Accessibility = {};
Expand Down Expand Up @@ -112,7 +112,7 @@
MapKit = {};
MediaAccessibility = { inherit CoreGraphics CoreText QuartzCore; };
MediaLibrary = {};
MediaPlayer = {};
MediaPlayer = { inherit AVFoundation; };
MediaToolbox = { inherit AudioToolbox AudioUnit CoreMedia; };
Message = {};
Metal = {};
Expand Down

0 comments on commit 4ce183c

Please sign in to comment.