@@ -126,7 +126,7 @@ public func getShell() async throws -> String {
126126}
127127#endif
128128
129- public func isAmazonLinux2 ( ) - > Bool {
129+ public func isRHEL9 ( ) - > Bool {
130130 let osReleaseFiles = [ " /etc/os-release " , " /usr/lib/os-release " ]
131131 var releaseFile : String ?
132132 for file in osReleaseFiles {
@@ -165,7 +165,7 @@ public func isAmazonLinux2() -> Bool {
165165 return false
166166 }
167167
168- guard let versionID = versionID , versionID == " 2 " , ( id + idlike) . contains ( " amzn " ) else {
168+ guard let versionID, versionID. hasPrefix ( " 9 " ) , ( id + idlike) . contains ( " rhel " ) else {
169169 return false
170170 }
171171
@@ -287,7 +287,7 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
287287
288288 func buildLinuxRelease( ) async throws {
289289 // Check system requirements
290- guard isAmazonLinux2 ( ) else {
290+ guard isRHEL9 ( ) else {
291291 // TODO: see if docker can be used to spawn an Amazon Linux 2 container to continue the release building process
292292 throw Error ( message: " Linux releases must be made from Amazon Linux 2 because it has the oldest version of glibc for maximum compatibility with other versions of Linux " )
293293 }
@@ -298,13 +298,19 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
298298 let make = try await self . assertTool ( " make " , message: " Please install make with `yum install make` " )
299299 let git = try await self . assertTool ( " git " , message: " Please install git with `yum install git` " )
300300 let strip = try await self . assertTool ( " strip " , message: " Please install strip with `yum install binutils` " )
301+ let sha256sum = try await self . assertTool ( " sha256sum " , message: " Please install sha256sum with `yum install coreutils` " )
301302
302303 let swift = try await self . checkSwiftRequirement ( )
303304
304305 try await self . checkGitRepoStatus ( git)
305306
306- // Build a specific version of libarchive
307+ // Start with a fresh SwiftPM package
308+ try runProgram ( swift, " package " , " reset " )
309+
310+ // Build a specific version of libarchive with a check on the tarball's SHA256
307311 let libArchiveVersion = " 3.7.4 "
312+ let libArchiveTarSha = " 7875d49596286055b52439ed42f044bd8ad426aa4cc5aabd96bfe7abb971d5e8 "
313+
308314 let buildCheckoutsDir = FileManager . default. currentDirectoryPath + " /.build/checkouts "
309315 let libArchivePath = buildCheckoutsDir + " /libarchive- \( libArchiveVersion) "
310316 let pkgConfigPath = libArchivePath + " /pkgconfig "
@@ -314,6 +320,11 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
314320
315321 try ? FileManager . default. removeItem ( atPath: libArchivePath)
316322 try runProgram ( curl, " -o " , " \( buildCheckoutsDir + " /libarchive- \( libArchiveVersion) .tar.gz " ) " , " --remote-name " , " --location " , " https://github.com/libarchive/libarchive/releases/download/v \( libArchiveVersion) /libarchive- \( libArchiveVersion) .tar.gz " )
323+ let libArchiveTarShaActual = try await runProgramOutput ( sha256sum, " \( buildCheckoutsDir) /libarchive- \( libArchiveVersion) .tar.gz " )
324+ guard let libArchiveTarShaActual, libArchiveTarShaActual. starts ( with: libArchiveTarSha) else {
325+ let shaActual = libArchiveTarShaActual ?? " none "
326+ throw Error ( message: " The libarchive tar.gz file sha256sum is \( shaActual) , but expected \( libArchiveTarSha) " )
327+ }
317328 try runProgram ( tar, " --directory= \( buildCheckoutsDir) " , " -xzf " , " \( buildCheckoutsDir) /libarchive- \( libArchiveVersion) .tar.gz " )
318329
319330 let cwd = FileManager . default. currentDirectoryPath
@@ -350,8 +361,6 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
350361
351362 FileManager . default. changeCurrentDirectoryPath ( cwd)
352363
353- try runProgram ( swift, " package " , " clean " )
354-
355364 // Statically link standard libraries for maximum portability of the swiftly binary
356365 try runProgram ( swift, " build " , " --product=swiftly " , " --pkg-config-path= \( pkgConfigPath) /lib/pkgconfig " , " --static-swift-stdlib " , " --configuration=release " )
357366
0 commit comments