Skip to content

Commit

Permalink
Add SwiftPM based example
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ye committed Jan 9, 2024
1 parent 77071bd commit 160e1d8
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 3 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
Example/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
/.build-*
/Benchmarks/.build
/Benchmarks/.build
/Example/.build
Example/Package.resolved
64 changes: 64 additions & 0 deletions Example/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import Foundation
import PackageDescription

let exampleTarget = Target.executableTarget(
name: "Example",
dependencies: [
.product(name: "OpenSwiftUI", package: "OpenSwiftUI"),
],
path: "Example",
sources: ["ExampleApp.swift", "ContentView.swift"]
)

let package = Package(
name: "Example",
platforms: [
.macOS(.v10_15),
],
products: [.executable(name: "Example", targets: ["Example"])],
dependencies: [
.package(path: "../"),
.package(url: "https://github.com/OpenSwiftUIProject/OpenGraph", branch: "main"),
],
targets: [
exampleTarget,
]
)

func envEnable(_ key: String, default defaultValue: Bool = false) -> Bool {
guard let value = ProcessInfo.processInfo.environment[key] else {
return defaultValue
}
if value == "1" {
return true
} else if value == "0" {
return false
} else {
return defaultValue
}
}

#if os(macOS)
let attributeGraphCondition = envEnable("OPENGRAPH_ATTRIBUTEGRAPH", default: true)
#else
let attributeGraphCondition = envEnable("OPENGRAPH_ATTRIBUTEGRAPH")
#endif

extension Target {
func addAGSettings() {
// FIXME: Weird SwiftPM behavior for binary Target. Otherwize we'll get the following error message
// "could not determine executable path for bundle 'AttributeGraph.framework'"
dependencies.append(.product(name: "AttributeGraph", package: "OpenGraph"))

var swiftSettings = swiftSettings ?? []
swiftSettings.append(.define("OPENGRAPH_ATTRIBUTEGRAPH"))
self.swiftSettings = swiftSettings
}
}

if attributeGraphCondition {
exampleTarget.addAGSettings()
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// Lastest Version: iOS 15.5
// Status: WIP

#if canImport(Darwin)
@frozen
public struct LocalizedStringKey {}

Expand Down Expand Up @@ -58,4 +57,3 @@ public struct WindowGroup<Content>: Scene where Content: View {

var id: String?
}
#endif

0 comments on commit 160e1d8

Please sign in to comment.