Skip to content

Commit 3f281fb

Browse files
committed
Swift Build linker fixes for linux tests
1 parent a99919e commit 3f281fb

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

Sources/SwiftBuildSupport/PackagePIFBuilder+Helpers.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ extension ProjectModel.BuildSettings {
897897
// Appending implies the setting is resilient to having ["$(inherited)"]
898898
self.platformSpecificSettings[platform]![setting]!.append(contentsOf: values)
899899

900-
case .SWIFT_VERSION:
900+
case .SWIFT_VERSION, .DYLIB_INSTALL_NAME_BASE:
901901
self.platformSpecificSettings[platform]![setting] = values // We are not resilient to $(inherited).
902902

903903
case .ARCHS, .IPHONEOS_DEPLOYMENT_TARGET, .SPECIALIZATION_SDK_OPTIONS:
@@ -919,6 +919,9 @@ extension ProjectModel.BuildSettings {
919919
case .SWIFT_VERSION:
920920
self[.SWIFT_VERSION] = values.only.unwrap(orAssert: "Invalid values for 'SWIFT_VERSION': \(values)")
921921

922+
case .DYLIB_INSTALL_NAME_BASE:
923+
self[.DYLIB_INSTALL_NAME_BASE] = values.only.unwrap(orAssert: "Invalid values for 'DYLIB_INSTALL_NAME_BASE': \(values)")
924+
922925
case .ARCHS, .IPHONEOS_DEPLOYMENT_TARGET, .SPECIALIZATION_SDK_OPTIONS:
923926
fatalError("Unexpected BuildSettings.Declaration: \(setting)")
924927
}
@@ -947,7 +950,7 @@ extension ProjectModel.BuildSettings.MultipleValueSetting {
947950
self = .SPECIALIZATION_SDK_OPTIONS
948951
case .SWIFT_ACTIVE_COMPILATION_CONDITIONS:
949952
self = .SWIFT_ACTIVE_COMPILATION_CONDITIONS
950-
case .ARCHS, .IPHONEOS_DEPLOYMENT_TARGET, .SWIFT_VERSION:
953+
case .ARCHS, .IPHONEOS_DEPLOYMENT_TARGET, .SWIFT_VERSION, .DYLIB_INSTALL_NAME_BASE:
951954
return nil
952955
}
953956
}

Sources/SwiftBuildSupport/PackagePIFBuilder.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ public final class PackagePIFBuilder {
364364
case .framework: .framework
365365
case .executable: .executable
366366
case .unitTest: .unitTest
367+
case .swiftpmTestRunner: .unitTestRunner
367368
case .bundle: .bundle
368369
case .packageProduct: .packageProduct
369370
case .hostBuildTool: fatalError("Unexpected hostBuildTool type")
@@ -499,7 +500,15 @@ public final class PackagePIFBuilder {
499500
settings[.WATCHOS_DEPLOYMENT_TARGET] = builder.deploymentTargets[.watchOS] ?? nil
500501
settings[.DRIVERKIT_DEPLOYMENT_TARGET] = builder.deploymentTargets[.driverKit] ?? nil
501502
settings[.XROS_DEPLOYMENT_TARGET] = builder.deploymentTargets[.visionOS] ?? nil
502-
settings[.DYLIB_INSTALL_NAME_BASE] = "@rpath"
503+
504+
for machoPlatform in [ProjectModel.BuildSettings.Platform.macOS, .macCatalyst, .iOS, .watchOS, .tvOS, .xrOS, .driverKit] {
505+
settings.platformSpecificSettings[machoPlatform]![.DYLIB_INSTALL_NAME_BASE]! = ["@rpath"]
506+
}
507+
for elfPlatform in [ProjectModel.BuildSettings.Platform.linux, .android] {
508+
// FIXME: Treating $ORIGIN as part of the soname is not really the right thing to do here
509+
settings.platformSpecificSettings[elfPlatform]![.DYLIB_INSTALL_NAME_BASE]! = ["$ORIGIN"]
510+
}
511+
503512
settings[.USE_HEADERMAP] = "NO"
504513
settings[.OTHER_SWIFT_FLAGS].lazilyInitializeAndMutate(initialValue: ["$(inherited)"]) { $0.append("-DXcode") }
505514

Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Products.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,13 +1036,10 @@ extension PackagePIFProjectBuilder {
10361036
settings[.PRODUCT_BUNDLE_IDENTIFIER] = "\(self.package.identity).\(name)"
10371037
.spm_mangledToBundleIdentifier()
10381038
settings[.EXECUTABLE_NAME] = name
1039-
settings[.LD_RUNPATH_SEARCH_PATHS] = [
1040-
"@loader_path/Frameworks",
1041-
"@loader_path/../Frameworks",
1042-
"$(inherited)"
1043-
]
10441039
settings[.SKIP_INSTALL] = "NO"
10451040
settings[.SWIFT_VERSION] = "5.0"
1041+
// This should eventually be set universally for all package targets/products.
1042+
settings[.LINKER_DRIVER] = "swiftc"
10461043

10471044
let deploymentTargets = unitTestProduct.deploymentTargets
10481045
settings[.MACOSX_DEPLOYMENT_TARGET] = deploymentTargets?[.macOS] ?? nil

0 commit comments

Comments
 (0)