Mpv: macOS: build fails with swift errors (workaround included), update Swift 3 to 4/5

Created on 29 Jan 2019  Ā·  16Comments  Ā·  Source: mpv-player/mpv

mpv version and platform

mpv https://github.com/mpv-player/mpv/commit/f2e7e81bda653c1f2cb3b27cf867e9195d184ddc
macOS Mojave 10.14.4 Beta (18E174f)

Reproduction steps

  1. Run the compilation steps.

Expected behavior

mpv compiles.

Actual behavior

mpv doesn't compile, because Xcode 10.2 doesn't ship with a compiler that supports Swift 3. Would you like me to migrate the code to Swift 5?

Log file



Compilation log

$ ./bootstrap.py
Downloading https://waf.io/waf-2.0.9...
Checksum verified.
$ ./waf configure
Setting top to                           : /Users/saagarjha/Git/mpv
Setting out to                           : /Users/saagarjha/Git/mpv/build
Checking for waf version in 1.8.4-2.1.0  : ok
Checking for program 'cc'                : /usr/bin/cc
Checking for program 'pkg-config'        : /opt/local/bin/pkg-config
Checking for program 'ar'                : /opt/local/bin/ar
Checking for program 'rst2html'          : not found
Checking for program 'rst2man'           : not found
Checking for program 'rst2pdf'           : not found
Checking for program 'windres'           : not found
Checking for program 'perl'              : /opt/local/bin/perl
Checking for 'clang' (C compiler)        : /usr/bin/cc
Detected target OS:                      : os-darwin
Checking for macOS SDK                   : /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
Checking for swift (Swift compiler)      : /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift
Checking for Swift Library               : /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift_static/macosx
Checking for compiler flags -Werror=implicit-function-declaration : yes
Checking for compiler flags -Wno-error=deprecated-declarations    : yes
Checking for compiler flags -Wno-error=unused-function            : yes
Checking for compiler flags -Wempty-body                          : yes
Checking for compiler flags -Wdisabled-optimization               : yes
Checking for compiler flags -Wstrict-prototypes                   : yes
Checking for compiler flags -Wno-format-zero-length               : yes
Checking for compiler flags -Werror=format-security               : yes
Checking for compiler flags -Wno-redundant-decls                  : yes
Checking for compiler flags -Wvla                                 : yes
Checking for LGPL (version 2.1 or later) build                    : disabled
Checking for GPL (version 2 or later) build                       : yes
Checking for internal audio filter chain                          : yes
Checking for mpv CLI player                                       : yes
Checking for shared library                                       : disabled
Checking for static library                                       : disabled
Checking for static build                                         : disabled
Checking for whether to include binary compile time               : yes
Checking for whether to optimize                                  : yes
Checking for whether to compile-in debugging information          : yes
Checking for manpage generation                                   : no (missing RST2MAN)
Checking for html manual generation                               : disabled
Checking for pdf manual generation                                : disabled
Checking for dynamic loader                                       : yes
Checking for C plugins                                            : yes
Checking for zsh completion                                       : disabled
Checking for inline assembly (currently without effect)           : yes
Checking for test suite (using cmocka)                            : disabled
Checking for generate a clang compilation database                : disabled
Checking for compiler support for noexecstack                     : no
Checking for linker support for --nxcompat --no-seh --dynamicbase : no
Checking for -lm                                                  : yes
Checking for MinGW                                                : os-win32 not found
Checking for POSIX environment                                    : yes
Checking for Android environment                                  : no
Checking for Android EGL support                                  : android not found
Checking for development environment                              : yes
Checking for macOS Swift build tools                              : yes (version found: 5.0)
Checking for Universal Windows Platform                           : disabled
Checking for win32 desktop APIs                                   : os-win32 not found
Checking for internal pthread wrapper for win32 (Vista+)          : posix found
Checking for POSIX threads                                        : yes
Checking for GNU C extensions                                     : yes
Checking for stdatomic.h                                          : yes
Checking for stdatomic.h support or slow emulation                : yes
Checking for linking with -lrt                                    : no
Checking for iconv                                                : yes
Checking for w32/dos paths                                        : os-win32 not found
Checking for spawnp()/kill() POSIX support                        : yes
Checking for spawnp()/kill() Android replacement                  : posix-spawn-native found
Checking for any spawnp()/kill() support                          : yes
Checking for Windows pipe support                                 : posix found
Checking for glob() POSIX support                                 : yes
Checking for glob() win32 replacement                             : posix found
Checking for any glob() support                                   : yes
Checking for fchmod()                                             : yes
Checking for vt.h                                                 : no
Checking for gbm.h                                                : no
Checking for GLIBC API for setting thread name                    : no
Checking for OSX API for setting thread name                      : yes
Checking for BSD API for setting thread name                      : osx-thread-name found
Checking for BSD's fstatfs()                                      : yes
Checking for Linux's fstatfs()                                    : os-linux not found
Checking for Samba support (makes mpv GPLv3)                      : disabled
Checking for Lua                                                  : yes (version found: 52fbsd)
Checking for Javascript (MuJS backend)                            : no ('mujs >= 1.0.0' not found)
Checking for SSA/ASS support                                      : yes
Checking for libass OSD support                                   : yes
Checking for dummy OSD support                                    : libass-osd found
Checking for zlib                                                 : yes
Checking for Bluray support                                       : yes
Checking for dvdread support                                      : disabled
Checking for dvdnav support                                       : disabled
Checking for DVD/IFO support                                      : dvdread not found
Checking for cdda support (libcdio)                               : disabled
Checking for uchardet support                                     : yes
Checking for librubberband support                                : yes
Checking for LCMS2 support                                        : yes
Checking for VapourSynth filter bridge (Python)                   : no ('vapoursynth >= 24 vapoursynth-script >= 23' not found)
Checking for VapourSynth filter bridge (Lazy Lua)                 : no ('vapoursynth >= 24' not found)
Checking for VapourSynth filter bridge (core)                     : vapoursynth not found
Checking for libarchive wrapper for reading zip files and more    : yes
Checking for SDL2                                                 : disabled
Checking for OSS                                                  : no
Checking for RSound audio output                                  : no
Checking for sndio audio input/output                             : disabled
Checking for PulseAudio audio output                              : no ('libpulse >= 1.0' not found)
Checking for JACK audio output                                    : no ('jack' not found)
Checking for OpenAL audio output                                  : disabled
Checking for OpenSL ES audio output                               : no
Checking for ALSA audio output                                    : no ('alsa >= 1.0.18' not found)
Checking for CoreAudio audio output                               : yes
Checking for AudioUnit output for iOS                             : no
Checking for WASAPI audio output                                  : os-win32 not found
Checking for Cocoa                                                : yes
Checking for DRM                                                  : vt.h not found
Checking for DRM Prime ffmpeg support                             : yes
Checking for GBM                                                  : gbm.h not found
Checking for wayland-scanner                                      : no
Checking for wayland-protocols                                    : no ('wayland-protocols >= 1.15' not found)
Checking for Wayland                                              : wayland-protocols not found
Checking for X11                                                  : no ('x11 >= 1.0.0 xscrnsaver >= 1.0.0 xext >= 1.0.0 xinerama >= 1.0.0 xrandr >= 1.2.0' not found)
Checking for Xv video output                                      : x11 not found
Checking for OpenGL Cocoa Backend                                 : yes
Checking for OpenGL X11 Backend                                   : x11 not found
Checking for OpenGL X11 EGL Backend                               : x11 not found
Checking for OpenGL DRM EGL Backend                               : drm not found
Checking for OpenGL Wayland Backend                               : wayland not found
Checking for OpenGL Win32 Backend                                 : win32-desktop not found
Checking for OpenGL/DirectX Interop Backend                       : gl-win32 not found
Checking for OpenGL ANGLE headers                                 : os-win32 not found
Checking for OpenGL Win32 ANGLE Library                           : egl-angle not found
Checking for OpenGL Win32 ANGLE Backend                           : egl-angle not found
Checking for VDPAU acceleration                                   : x11 not found
Checking for VDPAU with OpenGL/X11                                : vdpau not found
Checking for VAAPI acceleration                                   : x11 not found
Checking for VAAPI (X11 support)                                  : vaapi not found
Checking for VAAPI (Wayland support)                              : vaapi not found
Checking for VAAPI (DRM/EGL support)                              : vaapi not found
Checking for VAAPI GLX                                            : vaapi-x11 not found
Checking for VAAPI EGL on X11                                     : vaapi-x11 not found
Checking for VAAPI EGL                                            : vaapi-x-egl not found
Checking for CACA                                                 : no ('caca >= 0.99.beta18' not found)
Checking for JPEG support                                         : yes
Checking for Direct3D support                                     : win32-desktop not found
Checking for libshaderc SPIR-V compiler (shared library)          : no
Checking for libshaderc SPIR-V compiler (static library)          : no
Checking for libshaderc SPIR-V compiler                           : shaderc-shared not found
Checking for libcrossc SPIR-V translator                          : no ('crossc' not found)
Checking for Direct3D 11 video output                             : win32-desktop not found
Checking for Raspberry Pi support                                 : no
Checking for iOS OpenGL ES hardware decoding interop support      : no
Checking for OpenGL without platform-specific code (e.g. for libmpv) : libmpv-shared not found
Checking for MALI via Linux fbdev                                    : no
Checking for OpenGL context support                                  : yes
Checking for Vulkan context support                                  : shaderc not found
Checking for EGL helper functions                                    : egl-x11 not found
Checking for FFmpeg/Libav present                                    : yes
Checking for libav* is FFmpeg                                        : yes
Checking for libav* is Libav                                         : no
Checking for Libav/FFmpeg library versions                           : yes
Checking for libavdevice                                             : yes
Checking for libavcodec videotoolbox hwaccel                         : yes
Checking for Videotoolbox with OpenGL                                : yes
Checking for D3D11VA hwaccel                                         : os-win32 not found
Checking for DXVA2 hwaccel                                           : d3d-hwaccel not found
Checking for OpenGL/DirectX Interop Backend DXVA2 interop            : gl-dxinterop not found
Checking for CUDA Headers and dynamic loader                         : no ('ffnvcodec >= 8.2.15.3' not found)
Checking for CUDA hwaccel                                            : ffnvcodec not found
Checking for TV interface                                            : disabled
Checking for videoio.h                                               : tv not found
Checking for videodev2.h                                             : tv not found
Checking for Video4Linux2 TV interface                               : tv not found
Checking for libv4l2 support                                         : tv-v4l2 not found
Checking for audio input support                                     : tv-v4l2 not found
Checking for DVB input module                                        : disabled
Checking for w32 executable                                          : os-win32 not found
Checking for Apple Remote support                                    : yes
Checking for macOS Touch Bar support                                 : yes
Checking for macOS opengl-cb backend                                 : yes
Writing configuration header:                                        : config.h
'configure' finished successfully (9.760s)
$ ./waf
Waf: Entering directory `/Users/saagarjha/Git/mpv/build'
[1/1] Compiling version.sh
[  2/219] Processing osdep/macOS_swift.o,osdep/macOS_swift.h,osdep/macOS_swift.swiftmodule: osdep/macOS_mpv_helper.swift video/out/cocoa-cb/events_view.swift video/out/cocoa-cb/video_layer.swift video/out/cocoa-cb/window.swift video/out/cocoa_cb_common.swift -> build/osdep/macOS_swift.o build/osdep/macOS_swift.h build/osdep/macOS_swift.swiftmodule
[  3/219] Compiling TOOLS/osxbundle/mpv.app/Contents/Resources/icon.icns
[  4/219] Compiling etc/mpv-icon-8bit-16x16.png
[  5/219] Compiling etc/mpv-icon-8bit-32x32.png
[  6/219] Compiling etc/mpv-icon-8bit-64x64.png
[  7/219] Compiling etc/mpv-icon-8bit-128x128.png
[  8/219] Compiling etc/input.conf
[  9/219] Compiling etc/builtin.conf
[ 10/219] Compiling sub/osd_font.otf
[ 11/219] Compiling player/lua/defaults.lua
[ 12/219] Compiling player/lua/assdraw.lua
[ 13/219] Compiling player/lua/options.lua
[ 14/219] Compiling player/lua/osc.lua
[ 15/219] Compiling player/lua/ytdl_hook.lua
[ 16/219] Compiling player/lua/stats.lua
[ 17/219] Compiling player/javascript/defaults.js
[ 18/219] Creating build/ebml_types.h
[ 19/219] Creating build/ebml_defs.c
[ 20/219] Compiling libmpv/mpv.def
<unknown>:0: error: invalid value '3' in '-swift-version 3'
<unknown>:0: note: valid arguments to '-swift-version' are '4', '4.2', '5'
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/events_view.swift:37:30: error: 'viewWidthSizable' has been renamed to 'width'
        autoresizingMask = [.viewWidthSizable, .viewHeightSizable]
                             ^~~~~~~~~~~~~~~~
                             width
AppKit.NSView:21:27: note: 'viewWidthSizable' was obsoleted in Swift 4
        public static var viewWidthSizable: NSView.AutoresizingMask { get }
                          ^
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/events_view.swift:37:49: error: 'viewHeightSizable' has been renamed to 'height'
        autoresizingMask = [.viewWidthSizable, .viewHeightSizable]
                                                ^~~~~~~~~~~~~~~~~
                                                height
AppKit.NSView:36:27: note: 'viewHeightSizable' was obsoleted in Swift 4
        public static var viewHeightSizable: NSView.AutoresizingMask { get }
                          ^
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/events_view.swift:39:9: error: 'register(forDraggedTypes:)' has been renamed to 'registerForDraggedTypes(_:)'
        register(forDraggedTypes: [NSFilenamesPboardType, NSURLPboardType])
        ^~~~~~~~ ~~~~~~~~~~~~~~~~~
        registerForDraggedTypes
AppKit.NSView:10:15: note: 'register(forDraggedTypes:)' was obsoleted in Swift 4
    open func register(forDraggedTypes newTypes: [NSPasteboard.PasteboardType])
              ^
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/events_view.swift:39:36: error: 'NSFilenamesPboardType' is unavailable in Swift: use 'PasteboardType.fileURL'
        register(forDraggedTypes: [NSFilenamesPboardType, NSURLPboardType])
                                   ^~~~~~~~~~~~~~~~~~~~~
AppKit.NSFilenamesPboardType:4:12: note: 'NSFilenamesPboardType' has been explicitly marked unavailable here
public let NSFilenamesPboardType: NSPasteboard.PasteboardType
           ^
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/events_view.swift:39:59: error: 'NSURLPboardType' is unavailable in Swift: use 'PasteboardType.url'
        register(forDraggedTypes: [NSFilenamesPboardType, NSURLPboardType])
                                                          ^~~~~~~~~~~~~~~
AppKit.NSURLPboardType:4:12: note: 'NSURLPboardType' has been explicitly marked unavailable here
public let NSURLPboardType: NSPasteboard.PasteboardType
           ^
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/events_view.swift:62:52: error: cannot call value of non-function type 'NSPasteboard'
        guard let types = sender.draggingPasteboard().types else { return [] }
                          ~~~~~~~~~~~~~~~~~~~~~~~~~^~

/Users/saagarjha/Git/mpv/video/out/cocoa-cb/events_view.swift:70:43: error: cannot call value of non-function type 'NSPasteboard'
        let pb = sender.draggingPasteboard()
                 ~~~~~~~~~~~~~~~~~~~~~~~~~^~

/Users/saagarjha/Git/mpv/video/out/cocoa-cb/events_view.swift:71:52: error: cannot call value of non-function type 'NSPasteboard'
        guard let types = sender.draggingPasteboard().types else { return false }
                          ~~~~~~~~~~~~~~~~~~~~~~~~~^~

/Users/saagarjha/Git/mpv/video/out/cocoa-cb/events_view.swift:193:12: warning: 'fabs' is deprecated: renamed to 'abs'
        if fabs(event.deltaY) >= fabs(event.deltaX) {
           ^
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/events_view.swift:193:12: note: use 'abs' instead
        if fabs(event.deltaY) >= fabs(event.deltaX) {
           ^~~~
           abs
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/events_view.swift:193:34: warning: 'fabs' is deprecated: renamed to 'abs'
        if fabs(event.deltaY) >= fabs(event.deltaX) {
                                 ^
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/events_view.swift:193:34: note: use 'abs' instead
        if fabs(event.deltaY) >= fabs(event.deltaX) {
                                 ^~~~
                                 abs
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/events_view.swift:217:16: warning: 'fabs' is deprecated: renamed to 'abs'
            if fabs(deltaY) >= fabs(deltaX) {
               ^
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/events_view.swift:217:16: note: use 'abs' instead
            if fabs(deltaY) >= fabs(deltaX) {
               ^~~~
               abs
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/events_view.swift:217:32: warning: 'fabs' is deprecated: renamed to 'abs'
            if fabs(deltaY) >= fabs(deltaX) {
                               ^
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/events_view.swift:217:32: note: use 'abs' instead
            if fabs(deltaY) >= fabs(deltaX) {
                               ^~~~
                               abs
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/window.swift:95:29: error: 'NSWindowStyleMask' has been renamed to 'NSWindow.StyleMask'
    override var styleMask: NSWindowStyleMask {
                            ^~~~~~~~~~~~~~~~~
                            NSWindow.StyleMask
AppKit.NSWindowStyleMask:2:18: note: 'NSWindowStyleMask' was obsoleted in Swift 4
public typealias NSWindowStyleMask = NSWindow.StyleMask
                 ^
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/window.swift:95:18: error: property does not override any property from its superclass
    override var styleMask: NSWindowStyleMask {
    ~~~~~~~~     ^
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/window.swift:602:10: warning: instance method 'windowShouldClose' nearly matches optional requirement 'windowShouldClose' of protocol 'NSWindowDelegate'
    func windowShouldClose(_ sender: Any) -> Bool {
         ^
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/window.swift:602:10: note: candidate has non-matching type '(Any) -> Bool'
    func windowShouldClose(_ sender: Any) -> Bool {
         ^
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/window.swift:602:10: note: move 'windowShouldClose' to an extension to silence this warning
    func windowShouldClose(_ sender: Any) -> Bool {
         ^
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/window.swift:602:10: note: make 'windowShouldClose' private to silence this warning
    func windowShouldClose(_ sender: Any) -> Bool {
         ^
    private
AppKit.NSWindowDelegate:2:19: note: requirement 'windowShouldClose' declared here
    optional func windowShouldClose(_ sender: NSWindow) -> Bool
                  ^
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/window.swift:89:75: error: 'NSWindowButton' has been renamed to 'NSWindow.ButtonType'
        get { return ([.closeButton, .miniaturizeButton, .zoomButton] as [NSWindowButton]).flatMap { standardWindowButton($0) } }
                                                                          ^~~~~~~~~~~~~~
                                                                          NSWindow.ButtonType
AppKit.NSWindowButton:2:18: note: 'NSWindowButton' was obsoleted in Swift 4
public typealias NSWindowButton = NSWindow.ButtonType
                 ^
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/window.swift:89:75: error: 'NSWindowButton' has been renamed to 'NSWindow.ButtonType'
        get { return ([.closeButton, .miniaturizeButton, .zoomButton] as [NSWindowButton]).flatMap { standardWindowButton($0) } }
                                                                          ^~~~~~~~~~~~~~
                                                                          NSWindow.ButtonType
AppKit.NSWindowButton:2:18: note: 'NSWindowButton' was obsoleted in Swift 4
public typealias NSWindowButton = NSWindow.ButtonType
                 ^
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/window.swift:125:34: error: argument of '#selector' refers to instance method 'setHalfWindowSize()' that is not exposed to Objective-C
            app.menuBar.register(#selector(setHalfWindowSize), for: MPM_H_SIZE)
                                 ^         ~~~~~~~~~~~~~~~~~
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/window.swift:566:10: note: add '@objc' to expose this instance method to Objective-C
    func setHalfWindowSize()   { setWindowScale(0.5) }
         ^
    @objc
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/window.swift:126:34: error: argument of '#selector' refers to instance method 'setNormalWindowSize()' that is not exposed to Objective-C
            app.menuBar.register(#selector(setNormalWindowSize), for: MPM_N_SIZE)
                                 ^         ~~~~~~~~~~~~~~~~~~~
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/window.swift:565:10: note: add '@objc' to expose this instance method to Objective-C
    func setNormalWindowSize() { setWindowScale(1.0) }
         ^
    @objc
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/window.swift:127:34: error: argument of '#selector' refers to instance method 'setDoubleWindowSize()' that is not exposed to Objective-C
            app.menuBar.register(#selector(setDoubleWindowSize), for: MPM_D_SIZE)
                                 ^         ~~~~~~~~~~~~~~~~~~~
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/window.swift:567:10: note: add '@objc' to expose this instance method to Objective-C
    func setDoubleWindowSize() { setWindowScale(2.0) }
         ^
    @objc
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/window.swift:144:46: error: 'viewWidthSizable' has been renamed to 'width'
        titleBarEffect!.autoresizingMask = [.viewWidthSizable, .viewMinYMargin]
                                             ^~~~~~~~~~~~~~~~
                                             width
AppKit.NSView:21:27: note: 'viewWidthSizable' was obsoleted in Swift 4
        public static var viewWidthSizable: NSView.AutoresizingMask { get }
                          ^
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/window.swift:144:65: error: 'viewMinYMargin' has been renamed to 'minYMargin'
        titleBarEffect!.autoresizingMask = [.viewWidthSizable, .viewMinYMargin]
                                                                ^~~~~~~~~~~~~~
                                                                minYMargin
AppKit.NSView:31:27: note: 'viewMinYMargin' was obsoleted in Swift 4
        public static var viewMinYMargin: NSView.AutoresizingMask { get }
                          ^
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/window.swift:178:46: error: 'NSAppearanceNameVibrantLight' has been renamed to 'NSAppearance.Name.vibrantLight'
            appearance = NSAppearance(named: NSAppearanceNameVibrantLight)
                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                             NSAppearance.Name.vibrantLight
AppKit.NSAppearanceNameVibrantLight:3:12: note: 'NSAppearanceNameVibrantLight' was obsoleted in Swift 3
public let NSAppearanceNameVibrantLight: NSAppearance.Name
           ^
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/window.swift:182:46: error: 'NSAppearanceNameVibrantLight' has been renamed to 'NSAppearance.Name.vibrantLight'
            appearance = NSAppearance(named: NSAppearanceNameVibrantLight)
                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                             NSAppearance.Name.vibrantLight
AppKit.NSAppearanceNameVibrantLight:3:12: note: 'NSAppearanceNameVibrantLight' was obsoleted in Swift 3
public let NSAppearanceNameVibrantLight: NSAppearance.Name
           ^
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/window.swift:186:46: error: 'NSAppearanceNameVibrantDark' has been renamed to 'NSAppearance.Name.vibrantDark'
            appearance = NSAppearance(named: NSAppearanceNameVibrantDark)
                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~
                                             NSAppearance.Name.vibrantDark
AppKit.NSAppearanceNameVibrantDark:3:12: note: 'NSAppearanceNameVibrantDark' was obsoleted in Swift 3
public let NSAppearanceNameVibrantDark: NSAppearance.Name
           ^
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/window.swift:191:46: error: 'NSAppearanceNameVibrantDark' has been renamed to 'NSAppearance.Name.vibrantDark'
            appearance = NSAppearance(named: NSAppearanceNameVibrantDark)
                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~
                                             NSAppearance.Name.vibrantDark
AppKit.NSAppearanceNameVibrantDark:3:12: note: 'NSAppearanceNameVibrantDark' was obsoleted in Swift 3
public let NSAppearanceNameVibrantDark: NSAppearance.Name
           ^
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/window.swift:214:80: error: argument of '#selector' refers to instance method 'hideTitleBar()' that is not exposed to Objective-C
            NSObject.cancelPreviousPerformRequests(withTarget: self, selector: #selector(hideTitleBar), object: nil)
                                                                               ^         ~~~~~~~~~~~~
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/window.swift:218:10: note: add '@objc' to expose this instance method to Objective-C
    func hideTitleBar() {
         ^
    @objc
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/window.swift:237:60: error: argument of '#selector' refers to instance method 'hideTitleBar()' that is not exposed to Objective-C
                                                 selector: #selector(hideTitleBar),
                                                           ^         ~~~~~~~~~~~~
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/window.swift:218:10: note: add '@objc' to expose this instance method to Objective-C
    func hideTitleBar() {
         ^
    @objc
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/window.swift:239:17: error: argument of '#selector' refers to instance method 'hideTitleBar()' that is not exposed to Objective-C
        perform(#selector(hideTitleBar), with: nil, afterDelay: 0.5)
                ^         ~~~~~~~~~~~~
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/window.swift:218:10: note: add '@objc' to expose this instance method to Objective-C
    func hideTitleBar() {
         ^
    @objc
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/window.swift:388:29: error: cannot assign value of type 'Int' to type 'NSWindow.Level'
                    level = Int(CGWindowLevelForKey(.floatingWindow))
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                            NSWindow.Level(rawValue:                 )
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/window.swift:390:68: error: cannot assign value of type 'Int' to type 'NSWindow.Level'
                    level = Int(CGWindowLevelForKey(.statusWindow))+1
                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
                            NSWindow.Level(rawValue:                 )
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/window.swift:392:40: error: cannot assign value of type 'Int' to type 'NSWindow.Level'
                    level = ontopLevel as! Int
                            ~~~~~~~~~~~^~~~~~~
                            NSWindow.Level(rawValue:  )
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/window.swift:397:29: error: cannot assign value of type 'Int' to type 'NSWindow.Level'
                    level = Int(CGWindowLevelForKey(.floatingWindow))
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                            NSWindow.Level(rawValue:                 )
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/window.swift:399:68: error: cannot assign value of type 'Int' to type 'NSWindow.Level'
                    level = Int(CGWindowLevelForKey(.statusWindow))+1
                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
                            NSWindow.Level(rawValue:                 )
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/window.swift:401:55: error: cannot assign value of type 'Int' to type 'NSWindow.Level'
                    level = Int(ontopLevel as! String)!
                            ~~~~~~~~~~~~~~~~~~~~~~~~~~^
                            NSWindow.Level(rawValue:   )
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/window.swift:407:21: error: cannot assign value of type 'Int' to type 'NSWindow.Level'
            level = Int(CGWindowLevelForKey(.normalWindow))
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                    NSWindow.Level(rawValue:               )
/Users/saagarjha/Git/mpv/video/out/cocoa-cb/window.swift:535:62: error: cannot call value of non-function type 'NSScreen?'
        let ts: NSScreen = tScreen ?? screen ?? NSScreen.main()!
                                                ~~~~~~~~~~~~~^~

/Users/saagarjha/Git/mpv/video/out/cocoa_cb_common.swift:305:41: error: expression type 'NSScreen?' is ambiguous without more context
            let displayID = (ccb.window.screen!.deviceDescription["NSScreenNumber"] as! NSNumber).intValue
                             ~~~~~~~~~~~^~~~~~
/Users/saagarjha/Git/mpv/video/out/cocoa_cb_common.swift:94:81: error: cannot call value of non-function type 'NSScreen?'
        let targetScreen = getScreenBy(id: Int(opts.screen_id)) ?? NSScreen.main()
                                                                   ~~~~~~~~~~~~~^~

/Users/saagarjha/Git/mpv/video/out/cocoa_cb_common.swift:121:81: error: cannot call value of non-function type 'NSScreen?'
        let targetScreen = getScreenBy(id: Int(opts.screen_id)) ?? NSScreen.main()
                                                                   ~~~~~~~~~~~~~^~

/Users/saagarjha/Git/mpv/video/out/cocoa_cb_common.swift:150:75: error: cannot call value of non-function type 'NSScreen?'
        let screen = getScreenBy(id: Int(opts.screen_id)) ?? NSScreen.main()
                                                             ~~~~~~~~~~~~~^~

/Users/saagarjha/Git/mpv/video/out/cocoa_cb_common.swift:173:39: error: expression type 'NSScreen?' is ambiguous without more context
        let displayId = UInt32(window.screen!.deviceDescription["NSScreenNumber"] as! Int)
                               ~~~~~~~^~~~~~
/Users/saagarjha/Git/mpv/video/out/cocoa_cb_common.swift:254:29: warning: 'init(_:)' is deprecated: replaced by 'init(truncating:)'
        let lux = Int(ceil( Double((term4 + term3 + term2 + term1 - 0.19) as NSNumber)))
                            ^
/Users/saagarjha/Git/mpv/video/out/cocoa_cb_common.swift:254:29: note: use 'init(truncating:)' instead
        let lux = Int(ceil( Double((term4 + term3 + term2 + term1 - 0.19) as NSNumber)))
                            ^
                                   truncating:
/Users/saagarjha/Git/mpv/video/out/cocoa_cb_common.swift:334:39: error: cannot call value of non-function type '[NSScreen]'
        let screens = NSScreen.screens()
                      ~~~~~~~~~~~~~~~~^~


Waf: Leaving directory `/Users/saagarjha/Git/mpv/build'
Build failed
 -> task in 'osdep/macOS_swift.o,osdep/macOS_swift.h,osdep/macOS_swift.swiftmodule' failed with exit status 1 (run with -v to display more information)

mac

All 16 comments

yeah i already planned to migrate and actually talked about it yesterday on irc. though right now is a bad idea. xcode is still in beta, there are 14 open related PRs that will get in the way, there is still the problem with dynamic linking and i am not sure how we want to deal with older system (ignore or support).

so i wouldn't want you to waste your effort just yet.

Sure, no problem; let me know if I can be of assistance in any way. I'm usually the one who ends up trying to get IINA and its dependencies working on beta toolchains, since that's what I'm always using, so since I can't get IINA to build there's not much else for me to do ;)

this is mostly for me to help me make a decision. currently we support building on 10.11.5 to 10.14.4 (excluding the Beta toolchain). i personally always tried to support the last 3 major macOS versions. so now that would be 10.12.6 to 10.14.x. for that we can at max port everything to swift 4.0.3.

i kinda dislike having to use different code paths for different swift versions. so i am contemplating to just make a hard cut and stop supporting anything older than swift 5 (since i would really dislike to just port to swift 4.x). for that to happen i would like to have all open macOS PRs merged and at least one new release for the package manager to deal with that. i am probably gonna piss off quite a few people with such a decision i suppose.

let me know if i missed some crucial information, have a different suggestion, or just let me know your opinion on it.

| xcode | swift | macOS min |
| ----- | ------ | --------- |
| 8.0 | 3.0 | 10.11.5 |
| 8.1 | 3.0.1 | 10.11.5 |
| 8.2 | 3.0.2 | 10.11.5 |
| 8.2.1 | 3.0.2 | 10.11.5 |
| 8.3 | 3.1 | 10.12 |
| 8.3.1 | 3.1 | 10.12 |
| 8.3.2 | 3.1 | 10.12 |
| 8.3.3 | 3.1 | 10.12 |
| 9.0 | 4.0 | 10.12.6 |
| 9.1 | 4.0.2 | 10.12.6 |
| 9.2 | 4.0.3 | 10.12.6 |
| 9.3 | 4.1 | 10.13.2 |
| 9.3.1 | 4.1 | 10.13.2 |
| 9.4 | 4.1.2 | 10.13.2 |
| 9.4.1 | 4.1.2 | 10.13.2 |
| 10.0 | 4.2 | 10.13.6 |
| 10.1 | 4.2.1 | 10.13.6 |
| 10.2 | 5.0 | 10.14.4 |

Ok, since you seem to be going in this direction, I'll admit that I was a bit misleading: the real change is that the AppKit API Notes have been updated, and the Swift version we choose has much less of an impact in terms of lines of code we'll have to change. This change must be made independently of which version of Swift you choose, and if you'd like your code to continue to compile you'll have to wrap the old implementation in inverted #available(macOS 10.14, *) checks.

With regards to which Swift version you should use, I have come to realize the details of what mpv has been doing and as such will very strongly recommend you update to Swift 5 immediately. Unless I'm misunderstanding the code, it seems that you were using Swift in libmpv.dylib (!), which means it cannot be used safely (especially the way it builds currently, where it will grab any Swift libraries it finds, such as the ones that ship with IINA irrespective of whether they have a common ABI). I'm sure @lhc70000 must have been keeping our copy of libmpv that we dynamically link against relatively up-to-date, so no issues have cropped up as far as I'm aware, but it's still quite unsafe to be using this library the way we are. (Technically, it's unsafe to do this even with Swift 5's stable ABI, since we would also need module stability too be able to safely link against the binary, but that would require us to make major changes in how we build mpv for IINA…)

Keeping this in mind, your code will unfortunately no longer build on anything older than the current beta toolchain; however this shouldn't be a regular thing and you should be able to stick with this for as long as Xcode's toolchain supports -swift-version 5. Due to drastically improved source stability in recent versions of Swift, the churn with regards to updating our Swift version might actually be zero lines of code, or we may be able to make some small tweaks to bring it to zero by removing code that relies on Swift 3's quirks and not using new features.

seems like you misunderstood something. swift is not used in any libmpv functionality. it's just the cocoa-cb part (which is completely unnecessary for iina's use-case) that could still be linked into it when activated, like all other parts. you can safely --disable-swift and have a swift free libmpv.dylib if you wish to. so it's perfectly safe to use. i deliberately left it this way because that reason, among others.

there are not many choices:

  1. do a soft transition. porting to swift 4.x and scraping compiling with swift 3.x (the latter we would have to do anyway). this will leave us with build support from 10.12.6 onwards and would fall into our regular approach to support at least the latest 3 major macOS versions for compiling.
  2. do the same as above, but additional add swift 5 parts to the code via #available(swift 5, *) or equivalent. basically having different code paths. probably not really a benefit.
  3. make a hard transition, eg just go full swift 5 and only support the very latest OS (10.14.4+) and toolchain version. for that we will want to merge all current open PRs, make a release (for package managers) and possibly wait for macOS 10.15.

i personally fancy choice 3, since it's the least work on my end. though it will most likely piss off a few people. choice 1 is probably the most "we try to make everyone happy" choice. i would totally dislike choice 2.

swift is not used in any libmpv functionality. it's just the cocoa-cb part (which is completely unnecessary for iina's use-case) that could still be linked into it when activated, like all other parts. you can safely --disable-swift and have a swift free libmpv.dylib if you wish to.

Ah, I didn't see that; I'll make sure we build with that option from now on. Since we're not using the Swift portion, it really doesn't matter all that much to us what version of Swift you're using ;)

If you're still looking for input, though, Swift 4 should probably be OK from what I've seen. There shouldn't be much that breaks or requires conditions.

Well, it no longer builds on stable macOS now, since 10.14.4 was released yesterday. I wish Apple weren't so draconian with their updates.

The release blog for Swift 5 says ā€œSwift 5 is source compatible with Swift 4, Swift 4.1 and Swift 4.2ā€. Does this mean mpv will have to limit itself to building on 10.12.6+?

that question was already answered here. though to answer regardless. no not necessarily, but i am not willing to support several code paths.

also can't you just not update xcode or does it force the update?

Sorry for the dumb question, I should have rather asked if you settled on one of the three approaches you mentioned.

The Xcode update’s not forced, but I was unaware of this problem, so I went ahead with the update šŸ˜…

I’m using High Sierra anyway because Apple has broken OpenGL even more in Mojave. I’m getting transient graphic glitches when playing back video in mpv (with both CPU and GPU decoding). Doesn’t happen with Netflix on Safari, so I assume it has to do with OpenGL (I’m assuming Apple’s players use Metal), although I swear I’ve seen the glitches on YouTube in early Mojave releases. Interpolation also seems a bit broken. Unfortunately, it can’t reliably be reproduced. It happens randomly.
(On a Late 2014 Retina 5K iMac with an R9 M295X)

So, I guess I’m putting in a vote for option 1, although I totally understand if you end up going for option 3.

I'm also on High Sierra and this Xcode Update is marked as "incompatible" in my App Store. Wasn't it for you?
I assumed it was like that because Xcode claims Mojave is required to run. I didn't even think you could install it.

you are getting graphic glitches even with the cocoa-cb/libmpv backend?

@Argon- Oh yeah, no, this was on Mojave. I couldn't update on High Sierra either. I dual boot.

@Akemi Yeah, this is my mpv config:

vo=libmpv
profile=gpu-hq
interpolation
tscale=nearest
video-sync=display-resample
sub-font-size=36
icc-profile-auto
icc-cache-dir=~/.config/mpv/icc-cache

I've been able to downgrade Xcode and build on Mojave again, but I wasn't able to reproduce the graphic glitches. They might have fixed the driver in-between 10.14.4 Beta 4 and release. That was the last version I tested on. I'll try to record it if I see it.

graphic glitches sounds like something only vo=gpu will cause.

since i wrote at so many times now, here a fast workaround:

  1. download "Command Line Tools (macOS 10.14) for Xcode 10.1" from https://developer.apple.com/download/more/
  2. xcode-select -s /Library/Developer/CommandLineTools execute following command in your terminal
  3. re-configure and build mpv
  4. profit

I know Swift well, I can probably offer a compatibility layer so that it builds for Swift 3.1, 4.0, 4.2 and 5.0 transparently. But really, Swift 3.x should be abandoned, as it has been dropped by Xcode. So I would recommend solution 1 from Akemi et target macOS 10.12.6+.

the problem is and never was the actual code migration to another swift version or the compatibility to several swift versions.

keeping swift 3 was never an option, because it's a bloody mess.

the actual problem, or rather work, is the migration of the build system, with that all the testing on various platforms and setups that has to be done, and the bundle creation and distribution.

the actual code migration has already been done (#6612), as have been some of the build system changes and tests (#6635, #6655).

Was this page helpful?
0 / 5 - 0 ratings