@@ -528,7 +528,7 @@ extension VercelOutput {
528528 print ( " ------------------------------------------------------------------------- " )
529529 print ( " Building product: \" \( product. name) \" " )
530530 print ( " ------------------------------------------------------------------------- " )
531- print ( " " )
531+ print ( " hello " )
532532
533533 if isDeploy, Utils . isAmazonLinux == false {
534534 return try await buildDockerProduct ( product)
@@ -566,27 +566,80 @@ extension VercelOutput {
566566 ? " swiftlang/swift:nightly- \( context. package . toolsVersion. major) . \( context. package . toolsVersion. minor) -amazonlinux2 "
567567 : " swift: \( context. package . toolsVersion. major) . \( context. package . toolsVersion. minor) -amazonlinux2 "
568568
569+ let cleanCommand = arguments. contains ( " --clean " )
570+ ? " rm -rf .build && rm -rf ~/.swift/pm && "
571+ : " "
572+
573+ let buildCommand = " swift build -c release -Xswiftc -Osize -Xlinker -S --product \( product. name) --static-swift-stdlib "
574+ let buildOutputPathCommand = " \( cleanCommand) \( buildCommand) --show-bin-path "
575+
576+ let workspacePathPrefix = arguments. contains ( " --parent " )
577+ ? context. package . directory. removingLastComponent ( )
578+ : context. package . directory
579+
580+ let lastPathComponent = arguments. contains ( " --parent " )
581+ ? context. package . directory. lastComponent
582+ : " "
583+
584+ let dockerWorkspacePath = " /workspace/ \( lastPathComponent) "
585+
586+ // get the build output path
587+ let dockerBuildOutputPath = try Shell . execute (
588+ executable: dockerToolPath,
589+ arguments: [
590+ " run " ,
591+ " --platform " , " linux/ \( architecture. rawValue) " ,
592+ " --rm " ,
593+ " -v " , " \( workspacePathPrefix) :/workspace " ,
594+ " -w " , dockerWorkspacePath,
595+ baseImage,
596+ " bash " , " -cl " , " pwd && \( buildOutputPathCommand) "
597+ ]
598+ )
599+
600+ guard let buildPathOutput = dockerBuildOutputPath. split ( separator: " \n " ) . last else {
601+ throw BuildError . failedParsingDockerOutput ( dockerBuildOutputPath)
602+ }
603+
604+ let productPath = Path ( buildPathOutput. replacingOccurrences ( of: dockerWorkspacePath, with: context. package . directory. string) )
605+
569606 // build the product
570607 try Shell . execute (
571608 executable: dockerToolPath,
572609 arguments: [
573610 " run " ,
574611 " --platform " , " linux/ \( architecture. rawValue) " ,
575612 " --rm " ,
576- " -v " , " \( context . package . directory . string ) :/workspace " ,
577- " -w " , " /workspace " ,
613+ " -v " , " \( workspacePathPrefix ) :/workspace " ,
614+ " -w " , dockerWorkspacePath ,
578615 baseImage,
579616 " bash " , " -cl " , " swift build -c release -Xswiftc -Osize --static-swift-stdlib " ,
580617 ]
581618 )
582619
583620 // ensure the final binary built correctly
584- let productPath = swiftBuildReleaseDirectory. appending ( product. name)
585- guard fs. fileExists ( atPath: productPath . string) else {
621+ let productPathFinal = swiftBuildReleaseDirectory. appending ( product. name)
622+ guard fs. fileExists ( atPath: productPathFinal . string) else {
586623 Diagnostics . error ( " expected ' \( product. name) ' binary at \" \( productPath. string) \" " )
587624 throw BuildError . productExecutableNotFound ( product. name)
588625 }
589- return productPath
626+
627+ // strip the binary
628+ let stripCommand = " ls -la .build/release/ \( product. name) && strip .build/release/ \( product. name) && ls -la .build/release/ \( product. name) "
629+ try Shell . execute (
630+ executable: dockerToolPath,
631+ arguments: [
632+ " run " ,
633+ " --platform " , " linux/ \( architecture. rawValue) " ,
634+ " --rm " ,
635+ " -v " , " \( workspacePathPrefix) :/workspace " ,
636+ " -w " , dockerWorkspacePath,
637+ baseImage,
638+ " bash " , " -cl " , stripCommand
639+ ]
640+ )
641+
642+ return productPathFinal
590643 }
591644}
592645
0 commit comments