Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 52 additions & 8 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let package = Package(
.library(
name: "SQLClientSwift",
targets: ["SQLClientSwift"]
),
)
],

targets: [
Expand All @@ -27,10 +27,10 @@ let package = Package(
// On macOS/iOS you still need to link libsybdb.a manually.
.systemLibrary(
name: "CFreeTDS",
pkgConfig: "freetds", // resolved via `pkg-config freetds`
pkgConfig: "freetds", // resolved via `pkg-config freetds`
providers: [
.brew(["freetds"]), // macOS: brew install freetds
.apt(["freetds-dev"]), // Linux: apt install freetds-dev
.brew(["freetds"]), // macOS: brew install freetds
.apt(["freetds-dev"]), // Linux: apt install freetds-dev
]
),

Expand All @@ -39,14 +39,35 @@ let package = Package(
name: "SQLClientSwift",
dependencies: ["CFreeTDS"],
path: "Sources/SQLClientSwift",
cSettings: [
// Added compiler flags to direct CC to look for freetds in both
// MacOS intel and MacOS Arm directories.
.unsafeFlags([
"-I/opt/homebrew/opt/freetds/include/", // Apple Silicon
"-I/usr/local/opt/freetds/include/", // Intel
])
],
swiftSettings: [
// Enable strict concurrency checking (Swift 5.9+)
.enableExperimentalFeature("StrictConcurrency=complete"),
// Pass both Homebrew prefix locations to the C compiler so
// angle bracket includes in CFreeTDS.h resolve on both
// Intel (/usr/local) and Apple Silicon (/opt/homebrew) Macs.
// The compiler silently ignores paths that don't exist,
// so providing both is safe.
.unsafeFlags(
[
"-Xcc", "-I/opt/homebrew/opt/freetds/include/", // Apple Silicon
"-Xcc", "-I/usr/local/opt/freetds/include/", // Intel
], .when(platforms: [.macOS])),
],
linkerSettings: [
.unsafeFlags(["-L/opt/homebrew/opt/freetds/lib"], .when(platforms: [.macOS])),
.unsafeFlags(
[
"-L/opt/homebrew/opt/freetds/lib", // Apple Silicon
"-L/usr/local/opt/freetds/lib", // Intel
], .when(platforms: [.macOS])),
.linkedLibrary("sybdb"),
.linkedLibrary("iconv", .when(platforms: [.macOS]))
.linkedLibrary("iconv", .when(platforms: [.macOS])),
]
),

Expand All @@ -56,7 +77,30 @@ let package = Package(
.testTarget(
name: "SQLClientSwiftTests",
dependencies: ["SQLClientSwift"],
path: "Tests/SQLClientSwiftTests"
path: "Tests/SQLClientSwiftTests",
cSettings: [
.unsafeFlags([
"-I/opt/homebrew/opt/freetds/include/", // Apple Silicon
"-I/usr/local/opt/freetds/include/", // Intel
])
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency=complete"),
.unsafeFlags(
[
"-Xcc", "-I/opt/homebrew/opt/freetds/include/", // Apple Silicon
"-Xcc", "-I/usr/local/opt/freetds/include/", // Intel
], .when(platforms: [.macOS])),
],
linkerSettings: [
.unsafeFlags(
[
"-L/opt/homebrew/opt/freetds/lib", // Apple Silicon
"-L/usr/local/opt/freetds/lib", // Intel
], .when(platforms: [.macOS])),
.linkedLibrary("sybdb"),
.linkedLibrary("iconv", .when(platforms: [.macOS])),
]
),
]
)
7 changes: 2 additions & 5 deletions Sources/CFreeTDS/include/CFreeTDS.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#ifndef CFREETDS_H
#define CFREETDS_H

#ifdef __APPLE__
#include "/opt/homebrew/opt/freetds/include/sybdb.h"
#include "/opt/homebrew/opt/freetds/include/sybfront.h"
#else
#pragma once

#include <sybdb.h>
#include <sybfront.h>
#endif

#endif /* CFREETDS_H */