@@ -69,7 +69,8 @@ final class BuildPlanTests: XCTestCase {
6969 canRenameEntrypointFunctionName: Bool = false ,
7070 destinationTriple: TSCUtility . Triple = hostTriple,
7171 indexStoreMode: BuildParameters . IndexStoreMode = . off,
72- useExplicitModuleBuild: Bool = false
72+ useExplicitModuleBuild: Bool = false ,
73+ disableDeadStrip: Bool = false
7374 ) -> BuildParameters {
7475 return BuildParameters (
7576 dataPath: buildPath,
@@ -82,7 +83,8 @@ final class BuildPlanTests: XCTestCase {
8283 shouldLinkStaticSwiftStdlib: shouldLinkStaticSwiftStdlib,
8384 canRenameEntrypointFunctionName: canRenameEntrypointFunctionName,
8485 indexStoreMode: indexStoreMode,
85- useExplicitModuleBuild: useExplicitModuleBuild
86+ useExplicitModuleBuild: useExplicitModuleBuild,
87+ disableDeadStrip: disableDeadStrip
8688 )
8789 }
8890
@@ -472,6 +474,60 @@ final class BuildPlanTests: XCTestCase {
472474 " -Xlinker " , " -rpath " , " -Xlinker " , " /fake/path/lib/swift-5.5/macosx " ,
473475 " -target " , defaultTargetTriple,
474476 ] )
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+ ] )
475531 #else
476532 XCTAssertEqual ( try result. buildProduct ( for: " exe " ) . linkArguments ( ) , [
477533 " /fake/path/to/swiftc " , " -g " , " -L " , " /path/to/build/release " ,
0 commit comments