I see we have added Git information on PD context recently.
Can we add Swift SDK path info here too?
I found I need some include information related to it on non-Darwin platform when writing C target code in SwiftPM.
Currently, I have to use some environment trick here to manually inject it and read it in the package manifest file.
// Package.swift
let SDKPath = ProcessInfo.processInfo.environment["xx"] ?? "" // or Context.environment["xx"]
let includePath = SDKPath.appending("../usr/lib/swift_static")
let targetA: Target = .target(
name: "A",
cSettings: [
.unsafeFlags(["-I", includePath]),
....
],
)
There is also a trick to rely on "_" environment value which will be swift executable path.
let swiftBinPath = Context.environment["_"] ?? ""
let swiftBinURL = URL(fileURLWithPath: swiftBinPath)
let SDKPath = swiftBinURL.deletingLastPathComponent().deletingLastPathComponent().path
let includePath = SDKPath.appending("/lib/swift_static")
Anyway, none of those methods are simple nor reliable. And that's why I'm expecting PackageDescription
module can provide such info via Context
.