Skip to content

Commit

Permalink
Update OGComparisionMode (#10)
Browse files Browse the repository at this point in the history
* Update OGComparisionMode to fix __C issue

* Add compareValues and update test
  • Loading branch information
Kyle-Ye committed Dec 20, 2023
1 parent ef985c1 commit cb8da29
Show file tree
Hide file tree
Showing 30 changed files with 460 additions and 46 deletions.
47 changes: 39 additions & 8 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let openSwiftUITarget = Target.target(
],
swiftSettings: [
.enableExperimentalFeature("AccessLevelOnImport"),
.define("OPENSWIFTUI_SUPPRESS_DEPRECATED_WARNINGS")
.define("OPENSWIFTUI_SUPPRESS_DEPRECATED_WARNINGS"),
],
linkerSettings: [
.unsafeFlags(
Expand Down Expand Up @@ -80,17 +80,42 @@ let package = Package(
]
)

// FIXME: The binary of AG for macOS is copied from dyld shared cache and it will cause a link error when running. Use iOS Simulator to run this target as a temporary workaround
let graphCompatibilityTest = ProcessInfo.processInfo.environment["OPENGRAPH_COMPATIBILITY_TEST"] != nil
let openGraphCompatibilityTestTarget = Target.testTarget(
name: "OpenGraphCompatibilityTests",
dependencies: [
graphCompatibilityTest ? "AttributeGraph" : "OpenGraph",
],
exclude: ["README.md"],
swiftSettings: graphCompatibilityTest ? [
.define("OPENGRAPH_COMPATIBILITY_TEST")
] : []
)
package.targets.append(openGraphCompatibilityTestTarget)

let useAG = ProcessInfo.processInfo.environment["OPENSWIFTUI_USE_AG"] != nil
if useAG {
if !graphCompatibilityTest {
let targets: [Target] = [
// FIXME: Merge into one target
// OpenGraph is a C++ & Swift mix target.
// The SwiftPM support for such usage is still in progress.
.target(
name: "_OpenGraph",
dependencies: [.product(name: "OpenFoundation", package: "OpenFoundation")],
cSettings: [clangEnumFixSetting]
),
.target(
name: "OpenGraph",
dependencies: ["_OpenGraph"],
cSettings: [clangEnumFixSetting]
),
]
package.targets.append(contentsOf: targets)
}
let targets: [Target] = [
.binaryTarget(name: "AttributeGraph", path: "Sources/AttributeGraph.xcframework"),
// FIXME: The binary of AG for macOS is copied from dyld shared cache and it will cause a link error when running. Use iOS Simulator to run this target as a temporary workaround
.testTarget(
name: "AttributeGraphTests",
dependencies: [
"AttributeGraph",
]
),
]
package.targets.append(contentsOf: targets)
openSwiftUITarget.dependencies.append(
Expand All @@ -100,6 +125,12 @@ if useAG {
swiftSettings.append(.define("OPENSWIFTUI_USE_AG"))
openSwiftUITarget.swiftSettings = swiftSettings
} else {
if graphCompatibilityTest {
let targets: [Target] = [
.binaryTarget(name: "AttributeGraph", path: "Sources/AttributeGraph.xcframework"),
]
package.targets.append(contentsOf: targets)
}
package.products.append(
.library(name: "OpenGraph", targets: ["OpenGraph", "_OpenGraph"])
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// AGCompareValues.h
//
//
// Created by Kyle on 2023/10/9.
//

#ifndef AGCompareValues_h
#define AGCompareValues_h

#include <CoreFoundation/CoreFoundation.h>
#include "AGComparisonMode.h"
#include <stdbool.h>

CF_EXTERN_C_BEGIN
CF_EXPORT
bool AGCompareValues(const void *lhs, const void *rhs, const AGComparisonMode comparisonMode, const void *type);
CF_EXTERN_C_END

#endif /* AGCompareValues_h */
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// AGComparisonMode.hpp
//
//
// Created by Kyle on 2023/12/20.
//

#ifndef AGComparisonMode_h
#define AGComparisonMode_h

#include <CoreFoundation/CoreFoundation.h>

typedef CF_OPTIONS(uint32_t, AGComparisonMode) {
AGComparisonMode_0 = 0,
AGComparisonMode_1 = 1 << 0,
AGComparisonMode_2 = 1 << 1,
AGComparisonMode_3 = AGComparisonMode_1 | AGComparisonMode_2,
};

#endif /* AGComparisonMode_h */

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//
// AGMakeUniqueID.hpp
// AGUniqueID.h
//
//
// Created by Kyle on 2023/10/9.
//

#ifndef AGMakeUniqueID_hpp
#define AGMakeUniqueID_hpp
#ifndef AGUniqueID_h
#define AGUniqueID_h

#include <CoreFoundation/CoreFoundation.h>
typedef long long AGUniqueID;
Expand All @@ -16,4 +16,4 @@ CF_EXPORT
AGUniqueID AGMakeUniqueID(void);
CF_EXTERN_C_END

#endif /* AGMakeUniqueID_hpp */
#endif /* AGUniqueID_h */
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#import "AGAttribute.h"
#import "AGUniqueID.h"
#import "AGComparisonMode.h"
#import "AGCompareValues.h"

FOUNDATION_EXPORT double AGAttributeVersionNumber;
FOUNDATION_EXPORT const unsigned char AGAttributeVersionString[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ public protocol _AttributeBody {
static func _destroySelf(_ value: Swift.UnsafeMutableRawPointer)
static var _hasDestroySelf: Swift.Bool { get }
static func _updateDefault(_ value: Swift.UnsafeMutableRawPointer)
static var comparisonMode: AGComparisonMode { get }
}
extension AttributeGraph._AttributeBody {
public static func _destroySelf(_ value: Swift.UnsafeMutableRawPointer)
public static var _hasDestroySelf: Swift.Bool {
get
}
public static func _updateDefault(_ value: Swift.UnsafeMutableRawPointer)
public static var comparisonMode: AGComparisonMode { get }
}
public protocol Rule : AttributeGraph._AttributeBody {
associatedtype Value
Expand All @@ -61,3 +63,4 @@ extension AttributeGraph.Rule {
get
}
}
public func compareValues<A>(_ lhs: A, _ rhs: A, mode: AGComparisonMode = ._3) -> Swift.Bool
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ public protocol _AttributeBody {
static func _destroySelf(_ value: Swift.UnsafeMutableRawPointer)
static var _hasDestroySelf: Swift.Bool { get }
static func _updateDefault(_ value: Swift.UnsafeMutableRawPointer)
static var comparisonMode: AGComparisonMode { get }
}
extension AttributeGraph._AttributeBody {
public static func _destroySelf(_ value: Swift.UnsafeMutableRawPointer)
public static var _hasDestroySelf: Swift.Bool {
get
}
public static func _updateDefault(_ value: Swift.UnsafeMutableRawPointer)
public static var comparisonMode: AGComparisonMode { get }
}
public protocol Rule : AttributeGraph._AttributeBody {
associatedtype Value
Expand All @@ -61,3 +63,4 @@ extension AttributeGraph.Rule {
get
}
}
public func compareValues<A>(_ lhs: A, _ rhs: A, mode: AGComparisonMode = ._3) -> Swift.Bool
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// AGCompareValues.h
//
//
// Created by Kyle on 2023/10/9.
//

#ifndef AGCompareValues_h
#define AGCompareValues_h

#include <CoreFoundation/CoreFoundation.h>
#include "AGComparisonMode.h"
#include <stdbool.h>

CF_EXTERN_C_BEGIN
CF_EXPORT
bool AGCompareValues(const void *lhs, const void *rhs, const AGComparisonMode comparisonMode, const void *type);
CF_EXTERN_C_END

#endif /* AGCompareValues_h */
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// AGComparisonMode.hpp
//
//
// Created by Kyle on 2023/12/20.
//

#ifndef AGComparisonMode_h
#define AGComparisonMode_h

#include <CoreFoundation/CoreFoundation.h>

typedef CF_OPTIONS(uint32_t, AGComparisonMode) {
AGComparisonMode_0 = 0,
AGComparisonMode_1 = 1 << 0,
AGComparisonMode_2 = 1 << 1,
AGComparisonMode_3 = AGComparisonMode_1 | AGComparisonMode_2,
};

#endif /* AGComparisonMode_h */

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//
// AGMakeUniqueID.hpp
// AGUniqueID.h
//
//
// Created by Kyle on 2023/10/9.
//

#ifndef AGMakeUniqueID_hpp
#define AGMakeUniqueID_hpp
#ifndef AGUniqueID_h
#define AGUniqueID_h

#include <CoreFoundation/CoreFoundation.h>
typedef long long AGUniqueID;
Expand All @@ -16,4 +16,4 @@ CF_EXPORT
AGUniqueID AGMakeUniqueID(void);
CF_EXTERN_C_END

#endif /* AGMakeUniqueID_hpp */
#endif /* AGUniqueID_h */
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#import "AGAttribute.h"
#import "AGUniqueID.h"
#import "AGComparisonMode.h"
#import "AGCompareValues.h"

FOUNDATION_EXPORT double AGAttributeVersionNumber;
FOUNDATION_EXPORT const unsigned char AGAttributeVersionString[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ public protocol _AttributeBody {
static func _destroySelf(_ value: Swift.UnsafeMutableRawPointer)
static var _hasDestroySelf: Swift.Bool { get }
static func _updateDefault(_ value: Swift.UnsafeMutableRawPointer)
static var comparisonMode: AGComparisonMode { get }
}
extension AttributeGraph._AttributeBody {
public static func _destroySelf(_ value: Swift.UnsafeMutableRawPointer)
public static var _hasDestroySelf: Swift.Bool {
get
}
public static func _updateDefault(_ value: Swift.UnsafeMutableRawPointer)
public static var comparisonMode: AGComparisonMode { get }
}
public protocol Rule : AttributeGraph._AttributeBody {
associatedtype Value
Expand All @@ -61,3 +63,4 @@ extension AttributeGraph.Rule {
get
}
}
public func compareValues<A>(_ lhs: A, _ rhs: A, mode: AGComparisonMode = ._3) -> Swift.Bool
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// AGCompareValues.h
//
//
// Created by Kyle on 2023/10/9.
//

#ifndef AGCompareValues_h
#define AGCompareValues_h

#include <CoreFoundation/CoreFoundation.h>
#include "AGComparisonMode.h"
#include <stdbool.h>

CF_EXTERN_C_BEGIN
CF_EXPORT
bool AGCompareValues(const void *lhs, const void *rhs, const AGComparisonMode comparisonMode, const void *type);
CF_EXTERN_C_END

#endif /* AGCompareValues_h */
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// AGComparisonMode.hpp
//
//
// Created by Kyle on 2023/12/20.
//

#ifndef AGComparisonMode_h
#define AGComparisonMode_h

#include <CoreFoundation/CoreFoundation.h>

typedef CF_OPTIONS(uint32_t, AGComparisonMode) {
AGComparisonMode_0 = 0,
AGComparisonMode_1 = 1 << 0,
AGComparisonMode_2 = 1 << 1,
AGComparisonMode_3 = AGComparisonMode_1 | AGComparisonMode_2,
};

#endif /* AGComparisonMode_h */

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//
// AGMakeUniqueID.hpp
// AGUniqueID.h
//
//
// Created by Kyle on 2023/10/9.
//

#ifndef AGMakeUniqueID_hpp
#define AGMakeUniqueID_hpp
#ifndef AGUniqueID_h
#define AGUniqueID_h

#include <CoreFoundation/CoreFoundation.h>
typedef long long AGUniqueID;
Expand All @@ -16,4 +16,4 @@ CF_EXPORT
AGUniqueID AGMakeUniqueID(void);
CF_EXTERN_C_END

#endif /* AGMakeUniqueID_hpp */
#endif /* AGUniqueID_h */
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#import "AGAttribute.h"
#import "AGUniqueID.h"
#import "AGComparisonMode.h"
#import "AGCompareValues.h"

FOUNDATION_EXPORT double AGAttributeVersionNumber;
FOUNDATION_EXPORT const unsigned char AGAttributeVersionString[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ public protocol _AttributeBody {
static func _destroySelf(_ value: Swift.UnsafeMutableRawPointer)
static var _hasDestroySelf: Swift.Bool { get }
static func _updateDefault(_ value: Swift.UnsafeMutableRawPointer)
static var comparisonMode: AGComparisonMode { get }
}
extension AttributeGraph._AttributeBody {
public static func _destroySelf(_ value: Swift.UnsafeMutableRawPointer)
public static var _hasDestroySelf: Swift.Bool {
get
}
public static func _updateDefault(_ value: Swift.UnsafeMutableRawPointer)
public static var comparisonMode: AGComparisonMode { get }
}
public protocol Rule : AttributeGraph._AttributeBody {
associatedtype Value
Expand All @@ -61,3 +63,4 @@ extension AttributeGraph.Rule {
get
}
}
public func compareValues<A>(_ lhs: A, _ rhs: A, mode: AGComparisonMode = ._3) -> Swift.Bool
6 changes: 0 additions & 6 deletions Sources/OpenGraph/TODO/OGComparisonMode.swift

This file was deleted.

Loading

0 comments on commit cb8da29

Please sign in to comment.