@@ -69,7 +69,8 @@ final class BuildPlanTests: XCTestCase {
69
69
canRenameEntrypointFunctionName: Bool = false ,
70
70
destinationTriple: TSCUtility . Triple = hostTriple,
71
71
indexStoreMode: BuildParameters . IndexStoreMode = . off,
72
- useExplicitModuleBuild: Bool = false
72
+ useExplicitModuleBuild: Bool = false ,
73
+ disableDeadStrip: Bool = false
73
74
) -> BuildParameters {
74
75
return BuildParameters (
75
76
dataPath: buildPath,
@@ -82,7 +83,8 @@ final class BuildPlanTests: XCTestCase {
82
83
shouldLinkStaticSwiftStdlib: shouldLinkStaticSwiftStdlib,
83
84
canRenameEntrypointFunctionName: canRenameEntrypointFunctionName,
84
85
indexStoreMode: indexStoreMode,
85
- useExplicitModuleBuild: useExplicitModuleBuild
86
+ useExplicitModuleBuild: useExplicitModuleBuild,
87
+ disableDeadStrip: disableDeadStrip
86
88
)
87
89
}
88
90
@@ -472,6 +474,60 @@ final class BuildPlanTests: XCTestCase {
472
474
" -Xlinker " , " -rpath " , " -Xlinker " , " /fake/path/lib/swift-5.5/macosx " ,
473
475
" -target " , defaultTargetTriple,
474
476
] )
477
+ #else
478
+ XCTAssertEqual ( try result. buildProduct ( for: " exe " ) . linkArguments ( ) , [
479
+ " /fake/path/to/swiftc " , " -g " , " -L " , " /path/to/build/release " ,
480
+ " -o " , " /path/to/build/release/exe " , " -module-name " , " exe " , " -emit-executable " ,
481
+ " -Xlinker " , " --gc-sections " , " -Xlinker " , " -rpath=$ORIGIN " ,
482
+ " @/path/to/build/release/exe.product/Objects.LinkFileList " ,
483
+ " -target " , defaultTargetTriple,
484
+ ] )
485
+ #endif
486
+ }
487
+
488
+ func testBasicReleasePackageNoDeadStrip( ) throws {
489
+ let fs = InMemoryFileSystem ( emptyFiles:
490
+ " /Pkg/Sources/exe/main.swift "
491
+ )
492
+
493
+ let observability = ObservabilitySystem . makeForTesting ( )
494
+ let graph = try loadPackageGraph (
495
+ fs: fs,
496
+ manifests: [
497
+ Manifest . createRootManifest (
498
+ name: " Pkg " ,
499
+ path: . init( " /Pkg " ) ,
500
+ targets: [
501
+ TargetDescription ( name: " exe " , dependencies: [ ] ) ,
502
+ ] ) ,
503
+ ] ,
504
+ observabilityScope: observability. topScope
505
+ )
506
+ XCTAssertNoDiagnostics ( observability. diagnostics)
507
+
508
+ let result = try BuildPlanResult ( plan: BuildPlan (
509
+ buildParameters: mockBuildParameters ( config: . release, disableDeadStrip: true ) ,
510
+ graph: graph,
511
+ fileSystem: fs,
512
+ observabilityScope: observability. topScope
513
+ ) )
514
+
515
+ result. checkProductsCount ( 1 )
516
+ result. checkTargetsCount ( 1 )
517
+
518
+ let exe = try result. target ( for: " exe " ) . swiftTarget ( ) . compileArguments ( )
519
+ XCTAssertMatch ( exe, [ " -swift-version " , " 4 " , " -O " , " -g " , . equal( j) , " -DSWIFT_PACKAGE " , " -module-cache-path " , " /path/to/build/release/ModuleCache " , . anySequence] )
520
+
521
+ #if os(macOS)
522
+ XCTAssertEqual ( try result. buildProduct ( for: " exe " ) . linkArguments ( ) , [
523
+ " /fake/path/to/swiftc " , " -g " , " -L " , " /path/to/build/release " ,
524
+ " -o " , " /path/to/build/release/exe " , " -module-name " , " exe " , " -emit-executable " ,
525
+ " -Xlinker " , " -rpath " , " -Xlinker " , " @loader_path " ,
526
+ " @/path/to/build/release/exe.product/Objects.LinkFileList " ,
527
+ " -Xlinker " , " -rpath " , " -Xlinker " , " /fake/path/lib/swift/macosx " ,
528
+ " -Xlinker " , " -rpath " , " -Xlinker " , " /fake/path/lib/swift-5.5/macosx " ,
529
+ " -target " , defaultTargetTriple,
530
+ ] )
475
531
#else
476
532
XCTAssertEqual ( try result. buildProduct ( for: " exe " ) . linkArguments ( ) , [
477
533
" /fake/path/to/swiftc " , " -g " , " -L " , " /path/to/build/release " ,
0 commit comments