Skip to content

Commit 127edb9

Browse files
committed
CoreCommands: support -debug-info-format none for Windows
Windows does not have a reliable way to strip the binary as stripping is not an operation that MSVC ever performs (PDBs are always externalised and have support for private and public symbols). This allows us to have builds in release mode which do not embed debug information which would then need to be extricated.
1 parent 0100d60 commit 127edb9

File tree

4 files changed

+41
-12
lines changed

4 files changed

+41
-12
lines changed

Sources/CoreCommands/Options.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,8 @@ public struct BuildOptions: ParsableArguments {
510510
case dwarf
511511
/// See `BuildParameters.DebugInfoFormat.codeview` for details.
512512
case codeview
513+
/// See `BuildParameters.DebugInfoFormat.none` for details.
514+
case none
513515
}
514516
}
515517

Sources/CoreCommands/SwiftTool.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,8 @@ extension BuildOptions.DebugInfoFormat {
988988
return .dwarf
989989
case .codeview:
990990
return .codeview
991+
case .none:
992+
return .none
991993
}
992994
}
993995
}

Sources/SPMBuildCore/BuildParameters.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ public struct BuildParameters: Encodable {
6262
case dwarf
6363
/// CodeView debug information format, used on Windows.
6464
case codeview
65+
/// No debug information to be emitted.
66+
case none
6567
}
6668

6769
/// Represents the debugging strategy.
@@ -321,6 +323,13 @@ public struct BuildParameters: Encodable {
321323
swiftCompilerFlags: ["-g", "-debug-info-format=codeview"],
322324
linkerFlags: ["-debug"]
323325
))
326+
case .none:
327+
var flags = flags
328+
self.flags = flags.merging(BuildFlags(
329+
cCompilerFlags: ["-g0"],
330+
cxxCompilerFlags: ["-g0"],
331+
swiftCompilerFlags: ["-gnone"]
332+
))
324333
}
325334
self.pkgConfigDirectories = pkgConfigDirectories
326335
self.architectures = architectures

Tests/CommandsTests/SwiftToolTests.swift

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,6 @@ final class SwiftToolTests: CommandsTestCase {
241241
"/Pkg/Sources/exe/main.swift",
242242
])
243243

244-
let explicitDwarfOptions = try GlobalOptions.parse(["--triple", "x86_64-unknown-windows-msvc", "-debug-info-format", "dwarf"])
245-
let explicitDwarf = try SwiftTool.createSwiftToolForTest(options: explicitDwarfOptions)
246-
247244
let observer = ObservabilitySystem.makeForTesting()
248245
let graph = try loadPackageGraph(fileSystem: fs, manifests: [
249246
Manifest.createRootManifest(displayName: "Pkg",
@@ -253,6 +250,10 @@ final class SwiftToolTests: CommandsTestCase {
253250

254251
var plan: BuildPlan
255252

253+
254+
/* -debug-info-format dwarf */
255+
let explicitDwarfOptions = try GlobalOptions.parse(["--triple", "x86_64-unknown-windows-msvc", "-debug-info-format", "dwarf"])
256+
let explicitDwarf = try SwiftTool.createSwiftToolForTest(options: explicitDwarfOptions)
256257
plan = try BuildPlan(
257258
buildParameters: explicitDwarf.buildParameters(),
258259
graph: graph,
@@ -262,6 +263,8 @@ final class SwiftToolTests: CommandsTestCase {
262263
try XCTAssertMatch(plan.buildProducts.compactMap { $0 as? Build.ProductBuildDescription }.first?.linkArguments() ?? [],
263264
[.anySequence, "-g", "-use-ld=lld", "-Xlinker", "-debug:dwarf"])
264265

266+
267+
/* -debug-info-format codeview */
265268
let explicitCodeViewOptions = try GlobalOptions.parse(["--triple", "x86_64-unknown-windows-msvc", "-debug-info-format", "codeview"])
266269
let explicitCodeView = try SwiftTool.createSwiftToolForTest(options: explicitCodeViewOptions)
267270

@@ -274,6 +277,17 @@ final class SwiftToolTests: CommandsTestCase {
274277
try XCTAssertMatch(plan.buildProducts.compactMap { $0 as? Build.ProductBuildDescription }.first?.linkArguments() ?? [],
275278
[.anySequence, "-g", "-debug-info-format=codeview", "-Xlinker", "-debug"])
276279

280+
// Explicitly pass Linux as when the SwiftTool tests are enabled on
281+
// Windows, this would fail otherwise as CodeView is supported on the
282+
// native host.
283+
let unsupportedCodeViewOptions = try GlobalOptions.parse(["--triple", "x86_64-unknown-linux-gnu", "-debug-info-format", "codeview"])
284+
let unsupportedCodeView = try SwiftTool.createSwiftToolForTest(options: unsupportedCodeViewOptions)
285+
286+
XCTAssertThrowsError(try unsupportedCodeView.buildParameters()) {
287+
XCTAssertEqual($0 as? StringError, StringError("CodeView debug information is currently not supported on linux"))
288+
}
289+
290+
/* <<null>> */
277291
let implicitDwarfOptions = try GlobalOptions.parse(["--triple", "x86_64-unknown-windows-msvc"])
278292
let implicitDwarf = try SwiftTool.createSwiftToolForTest(options: implicitDwarfOptions)
279293
plan = try BuildPlan(
@@ -285,15 +299,17 @@ final class SwiftToolTests: CommandsTestCase {
285299
try XCTAssertMatch(plan.buildProducts.compactMap { $0 as? Build.ProductBuildDescription }.first?.linkArguments() ?? [],
286300
[.anySequence, "-g", "-use-ld=lld", "-Xlinker", "-debug:dwarf"])
287301

288-
// Explicitly pass Linux as when the SwiftTool tests are enabled on
289-
// Windows, this would fail otherwise as CodeView is supported on the
290-
// native host.
291-
let unsupportedCodeViewOptions = try GlobalOptions.parse(["--triple", "x86_64-unknown-linux-gnu", "-debug-info-format", "codeview"])
292-
let unsupportedCodeView = try SwiftTool.createSwiftToolForTest(options: unsupportedCodeViewOptions)
293-
294-
XCTAssertThrowsError(try unsupportedCodeView.buildParameters()) {
295-
XCTAssertEqual($0 as? StringError, StringError("CodeView debug information is currently not supported on linux"))
296-
}
302+
/* -debug-info-format none */
303+
let explicitNoDebugInfoOptions = try GlobalOptions.parse(["--triple", "x86_64-unknown-windows-msvc", "-debug-info-format", "none"])
304+
let explicitNoDebugInfo = try SwiftTool.createSwiftToolForTest(options: explicitNoDebugInfoOptions)
305+
plan = try BuildPlan(
306+
buildParameters: explicitNoDebugInfo.buildParameters(),
307+
graph: graph,
308+
fileSystem: fs,
309+
observabilityScope: observer.topScope
310+
)
311+
try XCTAssertMatch(plan.buildProducts.compactMap { $0 as? Build.ProductBuildDescription }.first?.linkArguments() ?? [],
312+
[.anySequence, "-gnone", .anySequence])
297313
}
298314
}
299315

0 commit comments

Comments
 (0)