Skip to content

[6.0] Fix SwiftPM build dispatch include path on Windows #5035

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
15 changes: 8 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,15 @@ endif()
find_package(dispatch CONFIG)
if(NOT dispatch_FOUND)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android")
set(DISPATCH_INCLUDE_PATH "/usr/lib/swift" CACHE STRING "A path to where you can find libdispatch headers")
message("-- dispatch_DIR not found, using dispatch from SDK at ${DISPATCH_INCLUDE_PATH}")
list(APPEND _Foundation_common_build_flags
"-I${DISPATCH_INCLUDE_PATH}"
"-I${DISPATCH_INCLUDE_PATH}/Block")
else()
message(FATAL_ERROR "-- dispatch_DIR is required on this platform")
set(DEFAULT_DISPATCH_INCLUDE_PATH "/usr/lib/swift")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(DEFAULT_DISPATCH_INCLUDE_PATH "$ENV{SDKROOT}usr/include")
endif()
set(DISPATCH_INCLUDE_PATH "${DEFAULT_DISPATCH_INCLUDE_PATH}" CACHE STRING "A path to where you can find libdispatch headers")
message("-- dispatch_DIR not found, using dispatch from SDK at ${DISPATCH_INCLUDE_PATH}")
list(APPEND _Foundation_common_build_flags
"-I${DISPATCH_INCLUDE_PATH}"
"-I${DISPATCH_INCLUDE_PATH}/Block")
endif()
find_package(LibXml2 REQUIRED)
find_package(CURL REQUIRED)
Expand Down
32 changes: 19 additions & 13 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,25 @@

import PackageDescription

var dispatchIncludeFlags: CSetting
var dispatchIncludeFlags: [CSetting]
if let environmentPath = Context.environment["DISPATCH_INCLUDE_PATH"] {
dispatchIncludeFlags = .unsafeFlags([
dispatchIncludeFlags = [.unsafeFlags([
"-I\(environmentPath)",
"-I\(environmentPath)/Block"
])
])]
} else {
dispatchIncludeFlags = .unsafeFlags([
"-I/usr/lib/swift",
"-I/usr/lib/swift/Block"
], .when(platforms: [.linux, .android]))
dispatchIncludeFlags = [
.unsafeFlags([
"-I/usr/lib/swift",
"-I/usr/lib/swift/Block"
], .when(platforms: [.linux, .android]))
]
if let sdkRoot = Context.environment["SDKROOT"] {
dispatchIncludeFlags.append(.unsafeFlags([
"-I\(sdkRoot)usr\\include",
"-I\(sdkRoot)usr\\include\\Block",
], .when(platforms: [.windows])))
}
}

let coreFoundationBuildSettings: [CSetting] = [
Expand Down Expand Up @@ -43,9 +51,8 @@ let coreFoundationBuildSettings: [CSetting] = [
"-include",
"\(Context.packageDirectory)/Sources/CoreFoundation/internalInclude/CoreFoundation_Prefix.h",
// /EHsc for Windows
]),
dispatchIncludeFlags
]
])
] + dispatchIncludeFlags

// For _CFURLSessionInterface, _CFXMLInterface
let interfaceBuildSettings: [CSetting] = [
Expand All @@ -71,9 +78,8 @@ let interfaceBuildSettings: [CSetting] = [
"-fno-common",
"-fcf-runtime-abi=swift"
// /EHsc for Windows
]),
dispatchIncludeFlags
]
])
] + dispatchIncludeFlags

let swiftBuildSettings: [SwiftSetting] = [
.define("DEPLOYMENT_RUNTIME_SWIFT"),
Expand Down