Skip to content
Open
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
12 changes: 12 additions & 0 deletions Fixtures/PIFBuilder/BasicExecutable/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// swift-tools-version: 6.2

import PackageDescription

let package = Package(
name: "BasicExecutable",
targets: [
.executableTarget(
name: "Executable",
),
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// The Swift Programming Language
// https://docs.swift.org/swift-book

@main
struct BasicExecutable {
static func main() {
print("Hello, world!")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,9 @@ extension PackagePIFProjectBuilder {
// Redirect the built executable into a separate directory so it won't conflict with the real one.
settings[.TARGET_BUILD_DIR] = "$(TARGET_BUILD_DIR)/ExecutableModules"

// on windows modules are libraries, so we need to add a search path so the linker finds them
impartedSettings[.LIBRARY_SEARCH_PATHS, .windows] = ["$(inherited)", "$(TARGET_BUILD_DIR)/ExecutableModules"]

// Don't install the Swift module of the testable side-built artifact, lest it conflict with the regular
// one.
// The modules should have compatible contents in any case — only the entry point function name is
Expand Down
22 changes: 21 additions & 1 deletion Tests/SwiftBuildSupportTests/PIFBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,26 @@ extension SwiftBuild.ProjectModel.BaseTarget {

@Suite
struct PIFBuilderTests {

@Test func platformExecutableModuleLibrarySearchPath() async throws {
try await withGeneratedPIF(fromFixture: "PIFBuilder/BasicExecutable") { pif, observabilitySystem in
let releaseConfig = try pif.workspace
.project(named: "BasicExecutable")
.target(named: "Executable")
.buildConfig(named: "Release")

for platform in ProjectModel.BuildSettings.Platform.allCases {
let search_paths = releaseConfig.impartedBuildProperties.settings[.LIBRARY_SEARCH_PATHS, platform]
switch platform {
case .macOS, .macCatalyst, .iOS, .watchOS, .tvOS, .xrOS, .driverKit, .freebsd, .android, .linux, .wasi, .openbsd, ._iOSDevice:
#expect(search_paths == nil, "for platform \(platform)")
case .windows:
#expect(search_paths == ["$(inherited)", "$(TARGET_BUILD_DIR)/ExecutableModules"], "for platform \(platform)")
}
}
}
}

@Test func platformConditionBasics() async throws {
try await withGeneratedPIF(fromFixture: "PIFBuilder/UnknownPlatforms") { pif, observabilitySystem in
// We should emit a warning to the PIF log about the unknown platform
Expand Down Expand Up @@ -182,7 +202,7 @@ struct PIFBuilderTests {
case .macOS, .macCatalyst, .iOS, .watchOS, .tvOS, .xrOS, .driverKit, .freebsd:
#expect(ld_flags == ["-lc++", "$(inherited)"], "for platform \(platform)")
case .android, .linux, .wasi, .openbsd:
#expect(ld_flags == ["-lstdc++", "$(inherited)"], "for platform \(platform)")
#expect(ld_flags == ["-lstdc++", "$(inherited)"], "for platform \(platform)")
case .windows, ._iOSDevice:
#expect(ld_flags == nil, "for platform \(platform)")
}
Expand Down