Skip to content

Commit 7057b4b

Browse files
michael-yujijakepetroules
authored andcommitted
check linker settings by triples' object format instead of os name
1 parent 98633fe commit 7057b4b

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

Sources/Build/BuildDescription/ProductBuildDescription.swift

+5-2
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,14 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
270270
// Set rpath such that dynamic libraries are looked up
271271
// adjacent to the product, unless overridden.
272272
if !self.buildParameters.linkingParameters.shouldDisableLocalRpath {
273-
if triple.isLinux() || triple.isFreeBSD() {
273+
switch triple.objectFormat {
274+
case .elf:
274275
args += ["-Xlinker", "-rpath=$ORIGIN"]
275-
} else if triple.isDarwin() {
276+
case .macho:
276277
let rpath = self.product.type == .test ? "@loader_path/../../../" : "@loader_path"
277278
args += ["-Xlinker", "-rpath", "-Xlinker", rpath]
279+
case .coff, .xcoff, .wasm:
280+
break
278281
}
279282
}
280283
args += ["@\(self.linkFileListPath.pathString)"]

Sources/Build/BuildDescription/SwiftModuleBuildDescription.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public final class SwiftModuleBuildDescription {
144144
public var moduleOutputPath: AbsolutePath { // note: needs to be public because of sourcekit-lsp
145145
// If we're an executable and we're not allowing test targets to link against us, we hide the module.
146146
let triple = buildParameters.triple
147-
let allowLinkingAgainstExecutables = (triple.isDarwin() || triple.isLinux() || triple.isFreeBSD() || triple.isWindows()) && self.toolsVersion >= .v5_5
147+
let allowLinkingAgainstExecutables = [.coff, .macho, .elf].contains(triple.objectFormat) && self.toolsVersion >= .v5_5
148148
let dirPath = (target.type == .executable && !allowLinkingAgainstExecutables) ? self.tempsPath : self.modulesPath
149149
return dirPath.appending(component: "\(self.target.c99name).swiftmodule")
150150
}

Sources/Build/BuildPlan/BuildPlan.swift

+4-3
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,12 @@ extension BuildParameters {
146146
/// platform, or nil if the linker doesn't support it for the platform.
147147
func linkerFlagsForRenamingMainFunction(of target: ResolvedModule) -> [String]? {
148148
let args: [String]
149-
if self.triple.isApple() {
149+
switch self.triple.objectFormat {
150+
case .macho:
150151
args = ["-alias", "_\(target.c99name)_main", "_main"]
151-
} else if self.triple.isLinux() || self.triple.isFreeBSD() {
152+
case .elf:
152153
args = ["--defsym", "main=\(target.c99name)_main"]
153-
} else {
154+
case .xcoff, .coff, .wasm:
154155
return nil
155156
}
156157
return args.asSwiftcLinkerFlags()

0 commit comments

Comments
 (0)