-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPackage.swift
More file actions
87 lines (80 loc) · 2.6 KB
/
Package.swift
File metadata and controls
87 lines (80 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// swift-tools-version: 5.9
import PackageDescription
import Foundation
// SPI Runners do not have FreeTDS installed.
// We detect its presence to avoid Clang scanner errors on SPI.
let hasFreeTDS: Bool = {
// Manual override for local testing
if ProcessInfo.processInfo.environment["SKIP_FREETDS"] != nil { return false }
// 1. Check if the header exists in standard paths.
let standardPaths = [
"/opt/homebrew/include/sybdb.h", // macOS Apple Silicon
"/usr/local/include/sybdb.h", // macOS Intel
"/usr/include/sybdb.h", // Linux (Standard)
"/usr/include/freetds/sybdb.h", // Linux (Alternative)
"/opt/homebrew/opt/freetds/include/sybdb.h" // Brew opt path
]
let headerExists = standardPaths.contains { FileManager.default.fileExists(atPath: $0) }
guard headerExists else { return false }
// 2. Check if pkg-config can actually find it.
// If headers exist but pkg-config fails, the systemLibrary target will cause a build failure.
let process = Process()
process.executableURL = URL(fileURLWithPath: "/usr/bin/env")
process.arguments = ["pkg-config", "--exists", "freetds"]
process.standardOutput = Pipe()
process.standardError = Pipe()
do {
try process.run()
process.waitUntilExit()
return process.terminationStatus == 0
} catch {
return false
}
}()
var packageTargets: [Target] = [
.target(
name: "SQLClientSwift",
dependencies: hasFreeTDS ? ["CFreeTDS"] : [],
path: "Sources/SQLClientSwift",
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency=complete"),
] + (hasFreeTDS ? [.define("FREETDS_FOUND"), .define("DBBCP")] : []),
linkerSettings: [
.linkedLibrary("sybdb", .when(platforms: [.linux]))
]
),
.testTarget(
name: "SQLClientSwiftTests",
dependencies: ["SQLClientSwift"],
path: "Tests/SQLClientSwiftTests"
),
]
if hasFreeTDS {
packageTargets.append(
.systemLibrary(
name: "CFreeTDS",
path: "Sources/CFreeTDS",
pkgConfig: "freetds",
providers: [
.brew(["freetds"]),
.apt(["freetds-dev"]),
]
)
)
}
let package = Package(
name: "SQLClientSwift",
platforms: [
.macOS(.v13),
.iOS(.v16),
.tvOS(.v16),
.visionOS(.v1)
],
products: [
.library(
name: "SQLClientSwift",
targets: ["SQLClientSwift"]
),
],
targets: packageTargets
)