Skip to content

Commit 0df5c34

Browse files
committed
Fix build for Swift Package Index by dynamically detecting FreeTDS and guarding imports
1 parent f6d1387 commit 0df5c34

1,334 files changed

Lines changed: 1595 additions & 191 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.spi.yml

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,5 @@
11
version: 1
22
builder:
33
configs:
4-
# Linux builds — apt-install FreeTDS before building.
5-
# macOS builds are excluded: SPI's macOS runners cannot pre-install
6-
# Homebrew packages, so pkg-config cannot locate FreeTDS at build time.
7-
# macOS users install via: brew install freetds
4+
- platform: macos-spm
85
- platform: linux
9-
swift_version: '5.10'
10-
linux_packages:
11-
- freetds-dev
12-
- pkg-config
13-
- platform: linux
14-
swift_version: '6.0'
15-
linux_packages:
16-
- freetds-dev
17-
- pkg-config
18-
- platform: linux
19-
swift_version: '6.1'
20-
linux_packages:
21-
- freetds-dev
22-
- pkg-config
23-
- platform: linux
24-
swift_version: '6.2'
25-
linux_packages:
26-
- freetds-dev
27-
- pkg-config

Package.swift

Lines changed: 52 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,55 @@
11
// swift-tools-version: 5.9
22
import 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

454
let 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+
)
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
#ifndef CFREETDS_H
2-
#define CFREETDS_H
3-
41
#pragma once
52

3+
// Wrapper header for FreeTDS / libsybdb.
4+
// This module is only included in the package graph if sybdb.h is detected.
5+
66
#include <sybdb.h>
77
#include <sybfront.h>
8-
9-
#endif /* CFREETDS_H */

0 commit comments

Comments
 (0)