mirror of
https://github.com/actions/runner-images.git
synced 2025-12-11 19:46:46 +00:00
[SourceKitten](https://github.com/jpsim/SourceKitten), a popular Swift
library for interacting with SourceKit, needs to know (or be told) the
location of the sourcekitd framework. SourceKitten is somewhat
[ubiquitous](https://github.com/jpsim/SourceKitten#projects-built-with-sourcekitten);
most Swift projects I've seen or worked on used SourceKitten in some
way.
On macOS, the sourcekit framework is baked-in to the Xcode toolchain(s) and
therefore its location is generally known. On Linux, the location of the
sourcekit framework is wherever swift is installed, which is unknown to
libraries like SourceKitten.
SourceKitten searches for the sourcekit framework in [a few
locations](f7cf1e3b63/Source/SourceKittenFramework/library_wrapper.swift (L51-L104)),
but it's unable to infer the location of the framework on these ubuntu
images. The result when attempting to run any SourceKitten-based tool in
Github Actions on an ubuntu VM is the following error:
```
SourceKittenFramework/library_wrapper.swift:31: Fatal error: Loading libsourcekitdInProc.so failed
/home/runner/work/_temp/cb002a5e-1916-4e05-ba4d-f70ad3bb2266.sh: line 1: 3944 Illegal instruction (core dumped) mint run swiftlint .
```
(to be clear, this error is not specific to the Github Actions ubuntu
VMs. The same error occurs on any Ubuntu system).
Individual users can work around this by setting the following
environment variable:
```
LINUX_SOURCEKIT_LIB_PATH="/usr/share/swift/usr/lib"
```
This is not a good workaround for the following reasons:
1. The end user doesn't necessarily know where swift is installed.
2. A change to the location of the swift installation would break this
workaround.
3. The error will occur virtually 100% of the time on a user's first
attempt to run SourceKitten on ubuntu, and takes at least a
few minutes to troubleshoot. This will quickly add up to a
non-trivial amount of lost productivity.
So, anyways, my proposal is to just link sourcekitd to a location where
SourceKitten will find it, so most developers don't have to think about it.
`LINUX_SOURCEKIT_LIB_PATH` can be defined by the user if they have an
unusual setup.
Alternative:
- Don't symlink, add `LINUX_SOURCEKIT_LIB_PATH` to `/etc/environment`.
34 lines
1.3 KiB
Bash
34 lines
1.3 KiB
Bash
#!/bin/bash -e
|
|
################################################################################
|
|
## File: swift.sh
|
|
## Desc: Installs Swift
|
|
################################################################################
|
|
|
|
# Source the helpers for use with the script
|
|
source $HELPER_SCRIPTS/install.sh
|
|
|
|
# Install
|
|
image_label="$(lsb_release -rs)"
|
|
swift_version=$(curl -s "https://api.github.com/repos/apple/swift/releases/latest" | jq -r '.tag_name | match("[0-9.]+").string')
|
|
|
|
swift_tar_name="swift-$swift_version-RELEASE-ubuntu$image_label.tar.gz"
|
|
swift_tar_url="https://swift.org/builds/swift-$swift_version-release/ubuntu${image_label//./}/swift-$swift_version-RELEASE/$swift_tar_name"
|
|
download_with_retries $swift_tar_url "/tmp" "$swift_tar_name"
|
|
|
|
tar xzf /tmp/$swift_tar_name
|
|
|
|
SWIFT_INSTALL_ROOT="/usr/share/swift"
|
|
SWIFT_BIN_ROOT="$SWIFT_INSTALL_ROOT/usr/bin"
|
|
SWIFT_LIB_ROOT="$SWIFT_INSTALL_ROOT/usr/lib"
|
|
|
|
mv swift-$swift_version-RELEASE-ubuntu$image_label $SWIFT_INSTALL_ROOT
|
|
mkdir -p /usr/local/lib
|
|
|
|
ln -s "$SWIFT_BIN_ROOT/swift" /usr/local/bin/swift
|
|
ln -s "$SWIFT_BIN_ROOT/swiftc" /usr/local/bin/swiftc
|
|
ln -s "$SWIFT_LIB_ROOT/libsourcekitdInProc.so" /usr/local/lib/libsourcekitdInProc.so
|
|
|
|
echo "SWIFT_PATH=$SWIFT_BIN_ROOT" | tee -a /etc/environment
|
|
|
|
invoke_tests "Common" "Swift"
|