Skip to content

Remove OpenFoundation dependency #17

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

Merged
merged 5 commits into from
Feb 5, 2024
Merged
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
3 changes: 3 additions & 0 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ jobs:
container: swift:${{ matrix.swift_version }}-jammy
steps:
- uses: actions/checkout@v4
- name: Swift version
run: |
which swift && swift --version
- name: Building and running tests in debug mode with coverage
run: |
swift test \
Expand Down
2 changes: 2 additions & 0 deletions AG/Sources/Headers/AGBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@

#include <CoreFoundation/CoreFoundation.h>
#include <TargetConditionals.h>
#ifndef TARGET_OS_DARWIN
#define TARGET_OS_DARWIN TARGET_OS_MAC
#endif
#define AG_OPTIONS CF_OPTIONS
#define AG_EXTERN_C_BEGIN CF_EXTERN_C_BEGIN
#define AG_EXTERN_C_END CF_EXTERN_C_END
Expand Down
14 changes: 0 additions & 14 deletions Package.resolved

This file was deleted.

30 changes: 17 additions & 13 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
import Foundation
import PackageDescription

// https://github.com/llvm/llvm-project/issues/48757
let clangEnumFixSetting = CSetting.unsafeFlags(["-Wno-elaborated-enum-base"], .when(platforms: [.linux]))

let openGraphShimsTarget = Target.target(
name: "OpenGraphShims"
)
Expand All @@ -22,6 +19,11 @@ let openGraphCompatibilityTestTarget = Target.testTarget(
exclude: ["README.md"]
)

let swiftBinPath = Context.environment["_"] ?? ""
let swiftBinURL = URL(fileURLWithPath: swiftBinPath)
let SDKPath = swiftBinURL.deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent().path
let includePath = SDKPath.appending("/usr/lib/swift_static")

let package = Package(
name: "OpenGraph",
platforms: [
Expand All @@ -36,24 +38,20 @@ let package = Package(
.library(name: "OpenGraphShims", targets: ["OpenGraphShims"]),
.library(name: "OpenGraph", targets: ["OpenGraph"]),
],
dependencies: [
.package(url: "https://github.com/OpenSwiftUIProject/OpenFoundation", from: "0.0.2"),
],
targets: [
// 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]
cxxSettings: [
.unsafeFlags(["-I", includePath], .when(platforms: .nonDarwinPlatforms)),
.define("__COREFOUNDATION_FORSWIFTFOUNDATIONONLY__", to: "1", .when(platforms: .nonDarwinPlatforms)),
]
),
.target(
name: "OpenGraph",
dependencies: ["_OpenGraph"],
cSettings: [clangEnumFixSetting]
dependencies: ["_OpenGraph"]
),
openGraphShimsTarget,
openGraphTestTarget,
Expand All @@ -63,7 +61,7 @@ let package = Package(
)

func envEnable(_ key: String, default defaultValue: Bool = false) -> Bool {
guard let value = ProcessInfo.processInfo.environment[key] else {
guard let value = Context.environment[key] else {
return defaultValue
}
if value == "1" {
Expand Down Expand Up @@ -119,3 +117,9 @@ if swiftTestingCondition {
swiftSettings.append(.define("OPENGRAPH_SWIFT_TESTING"))
openGraphTestTarget.swiftSettings = swiftSettings
}

extension [Platform] {
static var nonDarwinPlatforms: [Platform] {
[.linux, .android, .wasi, .openbsd, .windows]
}
}
18 changes: 6 additions & 12 deletions Sources/_OpenGraph/include/OGBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@

#define OG_SWIFT_STRUCT __attribute__((swift_wrapper(struct)))

#ifdef __APPLE__
#include <CoreFoundation/CoreFoundation.h>
#ifdef __APPLE__
#include <TargetConditionals.h>
#ifndef TARGET_OS_DARWIN
#define TARGET_OS_DARWIN TARGET_OS_MAC
#endif
#else
#include <CoreFoundation/TargetConditionals.h>
#endif
#define OG_OPTIONS CF_OPTIONS
#define OG_EXTERN_C_BEGIN CF_EXTERN_C_BEGIN
#define OG_EXTERN_C_END CF_EXTERN_C_END
Expand All @@ -53,15 +58,4 @@
#define OG_EXPORT CF_EXPORT
#define OG_REFINED_FOR_SWIFT CF_REFINED_FOR_SWIFT
#define OG_SWIFT_NAME CF_SWIFT_NAME
#else
#include <OpenFoundation/OpenFoundation.h>
#define OG_OPTIONS OF_OPTIONS
#define OG_EXTERN_C_BEGIN OF_EXTERN_C_BEGIN
#define OG_EXTERN_C_END OF_EXTERN_C_END
#define OG_ASSUME_NONNULL_BEGIN OF_ASSUME_NONNULL_BEGIN
#define OG_ASSUME_NONNULL_END OF_ASSUME_NONNULL_END
#define OG_EXPORT OF_EXPORT
#define OG_REFINED_FOR_SWIFT OF_REFINED_FOR_SWIFT
#define OG_SWIFT_NAME OF_SWIFT_NAME
#endif /* __APPLE__ */
#endif /* OGBase_h */