Skip to content

Instantly share code, notes, and snippets.

@Kyle-Ye
Created May 7, 2023 07:48
Show Gist options
  • Save Kyle-Ye/9e960dad379e0ded065be366b4233a6c to your computer and use it in GitHub Desktop.
Save Kyle-Ye/9e960dad379e0ded065be366b4233a6c to your computer and use it in GitHub Desktop.
Add system framework search path on Package.swift
// swift-tools-version: 5.8
// The swift-tools-version declares the minimum version of Swift required to build this package.
import Foundation
import PackageDescription
let isXcodeEnv = ProcessInfo.processInfo.environment["__CFBundleIdentifier"] == "com.apple.dt.Xcode"
// Xcode use clang as linker which supports "-iframework" while SwiftPM use swiftc as linker which supports "-Fsystem"
let systemFrameworkSearchFlag = isXcodeEnv ? "-iframework" : "-Fsystem"
let package = Package(
...
targets: [
.target(
name: "Sharing",
linkerSettings: [
.unsafeFlags([systemFrameworkSearchFlag, "/System/Library/PrivateFrameworks/"]),
]
),
]
)
@Kyle-Ye
Copy link
Author

Kyle-Ye commented May 7, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment