Skip to content

Commit 051c8e6

Browse files
committed
Added cSettings flags directing CLANG to look for import directories in both X86 and ARM64 locations.
Added all build targets to test target as well, so the program compiles under test and build instructions.
1 parent 7718f48 commit 051c8e6

File tree

2 files changed

+49
-26
lines changed

2 files changed

+49
-26
lines changed

Package.swift

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ let package = Package(
1717
.library(
1818
name: "SQLClientSwift",
1919
targets: ["SQLClientSwift"]
20-
),
20+
)
2121
],
2222

2323
targets: [
@@ -27,10 +27,10 @@ let package = Package(
2727
// On macOS/iOS you still need to link libsybdb.a manually.
2828
.systemLibrary(
2929
name: "CFreeTDS",
30-
pkgConfig: "freetds", // resolved via `pkg-config freetds`
30+
pkgConfig: "freetds", // resolved via `pkg-config freetds`
3131
providers: [
32-
.brew(["freetds"]), // macOS: brew install freetds
33-
.apt(["freetds-dev"]), // Linux: apt install freetds-dev
32+
.brew(["freetds"]), // macOS: brew install freetds
33+
.apt(["freetds-dev"]), // Linux: apt install freetds-dev
3434
]
3535
),
3636

@@ -39,25 +39,35 @@ let package = Package(
3939
name: "SQLClientSwift",
4040
dependencies: ["CFreeTDS"],
4141
path: "Sources/SQLClientSwift",
42+
cSettings: [
43+
// Added compiler flags to direct CC to look for freetds in both
44+
// MacOS intel and MacOS Arm directories.
45+
.unsafeFlags([
46+
"-I/opt/homebrew/opt/freetds/include/", // Apple Silicon
47+
"-I/usr/local/opt/freetds/include/", // Intel
48+
])
49+
],
4250
swiftSettings: [
4351
.enableExperimentalFeature("StrictConcurrency=complete"),
4452
// Pass both Homebrew prefix locations to the C compiler so
4553
// angle bracket includes in CFreeTDS.h resolve on both
4654
// Intel (/usr/local) and Apple Silicon (/opt/homebrew) Macs.
4755
// The compiler silently ignores paths that don't exist,
4856
// so providing both is safe.
49-
.unsafeFlags([
50-
"-Xcc", "-I/opt/homebrew/opt/freetds/include", // Apple Silicon
51-
"-Xcc", "-I/usr/local/opt/freetds/include", // Intel
52-
], .when(platforms: [.macOS])),
57+
.unsafeFlags(
58+
[
59+
"-Xcc", "-I/opt/homebrew/opt/freetds/include/", // Apple Silicon
60+
"-Xcc", "-I/usr/local/opt/freetds/include/", // Intel
61+
], .when(platforms: [.macOS])),
5362
],
5463
linkerSettings: [
55-
.unsafeFlags([
56-
"-L/opt/homebrew/opt/freetds/lib", // Apple Silicon
57-
"-L/usr/local/opt/freetds/lib", // Intel
58-
], .when(platforms: [.macOS])),
64+
.unsafeFlags(
65+
[
66+
"-L/opt/homebrew/opt/freetds/lib", // Apple Silicon
67+
"-L/usr/local/opt/freetds/lib", // Intel
68+
], .when(platforms: [.macOS])),
5969
.linkedLibrary("sybdb"),
60-
.linkedLibrary("iconv", .when(platforms: [.macOS]))
70+
.linkedLibrary("iconv", .when(platforms: [.macOS])),
6171
]
6272
),
6373

@@ -67,7 +77,30 @@ let package = Package(
6777
.testTarget(
6878
name: "SQLClientSwiftTests",
6979
dependencies: ["SQLClientSwift"],
70-
path: "Tests/SQLClientSwiftTests"
80+
path: "Tests/SQLClientSwiftTests",
81+
cSettings: [
82+
.unsafeFlags([
83+
"-I/opt/homebrew/opt/freetds/include/", // Apple Silicon
84+
"-I/usr/local/opt/freetds/include/", // Intel
85+
])
86+
],
87+
swiftSettings: [
88+
.enableExperimentalFeature("StrictConcurrency=complete"),
89+
.unsafeFlags(
90+
[
91+
"-Xcc", "-I/opt/homebrew/opt/freetds/include/", // Apple Silicon
92+
"-Xcc", "-I/usr/local/opt/freetds/include/", // Intel
93+
], .when(platforms: [.macOS])),
94+
],
95+
linkerSettings: [
96+
.unsafeFlags(
97+
[
98+
"-L/opt/homebrew/opt/freetds/lib", // Apple Silicon
99+
"-L/usr/local/opt/freetds/lib", // Intel
100+
], .when(platforms: [.macOS])),
101+
.linkedLibrary("sybdb"),
102+
.linkedLibrary("iconv", .when(platforms: [.macOS])),
103+
]
71104
),
72105
]
73106
)

Sources/CFreeTDS/include/CFreeTDS.h

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,7 @@
33

44
#pragma once
55

6-
#ifdef __APPLE__
7-
#ifdef __x86_64__
8-
#include "/usr/local/opt/freetds/include/sybdb.h"
9-
#include "/usr/local/opt/freetds/include/sybfront.h"
10-
#else
11-
#include "/opt/homebrew/opt/freetds/include/sybdb.h"
12-
#include "/opt/homebrew/opt/freetds/include/sybfront.h"
13-
#endif
14-
#else
15-
#include <sybdb.h>
16-
#include <sybfront.h>
17-
#endif
6+
#include <sybdb.h>
7+
#include <sybfront.h>
188

199
#endif /* CFREETDS_H */

0 commit comments

Comments
 (0)