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

Build via Swift package manager #384

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// swift-tools-version:5.7
import PackageDescription

let package = Package(
name: "UIKit",
platforms: [.macOS(.v10_15)],
products: [
.library(name: "UIKit", targets: ["UIKit"])
],
dependencies: [
.package(path: "./swift-jni"),
.package(path: "./SDL"),
],
targets: [
.target(
name: "UIKit",
dependencies: [
.product(name: "SDL", package: "SDL"),
.product(name: "JNI", package: "swift-jni", condition: .when(platforms: [.android])),
.target(name: "UIKit_C_API", condition: .when(platforms: [.android])),
],
path: "Sources",
exclude: ["Mac-Info.plist"]
),
.target(name: "UIKit_C_API", path: "UIKit_C_API"),
]
)
2 changes: 2 additions & 0 deletions Sources/AVPlayer+Android.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if os(Android)
//
// JNIVideo.swift
// UIKit
Expand Down Expand Up @@ -85,3 +86,4 @@ public func nativeOnVideoError(env: UnsafeMutablePointer<JNIEnv>, cls: JavaObjec
)
globalAVPlayer?.onError?(error)
}
#endif
2 changes: 2 additions & 0 deletions Sources/AVPlayerItem+Mac.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if os(macOS)
//
// AVPlayerItem+Mac.swift
// UIKit
Expand All @@ -17,3 +18,4 @@ extension AVPlayerItem {
return duration.seconds * 1000
}
}
#endif
2 changes: 2 additions & 0 deletions Sources/AVPlayerLayer+Android.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if os(Android)
//
// JNIVideo.swift
// UIKit
Expand Down Expand Up @@ -51,3 +52,4 @@ public class AVPlayerLayer: JNIObject {
}
}
}
#endif
4 changes: 3 additions & 1 deletion Sources/AVPlayerLayer+Mac.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if os(macOS)
//
// AVPlayerLayer+Mac.swift
// UIKit
Expand All @@ -7,7 +8,7 @@
//

import AVFoundation
import var SDL_gpu.GPU_FORMAT_RGBA
internal import var SDL_gpu.GPU_FORMAT_RGBA

public typealias AVPlayer = AVFoundation.AVPlayer

Expand Down Expand Up @@ -123,3 +124,4 @@ public final class AVPlayerLayer: CALayer {
contents?.replacePixels(with: pixelBytes, bytesPerPixel: 4)
}
}
#endif
3 changes: 3 additions & 0 deletions Sources/AVURLAsset+Android.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if os(Android)
//
// AVPlayerItem+Android.swift
// UIKit
Expand All @@ -18,6 +19,7 @@ public class AVPlayerItem {
public class AVURLAsset: JNIObject {
public override static var className: String { "org.uikit.AVURLAsset" }

@MainActor
public var url: String?

@MainActor
Expand All @@ -26,3 +28,4 @@ public class AVURLAsset: JNIObject {
self.url = url
}
}
#endif
15 changes: 9 additions & 6 deletions Sources/Button.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@

fileprivate let labelVerticalPadding: CGFloat = 6

@MainActor
open class Button: UIControl {
internal (set) public var imageView: UIImageView? {
internal(set) public var imageView: UIImageView? {
didSet {
oldValue?.removeFromSuperview()
if let imageView = imageView { addSubview(imageView) }
}
}
internal (set) public var titleLabel: UILabel? {

internal(set) public var titleLabel: UILabel? {
didSet {
oldValue?.removeFromSuperview()
if let titleLabel = titleLabel { addSubview(titleLabel) }
Expand Down Expand Up @@ -75,22 +76,24 @@ open class Button: UIControl {
}
}

public let tapGestureRecognizer = UITapGestureRecognizer()
public let tapGestureRecognizer: UITapGestureRecognizer
public var onPress: (@MainActor () -> Void)? {
get { return tapGestureRecognizer.onPress }
set { tapGestureRecognizer.onPress = newValue }
}

@MainActor
public override init(frame: CGRect) {
tapGestureRecognizer = UITapGestureRecognizer(onPress: nil)
super.init(frame: frame)

let titleLabel = UILabel()
let titleLabel = UILabel(frame: .zero)
titleLabel.isHidden = true
addSubview(titleLabel)
setTitleColor(.white, for: .normal)
self.titleLabel = titleLabel

let imageView = UIImageView()
let imageView = UIImageView(frame: .zero)
imageView.isHidden = true
imageView.contentMode = .scaleAspectFit
addSubview(imageView)
Expand Down
3 changes: 2 additions & 1 deletion Sources/CALayer+SDL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
// Copyright © 2017 flowkey. All rights reserved.
//

import SDL_gpu
internal import SDL_gpu

extension CALayer {
@MainActor
final func sdlRender(parentAbsoluteOpacity: Float = 1) {
guard let renderer = UIScreen.main else { return }
let opacity = self.opacity * parentAbsoluteOpacity
Expand Down
2 changes: 1 addition & 1 deletion Sources/CALayer+animations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ extension CALayer {
}

extension CALayer {
static let defaultAnimationDuration: CGFloat = 0.25
nonisolated static let defaultAnimationDuration: CGFloat = 0.25

static func defaultAction(forKey event: String) -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: AnimationKeyPath(stringLiteral: event))
Expand Down
10 changes: 5 additions & 5 deletions Sources/CALayer.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SDL
internal import SDL

@MainActor
open class CALayer {
Expand All @@ -14,8 +14,8 @@ open class CALayer {

open var contentsGravity: CALayerContentsGravity = .resize

internal (set) public weak var superlayer: CALayer?
internal (set) public var sublayers: [CALayer]? {
internal(set) public weak var superlayer: CALayer?
internal(set) public var sublayers: [CALayer]? {
didSet { CALayer.layerTreeIsDirty = true }
}

Expand Down Expand Up @@ -283,11 +283,11 @@ extension CALayer {
}

extension CALayer: Hashable {
public func hash(into hasher: inout Hasher) {
nonisolated public func hash(into hasher: inout Hasher) {
hasher.combine(ObjectIdentifier(self).hashValue)
}

public static func == (lhs: CALayer, rhs: CALayer) -> Bool {
nonisolated public static func == (lhs: CALayer, rhs: CALayer) -> Bool {
return lhs === rhs
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/CATransform3D+SDL_gpu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2018 flowkey. All rights reserved.
//

import SDL_gpu
internal import SDL_gpu

extension CATransform3D {
/// Set the current transformation as SDL_GPU's current transform matrix
Expand Down
2 changes: 1 addition & 1 deletion Sources/CATransform3D+animations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by Michael Knoch on 19.01.18.
//

import SDL_gpu
internal import SDL_gpu

// It doesn't make sense to make these public, they're only to simplify our animation code:
internal extension CATransform3D {
Expand Down
2 changes: 1 addition & 1 deletion Sources/CGDataProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2017 flowkey. All rights reserved.
//

import SDL
internal import SDL

public class CGDataProvider {
public var data: [CChar]
Expand Down
4 changes: 2 additions & 2 deletions Sources/CGImage.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import SDL
import SDL_gpu
internal import SDL
internal import SDL_gpu

public class CGImage {
/// Be careful using this pointer e.g. for another CGImage instance.
Expand Down
4 changes: 3 additions & 1 deletion Sources/Data+fromRelativePathCrossPlatform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
// Copyright © 2018 flowkey. All rights reserved.
//

internal import SDL

extension Data {
public static func _fromPathCrossPlatform(_ path: String) -> Data? {
static func _fromPathCrossPlatform(_ path: String) -> Data? {
guard let fileReader = SDL_RWFromFile(path, "r") else {
return nil
}
Expand Down
19 changes: 0 additions & 19 deletions Sources/DispatchQueue+syncSafe.swift

This file was deleted.

4 changes: 2 additions & 2 deletions Sources/DisplayLink.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ open class DisplayLink {
}

extension DisplayLink: Hashable {
public func hash(into hasher: inout Hasher) {
nonisolated public func hash(into hasher: inout Hasher) {
hasher.combine(ObjectIdentifier(self).hashValue)
}

public static func == (lhs: DisplayLink, rhs: DisplayLink) -> Bool {
nonisolated public static func ==(lhs: DisplayLink, rhs: DisplayLink) -> Bool {
return lhs === rhs
}
}
2 changes: 1 addition & 1 deletion Sources/FontRenderer+renderAttributedString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2018 flowkey. All rights reserved.
//

import SDL_ttf
internal import SDL_ttf

extension FontRenderer {
func getFontKerningOffset(between previousIndex: FT_UInt?, and currentIndex: FT_UInt) -> Int32 {
Expand Down
2 changes: 1 addition & 1 deletion Sources/FontRenderer+singleLineSize.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2018 flowkey. All rights reserved.
//

import SDL_ttf
internal import SDL_ttf

extension FontRenderer {
// From `TTF_HANDLE_STYLE_BOLD`
Expand Down
2 changes: 1 addition & 1 deletion Sources/FontRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2017 flowkey. All rights reserved.
//

import SDL_ttf
internal import SDL_ttf


extension FontRenderer {
Expand Down
4 changes: 3 additions & 1 deletion Sources/Logging.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if os(Android)
//
// Logging.swift
// UIKit
Expand All @@ -6,7 +7,7 @@
// Copyright © 2017 flowkey. All rights reserved.
//

import SDL
internal import SDL

#if os(Android)
import Bionic
Expand Down Expand Up @@ -48,3 +49,4 @@ public func fatalError(_ message: @autoclosure () -> String = "", file: StaticSt
public enum LogPriority: Int32 {
case `unknown`,`default`,`verbose`,`debug`,`info`,`warn`,`error`,`fatal`,`silent`
}
#endif
29 changes: 29 additions & 0 deletions Sources/Math.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#if os(WASI)
Copy link
Member

Choose a reason for hiding this comment

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

nit: WASI shouldn't be needed for UIKit, right?

@_exported import func WASILibc.pow
@_exported import func WASILibc.log10
@_exported import func WASILibc.log
@_exported import func WASILibc.sin
@_exported import func WASILibc.cos
#elseif canImport(Bionic)
@_exported import func Bionic.pow
@_exported import func Bionic.acosf
@_exported import func Bionic.log10
@_exported import func Bionic.log
@_exported import func Bionic.sin
@_exported import func Bionic.sinf
@_exported import func Bionic.cos
@_exported import var Bionic.CLOCK_REALTIME
@_exported import func Bionic.clock_gettime
@_exported import struct Bionic.timespec
@_exported import struct Bionic.clockid_t
#elseif canImport(Darwin)
@_exported import func Foundation.acosf
@_exported import func Foundation.pow
@_exported import func Foundation.log10
@_exported import func Foundation.log
@_exported import func Foundation.sin
@_exported import func Foundation.sinf
@_exported import func Foundation.cos
@_exported import func Foundation.clock_gettime
@_exported import struct Foundation.timespec
#endif
2 changes: 1 addition & 1 deletion Sources/MeteringView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class MeteringView: UILabel {

private func updateDisplay(to value: Double) {
guard value.isFinite else { return }
let value = Int(round(value))
let value = Int(value.rounded())
self.text = metric + ": \(value)"
self.sizeToFit()
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/NotificationCenter.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#if os(Android)
import var JNI.isMainThread
#else
import Foundation
var isMainThread: Bool {
#elseif canImport(Darwin)
import class Foundation.Thread
private var isMainThread: Bool {
return Thread.isMainThread
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions Sources/SDL+JNIExtensions.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if os(Android)
//
// SDL+JNIExtensions.swift
// UIKit
Expand Down Expand Up @@ -50,3 +51,4 @@ struct JavaSDLView: JavaParameterConvertible {
return self.init(javaStringObject)
}
}
#endif
Loading