11// swift-tools-version: 5.9
22import PackageDescription
3+ import Foundation
4+
5+ // SPI Runners do not have FreeTDS installed.
6+ // We detect its presence to avoid Clang scanner errors on SPI.
7+ let hasFreeTDS : Bool = {
8+ // Manual override for local testing
9+ if ProcessInfo . processInfo. environment [ " SKIP_FREETDS " ] != nil { return false }
10+
11+ let standardPaths = [
12+ " /opt/homebrew/include/sybdb.h " , // macOS Apple Silicon
13+ " /usr/local/include/sybdb.h " , // macOS Intel
14+ " /usr/include/sybdb.h " , // Linux (Standard)
15+ " /usr/include/freetds/sybdb.h " , // Linux (Alternative)
16+ " /opt/homebrew/opt/freetds/include/sybdb.h " // Brew opt path
17+ ]
18+ return standardPaths. contains { FileManager . default. fileExists ( atPath: $0) }
19+ } ( )
20+
21+ var packageTargets : [ Target ] = [
22+ . target(
23+ name: " SQLClientSwift " ,
24+ dependencies: hasFreeTDS ? [ " CFreeTDS " ] : [ ] ,
25+ path: " Sources/SQLClientSwift " ,
26+ swiftSettings: [
27+ . enableExperimentalFeature( " StrictConcurrency=complete " ) ,
28+ ] + ( hasFreeTDS ? [ . define( " FREETDS_FOUND " ) ] : [ ] ) ,
29+ linkerSettings: [
30+ . linkedLibrary( " sybdb " , . when( platforms: [ . linux] ) )
31+ ]
32+ ) ,
33+ . testTarget(
34+ name: " SQLClientSwiftTests " ,
35+ dependencies: [ " SQLClientSwift " ] ,
36+ path: " Tests/SQLClientSwiftTests "
37+ ) ,
38+ ]
39+
40+ if hasFreeTDS {
41+ packageTargets. append (
42+ . systemLibrary(
43+ name: " CFreeTDS " ,
44+ path: " Sources/CFreeTDS " ,
45+ pkgConfig: " freetds " ,
46+ providers: [
47+ . brew( [ " freetds " ] ) ,
48+ . apt( [ " freetds-dev " ] ) ,
49+ ]
50+ )
51+ )
52+ }
353
454let package = Package (
555 name: " SQLClientSwift " ,
@@ -12,35 +62,5 @@ let package = Package(
1262 targets: [ " SQLClientSwift " ]
1363 ) ,
1464 ] ,
15- targets: [
16- // systemLibrary uses pkg-config to find FreeTDS at build time.
17- // No hardcoded paths, no unsafeFlags — works as an SPM dependency.
18- // macOS : brew install freetds && brew install pkg-config
19- // Linux : sudo apt install freetds-dev
20- . systemLibrary(
21- name: " CFreeTDS " ,
22- path: " Sources/CFreeTDS " ,
23- pkgConfig: " freetds " ,
24- providers: [
25- . brew( [ " freetds " ] ) ,
26- . apt( [ " freetds-dev " ] ) ,
27- ]
28- ) ,
29- . target(
30- name: " SQLClientSwift " ,
31- dependencies: [ " CFreeTDS " ] ,
32- path: " Sources/SQLClientSwift " ,
33- swiftSettings: [
34- . enableExperimentalFeature( " StrictConcurrency=complete " ) ,
35- ] ,
36- linkerSettings: [
37- . linkedLibrary( " sybdb " , . when( platforms: [ . linux] ) )
38- ]
39- ) ,
40- . testTarget(
41- name: " SQLClientSwiftTests " ,
42- dependencies: [ " SQLClientSwift " ] ,
43- path: " Tests/SQLClientSwiftTests "
44- ) ,
45- ]
46- )
65+ targets: packageTargets
66+ )
0 commit comments