@@ -14,11 +14,22 @@ struct PackageToJS {
14
14
var enableCodeCoverage : Bool = false
15
15
}
16
16
17
+ enum DebugInfoFormat : String , CaseIterable {
18
+ /// No debug info
19
+ case none
20
+ /// The all DWARF sections and "name" section
21
+ case dwarf
22
+ /// Only "name" section
23
+ case name
24
+ }
25
+
17
26
struct BuildOptions {
18
27
/// Product to build (default: executable target if there's only one)
19
28
var product : String ?
20
29
/// Whether to apply wasm-opt optimizations in release mode (default: true)
21
30
var noOptimize : Bool
31
+ /// The format of debug info to keep in the final wasm file (default: none)
32
+ var debugInfoFormat : DebugInfoFormat
22
33
/// The options for packaging
23
34
var packageOptions : PackageOptions
24
35
}
@@ -388,7 +399,7 @@ struct PackagingPlanner {
388
399
buildOptions: PackageToJS . BuildOptions
389
400
) throws -> MiniMake . TaskKey {
390
401
let ( allTasks, _, _, _) = try planBuildInternal (
391
- make: & make, noOptimize: buildOptions. noOptimize
402
+ make: & make, noOptimize: buildOptions. noOptimize, debugInfoFormat : buildOptions . debugInfoFormat
392
403
)
393
404
return make. addTask (
394
405
inputTasks: allTasks, output: BuildPath ( phony: " all " ) , attributes: [ . phony, . silent]
@@ -397,7 +408,8 @@ struct PackagingPlanner {
397
408
398
409
private func planBuildInternal(
399
410
make: inout MiniMake ,
400
- noOptimize: Bool
411
+ noOptimize: Bool ,
412
+ debugInfoFormat: PackageToJS . DebugInfoFormat
401
413
) throws -> (
402
414
allTasks: [ MiniMake . TaskKey ] ,
403
415
outputDirTask: MiniMake . TaskKey ,
@@ -432,24 +444,32 @@ struct PackagingPlanner {
432
444
let finalWasmPath = outputDir. appending ( path: wasmFilename)
433
445
434
446
if shouldOptimize {
435
- // Optimize the wasm in release mode
436
- let wasmWithoutDwarfPath = intermediatesDir. appending ( path: wasmFilename + " .no-dwarf " )
437
-
438
- // First, strip DWARF sections as their existence enables DWARF preserving mode in wasm-opt
439
- let wasmWithoutDwarf = make. addTask (
440
- inputFiles: [ selfPath, wasmProductArtifact] , inputTasks: [ outputDirTask, intermediatesDirTask] ,
441
- output: wasmWithoutDwarfPath
442
- ) {
443
- print ( " Stripping DWARF debug info... " )
444
- try system. wasmOpt ( [ " --strip-dwarf " , " --debuginfo " ] , input: $1. resolve ( path: wasmProductArtifact) . path, output: $1. resolve ( path: $0. output) . path)
447
+ let wasmOptInputFile : BuildPath
448
+ let wasmOptInputTask : MiniMake . TaskKey ?
449
+ switch debugInfoFormat {
450
+ case . dwarf:
451
+ // Keep the original wasm file
452
+ wasmOptInputFile = wasmProductArtifact
453
+ wasmOptInputTask = nil
454
+ case . name, . none:
455
+ // Optimize the wasm in release mode
456
+ wasmOptInputFile = intermediatesDir. appending ( path: wasmFilename + " .no-dwarf " )
457
+ // First, strip DWARF sections as their existence enables DWARF preserving mode in wasm-opt
458
+ wasmOptInputTask = make. addTask (
459
+ inputFiles: [ selfPath, wasmProductArtifact] , inputTasks: [ outputDirTask, intermediatesDirTask] ,
460
+ output: wasmOptInputFile
461
+ ) {
462
+ print ( " Stripping DWARF debug info... " )
463
+ try system. wasmOpt ( [ " --strip-dwarf " , " --debuginfo " ] , input: $1. resolve ( path: wasmProductArtifact) . path, output: $1. resolve ( path: $0. output) . path)
464
+ }
445
465
}
446
466
// Then, run wasm-opt with all optimizations
447
467
wasm = make. addTask (
448
- inputFiles: [ selfPath, wasmWithoutDwarfPath ] , inputTasks: [ outputDirTask, wasmWithoutDwarf ] ,
468
+ inputFiles: [ selfPath, wasmOptInputFile ] , inputTasks: [ outputDirTask] + ( wasmOptInputTask . map { [ $0 ] } ?? [ ] ) ,
449
469
output: finalWasmPath
450
470
) {
451
471
print ( " Optimizing the wasm file... " )
452
- try system. wasmOpt ( [ " -Os " , " --debuginfo " ] , input: $1. resolve ( path: wasmWithoutDwarfPath ) . path, output: $1. resolve ( path: $0. output) . path)
472
+ try system. wasmOpt ( [ " -Os " ] + ( debugInfoFormat != . none ? [ " --debuginfo " ] : [ ] ) , input: $1. resolve ( path: wasmOptInputFile ) . path, output: $1. resolve ( path: $0. output) . path)
453
473
}
454
474
} else {
455
475
// Copy the wasm product artifact
@@ -518,7 +538,7 @@ struct PackagingPlanner {
518
538
make: inout MiniMake
519
539
) throws -> ( rootTask: MiniMake . TaskKey , binDir: BuildPath ) {
520
540
var ( allTasks, outputDirTask, intermediatesDirTask, packageJsonTask) = try planBuildInternal (
521
- make: & make, noOptimize: false
541
+ make: & make, noOptimize: false , debugInfoFormat : . dwarf
522
542
)
523
543
524
544
// Install npm dependencies used in the test harness
0 commit comments