Skip to content

Commit

Permalink
build: inject the appropriate include paths
Browse files Browse the repository at this point in the history
This avoids the need for computing the actual path to the Swift includes
and instead will find `swiftc` from the path and use that to compute the
include path. This allows `swift build` to work again.
  • Loading branch information
compnerd committed Feb 16, 2024
1 parent a2bf484 commit 04853e1
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
// swift-tools-version:5.9

import PackageDescription
import Foundation
import WinSDK

let swiftc = "swiftc.exe".withCString(encodedAs: UTF16.self) { pwszCompiler in
let dwLength = SearchPathW(nil, pwszCompiler, nil, 0, nil, nil)
return withUnsafeTemporaryAllocation(of: WCHAR.self, capacity: Int(dwLength) + 1) {
_ = SearchPathW(nil, pwszCompiler, nil, dwLength + 1, $0.baseAddress, nil)
return String(decodingCString: $0.baseAddress!, as: UTF16.self)
}
}
let include = URL(fileURLWithPath: swiftc).deletingLastPathComponent()
.deletingLastPathComponent()
.appendingPathComponent("include")
.withUnsafeFileSystemRepresentation {
String(cString: $0!)
}

let SwiftFirebase =
Package(name: "SwiftFirebase",
Expand All @@ -23,12 +39,14 @@ let SwiftFirebase =
publicHeadersPath: "include",
cSettings: [
.headerSearchPath("../../third_party/firebase-development/usr/include"),
.unsafeFlags(["-I", include]),
],
cxxSettings: [
.define("__swift__"),
.define("INTERNAL_EXPERIMENTAL"),
.define("_CRT_SECURE_NO_WARNINGS",
.when(platforms: [.windows])),
.unsafeFlags(["-I", include]),
],
linkerSettings: [
.unsafeFlags([
Expand All @@ -53,6 +71,7 @@ let SwiftFirebase =
],
swiftSettings: [
.interoperabilityMode(.Cxx),
.unsafeFlags(["-Xcc", "-I\(include)"]),
]),
.target(name: "FirebaseAuth",
dependencies: ["firebase", "FirebaseCore"],
Expand All @@ -64,6 +83,7 @@ let SwiftFirebase =
],
swiftSettings: [
.interoperabilityMode(.Cxx),
.unsafeFlags(["-Xcc", "-I\(include)"]),
]),
.target(name: "FirebaseFirestore",
dependencies: ["firebase", "FirebaseCore"],
Expand All @@ -80,6 +100,7 @@ let SwiftFirebase =
],
swiftSettings: [
.interoperabilityMode(.Cxx),
.unsafeFlags(["-Xcc", "-I\(include)"]),
],
linkerSettings: [
.unsafeFlags([
Expand Down Expand Up @@ -155,6 +176,7 @@ let SwiftFirebase =
],
swiftSettings: [
.interoperabilityMode(.Cxx),
.unsafeFlags(["-parse-as-library"])
.unsafeFlags(["-parse-as-library"]),
.unsafeFlags(["-Xcc", "-I\(include)"]),
])
])

0 comments on commit 04853e1

Please sign in to comment.