@@ -528,7 +528,6 @@ extension VercelOutput {
528
528
print ( " ------------------------------------------------------------------------- " )
529
529
print ( " Building product: \" \( product. name) \" " )
530
530
print ( " ------------------------------------------------------------------------- " )
531
- print ( " " )
532
531
533
532
if isDeploy, Utils . isAmazonLinux == false {
534
533
return try await buildDockerProduct ( product)
@@ -566,27 +565,80 @@ extension VercelOutput {
566
565
? " swiftlang/swift:nightly- \( context. package . toolsVersion. major) . \( context. package . toolsVersion. minor) -amazonlinux2 "
567
566
: " swift: \( context. package . toolsVersion. major) . \( context. package . toolsVersion. minor) -amazonlinux2 "
568
567
568
+ let cleanCommand = arguments. contains ( " --clean " )
569
+ ? " rm -rf .build && rm -rf ~/.swift/pm && "
570
+ : " "
571
+
572
+ let buildCommand = " swift build -c release -Xswiftc -Osize -Xlinker -S --product \( product. name) --static-swift-stdlib "
573
+ let buildOutputPathCommand = " \( cleanCommand) \( buildCommand) --show-bin-path "
574
+
575
+ let workspacePathPrefix = arguments. contains ( " --parent " )
576
+ ? context. package . directory. removingLastComponent ( )
577
+ : context. package . directory
578
+
579
+ let lastPathComponent = arguments. contains ( " --parent " )
580
+ ? context. package . directory. lastComponent
581
+ : " "
582
+
583
+ let dockerWorkspacePath = " /workspace/ \( lastPathComponent) "
584
+
585
+ // get the build output path
586
+ let dockerBuildOutputPath = try Shell . execute (
587
+ executable: dockerToolPath,
588
+ arguments: [
589
+ " run " ,
590
+ " --platform " , " linux/ \( architecture. rawValue) " ,
591
+ " --rm " ,
592
+ " -v " , " \( workspacePathPrefix) :/workspace " ,
593
+ " -w " , dockerWorkspacePath,
594
+ baseImage,
595
+ " bash " , " -cl " , " pwd && \( buildOutputPathCommand) "
596
+ ]
597
+ )
598
+
599
+ guard let buildPathOutput = dockerBuildOutputPath. split ( separator: " \n " ) . last else {
600
+ throw BuildError . failedParsingDockerOutput ( dockerBuildOutputPath)
601
+ }
602
+
603
+ let productPath = Path ( buildPathOutput. replacingOccurrences ( of: dockerWorkspacePath, with: context. package . directory. string) )
604
+
569
605
// build the product
570
606
try Shell . execute (
571
607
executable: dockerToolPath,
572
608
arguments: [
573
609
" run " ,
574
610
" --platform " , " linux/ \( architecture. rawValue) " ,
575
611
" --rm " ,
576
- " -v " , " \( context . package . directory . string ) :/workspace " ,
577
- " -w " , " /workspace " ,
612
+ " -v " , " \( workspacePathPrefix ) :/workspace " ,
613
+ " -w " , dockerWorkspacePath ,
578
614
baseImage,
579
615
" bash " , " -cl " , " swift build -c release -Xswiftc -Osize --static-swift-stdlib " ,
580
616
]
581
617
)
582
618
583
619
// ensure the final binary built correctly
584
- let productPath = swiftBuildReleaseDirectory. appending ( product. name)
585
- guard fs. fileExists ( atPath: productPath . string) else {
620
+ let productPathFinal = swiftBuildReleaseDirectory. appending ( product. name)
621
+ guard fs. fileExists ( atPath: productPathFinal . string) else {
586
622
Diagnostics . error ( " expected ' \( product. name) ' binary at \" \( productPath. string) \" " )
587
623
throw BuildError . productExecutableNotFound ( product. name)
588
624
}
589
- return productPath
625
+
626
+ // strip the binary
627
+ let stripCommand = " ls -la .build/release/ \( product. name) && strip .build/release/ \( product. name) && ls -la .build/release/ \( product. name) "
628
+ try Shell . execute (
629
+ executable: dockerToolPath,
630
+ arguments: [
631
+ " run " ,
632
+ " --platform " , " linux/ \( architecture. rawValue) " ,
633
+ " --rm " ,
634
+ " -v " , " \( workspacePathPrefix) :/workspace " ,
635
+ " -w " , dockerWorkspacePath,
636
+ baseImage,
637
+ " bash " , " -cl " , stripCommand
638
+ ]
639
+ )
640
+
641
+ return productPathFinal
590
642
}
591
643
}
592
644
0 commit comments