Skip to content

Commit 7269128

Browse files
committed
Merge branch 'main' of github.com:cmcgee1024/swiftly into proxies-design
2 parents bb36de0 + c35819a commit 7269128

18 files changed

+138
-325
lines changed

.github/workflows/pull_request.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Pull request
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened, synchronize]
6+
7+
jobs:
8+
soundness:
9+
name: Soundness
10+
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
11+
with:
12+
license_header_check_enabled: false
13+
license_header_check_project_name: "Swift.org"
14+
api_breakage_check_enabled: false
15+
docs_check_enabled: false
16+
format_check_enabled: false
17+
shell_check_enabled: false
18+
unacceptable_language_check_enabled: true
19+
20+
tests:
21+
name: Test
22+
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
23+
with:
24+
# linux_os_versions: "[\"jammy\", \"noble\", \"focal\", \"amazonlinux2\", \"rhel-ubi9\", \"bookworm\", \"fedora39\"]"
25+
# Not working: noble (compile error in TSC FileSystem), bookworm (missing memory.h), fedora39 (missing memory.h)
26+
linux_os_versions: "[\"jammy\", \"focal\", \"rhel-ubi9\"]"
27+
# We only care about the current stable release, because that's where we make our swiftly releases
28+
linux_exclude_swift_versions: "[{\"swift_version\": \"nightly-main\"},{\"swift_version\": \"nightly-6.0\"},{\"swift_version\": \"5.8\"},{\"swift_version\": \"5.9\"},{\"swift_version\": \"5.10\"}]"
29+
linux_pre_build_command: ((apt-get update && apt-get -y install curl make) || ((curl --help || yum -y install curl) && yum -y install make)) && ./scripts/install-libarchive.sh
30+
enable_windows_checks: false
31+
32+
releasebuild:
33+
name: Release Build
34+
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
35+
with:
36+
linux_os_versions: "[\"rhel-ubi9\"]"
37+
# We only care about the current stable release, because that's where we make our swiftly releases
38+
linux_exclude_swift_versions: "[{\"swift_version\": \"nightly-main\"},{\"swift_version\": \"nightly-6.0\"},{\"swift_version\": \"5.8\"},{\"swift_version\": \"5.9\"},{\"swift_version\": \"5.10\"}]"
39+
linux_pre_build_command: echo ""
40+
linux_build_command: swift run build-swiftly-release --skip 0.4.0
41+
enable_windows_checks: false
42+
43+
formatcheck:
44+
name: Format Check
45+
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
46+
with:
47+
# We only need to run this with one swift release and on one of the linux distributions
48+
linux_os_versions: "[\"jammy\"]"
49+
linux_exclude_swift_versions: "[{\"swift_version\": \"nightly-main\"},{\"swift_version\": \"nightly-6.0\"},{\"swift_version\": \"5.8\"},{\"swift_version\": \"5.9\"},{\"swift_version\": \"5.10\"}]"
50+
linux_pre_build_command: echo ""
51+
linux_build_command: swift run swiftformat --lint --dryrun .
52+
enable_windows_checks: false

NOTICE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@ following third party libraries:
5656
* libarchive - Copyright (c) 2003-2018 Tim Kientzle. All rights reserved.
5757

5858
* LICENSE ("New BSD license"):
59-
* https://raw.githubusercontent.com/libarchive/libarchive/master/COPYING
59+
* https://raw.githubusercontent.com/libarchive/libarchive/release/COPYING
6060
* HOMEPAGE:
6161
* http://www.libarchive.org/

RELEASING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Swift has a tool for producing final product packages, suitable for distribution
1313
5. Create a tag on that commit with the format "x.y.z". Do not omit "z", even if its value is 0.
1414

1515
6. Build the executables for the release by running `swift run build-swiftly-release <version>` from the root of the swiftly repository
16-
* Build on a Apple silicon macOS machine to produce a universal package for x86_64 and arm64
16+
* Build on an Apple macOS machine to produce a universal package for x86_64 and arm64 (add the --cert option to provide a signing certificate file for the .pkg)
1717
* Build on an Amazon Linux 2 image for x86_64
1818
* Build on an Amazon Linux 2 image for arm64
1919

Sources/LinuxPlatform/Linux.swift

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,11 @@ public struct Linux: Platform {
162162

163163
let manager: String? = switch platformName {
164164
case "ubuntu1804":
165-
"apt"
165+
"apt-get"
166166
case "ubuntu2004":
167-
"apt"
167+
"apt-get"
168168
case "ubuntu2204":
169-
"apt"
169+
"apt-get"
170170
case "amazonlinux2":
171171
"yum"
172172
case "ubi9":
@@ -214,21 +214,38 @@ public struct Linux: Platform {
214214
return nil
215215
}
216216

217-
let missingPackages = packages.filter { !self.isSystemPackageInstalled(manager, $0) }.joined(separator: " ")
217+
var missingPackages: [String] = []
218+
219+
for pkg in packages {
220+
if case let pkgInstalled = await self.isSystemPackageInstalled(manager, pkg), !pkgInstalled {
221+
missingPackages.append(pkg)
222+
}
223+
}
218224

219225
guard !missingPackages.isEmpty else {
220226
return nil
221227
}
222228

223-
return "\(manager) -y install \(missingPackages)"
229+
return "\(manager) -y install \(missingPackages.joined(separator: " "))"
224230
}
225231

226-
public func isSystemPackageInstalled(_ manager: String?, _ package: String) -> Bool {
232+
public func isSystemPackageInstalled(_ manager: String?, _ package: String) async -> Bool {
227233
do {
228234
switch manager {
229-
case "apt":
230-
try self.runProgram("dpkg", "-l", package, quiet: true)
231-
return true
235+
case "apt-get":
236+
if let pkgList = try await self.runProgramOutput("dpkg", "-l", package) {
237+
// The package might be listed but not in an installed non-error state.
238+
//
239+
// Look for something like this:
240+
//
241+
// Desired=Unknown/Install/Remove/Purge/Hold
242+
// | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
243+
// |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
244+
// ||/
245+
// ii pkgfoo 1.0.0ubuntu12 My description goes here....
246+
return pkgList.contains("\nii ")
247+
}
248+
return false
232249
case "yum":
233250
try self.runProgram("yum", "list", "installed", package, quiet: true)
234251
return true

Tools/build-swiftly-release/BuildSwiftlyRelease.swift

Lines changed: 58 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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

@@ -182,6 +182,14 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
182182
@Flag(name: .long, help: "Skip the git repo checks and proceed.")
183183
var skip: Bool = false
184184

185+
#if os(macOS)
186+
@Option(help: "Installation certificate to use when building the macOS package")
187+
var cert: String?
188+
189+
@Option(help: "Package identifier of macOS package")
190+
var identifier: String = "org.swift.swiftly"
191+
#endif
192+
185193
@Argument(help: "Version of swiftly to build the release.")
186194
var version: String
187195

@@ -191,7 +199,7 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
191199
#if os(Linux)
192200
try await self.buildLinuxRelease()
193201
#elseif os(macOS)
194-
try await self.buildMacOSRelease()
202+
try await self.buildMacOSRelease(cert: self.cert, identifier: self.identifier)
195203
#else
196204
#error("Unsupported OS")
197205
#endif
@@ -234,6 +242,10 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
234242
}
235243

236244
func checkSwiftRequirement() async throws -> String {
245+
guard !self.skip else {
246+
return try await self.assertTool("swift", message: "Please install swift and make sure that it is added to your path.")
247+
}
248+
237249
guard let requiredSwiftVersion = try? self.findSwiftVersion() else {
238250
throw Error(message: "Unable to determine the required swift version for this version of swiftly. Please make sure that you `cd <swiftly_git_dir>` and there is a .swift-version file there.")
239251
}
@@ -275,7 +287,7 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
275287

276288
func buildLinuxRelease() async throws {
277289
// Check system requirements
278-
guard isAmazonLinux2() else {
290+
guard isRHEL9() else {
279291
// TODO: see if docker can be used to spawn an Amazon Linux 2 container to continue the release building process
280292
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")
281293
}
@@ -286,13 +298,19 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
286298
let make = try await self.assertTool("make", message: "Please install make with `yum install make`")
287299
let git = try await self.assertTool("git", message: "Please install git with `yum install git`")
288300
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`")
289302

290303
let swift = try await self.checkSwiftRequirement()
291304

292305
try await self.checkGitRepoStatus(git)
293306

294-
// 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
295311
let libArchiveVersion = "3.7.4"
312+
let libArchiveTarSha = "7875d49596286055b52439ed42f044bd8ad426aa4cc5aabd96bfe7abb971d5e8"
313+
296314
let buildCheckoutsDir = FileManager.default.currentDirectoryPath + "/.build/checkouts"
297315
let libArchivePath = buildCheckoutsDir + "/libarchive-\(libArchiveVersion)"
298316
let pkgConfigPath = libArchivePath + "/pkgconfig"
@@ -302,6 +320,11 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
302320

303321
try? FileManager.default.removeItem(atPath: libArchivePath)
304322
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+
}
305328
try runProgram(tar, "--directory=\(buildCheckoutsDir)", "-xzf", "\(buildCheckoutsDir)/libarchive-\(libArchiveVersion).tar.gz")
306329

307330
let cwd = FileManager.default.currentDirectoryPath
@@ -338,8 +361,6 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
338361

339362
FileManager.default.changeCurrentDirectoryPath(cwd)
340363

341-
try runProgram(swift, "package", "clean")
342-
343364
// Statically link standard libraries for maximum portability of the swiftly binary
344365
try runProgram(swift, "build", "--product=swiftly", "--pkg-config-path=\(pkgConfigPath)/lib/pkgconfig", "--static-swift-stdlib", "--configuration=release")
345366

@@ -361,7 +382,7 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
361382
print(releaseArchive)
362383
}
363384

364-
func buildMacOSRelease() async throws {
385+
func buildMacOSRelease(cert: String?, identifier: String) async throws {
365386
// Check system requirements
366387
let git = try await self.assertTool("git", message: "Please install git with either `xcode-select --install` or `brew install git`")
367388

@@ -389,17 +410,34 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
389410
try? FileManager.default.createDirectory(atPath: swiftlyLicenseDir, withIntermediateDirectories: true)
390411
try await self.collectLicenses(swiftlyLicenseDir)
391412

392-
try runProgram(
393-
pkgbuild,
394-
"--root",
395-
swiftlyBinDir + "/..",
396-
"--install-location",
397-
"usr/local",
398-
"--version",
399-
self.version,
400-
"--identifier",
401-
"org.swift.swiftly",
402-
".build/release/swiftly-\(self.version).pkg"
403-
)
413+
if let cert {
414+
try runProgram(
415+
pkgbuild,
416+
"--root",
417+
swiftlyBinDir + "/..",
418+
"--install-location",
419+
"usr/local",
420+
"--version",
421+
self.version,
422+
"--identifier",
423+
identifier,
424+
"--sign",
425+
cert,
426+
".build/release/swiftly-\(self.version).pkg"
427+
)
428+
} else {
429+
try runProgram(
430+
pkgbuild,
431+
"--root",
432+
swiftlyBinDir + "/..",
433+
"--install-location",
434+
"usr/local",
435+
"--version",
436+
self.version,
437+
"--identifier",
438+
identifier,
439+
".build/release/swiftly-\(self.version).pkg"
440+
)
441+
}
404442
}
405443
}

docker/docker-compose.1804.yaml

Lines changed: 0 additions & 28 deletions
This file was deleted.

docker/docker-compose.2004.yaml

Lines changed: 0 additions & 28 deletions
This file was deleted.

docker/docker-compose.2204.yaml

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)