diff --git a/Fixtures/PIFBuilder/BasicExecutable/Package.swift b/Fixtures/PIFBuilder/BasicExecutable/Package.swift new file mode 100644 index 00000000000..b369662574f --- /dev/null +++ b/Fixtures/PIFBuilder/BasicExecutable/Package.swift @@ -0,0 +1,12 @@ +// swift-tools-version: 6.2 + +import PackageDescription + +let package = Package( + name: "BasicExecutable", + targets: [ + .executableTarget( + name: "Executable", + ), + ] +) diff --git a/Fixtures/PIFBuilder/BasicExecutable/Sources/BasicExecutable/BasicExecutable.swift b/Fixtures/PIFBuilder/BasicExecutable/Sources/BasicExecutable/BasicExecutable.swift new file mode 100644 index 00000000000..8b32e00dca1 --- /dev/null +++ b/Fixtures/PIFBuilder/BasicExecutable/Sources/BasicExecutable/BasicExecutable.swift @@ -0,0 +1,9 @@ +// The Swift Programming Language +// https://docs.swift.org/swift-book + +@main +struct BasicExecutable { + static func main() { + print("Hello, world!") + } +} diff --git a/Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift b/Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift index a36ea1b48f2..0fa439ab914 100644 --- a/Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift +++ b/Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift @@ -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 diff --git a/Tests/SwiftBuildSupportTests/PIFBuilderTests.swift b/Tests/SwiftBuildSupportTests/PIFBuilderTests.swift index 80f00260ee5..864abe24846 100644 --- a/Tests/SwiftBuildSupportTests/PIFBuilderTests.swift +++ b/Tests/SwiftBuildSupportTests/PIFBuilderTests.swift @@ -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 @@ -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)") }