Skip to content

Commit bbe7277

Browse files
committed
Merge branch 'main' of github.com:cmcgee1024/swiftly into streamlined_init
2 parents bce8ab6 + 0ce6cc5 commit bbe7277

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+314
-552
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Build Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: "Version of swiftly to build release artifacts"
8+
required: true
9+
type: string
10+
default: "0.3.0"
11+
skip:
12+
description: "Perform release checks, such as the git tag, and swift version, or '--skip' to skip that."
13+
required: true
14+
type: string
15+
default: "--skip"
16+
17+
jobs:
18+
buildrelease:
19+
name: Build Release
20+
runs-on: ubuntu-latest
21+
container:
22+
image: "swift:6.0-rhel-ubi9"
23+
steps:
24+
- name: Checkout repository
25+
uses: actions/checkout@v4
26+
- name: Build Artifact
27+
run: swift run build-swiftly-release ${{ inputs.skip }} ${{ inputs.version }}
28+
- name: Upload Artifact
29+
uses: actions/upload-artifact@v4
30+
with:
31+
path: .build/release/swiftly-*.tar.gz
32+
if-no-files-found: error

.github/workflows/pull_request.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Pull Request
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened, synchronize]
6+
push:
7+
branches: [main]
8+
9+
jobs:
10+
soundness:
11+
name: Soundness
12+
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
13+
with:
14+
license_header_check_enabled: false
15+
license_header_check_project_name: "Swift.org"
16+
api_breakage_check_enabled: false
17+
docs_check_enabled: false
18+
format_check_enabled: false
19+
shell_check_enabled: false
20+
unacceptable_language_check_enabled: true
21+
22+
tests:
23+
name: Test
24+
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
25+
with:
26+
# Amazon Linux 2 won't work with GH infrastructure
27+
linux_os_versions: "[\"jammy\", \"focal\", \"rhel-ubi9\", \"noble\", \"bookworm\", \"fedora39\"]"
28+
# We only care about the current stable release, because that's where we make our swiftly releases
29+
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\"}]"
30+
linux_pre_build_command: ./scripts/prep-gh-action.sh && ./scripts/install-libarchive.sh
31+
enable_windows_checks: false
32+
33+
releasebuildcheck:
34+
name: Release Build Check
35+
runs-on: ubuntu-latest
36+
container:
37+
image: "swift:6.0-rhel-ubi9"
38+
steps:
39+
- name: Checkout repository
40+
uses: actions/checkout@v4
41+
- name: Build Artifact
42+
run: swift run build-swiftly-release --skip "999.0.0"
43+
- name: Upload Artifact
44+
uses: actions/upload-artifact@v4
45+
with:
46+
path: .build/release/swiftly-*.tar.gz
47+
if-no-files-found: error
48+
retention-days: 1
49+
50+
formatcheck:
51+
name: Format Check
52+
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
53+
with:
54+
# We only need to run this with one swift release and on one of the linux distributions
55+
linux_os_versions: "[\"jammy\"]"
56+
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\"}]"
57+
linux_pre_build_command: ./scripts/prep-gh-action.sh
58+
linux_build_command: swift run swiftformat --lint --dryrun .
59+
enable_windows_checks: false

DESIGN.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ A simple setup for managing the toolchains could look like this:
6767

6868
The toolchains (i.e. the contents of a given Swift download tarball) would be contained in the toolchains directory, each named according to the major/minor/patch version. `config.json` would contain any required metadata (e.g. the latest Swift version, which toolchain is selected, etc.). If pulling in Foundation to use `JSONEncoder`/`JSONDecoder` (or some other JSON tool) would be a problem, we could also use something simpler.
6969

70-
The `~/.local/bin` directory would include symlinks pointing to swiftly itself. When the proxies binaries are executed swiftly proxies them to the requested toolchain, or the default.
70+
The `~/.local/share/swiftly/bin` directory would include symlinks pointing to swiftly itself. When the proxies binaries are executed swiftly proxies them to the requested toolchain, or the default.
7171

7272
This is all very similar to how rustup does things, but I figure there's no need to reinvent the wheel here.
7373

@@ -115,7 +115,7 @@ This will install the latest available stable release of Swift. If the latest ve
115115

116116
##### Installing a specific release version of Swift
117117

118-
To install a specific version of Swift, the user can provide it.
118+
To install a specific version of Swift, the user can provide it.
119119

120120
If a patch version isn't specified, it’ll install the latest patch version that matches the minor version provided. If a version is already installed that has the same major and minor version, a message will be printed indicating so and directing the user to `swiftly update a.b` if they wish to check for updates.
121121

@@ -306,19 +306,21 @@ This command will provide the full path to the directory where the selected tool
306306

307307
#### Run with a selected toolchain
308308

309-
There are cases where you might want to run an arbitrary command using a selected toolchain. An example could be that you want to build something with CMake.
309+
There are cases where you might want to run an arbitrary command using a selected toolchain. An example could be that you want to build something with CMake or Autoconf.
310310

311311
```
312312
# CMake
313-
swiftly run cmake -G ninja
313+
swiftly run cmake -G ninja -D CMAKE_C_COMPILER=clang -D CMAKE_CXX_COMPILER=clang++
314314
swiftly run ninja build
315315
316316
# Autoconf
317-
swiftly run ./configure
318-
swiftly run make
317+
CC=clang swiftly run ./configure
318+
CC=clang swiftly run make
319319
```
320320

321-
Swiftly adjusts certain environment variables, such as prefixing the PATH to the selected toolchain directory, and setting the CC and CXX variables to the locations of clang and clang++ in those toolchains so that the build tools use them. If you want to explicitly specify a toolchain for the command you can do that with a selector notation like this:
321+
Swiftly prefixes the PATH to the selected toolchain directory and runs the command so that the toolchain executables are available and have precedence.
322+
323+
If you want to explicitly specify a toolchain for the command you can do that with a selector notation like this:
322324

323325
```
324326
swiftly run swift build +5.10.1 # Runs swift build with the 5.10.1 toolchain
@@ -333,8 +335,8 @@ If the selected toolchain is not installed then swiftly will exit with a message
333335
swiftly run swift build +main-snapshot
334336
335337
# Generate makefiles with the latest released Swift toolchain
336-
swiftly run +latest cmake -G "Unix Makefile"
337-
swiftly run +latest make
338+
swiftly run +latest cmake -G "Unix Makefile" -D CMAKE_C_COMPILER=clang
339+
CC=clang swiftly run +latest make
338340
```
339341

340342
## Detailed Design
@@ -498,7 +500,7 @@ If the tag is a newer version than the installed one, a prompt indicating the ne
498500
$ dpkg --status libcurl4
499501
```
500502

501-
If the exit code of the previous command was 0, then we know the dependency exists and can return true. If it wasn't, then we call fall back to attempting to locate the library via `pkg-config`:
503+
If the exit code of the previous command was 0, then we know the dependency exists and can return true. If it wasn't, then we can fall back to attempting to locate the library via `pkg-config`:
502504

503505
```
504506
$ pkg-config --exists libcurl

Documentation/SwiftlyDocs.docc/getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ $ swift --version
4343
Swift version 6.0.1 (swift-6.0.1-RELEASE)
4444
Target: x86_64-unknown-linux-gnu
4545
46-
$ swift build # Build your package with the latest toolchain
46+
$ swift build # Build with the latest (5.8.1) toolchain
4747
```
4848

4949
You can install (and use) another release toolchain:

Documentation/SwiftlyDocs.docc/swiftly-cli-reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ You can run one of the usual toolchain commands directly:
501501

502502
Or you can run another program (or script) that runs one or more toolchain commands:
503503

504-
$ swiftly run make # Builds targets using clang/swiftc
504+
$ CC=clang swiftly run make # Builds targets using clang
505505
$ swiftly run ./build-things.sh # Script invokes 'swift build' to create certain product binaries
506506

507507
Toolchain selection is determined by swift version files `.swift-version`, with a default global as the fallback. See the `swiftly use` command for more details.

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/

Package.resolved

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ let package = Package(
1717
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.3.0"),
1818
.package(url: "https://github.com/swift-server/async-http-client", from: "1.21.2"),
1919
.package(url: "https://github.com/apple/swift-nio.git", from: "2.64.0"),
20-
.package(url: "https://github.com/apple/swift-tools-support-core.git", from: "0.6.1"),
20+
.package(url: "https://github.com/apple/swift-tools-support-core.git", from: "0.7.1"),
2121
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.3.0"),
2222
// This dependency provides the correct version of the formatter so that you can run `swift run swiftformat Package.swift Plugins/ Sources/ Tests/`
2323
.package(url: "https://github.com/nicklockwood/SwiftFormat", exact: "0.49.18"),

Sources/LinuxPlatform/Linux.swift

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ var swiftGPGKeysRefreshed = false
99
public struct Linux: Platform {
1010
let linuxPlatforms = [
1111
PlatformDefinition.ubuntu2404,
12-
PlatformDefinition.ubuntu2310,
1312
PlatformDefinition.ubuntu2204,
1413
PlatformDefinition.ubuntu2004,
1514
PlatformDefinition.ubuntu1804,
@@ -26,17 +25,15 @@ public struct Linux: Platform {
2625
return URL(fileURLWithPath: dir)
2726
} else {
2827
return FileManager.default.homeDirectoryForCurrentUser
29-
.appendingPathComponent(".local", isDirectory: true)
30-
.appendingPathComponent("share", isDirectory: true)
28+
.appendingPathComponent(".local/share", isDirectory: true)
3129
}
3230
}
3331

3432
public var swiftlyBinDir: URL {
3533
SwiftlyCore.mockedHomeDir.map { $0.appendingPathComponent("bin", isDirectory: true) }
3634
?? ProcessInfo.processInfo.environment["SWIFTLY_BIN_DIR"].map { URL(fileURLWithPath: $0) }
3735
?? FileManager.default.homeDirectoryForCurrentUser
38-
.appendingPathComponent(".local", isDirectory: true)
39-
.appendingPathComponent("bin", isDirectory: true)
36+
.appendingPathComponent(".local/share/swiftly/bin", isDirectory: true)
4037
}
4138

4239
public var swiftlyToolchainsDir: URL {
@@ -137,27 +134,6 @@ public struct Linux: Platform {
137134
"tzdata",
138135
"zlib1g-dev",
139136
]
140-
case "ubuntu2310":
141-
[
142-
"binutils",
143-
"git",
144-
"unzip",
145-
"gnupg2",
146-
"libc6-dev",
147-
"libcurl4-openssl-dev",
148-
"libedit2",
149-
"libgcc-12-dev",
150-
"libpython3-dev",
151-
"libsqlite3-0",
152-
"libstdc++-12-dev",
153-
"libxml2-dev",
154-
"libncurses-dev",
155-
"libz3-dev",
156-
"pkg-config",
157-
"python3-lldb-13",
158-
"tzdata",
159-
"zlib1g-dev",
160-
]
161137
case "ubuntu2404":
162138
[
163139
"binutils",
@@ -224,6 +200,8 @@ public struct Linux: Platform {
224200
"libuuid-devel",
225201
"libxml2-devel",
226202
"python3-devel",
203+
"libstdc++-devel",
204+
"libstdc++-static",
227205
]
228206
case "debian12":
229207
[
@@ -240,6 +218,7 @@ public struct Linux: Platform {
240218
"tzdata",
241219
"git",
242220
"gcc",
221+
"libstdc++-12-dev",
243222
]
244223
default:
245224
[]
@@ -252,8 +231,6 @@ public struct Linux: Platform {
252231
"apt-get"
253232
case "ubuntu2204":
254233
"apt-get"
255-
case "ubuntu2310":
256-
"apt-get"
257234
case "ubuntu2404":
258235
"apt-get"
259236
case "amazonlinux2":
@@ -552,7 +529,7 @@ public struct Linux: Platform {
552529
}
553530

554531
return PlatformDefinition.rhel9
555-
} else if let pd = [PlatformDefinition.ubuntu1804, .ubuntu2004, .ubuntu2204, .ubuntu2310, .ubuntu2404, .debian12, .fedora39].first(where: { $0.name == id + versionID }) {
532+
} else if let pd = [PlatformDefinition.ubuntu1804, .ubuntu2004, .ubuntu2204, .ubuntu2404, .debian12, .fedora39].first(where: { $0.name == id + versionID }) {
556533
return pd
557534
}
558535

Sources/Swiftly/Init.swift

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ internal struct Init: SwiftlyCommand {
7171
// Ensure swiftly doesn't overwrite any existing executables without getting confirmation first.
7272
let swiftlyBinDir = Swiftly.currentPlatform.swiftlyBinDir
7373
let swiftlyBinDirContents = (try? FileManager.default.contentsOfDirectory(atPath: swiftlyBinDir.path)) ?? [String]()
74-
let willBeOverwritten = Set(proxyList + ["swiftly"]).intersection(swiftlyBinDirContents)
74+
let willBeOverwritten = Set(["swiftly"]).intersection(swiftlyBinDirContents)
7575
if !willBeOverwritten.isEmpty && !overwrite {
7676
SwiftlyCore.print("The following existing executables will be overwritten:")
7777

@@ -159,30 +159,6 @@ internal struct Init: SwiftlyCommand {
159159
}
160160
}
161161

162-
// Don't create the proxies in the tests
163-
if !cmd.path.hasSuffix("xctest") {
164-
SwiftlyCore.print("Setting up toolchain proxies...")
165-
166-
let proxyTo = if let systemManagedSwiftlyBin = systemManagedSwiftlyBin {
167-
systemManagedSwiftlyBin
168-
} else {
169-
swiftlyBin.path
170-
}
171-
172-
for p in proxyList {
173-
let proxy = Swiftly.currentPlatform.swiftlyBinDir.appendingPathComponent(p)
174-
175-
if proxy.fileExists() {
176-
try FileManager.default.removeItem(at: proxy)
177-
}
178-
179-
try FileManager.default.createSymbolicLink(
180-
atPath: proxy.path,
181-
withDestinationPath: proxyTo
182-
)
183-
}
184-
}
185-
186162
if overwrite || !FileManager.default.fileExists(atPath: envFile.path) {
187163
SwiftlyCore.print("Creating shell environment file for the user...")
188164
var env = ""
@@ -251,10 +227,11 @@ internal struct Init: SwiftlyCommand {
251227
}
252228

253229
var postInstall: String?
230+
var pathChanged: Bool = false
254231

255232
if !skipInstall {
256233
let latestVersion = try await Install.resolve(config: config, selector: ToolchainSelector.latest)
257-
postInstall = try await Install.execute(version: latestVersion, &config, useInstalledToolchain: true, verifySignature: true, verbose: verbose)
234+
(postInstall, pathChanged) = try await Install.execute(version: latestVersion, &config, useInstalledToolchain: true, verifySignature: true, verbose: verbose, assumeYes: assumeYes)
258235
}
259236

260237
if addEnvToProfile {
@@ -265,17 +242,15 @@ internal struct Init: SwiftlyCommand {
265242
\(sourceLine)
266243
267244
""")
245+
}
268246

269-
#if os(macOS)
247+
if pathChanged {
270248
SwiftlyCore.print("""
271-
NOTE: On macOS it is possible that the shell will pick up the system Swift on the path
272-
instead of the one that swiftly has installed for you. You can run this command to update
273-
the shell with the latest PATHs.
249+
Your shell caches items on your path for better performance. Swiftly has added items to your path that may not get picked up right away. You can run this command to update your shell to get these items.
274250
275-
hash -r
251+
hash -r
276252
277253
""")
278-
#endif
279254
}
280255

281256
if let postInstall {
@@ -284,7 +259,7 @@ internal struct Init: SwiftlyCommand {
284259
You can run the following script as the system administrator (e.g. root) to prepare
285260
your system:
286261
287-
\(postInstall)
262+
\(postInstall)
288263
289264
""")
290265
}

0 commit comments

Comments
 (0)