Skip to content

Commit

Permalink
Merge pull request #90 from p-x9/feature/enable-upcoming-feature-flags
Browse files Browse the repository at this point in the history
Enable swift upcoming feature flags
  • Loading branch information
p-x9 authored Jun 14, 2024
2 parents 9212cd2 + 1ac4f87 commit fb7aa28
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 12 deletions.
32 changes: 31 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ let package = Package(
name: "MachOKit",
dependencies: [
"MachOKitC"
]
],
swiftSettings: SwiftSetting.allCases
),
.target(
name: "MachOKitC",
Expand All @@ -31,3 +32,32 @@ let package = Package(
)
]
)

// https://github.com/treastrain/swift-upcomingfeatureflags-cheatsheet
extension SwiftSetting {
static let forwardTrailingClosures: Self = .enableUpcomingFeature("ForwardTrailingClosures") // SE-0286, Swift 5.3, SwiftPM 5.8+
static let existentialAny: Self = .enableUpcomingFeature("ExistentialAny") // SE-0335, Swift 5.6, SwiftPM 5.8+
static let bareSlashRegexLiterals: Self = .enableUpcomingFeature("BareSlashRegexLiterals") // SE-0354, Swift 5.7, SwiftPM 5.8+
static let conciseMagicFile: Self = .enableUpcomingFeature("ConciseMagicFile") // SE-0274, Swift 5.8, SwiftPM 5.8+
static let importObjcForwardDeclarations: Self = .enableUpcomingFeature("ImportObjcForwardDeclarations") // SE-0384, Swift 5.9, SwiftPM 5.9+
static let disableOutwardActorInference: Self = .enableUpcomingFeature("DisableOutwardActorInference") // SE-0401, Swift 5.9, SwiftPM 5.9+
static let deprecateApplicationMain: Self = .enableUpcomingFeature("DeprecateApplicationMain") // SE-0383, Swift 5.10, SwiftPM 5.10+
static let isolatedDefaultValues: Self = .enableUpcomingFeature("IsolatedDefaultValues") // SE-0411, Swift 5.10, SwiftPM 5.10+
static let globalConcurrency: Self = .enableUpcomingFeature("GlobalConcurrency") // SE-0412, Swift 5.10, SwiftPM 5.10+
}

extension SwiftSetting: CaseIterable {
public static var allCases: [Self] {
[
.forwardTrailingClosures,
.existentialAny,
.bareSlashRegexLiterals,
.conciseMagicFile,
.importObjcForwardDeclarations,
.disableOutwardActorInference,
.deprecateApplicationMain,
.isolatedDefaultValues,
.globalConcurrency
]
}
}
2 changes: 1 addition & 1 deletion Sources/MachOKit/Header/MachHeader/MachHeader+Flags.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extension MachHeader {
public struct Flags: BitFlags {
public typealias RawValue = UInt32

public var rawValue: RawValue
public let rawValue: RawValue

public init(rawValue: RawValue) {
self.rawValue = rawValue
Expand Down
2 changes: 1 addition & 1 deletion Sources/MachOKit/LoadCommand/Model/Section+Attribute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Foundation
public struct SectionAttributes: BitFlags {
public typealias RawValue = UInt32

public var rawValue: RawValue
public let rawValue: RawValue

public init(rawValue: RawValue) {
self.rawValue = rawValue
Expand Down
2 changes: 1 addition & 1 deletion Sources/MachOKit/LoadCommand/Model/VMProtection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Foundation
public struct VMProtection: BitFlags {
public typealias RawValue = vm_prot_t

public var rawValue: RawValue
public let rawValue: RawValue

public init(rawValue: RawValue) {
self.rawValue = rawValue
Expand Down
2 changes: 1 addition & 1 deletion Sources/MachOKit/LoadCommand/SegmentCommand+Flags.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Foundation
public struct SegmentCommandFlags: BitFlags {
public typealias RawValue = UInt32

public var rawValue: RawValue
public let rawValue: RawValue

public init(rawValue: RawValue) {
self.rawValue = rawValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import MachOKitC
public struct CodeSignExecSegmentFlags: BitFlags {
public typealias RawValue = UInt64

public var rawValue: RawValue
public let rawValue: RawValue

public init(rawValue: RawValue) {
self.rawValue = rawValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,18 @@ extension DyldCacheLocalSymbolsInfo {
/// - Returns: Sequence of symbols entries
public func entries(
in cache: DyldCache
) -> AnyRandomAccessCollection<DyldCacheLocalSymbolsEntryProtocol> {
) -> AnyRandomAccessCollection<any DyldCacheLocalSymbolsEntryProtocol> {
if let entries = entries64(in: cache) {
return AnyRandomAccessCollection(
entries
.lazy
.map { $0 as DyldCacheLocalSymbolsEntryProtocol }
.map { $0 as (any DyldCacheLocalSymbolsEntryProtocol) }
)
} else if let entries = entries32(in: cache) {
return AnyRandomAccessCollection(
entries
.lazy
.map { $0 as DyldCacheLocalSymbolsEntryProtocol }
.map { $0 as (any DyldCacheLocalSymbolsEntryProtocol) }
)
} else {
return AnyRandomAccessCollection([])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Foundation
public struct DyldCacheMappingFlags: BitFlags {
public typealias RawValue = UInt64

public var rawValue: RawValue
public let rawValue: RawValue

public init(rawValue: RawValue) {
self.rawValue = rawValue
Expand Down
2 changes: 1 addition & 1 deletion Sources/MachOKit/Model/Export/ExportSymbolFlags.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Foundation
public struct ExportSymbolFlags: BitFlags {
public typealias RawValue = Int32

public var rawValue: RawValue
public let rawValue: RawValue

public var kind: ExportSymbolKind? {
.init(rawValue: rawValue & EXPORT_SYMBOL_FLAGS_KIND_MASK)
Expand Down
2 changes: 1 addition & 1 deletion Sources/MachOKit/Util/BitFlags.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

public protocol BitFlags: OptionSet {
public protocol BitFlags: OptionSet, Sendable {
associatedtype Bit: CaseIterable & RawRepresentable & CustomStringConvertible where Bit.RawValue == RawValue

associatedtype Element = Self
Expand Down

0 comments on commit fb7aa28

Please sign in to comment.