Skip to content

Commit

Permalink
Fix platform conditions in Package.swift (#432)
Browse files Browse the repository at this point in the history
Cherry-pick of #431.

Current use of #if os is not compatible with cross-compilation.
  • Loading branch information
MaxDesiatov committed Sep 18, 2023
1 parent 5446eab commit 3695ee4
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ let package = Package(
/** Shim target to import missing C headers in Darwin and Glibc modulemap. */
name: "TSCclibc",
dependencies: [],
exclude: CMakeFiles),
exclude: CMakeFiles,
cSettings: [
.define("_GNU_SOURCE", .when(platforms: [.linux])),
]),
.target(
/** Cross-platform access to bare `libc` functionality. */
name: "TSCLibc",
Expand All @@ -68,7 +71,13 @@ let package = Package(
"TSCclibc",
.product(name: "SystemPackage", package: "swift-system"),
],
exclude: CMakeFiles + ["README.md"]),
exclude: CMakeFiles + ["README.md"],
cxxSettings: [
.define("_CRT_SECURE_NO_WARNINGS", .when(platforms: [.windows])),
],
linkerSettings: [
.linkedLibrary("Pathcch", .when(platforms: [.windows])),
]),
.target(
/** Abstractions for common operations, should migrate to TSCBasic */
name: "TSCUtility",
Expand Down Expand Up @@ -111,22 +120,3 @@ let package = Package(
.package(path: "../swift-system"),
]
}

// FIXME: conditionalise these flags since SwiftPM 5.3 and earlier will crash
// for platforms they don't know about.
#if os(Windows)
if let TSCBasic = package.targets.first(where: { $0.name == "TSCBasic" }) {
TSCBasic.cxxSettings = [
.define("_CRT_SECURE_NO_WARNINGS", .when(platforms: [.windows])),
]
TSCBasic.linkerSettings = [
.linkedLibrary("Pathcch", .when(platforms: [.windows])),
]
}
#elseif os(Linux)
if let TSCclibc = package.targets.first(where: { $0.name == "TSCclibc" }) {
TSCclibc.cSettings = [
.define("_GNU_SOURCE", .when(platforms: [.linux])),
]
}
#endif

0 comments on commit 3695ee4

Please sign in to comment.