From 3b13e439a341bbbfe0f710c7d1be37221745ef1a Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Mon, 18 Sep 2023 17:14:21 +0100 Subject: [PATCH] Fix platform conditions in `Package.swift` (#431) Current use of `#if os` is not compatible with cross-compilation. --- Package.swift | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/Package.swift b/Package.swift index 1e0500f6..ab2774c8 100644 --- a/Package.swift +++ b/Package.swift @@ -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", @@ -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", @@ -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