diff --git a/Fixtures/Miscellaneous/DoNotFilterLinkerDiagnostics/Package.swift b/Fixtures/Miscellaneous/DoNotFilterLinkerDiagnostics/Package.swift index 45efb831fa1..636e93fcc67 100644 --- a/Fixtures/Miscellaneous/DoNotFilterLinkerDiagnostics/Package.swift +++ b/Fixtures/Miscellaneous/DoNotFilterLinkerDiagnostics/Package.swift @@ -8,9 +8,7 @@ let package = Package( .executableTarget( name: "DoNotFilterLinkerDiagnostics", linkerSettings: [ - .linkedLibrary("z"), - .unsafeFlags(["-lz"]), - // should produce: ld: warning: ignoring duplicate libraries: '-lz' + .unsafeFlags(["-Lfoobar"]), ] ), ] diff --git a/Sources/Build/BuildDescription/ProductBuildDescription.swift b/Sources/Build/BuildDescription/ProductBuildDescription.swift index 2b662984c8a..88fa223eee9 100644 --- a/Sources/Build/BuildDescription/ProductBuildDescription.swift +++ b/Sources/Build/BuildDescription/ProductBuildDescription.swift @@ -182,6 +182,12 @@ package final class ProductBuildDescription: SPMBuildCore.ProductBuildDescriptio var isLinkingStaticStdlib = false let triple = self.buildParameters.triple + + // radar://112671586 supress unnecessary warnings + if triple.isMacOSX { + args += ["-Xlinker", "-no_warn_duplicate_libraries"] + } + switch derivedProductType { case .macro: throw InternalError("macro not supported") // should never be reached diff --git a/Sources/XCBuildSupport/PIFBuilder.swift b/Sources/XCBuildSupport/PIFBuilder.swift index 153fd73a58a..dffbc7cbe9f 100644 --- a/Sources/XCBuildSupport/PIFBuilder.swift +++ b/Sources/XCBuildSupport/PIFBuilder.swift @@ -685,6 +685,9 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder { impartedSettings[.OTHER_LDFLAGS, default: ["$(inherited)"]].append("-lc++") } + // radar://112671586 supress unnecessary warnings + impartedSettings[.OTHER_LDFLAGS, default: ["$(inherited)"]].append("-Wl,-no_warn_duplicate_libraries") + addSources(target.sources, to: pifTarget) // Handle the target's dependencies (but don't link against them). diff --git a/Tests/BuildTests/BuildPlanTests.swift b/Tests/BuildTests/BuildPlanTests.swift index a4c79b412df..bace9c92a9d 100644 --- a/Tests/BuildTests/BuildPlanTests.swift +++ b/Tests/BuildTests/BuildPlanTests.swift @@ -807,6 +807,7 @@ final class BuildPlanTests: XCTestCase { "-L", buildPath.pathString, "-o", buildPath.appending(components: "exe").pathString, "-module-name", "exe", + "-Xlinker", "-no_warn_duplicate_libraries", "-emit-executable", "-Xlinker", "-rpath", "-Xlinker", "@loader_path", "@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))", @@ -1220,6 +1221,7 @@ final class BuildPlanTests: XCTestCase { "-L", buildPath.pathString, "-o", buildPath.appending(components: "exe").pathString, "-module-name", "exe", + "-Xlinker", "-no_warn_duplicate_libraries", "-emit-executable", "-Xlinker", "-dead_strip", "-Xlinker", "-rpath", "-Xlinker", "@loader_path", @@ -1310,6 +1312,7 @@ final class BuildPlanTests: XCTestCase { "-L", buildPath.pathString, "-o", buildPath.appending(components: "exe").pathString, "-module-name", "exe", + "-Xlinker", "-no_warn_duplicate_libraries", "-emit-executable", "-Xlinker", "-rpath", "-Xlinker", "@loader_path", "@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))", @@ -1469,6 +1472,7 @@ final class BuildPlanTests: XCTestCase { "-L", buildPath.pathString, "-o", buildPath.appending(components: "exe").pathString, "-module-name", "exe", + "-Xlinker", "-no_warn_duplicate_libraries", "-emit-executable", "-Xlinker", "-rpath", "-Xlinker", "@loader_path", "@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))", @@ -1659,6 +1663,7 @@ final class BuildPlanTests: XCTestCase { "-L", buildPath.pathString, "-o", buildPath.appending(components: "exe").pathString, "-module-name", "exe", + "-Xlinker", "-no_warn_duplicate_libraries", "-emit-executable", "-Xlinker", "-rpath", "-Xlinker", "@loader_path", "@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))", @@ -1813,6 +1818,7 @@ final class BuildPlanTests: XCTestCase { "-L", buildPath.pathString, "-o", buildPath.appending(components: "exe").pathString, "-module-name", "exe", + "-Xlinker", "-no_warn_duplicate_libraries", "-emit-executable", "-Xlinker", "-rpath", "-Xlinker", "@loader_path", "@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))", @@ -2061,6 +2067,7 @@ final class BuildPlanTests: XCTestCase { buildPath.appending(components: "PkgPackageTests.xctest", "Contents", "MacOS", "PkgPackageTests") .pathString, "-module-name", "PkgPackageTests", + "-Xlinker", "-no_warn_duplicate_libraries", "-Xlinker", "-bundle", "-Xlinker", "-rpath", "-Xlinker", "@loader_path/../../../", "@\(buildPath.appending(components: "PkgPackageTests.product", "Objects.LinkFileList"))", @@ -2159,6 +2166,7 @@ final class BuildPlanTests: XCTestCase { "-L", buildPath.pathString, "-o", buildPath.appending(components: "exe").pathString, "-module-name", "exe", + "-Xlinker", "-no_warn_duplicate_libraries", "-emit-executable", "-Xlinker", "-dead_strip", "-Xlinker", "-rpath", "-Xlinker", "@loader_path", @@ -2523,6 +2531,7 @@ final class BuildPlanTests: XCTestCase { "-L", buildPath.pathString, "-o", buildPath.appending(components: "exe").pathString, "-module-name", "exe", + "-Xlinker", "-no_warn_duplicate_libraries", "-emit-executable", "-Xlinker", "-rpath", "-Xlinker", "@loader_path", "@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))", @@ -2670,6 +2679,7 @@ final class BuildPlanTests: XCTestCase { "-o", buildPath.appending(components: "Foo").pathString, "-module-name", "Foo", "-lBar-Baz", + "-Xlinker", "-no_warn_duplicate_libraries", "-emit-executable", "-Xlinker", "-rpath", "-Xlinker", "@loader_path", "@\(buildPath.appending(components: "Foo.product", "Objects.LinkFileList"))", @@ -2685,6 +2695,7 @@ final class BuildPlanTests: XCTestCase { "-L", buildPath.pathString, "-o", buildPath.appending(components: "libBar-Baz.dylib").pathString, "-module-name", "Bar_Baz", + "-Xlinker", "-no_warn_duplicate_libraries", "-emit-library", "-Xlinker", "-install_name", "-Xlinker", "@rpath/libBar-Baz.dylib", "-Xlinker", "-rpath", "-Xlinker", "@loader_path", @@ -2837,6 +2848,7 @@ final class BuildPlanTests: XCTestCase { "-L", buildPath.pathString, "-o", buildPath.appending(components: "liblib.dylib").pathString, "-module-name", "lib", + "-Xlinker", "-no_warn_duplicate_libraries", "-emit-library", "-Xlinker", "-install_name", "-Xlinker", "@rpath/liblib.dylib", "-Xlinker", "-rpath", "-Xlinker", "@loader_path", @@ -2976,6 +2988,7 @@ final class BuildPlanTests: XCTestCase { "-L", buildPath.pathString, "-o", buildPath.appending(components: "liblib.dylib").pathString, "-module-name", "lib", + "-Xlinker", "-no_warn_duplicate_libraries", "-emit-library", "-Xlinker", "-install_name", "-Xlinker", "@rpath/liblib.dylib", "-Xlinker", "-rpath", "-Xlinker", "@loader_path", @@ -2990,6 +3003,7 @@ final class BuildPlanTests: XCTestCase { "-L", buildPath.pathString, "-o", buildPath.appending(components: "exe").pathString, "-module-name", "exe", + "-Xlinker", "-no_warn_duplicate_libraries", "-emit-executable", "-Xlinker", "-rpath", "-Xlinker", "@loader_path", "@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))", @@ -6087,6 +6101,7 @@ final class BuildPlanTests: XCTestCase { "-L", buildPath.pathString, "-o", buildPath.appending(components: "exe").pathString, "-module-name", "exe", + "-Xlinker", "-no_warn_duplicate_libraries", "-emit-executable", "@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))", "-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-5.5/macosx", diff --git a/Tests/BuildTests/BuildSystemDelegateTests.swift b/Tests/BuildTests/BuildSystemDelegateTests.swift index 2251dde6d44..4e44a42dafe 100644 --- a/Tests/BuildTests/BuildSystemDelegateTests.swift +++ b/Tests/BuildTests/BuildSystemDelegateTests.swift @@ -25,7 +25,7 @@ final class BuildSystemDelegateTests: XCTestCase { try XCTSkipIf(true, "test is only supported on macOS") #endif let (fullLog, _) = try executeSwiftBuild(fixturePath) - XCTAssertTrue(fullLog.contains("ld: warning: ignoring duplicate libraries: '-lz'"), "log didn't contain expected linker diagnostics") + XCTAssertTrue(fullLog.contains("ld: warning: search path 'foobar' not found"), "log didn't contain expected linker diagnostics") } } diff --git a/Tests/XCBuildSupportTests/PIFBuilderTests.swift b/Tests/XCBuildSupportTests/PIFBuilderTests.swift index f1171d8c706..c03033ecb9f 100644 --- a/Tests/XCBuildSupportTests/PIFBuilderTests.swift +++ b/Tests/XCBuildSupportTests/PIFBuilderTests.swift @@ -1312,6 +1312,7 @@ class PIFBuilderTests: XCTestCase { "-fmodule-map-file=$(OBJROOT)/GeneratedModuleMaps/$(PLATFORM_NAME)/FooLib1.modulemap" ]) XCTAssertEqual(settings[.OTHER_LDRFLAGS], []) + XCTAssertEqual(settings[.OTHER_LDFLAGS], ["$(inherited)", "-Wl,-no_warn_duplicate_libraries"]) } } @@ -1384,7 +1385,7 @@ class PIFBuilderTests: XCTestCase { "-fmodule-map-file=$(OBJROOT)/GeneratedModuleMaps/$(PLATFORM_NAME)/FooLib2.modulemap" ]) XCTAssertEqual(settings[.OTHER_LDRFLAGS], []) - XCTAssertEqual(settings[.OTHER_LDFLAGS], ["$(inherited)", "-lc++"]) + XCTAssertEqual(settings[.OTHER_LDFLAGS], ["$(inherited)", "-lc++", "-Wl,-no_warn_duplicate_libraries"]) XCTAssertEqual(settings[.OTHER_SWIFT_FLAGS], [ "$(inherited)", "-Xcc", "-fmodule-map-file=$(OBJROOT)/GeneratedModuleMaps/$(PLATFORM_NAME)/FooLib2.modulemap" @@ -1463,6 +1464,7 @@ class PIFBuilderTests: XCTestCase { "-fmodule-map-file=$(OBJROOT)/GeneratedModuleMaps/$(PLATFORM_NAME)/BarLib.modulemap" ]) XCTAssertEqual(settings[.OTHER_LDRFLAGS], []) + XCTAssertEqual(settings[.OTHER_LDFLAGS], ["$(inherited)", "-Wl,-no_warn_duplicate_libraries"]) XCTAssertEqual(settings[.OTHER_SWIFT_FLAGS], [ "$(inherited)", "-Xcc", "-fmodule-map-file=$(OBJROOT)/GeneratedModuleMaps/$(PLATFORM_NAME)/BarLib.modulemap" @@ -2406,7 +2408,7 @@ class PIFBuilderTests: XCTestCase { target.checkImpartedBuildSettings { settings in XCTAssertEqual(settings[.GCC_PREPROCESSOR_DEFINITIONS], nil) XCTAssertEqual(settings[.HEADER_SEARCH_PATHS], nil) - XCTAssertEqual(settings[.OTHER_LDFLAGS], ["$(inherited)", "-lz"]) + XCTAssertEqual(settings[.OTHER_LDFLAGS], ["$(inherited)", "-Wl,-no_warn_duplicate_libraries", "-lz"]) XCTAssertEqual(settings[.OTHER_SWIFT_FLAGS], nil) } }