From 589471a967ffaca89fda9d9bad7fb1a33196b0c2 Mon Sep 17 00:00:00 2001 From: Chris McGee Date: Thu, 10 Apr 2025 14:59:25 -0400 Subject: [PATCH 1/6] Switch to swiftc as the linker driver in SwiftBuildSupport --- Sources/SwiftBuildSupport/SwiftBuildSystem.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sources/SwiftBuildSupport/SwiftBuildSystem.swift b/Sources/SwiftBuildSupport/SwiftBuildSystem.swift index 9127648ce3f..ea2ed5d92d8 100644 --- a/Sources/SwiftBuildSupport/SwiftBuildSystem.swift +++ b/Sources/SwiftBuildSupport/SwiftBuildSystem.swift @@ -435,6 +435,8 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem { var settings: [String: String] = [:] // An error with determining the override should not be fatal here. settings["CC"] = try? buildParameters.toolchain.getClangCompiler().pathString + // TODO see if this fixes some of the LD_LIBRARY_PATH problems on Linux + settings["LINKER_DRIVER"] = "swiftc" // Always specify the path of the effective Swift compiler, which was determined in the same way as for the // native build system. settings["SWIFT_EXEC"] = buildParameters.toolchain.swiftCompilerPath.pathString From 2ac1cf168a3c42c4d6f84ada58c5d4db9be98ea5 Mon Sep 17 00:00:00 2001 From: Chris McGee Date: Tue, 22 Apr 2025 08:39:36 -0400 Subject: [PATCH 2/6] Move linker driver setting into PIF Builder for non-CXX targets, and imparted targets --- Sources/SwiftBuildSupport/PackagePIFBuilder.swift | 6 +++--- .../PackagePIFProjectBuilder+Modules.swift | 4 ++++ Sources/SwiftBuildSupport/SwiftBuildSystem.swift | 2 -- Tests/CommandsTests/BuildCommandTests.swift | 9 --------- Tests/CommandsTests/TestCommandTests.swift | 4 ---- 5 files changed, 7 insertions(+), 18 deletions(-) diff --git a/Sources/SwiftBuildSupport/PackagePIFBuilder.swift b/Sources/SwiftBuildSupport/PackagePIFBuilder.swift index 88a2bee948f..ba854b1f461 100644 --- a/Sources/SwiftBuildSupport/PackagePIFBuilder.swift +++ b/Sources/SwiftBuildSupport/PackagePIFBuilder.swift @@ -651,9 +651,9 @@ extension PackagePIFBuilder.LinkedPackageBinary { init?(dependency: ResolvedModule.Dependency, package: ResolvedPackage) { switch dependency { - case .product(let producutDependency, _): - guard producutDependency.hasSourceTargets else { return nil } - self.init(name: producutDependency.name, packageName: package.name, type: .product) + case .product(let productDependency, _): + guard productDependency.hasSourceTargets else { return nil } + self.init(name: productDependency.name, packageName: package.name, type: .product) case .module(let moduleDependency, _): self.init(module: moduleDependency, package: package) diff --git a/Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift b/Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift index bc17d22ee15..ed85ec98ed8 100644 --- a/Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift +++ b/Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift @@ -745,6 +745,10 @@ extension PackagePIFProjectBuilder { } } + if !sourceModule.isCxx { + impartedSettings[.LINKER_DRIVER] = "swiftc" + } + // Impart the linker flags. for (platform, settingsByDeclaration) in sourceModule.allBuildSettings.impartedSettings { // Note: A `nil` platform means that the declaration applies to *all* platforms. diff --git a/Sources/SwiftBuildSupport/SwiftBuildSystem.swift b/Sources/SwiftBuildSupport/SwiftBuildSystem.swift index f86eebd0faf..374a02cf517 100644 --- a/Sources/SwiftBuildSupport/SwiftBuildSystem.swift +++ b/Sources/SwiftBuildSupport/SwiftBuildSystem.swift @@ -443,8 +443,6 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem { var settings: [String: String] = [:] // An error with determining the override should not be fatal here. settings["CC"] = try? buildParameters.toolchain.getClangCompiler().pathString - // TODO see if this fixes some of the LD_LIBRARY_PATH problems on Linux - settings["LINKER_DRIVER"] = "swiftc" // Always specify the path of the effective Swift compiler, which was determined in the same way as for the // native build system. settings["SWIFT_EXEC"] = buildParameters.toolchain.swiftCompilerPath.pathString diff --git a/Tests/CommandsTests/BuildCommandTests.swift b/Tests/CommandsTests/BuildCommandTests.swift index e4c607eff96..5d266543841 100644 --- a/Tests/CommandsTests/BuildCommandTests.swift +++ b/Tests/CommandsTests/BuildCommandTests.swift @@ -950,13 +950,4 @@ class BuildCommandSwiftBuildTests: BuildCommandTestCases { try await super.testBuildSystemDefaultSettings() } - - override func testBuildCompleteMessage() async throws { - #if os(Linux) - throw XCTSkip("SWBINTTODO: Need to properly set LD_LIBRARY_PATH on linux") - #else - try await super.testBuildCompleteMessage() - #endif - } - } diff --git a/Tests/CommandsTests/TestCommandTests.swift b/Tests/CommandsTests/TestCommandTests.swift index e4e79a69b61..28793799401 100644 --- a/Tests/CommandsTests/TestCommandTests.swift +++ b/Tests/CommandsTests/TestCommandTests.swift @@ -699,10 +699,6 @@ class TestCommandSwiftBuildTests: TestCommandTestCase { #endif #if !os(macOS) - override func testSwiftTestXMLOutputVerifySingleTestFailureMessageWithFlagDisabledXCTest() async throws { - throw XCTSkip("Result XML could not be found. The build fails due to an LD_LIBRARY_PATH issue finding swift core libraries. https://github.com/swiftlang/swift-package-manager/issues/8416") - } - override func testSwiftTestXMLOutputVerifyMultipleTestFailureMessageWithFlagEnabledXCTest() async throws { throw XCTSkip("Result XML could not be found. The build fails due to an LD_LIBRARY_PATH issue finding swift core libraries. https://github.com/swiftlang/swift-package-manager/issues/8416") } From dfd403aed9f92c9aa4ba190871006c8f3f86298e Mon Sep 17 00:00:00 2001 From: Chris McGee Date: Tue, 22 Apr 2025 09:23:29 -0400 Subject: [PATCH 3/6] Remove platform-specific linker setting from the PIF Builder --- .../PackagePIFProjectBuilder+Modules.swift | 6 ++++-- Tests/CommandsTests/TestCommandTests.swift | 10 +++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift b/Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift index ed85ec98ed8..62e63b6b53d 100644 --- a/Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift +++ b/Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift @@ -509,10 +509,12 @@ extension PackagePIFProjectBuilder { defaultValue: true ) if enableDuplicateLinkageCulling { - baselineOTHER_LDFLAGS = [ + baselineOTHER_LDFLAGS = [] + // The following linker option is specific to the macOS linker + /*[ "-Wl,-no_warn_duplicate_libraries", "$(inherited)" - ] + ]*/ } else { baselineOTHER_LDFLAGS = ["$(inherited)"] } diff --git a/Tests/CommandsTests/TestCommandTests.swift b/Tests/CommandsTests/TestCommandTests.swift index 28793799401..515339b8ac2 100644 --- a/Tests/CommandsTests/TestCommandTests.swift +++ b/Tests/CommandsTests/TestCommandTests.swift @@ -699,16 +699,20 @@ class TestCommandSwiftBuildTests: TestCommandTestCase { #endif #if !os(macOS) + override func testSwiftTestXMLOutputVerifySingleTestFailureMessageWithFlagDisabledXCTest() async throws { + throw XCTSkip("Result XML could not be found. The build fails because of missing test helper generation logic for non-macOS platforms: https://github.com/swiftlang/swift-package-manager/issues/8479") + } + override func testSwiftTestXMLOutputVerifyMultipleTestFailureMessageWithFlagEnabledXCTest() async throws { - throw XCTSkip("Result XML could not be found. The build fails due to an LD_LIBRARY_PATH issue finding swift core libraries. https://github.com/swiftlang/swift-package-manager/issues/8416") + throw XCTSkip("Result XML could not be found. The build fails because of missing test helper generation logic for non-macOS platforms: https://github.com/swiftlang/swift-package-manager/issues/8479") } override func testSwiftTestXMLOutputVerifySingleTestFailureMessageWithFlagEnabledXCTest() async throws { - throw XCTSkip("Result XML could not be found. The build fails due to an LD_LIBRARY_PATH issue finding swift core libraries. https://github.com/swiftlang/swift-package-manager/issues/8416") + throw XCTSkip("Result XML could not be found. The build fails because of missing test helper generation logic for non-macOS platforms: https://github.com/swiftlang/swift-package-manager/issues/8479") } override func testSwiftTestXMLOutputVerifyMultipleTestFailureMessageWithFlagDisabledXCTest() async throws { - throw XCTSkip("Result XML could not be found. The build fails due to an LD_LIBRARY_PATH issue finding swift core libraries. https://github.com/swiftlang/swift-package-manager/issues/8416") + throw XCTSkip("Result XML could not be found. The build fails because of missing test helper generation logic for non-macOS platforms: https://github.com/swiftlang/swift-package-manager/issues/8479") } override func testSwiftTestSkip() async throws { From 3fb0ef90df6ea6a43fc9332129b0a7a72671e08d Mon Sep 17 00:00:00 2001 From: Chris McGee Date: Tue, 22 Apr 2025 11:08:34 -0400 Subject: [PATCH 4/6] Enable a plugin test for non-macOS Update skip message descriptions with latest failure details Remove the switch for the swiftc linker driver --- .../PackagePIFProjectBuilder+Modules.swift | 4 ---- Tests/CommandsTests/PackageCommandTests.swift | 8 +------- Tests/CommandsTests/TestCommandTests.swift | 8 ++++---- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift b/Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift index 62e63b6b53d..5c560dd1b47 100644 --- a/Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift +++ b/Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift @@ -747,10 +747,6 @@ extension PackagePIFProjectBuilder { } } - if !sourceModule.isCxx { - impartedSettings[.LINKER_DRIVER] = "swiftc" - } - // Impart the linker flags. for (platform, settingsByDeclaration) in sourceModule.allBuildSettings.impartedSettings { // Note: A `nil` platform means that the declaration applies to *all* platforms. diff --git a/Tests/CommandsTests/PackageCommandTests.swift b/Tests/CommandsTests/PackageCommandTests.swift index eb1f658d432..b340ea131f1 100644 --- a/Tests/CommandsTests/PackageCommandTests.swift +++ b/Tests/CommandsTests/PackageCommandTests.swift @@ -3859,15 +3859,9 @@ class PackageCommandSwiftBuildTests: PackageCommandTestCase { } override func testCommandPluginBuildingCallbacks() async throws { - throw XCTSkip("SWBINTTODO: Test fails as plugins are not currenty supported") + throw XCTSkip("SWBINTTODO: Test fails because plugin is not producing expected output to stdout.") } override func testCommandPluginBuildTestability() async throws { throw XCTSkip("SWBINTTODO: Test fails as plugins are not currenty supported") } - -#if !os(macOS) - override func testCommandPluginTestingCallbacks() async throws { - throw XCTSkip("SWBINTTODO: Test fails on inability to find libclang on Linux. Also, plugins are not currently supported") - } -#endif } diff --git a/Tests/CommandsTests/TestCommandTests.swift b/Tests/CommandsTests/TestCommandTests.swift index 515339b8ac2..26cc625dd49 100644 --- a/Tests/CommandsTests/TestCommandTests.swift +++ b/Tests/CommandsTests/TestCommandTests.swift @@ -716,19 +716,19 @@ class TestCommandSwiftBuildTests: TestCommandTestCase { } override func testSwiftTestSkip() async throws { - throw XCTSkip("This fails due to a linker error on Linux. https://github.com/swiftlang/swift-package-manager/issues/8439") + throw XCTSkip("Result XML could not be found. The build fails because of missing test helper generation logic for non-macOS platforms: https://github.com/swiftlang/swift-package-manager/issues/8479") } override func testSwiftTestXMLOutputWhenEmpty() async throws { - throw XCTSkip("This fails due to a linker error on Linux. https://github.com/swiftlang/swift-package-manager/issues/8439") + throw XCTSkip("Result XML could not be found. The build fails because of missing test helper generation logic for non-macOS platforms: https://github.com/swiftlang/swift-package-manager/issues/8479") } override func testSwiftTestFilter() async throws { - throw XCTSkip("This fails due to an unknown linker error on Linux. https://github.com/swiftlang/swift-package-manager/issues/8439") + throw XCTSkip("Result XML could not be found. The build fails because of missing test helper generation logic for non-macOS platforms: https://github.com/swiftlang/swift-package-manager/issues/8479") } override func testSwiftTestParallel() async throws { - throw XCTSkip("This fails due to an unknown linker error on Linux. https://github.com/swiftlang/swift-package-manager/issues/8439") + throw XCTSkip("Result XML could not be found. The build fails because of missing test helper generation logic for non-macOS platforms: https://github.com/swiftlang/swift-package-manager/issues/8479") } #endif } From d9b8942265ddde93ffda04bcb41bab43370c6693 Mon Sep 17 00:00:00 2001 From: Chris McGee Date: Tue, 22 Apr 2025 15:52:54 -0400 Subject: [PATCH 5/6] Add inherited ldflag --- .../SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift b/Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift index 5c560dd1b47..9c8f7159ac8 100644 --- a/Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift +++ b/Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift @@ -509,7 +509,7 @@ extension PackagePIFProjectBuilder { defaultValue: true ) if enableDuplicateLinkageCulling { - baselineOTHER_LDFLAGS = [] + baselineOTHER_LDFLAGS = ["$(inherited)"] // The following linker option is specific to the macOS linker /*[ "-Wl,-no_warn_duplicate_libraries", From a473c9e2c1f5024fd8839f22b3eced1363672d9f Mon Sep 17 00:00:00 2001 From: Chris McGee Date: Thu, 24 Apr 2025 12:18:08 -0400 Subject: [PATCH 6/6] Use the new build setting to silence duplicate library warnings in the linker --- .../PackagePIFProjectBuilder+Modules.swift | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift b/Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift index 9c8f7159ac8..e5550e65003 100644 --- a/Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift +++ b/Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Modules.swift @@ -503,22 +503,14 @@ extension PackagePIFProjectBuilder { } // Additional settings for the linker. - let baselineOTHER_LDFLAGS: [String] let enableDuplicateLinkageCulling = UserDefaults.standard.bool( forKey: "IDESwiftPackagesEnableDuplicateLinkageCulling", defaultValue: true ) if enableDuplicateLinkageCulling { - baselineOTHER_LDFLAGS = ["$(inherited)"] - // The following linker option is specific to the macOS linker - /*[ - "-Wl,-no_warn_duplicate_libraries", - "$(inherited)" - ]*/ - } else { - baselineOTHER_LDFLAGS = ["$(inherited)"] + impartedSettings[.LD_WARN_DUPLICATE_LIBRARIES] = "NO" } - impartedSettings[.OTHER_LDFLAGS] = (sourceModule.isCxx ? ["-lc++"] : []) + baselineOTHER_LDFLAGS + impartedSettings[.OTHER_LDFLAGS] = (sourceModule.isCxx ? ["-lc++"] : []) + ["$(inherited)"] impartedSettings[.OTHER_LDRFLAGS] = [] log( .debug,