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 9 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
28 changes: 28 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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_macOS", package: "SDL", condition: .when(platforms: [.macOS])),
.product(name: "SDL_Android", package: "SDL", condition: .when(platforms: [.android])),
.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 @@ -50,3 +51,4 @@ public class AVPlayerLayer: JNIObject {
}
}
}
#endif
2 changes: 2 additions & 0 deletions 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 Down Expand Up @@ -123,3 +124,4 @@ public final class AVPlayerLayer: CALayer {
contents?.replacePixels(with: pixelBytes, bytesPerPixel: 4)
}
}
#endif
2 changes: 2 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 Down Expand Up @@ -26,3 +27,4 @@ public class AVURLAsset: JNIObject {
self.url = url
}
}
#endif
11 changes: 7 additions & 4 deletions Sources/Button.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@

fileprivate let labelVerticalPadding: CGFloat = 6

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

internal (set) public var titleLabel: UILabel? {
didSet {
oldValue?.removeFromSuperview()
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
@_implementationOnly 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.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SDL
@_implementationOnly import SDL

@MainActor
open class CALayer {
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
@_implementationOnly 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
@_implementationOnly 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
@_implementationOnly 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
@_implementationOnly import SDL
@_implementationOnly 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.
//

@_implementationOnly 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
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
@_implementationOnly 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
@_implementationOnly 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
@_implementationOnly import SDL_ttf


extension FontRenderer {
Expand Down
9 changes: 3 additions & 6 deletions 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,13 +7,8 @@
// Copyright © 2017 flowkey. All rights reserved.
//

import SDL

#if os(Android)
@_implementationOnly import SDL
Copy link
Member

Choose a reason for hiding this comment

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

I found some docs about this here but can you explain in our context what this actually changes?

import Glibc
#else
import Darwin.C.stdio
#endif

private let loggingTag = "Swift"

Expand Down Expand Up @@ -48,3 +44,4 @@ public func fatalError(_ message: @autoclosure () -> String = "", file: StaticSt
public enum LogPriority: Int32 {
case `unknown`,`default`,`verbose`,`debug`,`info`,`warn`,`error`,`fatal`,`silent`
}
#endif
25 changes: 25 additions & 0 deletions Sources/Math.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#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.log2
@_exported import func WASILibc.sin
@_exported import func WASILibc.cos
#elseif canImport(Glibc)
@_exported import func Glibc.pow
@_exported import func Glibc.log10
@_exported import func Glibc.log2
@_exported import func Glibc.sin
@_exported import func Glibc.cos
@_exported import var Glibc.CLOCK_REALTIME
@_exported import func Glibc.clock_gettime
@_exported import struct Glibc.timespec
@_exported import struct Glibc.clockid_t
#elseif canImport(Darwin)
@_exported import func Foundation.pow
@_exported import func Foundation.log10
@_exported import func Foundation.log2
@_exported import func Foundation.sin
@_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
7 changes: 7 additions & 0 deletions Sources/NotificationCenter.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#if os(Android)
import JNI
#elseif canImport(Darwin)
import class Foundation.Thread
private var isMainThread: Bool {
return Thread.isMainThread
}
#endif

public class NotificationCenter {
public internal(set) static var `default` = NotificationCenter()
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
27 changes: 2 additions & 25 deletions Sources/SDL2-Shims.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2017 Geordie Jay. All rights reserved.
//

import SDL
@_implementationOnly import SDL

struct SDLError: Error {
let description: String
Expand All @@ -27,30 +27,7 @@ extension SDLDisplayMode {
}
}

extension SDLBool: ExpressibleByBooleanLiteral {
extension SDLBool {
static let `true` = __SDL_TRUE
static let `false` = __SDL_FALSE

public init(booleanLiteral value: Bool) {
self = (value ? .true : .false)
}
}

extension SDLRect: Equatable {
public func intersects(_ other: SDLRect) -> Bool {
var other = other
return self.intersects(&other) == .true
}

public func intersection(with other: SDLRect) -> SDLRect {
var other = other
var result = SDLRect()
self.intersection(with: &other, result: &result)
return result
}

public static func == (lhs: SDLRect, rhs: SDLRect) -> Bool {
var rhs = rhs
return lhs.equals(&rhs) == .true
}
}
2 changes: 1 addition & 1 deletion Sources/Shader.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_gpu
@_implementationOnly import SDL_gpu

class VertexShader: Shader {
// Some keywords have changed since the earlier shader language versions available on Android:
Expand Down
2 changes: 1 addition & 1 deletion Sources/ShaderProgram+mask.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_gpu
@_implementationOnly import SDL_gpu

extension ShaderProgram {
static let mask = try! MaskShaderProgram()
Expand Down
2 changes: 1 addition & 1 deletion Sources/ShaderProgram.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_gpu
@_implementationOnly import SDL_gpu

// A ShaderProgram consists of a VertexShader and a FragmentShader linked together
// This is a class because Shaders need to be freed after use
Expand Down
Loading