Skip to content

Commit 9d2cf77

Browse files
committed
WIP: Add Linux support
1 parent f25f609 commit 9d2cf77

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

Sources/Build/BuildPlan.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,7 @@ public final class SwiftTargetBuildDescription {
504504

505505
/// The path to the swiftmodule file after compilation.
506506
var moduleOutputPath: AbsolutePath {
507-
let dirPath = (target.type == .executable) ? tempsPath : buildParameters.buildPath
508-
return dirPath.appending(component: target.c99name + ".swiftmodule")
507+
return buildParameters.buildPath.appending(component: target.c99name + ".swiftmodule")
509508
}
510509

511510
/// The path to the wrapped swift module which is created using the modulewrap tool. This is required

Sources/Build/ManifestBuilder.swift

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -632,15 +632,25 @@ extension LLBuildManifestBuilder {
632632
private func addMainSymbolRemovalCmd(toolchain: Toolchain,
633633
inputFile: AbsolutePath, outputFile: AbsolutePath,
634634
mainSymbolListFile: AbsolutePath) {
635-
let args = [
636-
// FIXME: Using `nmedit` only works on Darwin. For Linux (and Windows?) we need to use `strip` from the
637-
// `binutils`, and for other platforms, who knows. This needs to be made generic.
638-
// FIXME: Even on Darwin, we need the toolchain to provide the path of the `nmedit` tool.
639-
toolchain.swiftCompiler.parentDirectory.appending(component: "nmedit").pathString,
640-
"-R", mainSymbolListFile.pathString,
641-
inputFile.pathString,
642-
"-o", outputFile.pathString
643-
]
635+
let args: [String]
636+
#if canImport(Darwin)
637+
// On Darwin systems, use `nmedit` to remove the `main` symbol.
638+
args = [
639+
// FIXME: The toolchain should provide the path of the `nmedit` tool.
640+
toolchain.swiftCompiler.parentDirectory.appending(component: "nmedit").pathString,
641+
"-R", mainSymbolListFile.pathString,
642+
inputFile.pathString,
643+
"-o", outputFile.pathString
644+
]
645+
#else
646+
// On non-Darwin systems, use `objcopy` from `binutils` to mark the `main` symbol as local.
647+
args = [
648+
"objcopy",
649+
"-L", "main",
650+
inputFile.pathString,
651+
outputFile.pathString
652+
]
653+
#endif
644654
manifest.addShellCmd(
645655
name: outputFile.pathString,
646656
description: "Eliding symbols from \(outputFile.basename)",

0 commit comments

Comments
 (0)